diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cbaf667 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,37 @@ +# Top-most EditorConfig file +root = true + +[*] +end_of_line = crlf +indent_style = tab +tab_width = 4 +trim_trailing_whitespace = true +insert_final_newline = false + +[*.json] +indent_style = space +indent_size = 2 +insert_final_newline = true + +[*.cmd] +indent_style = space +indent_size = 4 + +[*.{xml,config,csproj,props,targets}] +indent_style = space +indent_size = 2 + +[*.sln] +insert_final_newline = true + +[*.{txt,md}] +indent_style = space +indent_size = unset + +[**/Resources/**] +charset = unset +end_of_line = unset +indent_style = unset +indent_size = unset +trim_trailing_whitespace = unset +insert_final_newline = unset \ No newline at end of file diff --git a/.gitignore b/.gitignore index 40f5ee9..00376ec 100644 --- a/.gitignore +++ b/.gitignore @@ -2,15 +2,23 @@ [Bb]in/ [Oo]bj/ +# Node.js tools +node_modules/ +package-lock.json + # NUnit test results TestResult.xml +# BenchmarkDotNet artifacts +BenchmarkDotNet.Artifacts/ + ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. # User-specific files .vs/ .vscode/ +.idea/ *.sln.docstates *.suo *.user @@ -53,6 +61,7 @@ PublishProfiles/ # NuGet Packages packages/ *.nupkg +*.snupkg # Others .build/ @@ -70,4 +79,8 @@ packages/ _UpgradeReport_Files/ Backup*/ UpgradeLog.htm -UpgradeLog*.XML \ No newline at end of file +UpgradeLog*.XML + +# Current project-specific folders and files +nuget/ +**/Resources/*.min.js \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 15c92cc..27dd2aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,34 @@ Change log ========== +## v3.2.5 - March 1, 2024 + * Added a `README.md` file to NuGet package + +## v3.2.4 - January 8, 2024 + * Fixed a error that occurred in the `ReflectionHelpers.IsAllowedProperty` method when running on .NET Core 1.0 + +## v3.2.3 - December 6, 2023 + * JSON2 library was updated to version of May 10, 2023 + +## v3.2.2 - April 10, 2023 + * Fixed a error due to which the global object to become read-only after embedding of the host objects and types. Special thanks to [Denis Pushkarev](https://github.com/zloirock). + +## v3.2.1 - February 27, 2023 + * In JsRT modes improved a performance of .NET methods projection + +## v3.2.0 - February 26, 2023 + * In JavaScript engine settings was added one new property - `AllowReflection` (default `false`) + +## v3.1.0 - February 6, 2023 + * In JsRT modes, `JsVariantToValue` and `JsValueToVariant` native methods are no longer used for embedding objects and types + * JSON2 library was updated to version of October 30, 2022 + +## v3.0.9 - July 20, 2022 + * Now a case-sensitive cultural postfixes are used in the names of `.resx` files + +## v3.0.8 - August 8, 2021 + * Improved a implementation of the `Dispose` method + ## v3.0.7 - March 8, 2020 * Fixed a error “Program crash after function call with too much parameters” @@ -227,14 +255,14 @@ Change log * Fixed [JavaScriptEngineSwitcher.Msie's bug #7](https://github.com/Taritsyn/JavaScriptEngineSwitcher/issues/7) "MsieJavaScriptEngine.ActiveScript.ActiveScriptException not wrapped" ## v1.4.2 - March 24, 2014 - * Fixed [JavaScriptEngineSwitcher.Msie's bug #5](http://github.com/Taritsyn/JavaScriptEngineSwitcher/issues/5) "MSIE "Catastrophic failure" when disposing" + * Fixed [JavaScriptEngineSwitcher.Msie's bug #5](https://github.com/Taritsyn/JavaScriptEngineSwitcher/issues/5) "MSIE "Catastrophic failure" when disposing" ## v1.4.1 - March 22, 2014 * Fixed minor bugs ## v1.4.0 - February 27, 2014 * Removed following methods: `HasProperty`, `GetPropertyValue`, `SetPropertyValue` and `RemoveProperty` - * Fixed [bug #3](http://github.com/Taritsyn/MsieJavaScriptEngine/issues/3) "execute code from different threads" + * Fixed [bug #3](https://github.com/Taritsyn/MsieJavaScriptEngine/issues/3) "execute code from different threads" * Now in the `ChakraJsRt` mode is available a more detailed information about errors * In ECMAScript 5 Polyfill improved a performance of the `String.prototype.trim` method * JSON2 library was updated to version of February 4, 2014 @@ -258,7 +286,7 @@ Change log * Assembly `MsieJavaScriptEngine.dll` now signed ## v1.1.0 - October 11, 2012 - * Added ability of using the Douglas Crockford's [JSON2](http://github.com/douglascrockford/JSON-js) library + * Added ability of using the Douglas Crockford's [JSON2](https://github.com/douglascrockford/JSON-js) library * By default using of the JSON2 library is disabled ## v1.0.8 - September 21, 2012 @@ -268,7 +296,7 @@ Change log * Added the `ActiveScriptErrorFormatter` class ## v1.0.5 - August 29, 2012 - * [JavaScript Array Polyfills from TutorialsPoint.com](http://www.tutorialspoint.com/javascript/) was replaced by the Douglas Crockford's [ECMAScript 5 Polyfill](http://nuget.org/packages/ES5) + * [JavaScript Array Polyfills from TutorialsPoint.com](https://www.tutorialspoint.com/javascript/) was replaced by the Douglas Crockford's [ECMAScript 5 Polyfill](https://www.nuget.org/packages/ES5) * By default using of the ECMAScript 5 Polyfill is disabled ## v1.0.1 - August 27, 2012 diff --git a/LICENSE.txt b/LICENSE.txt index a4ebd14..6e8f77b 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ - Copyright (c) 2012-2020 Andrey Taritsyn - http://www.taritsyn.ru + Copyright (c) 2012-2024 Andrey Taritsyn - http://www.taritsyn.ru Apache License Version 2.0, January 2004 diff --git a/Licenses/bundler-and-minifier-license.txt b/Licenses/bundler-and-minifier-license.txt deleted file mode 100644 index d8c64ce..0000000 --- a/Licenses/bundler-and-minifier-license.txt +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2015 Mads Kristensen - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. \ No newline at end of file diff --git a/Licenses/uglify-js-license.txt b/Licenses/uglify-js-license.txt new file mode 100644 index 0000000..87a0854 --- /dev/null +++ b/Licenses/uglify-js-license.txt @@ -0,0 +1,29 @@ +UglifyJS is released under the BSD license: + +Copyright 2012-2019 (c) Mihai Bazon + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above + copyright notice, this list of conditions and the following + disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md index b9a8c9b..ddbfcdc 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ MSIE JavaScript Engine for .NET [![NuGet version](http://img.shields.io/nuget/v/ ![MSIE JS Engine Logo](http://i.imgur.com/T3K5q.png) This project is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge Legacy (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). -Project was based on the code of [SassAndCoffee.JavaScript](http://github.com/paulcbetts/SassAndCoffee), [Chakra Sample Hosts](http://github.com/panopticoncentral/chakra-host) and [jsrt-dotnet](http://github.com/robpaveza/jsrt-dotnet). +Project was based on the code of [SassAndCoffee.JavaScript](https://github.com/anaisbetts/SassAndCoffee), [Chakra Sample Hosts](https://github.com/panopticoncentral/chakra-host) and [jsrt-dotnet](https://github.com/robpaveza/jsrt-dotnet). MSIE JavaScript Engine requires a installation of Internet Explorer or Edge Legacy on the machine and can work in 5 modes, that are defined in the JsEngineMode enumeration: @@ -23,7 +23,7 @@ The supported .NET types are as follows: * `System.String` ## Installation -This library can be installed through NuGet - [http://nuget.org/packages/MsieJavaScriptEngine](http://nuget.org/packages/MsieJavaScriptEngine). +This library can be installed through NuGet - [https://www.nuget.org/packages/MsieJavaScriptEngine](https://www.nuget.org/packages/MsieJavaScriptEngine). ## Usage Consider a simple example of usage of the MSIE JavaScript Engine: @@ -36,42 +36,42 @@ using MsieJavaScriptEngine.Helpers; namespace MsieJavaScriptEngine.Example.Console { - class Program - { - static void Main(string[] args) - { - try - { - using (var jsEngine = new MsieJsEngine()) - { - const string expression = "7 * 8 - 20"; - var result = jsEngine.Evaluate(expression); - - Console.WriteLine("{0} = {1}", expression, result); - } - } - catch (JsEngineLoadException e) - { - Console.WriteLine("During loading of JavaScript engine an error occurred."); - Console.WriteLine(); - Console.WriteLine(JsErrorHelpers.GenerateErrorDetails(e)); - } - catch (JsScriptException e) - { - Console.WriteLine("During processing of JavaScript code an error occurred."); - Console.WriteLine(); - Console.WriteLine(JsErrorHelpers.GenerateErrorDetails(e)); - } - catch (JsException e) - { - Console.WriteLine("During working of JavaScript engine an unknown error occurred."); - Console.WriteLine(); - Console.WriteLine(JsErrorHelpers.GenerateErrorDetails(e)); - } - - Console.ReadLine(); - } - } + class Program + { + static void Main(string[] args) + { + try + { + using (var jsEngine = new MsieJsEngine()) + { + const string expression = "7 * 8 - 20"; + var result = jsEngine.Evaluate(expression); + + Console.WriteLine("{0} = {1}", expression, result); + } + } + catch (JsEngineLoadException e) + { + Console.WriteLine("During loading of JavaScript engine an error occurred."); + Console.WriteLine(); + Console.WriteLine(JsErrorHelpers.GenerateErrorDetails(e)); + } + catch (JsScriptException e) + { + Console.WriteLine("During processing of JavaScript code an error occurred."); + Console.WriteLine(); + Console.WriteLine(JsErrorHelpers.GenerateErrorDetails(e)); + } + catch (JsException e) + { + Console.WriteLine("During working of JavaScript engine an unknown error occurred."); + Console.WriteLine(); + Console.WriteLine(JsErrorHelpers.GenerateErrorDetails(e)); + } + + Console.ReadLine(); + } + } } ``` @@ -94,49 +94,58 @@ Also, when you create an instance of the JsEngineSettings class: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Property nameData typeDefault valueDescription
EnableDebuggingBooleanfalseFlag for whether to allow debugging in Visual Studio by adding the debugger statement to script code.
EngineModeJsEngineMode enumerationAutoJavaScript engine mode.
MaxStackSizeInt32503 808 or 1 007 616 -

Maximum stack size in bytes.

-

Set a 0 to use the default maximum stack size specified in the header for the executable.

-
UseEcmaScript5PolyfillBooleanfalseFlag for whether to use the ECMAScript 5 Polyfill.
UseJson2LibraryBooleanfalseFlag for whether to use the JSON2 library
Property nameData typeDefault valueDescription
AllowReflectionBooleanfalse +

Flag for whether to allow the usage of reflection API in the script code.

+

This affects Object.GetType, Exception.GetType, Exception.TargetSite and Delegate.Method.

+
EnableDebuggingBooleanfalseFlag for whether to allow debugging in Visual Studio by adding the debugger statement to script code.
EngineModeJsEngineMode enumerationAutoJavaScript engine mode.
MaxStackSizeInt32503 808 or 1 007 616 +

Maximum stack size in bytes.

+

Set a 0 to use the default maximum stack size specified in the header for the executable.

+
UseEcmaScript5PolyfillBooleanfalseFlag for whether to use the ECMAScript 5 Polyfill.
UseJson2LibraryBooleanfalseFlag for whether to use the JSON2 library
@@ -147,21 +156,20 @@ See the [changelog](CHANGELOG.md). [Apache License Version 2.0](LICENSE.md) ## Credits - * [SassAndCoffee.JavaScript](http://github.com/xpaulbettsx/SassAndCoffee) - [License: Microsoft Public License (Ms-PL)](http://github.com/paulcbetts/SassAndCoffee/blob/master/COPYING) Part of the code of this library served as the basis for the ActiveScript version of Chakra and Classic JavaScript Engine. - * [Chakra Sample Hosts](http://github.com/panopticoncentral/chakra-host) - [License: Apache License 2.0 (Apache)](http://github.com/panopticoncentral/chakra-host/blob/master/LICENSE) C# example from this project served as the basis for the JsRT versions of Chakra. - * [jsrt-dotnet](http://github.com/robpaveza/jsrt-dotnet) - [License: The MIT License (MIT)](http://github.com/robpaveza/jsrt-dotnet/blob/master/LICENSE) Part of the code of this library is used in the JsRT versions of Chakra. - * [ECMAScript 5 Polyfill](http://nuget.org/packages/ES5) and [MDN JavaScript Polyfills](http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference) - Adds support for many of the new functions in ECMAScript 5 to downlevel browsers. - * [Cross-Browser Split](http://blog.stevenlevithan.com/archives/cross-browser-split) - Adds ECMAScript compliant and uniform cross-browser split method. - * [JSON2 library](http://github.com/douglascrockford/JSON-js) - Adds support of the JSON object from ECMAScript 5 to downlevel browsers. - * [Bundler and Minifier](http://github.com/madskristensen/BundlerMinifier) - [License: Apache License 2.0 (Apache)](http://github.com/madskristensen/BundlerMinifier/blob/master/LICENSE) JS-files, that used MSIE JS Engine, minificated by using this tool. + * [SassAndCoffee.JavaScript](https://github.com/anaisbetts/SassAndCoffee) - [License: Microsoft Public License (Ms-PL)](https://github.com/anaisbetts/SassAndCoffee/blob/master/COPYING) Part of the code of this library served as the basis for the ActiveScript version of Chakra and Classic JavaScript Engine. + * [Chakra Sample Hosts](https://github.com/panopticoncentral/chakra-host) - [License: Apache License 2.0 (Apache)](https://github.com/panopticoncentral/chakra-host/blob/master/LICENSE) C# example from this project served as the basis for the JsRT versions of Chakra. + * [jsrt-dotnet](https://github.com/robpaveza/jsrt-dotnet) - [License: The MIT License (MIT)](https://github.com/robpaveza/jsrt-dotnet/blob/master/LICENSE) Part of the code of this library is used in the JsRT versions of Chakra. + * [ECMAScript 5 Polyfill](https://www.nuget.org/packages/ES5) and [MDN JavaScript Polyfills](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference) - Adds support for many of the new functions in ECMAScript 5 to downlevel browsers. + * [Cross-Browser Split](https://blog.stevenlevithan.com/archives/cross-browser-split) - Adds ECMAScript compliant and uniform cross-browser split method. + * [JSON2 library](https://github.com/douglascrockford/JSON-js) - Adds support of the JSON object from ECMAScript 5 to downlevel browsers. + * [UglifyJS](https://github.com/mishoo/UglifyJS) - [License: BSD License (BSD)](https://github.com/mishoo/UglifyJS/blob/master/LICENSE) JS-files, that used MSIE JS Engine, minificated by using this tool. ## Who's Using MSIE JavaScript Engine If you use the MSIE JavaScript Engine in some project, please send me a message so I can include it in this list: - * [BitAdminCore.ALL](http://nuget.org/packages/BitAdminCore.ALL) - * [Chevron](http://github.com/SimonCropp/Chevron) by Simon Cropp - * [JavaScript Engine Switcher](http://github.com/Taritsyn/JavaScriptEngineSwitcher) by Andrey Taritsyn - * [PowerShell.JS](http://github.com/klumsy/powershellJS) by Karl Prosser - * [Serenity Application Platform](http://github.com/volkanceylan/Serenity) by Volkan Ceylan - * [SquishIt](http://github.com/jetheredge/SquishIt) by Justin Etheredge and Alex Ullrich - * [Strike](http://github.com/SimonCropp/Strike) by Simon Cropp \ No newline at end of file + * [BitAdminCore.ALL](https://www.nuget.org/packages/BitAdminCore.ALL) + * [Chevron](https://github.com/simoncropparchived/Chevron) by Simon Cropp + * [JavaScript Engine Switcher](https://github.com/Taritsyn/JavaScriptEngineSwitcher) by Andrey Taritsyn + * [PowerShell.JS](https://github.com/klumsy/powershellJS) by Karl Prosser + * [SquishIt](https://github.com/jetheredge/SquishIt) by Justin Etheredge and Alex Ullrich + * [Strike](https://github.com/simoncropparchived/Strike) by Simon Cropp \ No newline at end of file diff --git a/build-js.cmd b/build-js.cmd new file mode 100644 index 0000000..1e607da --- /dev/null +++ b/build-js.cmd @@ -0,0 +1,34 @@ +@echo off +setlocal + +cd ./src/MsieJavaScriptEngine/ + +::-------------------------------------------------------------------------------- +:: Build +::-------------------------------------------------------------------------------- + +echo Installing Node.js packages ... +echo. +call npm install +if errorlevel 1 goto error +echo. + +echo Minifying JS files ... +echo. +call npm run -s minify-js +if errorlevel 1 goto error +echo. + +::-------------------------------------------------------------------------------- +:: Exit +::-------------------------------------------------------------------------------- + +echo Succeeded! +goto exit + +:error +echo *** Error: The previous step failed! + +:exit +cd ../../ +endlocal \ No newline at end of file diff --git a/build/common.props b/build/common.props index d856f2a..6a65ecd 100644 --- a/build/common.props +++ b/build/common.props @@ -1,17 +1,7 @@ - - Copyright © 2012-2020 Andrey Taritsyn - - - - $(DefineConstants);NETFULL - - - - $(DefineConstants);NETSTANDARD - - - - $(DefineConstants);NETCOREAPP - + + Copyright © 2012-2024 Andrey Taritsyn + false + false + \ No newline at end of file diff --git a/build/net40-client-target.props b/build/net40-client-target.props index 85b46db..a6ecf13 100644 --- a/build/net40-client-target.props +++ b/build/net40-client-target.props @@ -1,7 +1,7 @@ - - .NETFramework - v4.0 - client - + + .NETFramework + v4.0 + client + \ No newline at end of file diff --git a/build/strong-name-signing.props b/build/strong-name-signing.props index 5130e09..543e8a3 100644 --- a/build/strong-name-signing.props +++ b/build/strong-name-signing.props @@ -1,7 +1,7 @@ - - ../../build/Key.snk - true - true - + + ../../build/Key.snk + true + true + \ No newline at end of file diff --git a/global.json b/global.json index 7031543..338c555 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { - "sdk": { - "version": "3.1.101" - } -} \ No newline at end of file + "sdk": { + "version": "8.0.200" + } +} diff --git a/src/MsieJavaScriptEngine/.uglifyjsrc b/src/MsieJavaScriptEngine/.uglifyjsrc new file mode 100644 index 0000000..8a91584 --- /dev/null +++ b/src/MsieJavaScriptEngine/.uglifyjsrc @@ -0,0 +1,11 @@ +{ + "compress": { + "hoist_funs": true, + "hoist_vars": true, + "passes": 2 + }, + "mangle": {}, + "output": { + "comments": "/^!/" + } +} diff --git a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptException.cs b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptException.cs index 88faecf..be86036 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptException.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptException.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.Serialization; using System.Security.Permissions; @@ -9,7 +9,7 @@ namespace MsieJavaScriptEngine.ActiveScript public sealed class ActiveScriptException : Exception { /// - /// The HRESULT of the error + /// The HRESULT of the error /// private int _errorCode; @@ -54,7 +54,7 @@ public sealed class ActiveScriptException : Exception private string _sourceFragment = string.Empty; /// - /// Gets or sets a HRESULT of the error + /// Gets or sets a HRESULT of the error /// public int ErrorCode { diff --git a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.ScriptSiteBase.cs b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.ScriptSiteBase.cs index 2bf1273..ef2011a 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.ScriptSiteBase.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.ScriptSiteBase.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Collections.Generic; using System.Globalization; diff --git a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs index 598de49..57bca46 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Collections.Generic; using System.Globalization; @@ -184,7 +184,7 @@ protected ActiveScriptJsEngineBase(JsEngineSettings settings, string clsid, /// Initializes a script dispatcher /// /// The maximum stack size, in bytes, to be used by the thread, - /// or 0 to use the default maximum stack size specified in the header for the executable. + /// or 0 to use the default maximum stack size specified in the header for the executable. private static void InitScriptDispatcher(int maxStackSize) { if (_dispatcher != null) @@ -209,7 +209,7 @@ private static void InitScriptDispatcher(int maxStackSize) /// CLSID of JS engine /// Flag indicating whether this JS engine is supported /// Support synchronizer - /// Result of check (true - supports; false - does not support) + /// Result of check (true - supports; false - does not support) protected static bool IsSupported(string clsid, ref bool? isSupported, ref object supportSynchronizer) { if (isSupported.HasValue) @@ -315,7 +315,7 @@ protected virtual void InitScriptContext() } /// - /// Gets and resets a last exception. Returns null for none. + /// Gets and resets a last exception. Returns null for none. /// private ActiveScriptException GetAndResetLastException() { @@ -417,7 +417,7 @@ private void InnerExecuteResource(string resourceName, Assembly assembly) /// Script text /// Application specific source context /// Debug document - /// Result of creating a debug document (true - is created; false - is not created) + /// Result of creating a debug document (true - is created; false - is not created) private bool TryCreateDebugDocument(string name, string code, out UIntPtr sourceContext, out DebugDocument document) { @@ -535,7 +535,7 @@ private void InnerEmbedHostItem(string itemName, object value) try { - _activeScriptWrapper.AddNamedItem(itemName, ScriptItemFlags.IsVisible | ScriptItemFlags.GlobalMembers); + _activeScriptWrapper.AddNamedItem(itemName, ScriptItemFlags.IsVisible); } catch { @@ -571,7 +571,7 @@ private void InnerCollectGarbage(ScriptGCType type) /// The mapped value private object MapToScriptType(object value) { - return TypeMappingHelpers.MapToScriptType(value, _settings.EngineMode); + return TypeMappingHelpers.MapToScriptType(value, _settings.EngineMode, _settings.AllowReflection); } /// @@ -581,7 +581,7 @@ private object MapToScriptType(object value) /// The mapped array private object[] MapToScriptType(object[] args) { - return TypeMappingHelpers.MapToScriptType(args, _settings.EngineMode); + return TypeMappingHelpers.MapToScriptType(args, _settings.EngineMode, _settings.AllowReflection); } /// @@ -900,7 +900,7 @@ public override void EmbedHostObject(string itemName, object value) public override void EmbedHostType(string itemName, Type type) { - var typeValue = new HostType(type, _settings.EngineMode); + var typeValue = new HostType(type, _settings.EngineMode, _settings.AllowReflection); _dispatcher.Invoke(() => { diff --git a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsErrorHelpers.cs b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsErrorHelpers.cs index 32c4c5f..92fef49 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsErrorHelpers.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsErrorHelpers.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Collections.Generic; @@ -16,7 +16,7 @@ internal static class ActiveScriptJsErrorHelpers /// Checks whether the specified error number is compilation error /// /// Error number - /// Result of check (true - is compilation error; false - is not compilation error) + /// Result of check (true - is compilation error; false - is not compilation error) public static bool IsCompilationError(int errorNumber) { bool result = errorNumber >= JScriptSyntaxErrorNumber.SyntaxError @@ -29,7 +29,7 @@ public static bool IsCompilationError(int errorNumber) /// Checks whether the specified error number is runtime error /// /// Error number - /// Result of check (true - is runtime error; false - is not runtime error) + /// Result of check (true - is runtime error; false - is not runtime error) public static bool IsRuntimeError(int errorNumber) { bool result = errorNumber == JScriptRuntimeErrorNumber.OutOfStackSpace || (errorNumber >= JScriptRuntimeErrorNumber.CannotAssignToThisKeyword diff --git a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapper32.cs b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapper32.cs index 099be6c..6893c38 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapper32.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapper32.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO; @@ -142,25 +142,33 @@ public override void Dispose() /// /// Destroys object /// - /// Flag, allowing destruction of - /// managed objects contained in fields of class + /// Flag, allowing destruction of managed objects contained in fields of class protected override void Dispose(bool disposing) { - if (_disposedFlag.Set()) + if (disposing) { - if (disposing) + if (_disposedFlag.Set()) { _debugStackFrameSniffer32 = null; _activeScriptDebug32 = null; _activeScriptParse32 = null; - } - - ComHelpers.ReleaseAndEmpty(ref _pDebugStackFrameSniffer32); - ComHelpers.ReleaseAndEmpty(ref _pActiveScriptDebug32); - ComHelpers.ReleaseAndEmpty(ref _pActiveScriptParse32); - base.Dispose(disposing); + DisposeUnmanagedResources(); + base.Dispose(true); + } } + else + { + DisposeUnmanagedResources(); + base.Dispose(false); + } + } + + private void DisposeUnmanagedResources() + { + ComHelpers.ReleaseAndEmpty(ref _pDebugStackFrameSniffer32); + ComHelpers.ReleaseAndEmpty(ref _pActiveScriptDebug32); + ComHelpers.ReleaseAndEmpty(ref _pActiveScriptParse32); } #endregion diff --git a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapper64.cs b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapper64.cs index d1ac8f2..bd849b9 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapper64.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapper64.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO; @@ -142,25 +142,33 @@ public override void Dispose() /// /// Destroys object /// - /// Flag, allowing destruction of - /// managed objects contained in fields of class + /// Flag, allowing destruction of managed objects contained in fields of class protected override void Dispose(bool disposing) { - if (_disposedFlag.Set()) + if (disposing) { - if (disposing) + if (_disposedFlag.Set()) { _debugStackFrameSniffer64 = null; _activeScriptDebug64 = null; _activeScriptParse64 = null; - } - - ComHelpers.ReleaseAndEmpty(ref _pDebugStackFrameSniffer64); - ComHelpers.ReleaseAndEmpty(ref _pActiveScriptDebug64); - ComHelpers.ReleaseAndEmpty(ref _pActiveScriptParse64); - base.Dispose(disposing); + DisposeUnmanagedResources(); + base.Dispose(true); + } } + else + { + DisposeUnmanagedResources(); + base.Dispose(false); + } + } + + private void DisposeUnmanagedResources() + { + ComHelpers.ReleaseAndEmpty(ref _pDebugStackFrameSniffer64); + ComHelpers.ReleaseAndEmpty(ref _pActiveScriptDebug64); + ComHelpers.ReleaseAndEmpty(ref _pActiveScriptParse64); } #endregion diff --git a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapperBase.cs b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapperBase.cs index 05d9c24..0aa68be 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapperBase.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapperBase.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; @@ -151,11 +151,11 @@ public object GetScriptDispatch() /// The scriptlet text to evaluate. The interpretation of this /// string depends on the scripting language /// The item name that gives the context in which the - /// scriptlet is to be evaluated. If this parameter is null, the code is evaluated + /// scriptlet is to be evaluated. If this parameter is null, the code is evaluated /// in the scripting engine's global context /// The context object. This object is reserved for use in a /// debugging environment, where such a context may be provided by the debugger to - /// represent an active run-time context. If this parameter is null, the engine + /// represent an active run-time context. If this parameter is null, the engine /// uses to identify the context. /// The end-of-scriptlet delimiter. When /// is parsed from a stream of text, the host typically uses a delimiter, such as two @@ -164,14 +164,14 @@ public object GetScriptDispatch() /// some conditional primitive preprocessing (for example, replacing a single quotation /// mark ['] with two single quotation marks for use as a delimiter). Exactly how /// (and if) the scripting engine makes use of this information depends on the - /// scripting engine. Set this parameter to null if the host did not use a delimiter + /// scripting engine. Set this parameter to null if the host did not use a delimiter /// to mark the end of the scriptlet. /// Application-defined value that is used for /// debugging purposes /// Zero-based value that specifies which line the /// parsing will begin at /// Flags associated with the scriptlet - /// The results of scriptlet processing, or null if the caller expects no + /// The results of scriptlet processing, or null if the caller expects no /// result (that is, the value is not set) public abstract object ParseScriptText(string code, string itemName, object context, string delimiter, UIntPtr sourceContextCookie, uint startingLineNumber, ScriptTextFlags flags); @@ -240,8 +240,7 @@ public void CollectGarbage(ScriptGCType type) /// /// Destroys object /// - /// Flag, allowing destruction of - /// managed objects contained in fields of class + /// Flag, allowing destruction of managed objects contained in fields of class protected virtual void Dispose(bool disposing) { if (disposing) diff --git a/src/MsieJavaScriptEngine/ActiveScript/ChakraActiveScriptJsEngine.ScriptSite.cs b/src/MsieJavaScriptEngine/ActiveScript/ChakraActiveScriptJsEngine.ScriptSite.cs index bcb8fb3..7a4fcb3 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ChakraActiveScriptJsEngine.ScriptSite.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ChakraActiveScriptJsEngine.ScriptSite.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using MsieJavaScriptEngine.Constants; using MsieJavaScriptEngine.Helpers; using MsieJavaScriptEngine.Resources; diff --git a/src/MsieJavaScriptEngine/ActiveScript/ChakraActiveScriptJsEngine.cs b/src/MsieJavaScriptEngine/ActiveScript/ChakraActiveScriptJsEngine.cs index ea885e9..21f1034 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ChakraActiveScriptJsEngine.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ChakraActiveScriptJsEngine.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Collections.Generic; using MsieJavaScriptEngine.Constants; @@ -72,7 +72,7 @@ public ChakraActiveScriptJsEngine(JsEngineSettings settings) /// /// Checks a support of the Chakra Active Script engine on the machine /// - /// Result of check (true - supports; false - does not support) + /// Result of check (true - supports; false - does not support) public static bool IsSupported() { bool isSupported = IsSupported(ClassId.Chakra, ref _isSupported, ref _supportSynchronizer); diff --git a/src/MsieJavaScriptEngine/ActiveScript/ClassicActiveScriptJsEngine.ScriptSite.cs b/src/MsieJavaScriptEngine/ActiveScript/ClassicActiveScriptJsEngine.ScriptSite.cs index acf5ef4..f23b32a 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ClassicActiveScriptJsEngine.ScriptSite.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ClassicActiveScriptJsEngine.ScriptSite.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Collections.Generic; using System.Runtime.InteropServices; diff --git a/src/MsieJavaScriptEngine/ActiveScript/ClassicActiveScriptJsEngine.cs b/src/MsieJavaScriptEngine/ActiveScript/ClassicActiveScriptJsEngine.cs index b268bbb..cfe4aec 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ClassicActiveScriptJsEngine.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ClassicActiveScriptJsEngine.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Collections.Generic; using MsieJavaScriptEngine.Constants; @@ -74,7 +74,7 @@ public ClassicActiveScriptJsEngine(JsEngineSettings settings) /// /// Checks a support of the Classic Active Script engine on the machine /// - /// Result of check (true - supports; false - does not support) + /// Result of check (true - supports; false - does not support) public static bool IsSupported() { bool isSupported = IsSupported(ClassId.Classic, ref _isSupported, ref _supportSynchronizer); diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/AppBreakFlags.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/AppBreakFlags.cs index e30918b..f18226d 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/AppBreakFlags.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/AppBreakFlags.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakReason.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakReason.cs index 013b0e7..e632c22 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakReason.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakReason.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakResumeAction.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakResumeAction.cs index 44250fa..67ba243 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakResumeAction.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakResumeAction.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakpointState.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakpointState.cs index 42d4959..71824dd 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakpointState.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakpointState.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugApplicationWrapper.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugApplicationWrapper.cs index 88c499f..e58dd18 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugApplicationWrapper.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugApplicationWrapper.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// @@ -112,7 +112,7 @@ public void CreateApplicationNode(out IDebugApplicationNode node) /// Returns the current debugger connected to the application /// /// The current debugger connected to the application - /// The method returns an HRESULT + /// The method returns an HRESULT public uint GetDebugger(out IApplicationDebugger debugger) { uint result = _is64Bit ? diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugDocument.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugDocument.cs index 7f05635..e44333e 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugDocument.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugDocument.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Collections.Generic; using System.Linq; diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugDocumentContext.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugDocumentContext.cs index 074f684..832ced4 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugDocumentContext.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugDocumentContext.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugLineInfo.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugLineInfo.cs index 241f1a4..7300bde 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugLineInfo.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugLineInfo.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugStackFrameDescriptor.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugStackFrameDescriptor.cs index 1a7ad39..4823b28 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugStackFrameDescriptor.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugStackFrameDescriptor.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; @@ -7,9 +7,11 @@ namespace MsieJavaScriptEngine.ActiveScript.Debugging /// /// Enumerates stack frames and merges output from several enumerators on the same thread /// - /// The process debug manager uses this structure to sort the stack frames from + /// + /// The process debug manager uses this structure to sort the stack frames from /// multiple script engines. By convention, stacks grow down. Consequently, on architectures - /// where stacks grow up, the addresses should be twos-complemented. + /// where stacks grow up, the addresses should be twos-complemented. + /// [StructLayout(LayoutKind.Sequential)] internal struct DebugStackFrameDescriptor { @@ -38,7 +40,7 @@ internal struct DebugStackFrameDescriptor public bool IsFinal; /// - /// If this parameter is not null, the current enumerator merging should stop and + /// If this parameter is not null, the current enumerator merging should stop and /// a new one should be started. The object indicates how to start the new enumeration. /// public IntPtr pFinalObject; diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DocumentNameType.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DocumentNameType.cs index f5c8715..9353c03 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/DocumentNameType.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/DocumentNameType.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/ErrorResumeAction.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/ErrorResumeAction.cs index 6931d88..c294997 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/ErrorResumeAction.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/ErrorResumeAction.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptDebug32.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptDebug32.cs index 25bddc8..21c2a6e 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptDebug32.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptDebug32.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; @@ -53,7 +53,7 @@ [In] [Out] ref IntPtr pAttrs /// Character offset relative to start of script text /// Number of characters in this context /// An enumerator of the code contexts in the specified range - /// The method returns an HRESULT + /// The method returns an HRESULT [PreserveSig] uint EnumCodeContextsOfPosition( [In] uint sourceContext, diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptDebug64.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptDebug64.cs index 39cbcd4..0a23f42 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptDebug64.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptDebug64.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; @@ -53,7 +53,7 @@ [In] [Out] ref IntPtr pAttrs /// Character offset relative to start of script text /// Number of characters in this context /// An enumerator of the code contexts in the specified range - /// The method returns an HRESULT + /// The method returns an HRESULT [PreserveSig] uint EnumCodeContextsOfPosition( [In] ulong sourceContext, diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptErrorDebug.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptErrorDebug.cs index e36b044..6932036 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptErrorDebug.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptErrorDebug.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO; diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebug32.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebug32.cs index 2cb9b82..a7c0618 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebug32.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebug32.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging @@ -13,7 +13,7 @@ namespace MsieJavaScriptEngine.ActiveScript.Debugging internal interface IActiveScriptSiteDebug32 { /// - /// Used by the language engine to delegate IDebugCodeContext.GetSourceContext + /// Used by the language engine to delegate /// /// The source context as provided to /// or diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebug64.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebug64.cs index c72eff4..0cec490 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebug64.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebug64.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebugEx.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebugEx.cs index 4de0efe..b44c9fd 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebugEx.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebugEx.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IApplicationDebugger.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IApplicationDebugger.cs index 48d0336..e72e43d 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IApplicationDebugger.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IApplicationDebugger.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplication32.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplication32.cs index 6f688c4..87a78c3 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplication32.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplication32.cs @@ -11,7 +11,7 @@ namespace MsieJavaScriptEngine.ActiveScript.Debugging [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] internal interface IDebugApplication32 // : IRemoteDebugApplication { -#if !NETSTANDARD +#if NETFRAMEWORK #region IRemoteDebugApplication methods /// @@ -48,7 +48,7 @@ [In] [MarshalAs(UnmanagedType.Interface)] IApplicationDebugger debugger /// Returns the current debugger connected to the application /// /// The current debugger connected to the application - /// The method returns an HRESULT + /// The method returns an HRESULT [PreserveSig] uint GetDebugger( [Out] [MarshalAs(UnmanagedType.Interface)] out IApplicationDebugger debugger @@ -207,7 +207,7 @@ [In] uint cookie /// /// Determines if the current running thread is the debugger thread /// - /// The method returns an HRESULT + /// The method returns an HRESULT [PreserveSig] uint QueryCurrentThreadIsDebuggerThread(); @@ -251,7 +251,7 @@ [In] [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 0)] object eventObje /// Action to take when the debugger resumes the application /// Action to take when the debugger resumes the application /// if there is an error - /// Flag which is true if the engine should call + /// Flag which is true if the engine should call /// the method void HandleRuntimeError( [In] [MarshalAs(UnmanagedType.Interface)] IActiveScriptErrorDebug errorDebug, @@ -264,8 +264,8 @@ [Out] [MarshalAs(UnmanagedType.Bool)] out bool callOnScriptError /// /// Determines if a JIT debugger is registered /// - /// If the method succeeds and a JIT debugger is registered, the method returns true. - /// Otherwise, it returns false. + /// If the method succeeds and a JIT debugger is registered, the method returns true. + /// Otherwise, it returns false. [PreserveSig] [return: MarshalAs(UnmanagedType.Bool)] bool FCanJitDebug(); @@ -274,7 +274,7 @@ [Out] [MarshalAs(UnmanagedType.Bool)] out bool callOnScriptError /// Determines if a JIT debugger is registered to auto-debug dumb hosts /// /// If the method succeeds and a JIT debugger is registered to auto-debug dumb hosts, - /// the method returns true. Otherwise, it returns false. + /// the method returns true. Otherwise, it returns false. [PreserveSig] [return: MarshalAs(UnmanagedType.Bool)] bool FIsAutoJitDebugEnabled(); diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplication64.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplication64.cs index c99d263..6f1993c 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplication64.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplication64.cs @@ -11,7 +11,7 @@ namespace MsieJavaScriptEngine.ActiveScript.Debugging [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] internal interface IDebugApplication64 // : IRemoteDebugApplication { -#if !NETSTANDARD +#if NETFRAMEWORK #region IRemoteDebugApplication methods /// @@ -48,7 +48,7 @@ [In] [MarshalAs(UnmanagedType.Interface)] IApplicationDebugger debugger /// Returns the current debugger connected to the application /// /// The current debugger connected to the application - /// The method returns an HRESULT + /// The method returns an HRESULT [PreserveSig] uint GetDebugger( [Out] [MarshalAs(UnmanagedType.Interface)] out IApplicationDebugger debugger @@ -207,7 +207,7 @@ [In] uint cookie /// /// Determines if the current running thread is the debugger thread /// - /// The method returns an HRESULT + /// The method returns an HRESULT [PreserveSig] uint QueryCurrentThreadIsDebuggerThread(); @@ -251,7 +251,7 @@ [In] [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 0)] object eventObje /// Action to take when the debugger resumes the application /// Action to take when the debugger resumes the application /// if there is an error - /// Flag which is true if the engine should call + /// Flag which is true if the engine should call /// the method void HandleRuntimeError( [In] [MarshalAs(UnmanagedType.Interface)] IActiveScriptErrorDebug errorDebug, @@ -264,8 +264,8 @@ [Out] [MarshalAs(UnmanagedType.Bool)] out bool callOnScriptError /// /// Determines if a JIT debugger is registered /// - /// If the method succeeds and a JIT debugger is registered, the method returns true. - /// Otherwise, it returns false. + /// If the method succeeds and a JIT debugger is registered, the method returns true. + /// Otherwise, it returns false. [PreserveSig] [return: MarshalAs(UnmanagedType.Bool)] bool FCanJitDebug(); @@ -274,7 +274,7 @@ [Out] [MarshalAs(UnmanagedType.Bool)] out bool callOnScriptError /// Determines if a JIT debugger is registered to auto-debug dumb hosts /// /// If the method succeeds and a JIT debugger is registered to auto-debug dumb hosts, - /// the method returns true. Otherwise, it returns false. + /// the method returns true. Otherwise, it returns false. [PreserveSig] [return: MarshalAs(UnmanagedType.Bool)] bool FIsAutoJitDebugEnabled(); diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplicationNode.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplicationNode.cs index fd6799e..0b892ae 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplicationNode.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplicationNode.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplicationThread.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplicationThread.cs index bf601fe..c8fc7de 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplicationThread.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplicationThread.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugAsyncOperation.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugAsyncOperation.cs index 769b129..68cfd16 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugAsyncOperation.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugAsyncOperation.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugCodeContext.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugCodeContext.cs index cf56785..18e0c86 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugCodeContext.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugCodeContext.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocument.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocument.cs index c5a3509..e70f7f4 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocument.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocument.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentContext.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentContext.cs index cf6b76c..3fe7cc1 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentContext.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentContext.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentHelper32.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentHelper32.cs index 59ebb17..958df77 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentHelper32.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentHelper32.cs @@ -4,8 +4,8 @@ namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// /// Provide implementations for many interfaces necessary for smart hosting, such as - /// the IDebugDocument, IDebugDocumentContext, IDebugDocumentProvider, IDebugDocumentText - /// and IDebugDocumentTextEvents interfaces + /// the IDebugDocument, IDebugDocumentContext, IDebugDocumentProvider, + /// IDebugDocumentText and IDebugDocumentTextEvents interfaces /// [ComImport] [Guid("51973C26-CB0C-11d0-B5C9-00A0244A0E7A")] diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentHelper64.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentHelper64.cs index c94ab07..4925b95 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentHelper64.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentHelper64.cs @@ -4,8 +4,8 @@ namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// /// Provide implementations for many interfaces necessary for smart hosting, such as - /// the IDebugDocument, IDebugDocumentContext, IDebugDocumentProvider, IDebugDocumentText - /// and IDebugDocumentTextEvents interfaces + /// the IDebugDocument, IDebugDocumentContext, IDebugDocumentProvider, + /// IDebugDocumentText and IDebugDocumentTextEvents interfaces /// [ComImport] [Guid("c4c7363c-20fd-47f9-bd82-4855e0150871")] diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentInfo.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentInfo.cs index 7be288a..488e9ea 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentInfo.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentInfo.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentProvider.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentProvider.cs index ab663e5..c749b6a 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentProvider.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentProvider.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentText.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentText.cs index ce96b55..af74329 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentText.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentText.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; @@ -49,9 +49,9 @@ [Out] out TextDocAttrs attrs /// /// Returns the number of lines and number of characters in the document /// - /// Number of lines in the document. If this parameter is null, + /// Number of lines in the document. If this parameter is null, /// the method does not return a value - /// Number of characters in the document. If this parameter is null, + /// Number of characters in the document. If this parameter is null, /// the method does not return a value void GetSize( [Out] out uint numLines, @@ -76,7 +76,7 @@ [Out] out uint position /// Start location of the character position range /// The line number of the range /// The character offset of the range within line . - /// If this parameter is null, the method does not return a value + /// If this parameter is null, the method does not return a value void GetLineOfPosition( [In] uint position, [Out] out uint lineNumber, @@ -88,9 +88,9 @@ [Out] out uint offsetInLine /// /// Start location of the character position range /// A character text buffer. The buffer must be large enough to hold - /// characters. If this parameter is null, the method does not return characters. + /// characters. If this parameter is null, the method does not return characters. /// A character attribute buffer. The buffer must be large enough to hold - /// characters. If this parameter is null, the method does not return attributes. + /// characters. If this parameter is null, the method does not return attributes. /// The number of characters/attributes returned. This parameter must be set to /// zero before calling this method. /// Number of characters in the character position range. Also specifies diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugProperty.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugProperty.cs index 9004d41..7e8df16 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugProperty.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugProperty.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrame.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrame.cs index b515d8e..9c62495 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrame.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrame.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging @@ -22,8 +22,8 @@ [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugCodeContext context /// /// Returns a short or long textual description of the stack frame /// - /// Flag, where true returns a long description and - /// false returns a short description + /// Flag, where true returns a long description and + /// false returns a short description /// The description of the stack frame void GetDescriptionString( [In] [MarshalAs(UnmanagedType.Bool)] bool longString, @@ -33,8 +33,8 @@ [Out] [MarshalAs(UnmanagedType.BStr)] out string description /// /// Returns a short or long textual description of the language /// - /// Flag, where true returns a long description and - /// false returns a short description + /// Flag, where true returns a long description and + /// false returns a short description /// The description of the language void GetLanguageString( [In] [MarshalAs(UnmanagedType.Bool)] bool longString, diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSniffer.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSniffer.cs index e0cfc15..e107105 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSniffer.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSniffer.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSnifferEx32.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSnifferEx32.cs index 71f1db1..8c301ab 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSnifferEx32.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSnifferEx32.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSnifferEx64.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSnifferEx64.cs index a6c83f7..3aa6d91 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSnifferEx64.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSnifferEx64.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugSyncOperation.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugSyncOperation.cs index 1cc92d7..64c872f 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugSyncOperation.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugSyncOperation.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugThreadCall32.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugThreadCall32.cs index ef392d7..270c035 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugThreadCall32.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugThreadCall32.cs @@ -1,11 +1,11 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// /// The interface is typically implemented by a component that makes - /// cross-thread calls with the IDebugThread marshalling implementation provided by + /// cross-thread calls with the IDebugThread marshalling implementation provided by /// the process debug manager (PDM). /// [ComImport] diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugThreadCall64.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugThreadCall64.cs index 53bbf75..2a87b8e 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugThreadCall64.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugThreadCall64.cs @@ -1,11 +1,11 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// /// The interface is typically implemented by a component that makes - /// cross-thread calls with the IDebugThread marshalling implementation provided by + /// cross-thread calls with the IDebugThread marshalling implementation provided by /// the process debug manager (PDM). /// [ComImport] diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugApplicationNodes.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugApplicationNodes.cs index cc41adf..7c311fe 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugApplicationNodes.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugApplicationNodes.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugCodeContexts.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugCodeContexts.cs index d3753f5..93bb198 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugCodeContexts.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugCodeContexts.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugExpressionContexts.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugExpressionContexts.cs index e698d46..fcc7d9d 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugExpressionContexts.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugExpressionContexts.cs @@ -1,10 +1,10 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging { /// - /// Enumerates a collection of IDebugExpressionContexts objects + /// Enumerates a collection of IDebugExpressionContexts objects /// [ComImport] [Guid("51973c40-cb0c-11d0-b5c9-00a0244a0e7a")] diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugStackFrames.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugStackFrames.cs index d426411..6c75645 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugStackFrames.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugStackFrames.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumRemoteDebugApplicationThreads.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumRemoteDebugApplicationThreads.cs index 020c2c6..e4121a9 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumRemoteDebugApplicationThreads.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumRemoteDebugApplicationThreads.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IProvideExpressionContexts.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IProvideExpressionContexts.cs index 258411b..de68303 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IProvideExpressionContexts.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IProvideExpressionContexts.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IRemoteDebugApplicationThread.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IRemoteDebugApplicationThread.cs index 33aa2a5..0cd3e26 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/IRemoteDebugApplicationThread.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/IRemoteDebugApplicationThread.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/NullEnumDebugStackFrames.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/NullEnumDebugStackFrames.cs index 2735f83..5cb29a8 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/NullEnumDebugStackFrames.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/NullEnumDebugStackFrames.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/ProcessDebugManagerWrapper.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/ProcessDebugManagerWrapper.cs index c18cadb..8ae8f24 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/ProcessDebugManagerWrapper.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/ProcessDebugManagerWrapper.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using MsieJavaScriptEngine.Helpers; using MsieJavaScriptEngine.Utilities; @@ -51,7 +51,7 @@ public ProcessDebugManagerWrapper(IProcessDebugManager64 processDebugManager) /// the creation succeeded. /// /// Wrapper for process debug manager - /// true if the wrapper was created successfully; otherwise, false. + /// true if the wrapper was created successfully; otherwise, false. public static bool TryCreate(out ProcessDebugManagerWrapper wrapper) { const string progId = "ProcessDebugManager"; @@ -104,7 +104,7 @@ public void CreateApplication(out DebugApplicationWrapper applicationWrapper) /// /// Wrapper for debug application /// An engine-defined cookie - /// true if the debug application was added successfully; otherwise, false. + /// true if the debug application was added successfully; otherwise, false. public bool TryAddApplication(DebugApplicationWrapper applicationWrapper, out uint cookie) { uint result; diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/SourceTextAttrs.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/SourceTextAttrs.cs index 407bf59..149e0d2 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/SourceTextAttrs.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/SourceTextAttrs.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; namespace MsieJavaScriptEngine.ActiveScript.Debugging @@ -13,7 +13,7 @@ internal enum SourceTextAttrs : ushort /// /// The character is part of a language keyword - /// (for example, the JavaScript keyword while) + /// (for example, the JavaScript keyword while) /// Keyword = 0x0001, @@ -30,19 +30,19 @@ internal enum SourceTextAttrs : ushort /// /// The character is part of a language operator - /// (for example, the arithmetic operator +) + /// (for example, the arithmetic operator +) /// Operator = 0x0008, /// /// The character is part of a language numeric constant - /// (for example, the constant 3.14159) + /// (for example, the constant 3.14159) /// Number = 0x0010, /// /// The character is part of a language string constant - /// (for example, the string "Hello World") + /// (for example, the string "Hello World") /// String = 0x0020, diff --git a/src/MsieJavaScriptEngine/ActiveScript/Debugging/TextDocAttrs.cs b/src/MsieJavaScriptEngine/ActiveScript/Debugging/TextDocAttrs.cs index 0cad8a1..a402865 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/Debugging/TextDocAttrs.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/Debugging/TextDocAttrs.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; namespace MsieJavaScriptEngine.ActiveScript.Debugging diff --git a/src/MsieJavaScriptEngine/HostItemBase.cs b/src/MsieJavaScriptEngine/ActiveScript/HostItemBase.cs similarity index 72% rename from src/MsieJavaScriptEngine/HostItemBase.cs rename to src/MsieJavaScriptEngine/ActiveScript/HostItemBase.cs index 55bd380..7d0b945 100644 --- a/src/MsieJavaScriptEngine/HostItemBase.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/HostItemBase.cs @@ -1,11 +1,11 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Globalization; using System.Reflection; using MsieJavaScriptEngine.Helpers; -namespace MsieJavaScriptEngine +namespace MsieJavaScriptEngine.ActiveScript { /// /// Base class of item, that implements interface @@ -27,6 +27,11 @@ internal abstract class HostItemBase : IReflect /// protected readonly JsEngineMode _engineMode; + /// + /// Flag for whether to allow the usage of reflection API in the script code + /// + protected readonly bool _allowReflection; + /// /// List of fields /// @@ -57,20 +62,26 @@ public object Target /// Target type /// Target object /// JS engine mode + /// Flag for whether to allow the usage of reflection API in the script code /// Flag for whether to allow access to members of the instance - protected HostItemBase(Type type, object target, JsEngineMode engineMode, bool instance) + protected HostItemBase(Type type, object target, JsEngineMode engineMode, bool allowReflection, bool instance) { _type = type; _target = target; + _allowReflection = allowReflection; _engineMode = engineMode; BindingFlags defaultBindingFlags = ReflectionHelpers.GetDefaultBindingFlags(instance); FieldInfo[] fields = _type.GetFields(defaultBindingFlags); PropertyInfo[] properties = _type.GetProperties(defaultBindingFlags); + if (properties.Length > 0 && !allowReflection) + { + properties = GetAvailableProperties(properties); + } MethodInfo[] methods = _type.GetMethods(defaultBindingFlags); - if (methods.Length > 0 && properties.Length > 0) + if (methods.Length > 0 && (properties.Length > 0 || !allowReflection)) { - methods = ReflectionHelpers.GetFullyFledgedMethods(methods); + methods = GetAvailableMethods(methods, allowReflection); } _fields = fields; @@ -79,6 +90,49 @@ protected HostItemBase(Type type, object target, JsEngineMode engineMode, bool i } + private static PropertyInfo[] GetAvailableProperties(PropertyInfo[] properties) + { + int propertyCount = properties.Length; + var availableProperties = new PropertyInfo[propertyCount]; + int availablePropertyIndex = 0; + + for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++) + { + PropertyInfo property = properties[propertyIndex]; + if (ReflectionHelpers.IsAllowedProperty(property)) + { + availableProperties[availablePropertyIndex] = property; + availablePropertyIndex++; + } + } + + Array.Resize(ref availableProperties, availablePropertyIndex); + + return availableProperties; + } + + private static MethodInfo[] GetAvailableMethods(MethodInfo[] methods, bool allowReflection) + { + int methodCount = methods.Length; + var availableMethods = new MethodInfo[methodCount]; + int availableMethodIndex = 0; + + for (int methodIndex = 0; methodIndex < methodCount; methodIndex++) + { + MethodInfo method = methods[methodIndex]; + if (ReflectionHelpers.IsFullyFledgedMethod(method) + && (allowReflection || ReflectionHelpers.IsAllowedMethod(method))) + { + availableMethods[availableMethodIndex] = method; + availableMethodIndex++; + } + } + + Array.Resize(ref availableMethods, availableMethodIndex); + + return availableMethods; + } + private bool IsField(string name) { bool isField = false; diff --git a/src/MsieJavaScriptEngine/HostObject.cs b/src/MsieJavaScriptEngine/ActiveScript/HostObject.cs similarity index 87% rename from src/MsieJavaScriptEngine/HostObject.cs rename to src/MsieJavaScriptEngine/ActiveScript/HostObject.cs index 405f0ad..cb00656 100644 --- a/src/MsieJavaScriptEngine/HostObject.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/HostObject.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Globalization; using System.Linq; @@ -7,7 +7,7 @@ using MsieJavaScriptEngine.Constants; using MsieJavaScriptEngine.Helpers; -namespace MsieJavaScriptEngine +namespace MsieJavaScriptEngine.ActiveScript { /// /// Wrapper for object, that implements interface @@ -25,8 +25,9 @@ internal sealed class HostObject : HostItemBase /// /// Target object /// JS engine mode - public HostObject(object target, JsEngineMode engineMode) - : base(target.GetType(), target, engineMode, true) + /// Flag for whether to allow the usage of reflection API in the script code + public HostObject(object target, JsEngineMode engineMode, bool allowReflection) + : base(target.GetType(), target, engineMode, allowReflection, true) { var del = _target as Delegate; if (del != null) @@ -88,7 +89,7 @@ protected override object InnerInvokeMember(string name, BindingFlags invokeAttr processedArgs, modifiers, culture, namedParameters); } - return TypeMappingHelpers.MapToScriptType(result, _engineMode); + return TypeMappingHelpers.MapToScriptType(result, _engineMode, _allowReflection); } #endregion diff --git a/src/MsieJavaScriptEngine/HostType.cs b/src/MsieJavaScriptEngine/ActiveScript/HostType.cs similarity index 82% rename from src/MsieJavaScriptEngine/HostType.cs rename to src/MsieJavaScriptEngine/ActiveScript/HostType.cs index 5b02a50..855d02d 100644 --- a/src/MsieJavaScriptEngine/HostType.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/HostType.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Globalization; using System.Linq; @@ -7,7 +7,7 @@ using MsieJavaScriptEngine.Constants; using MsieJavaScriptEngine.Helpers; -namespace MsieJavaScriptEngine +namespace MsieJavaScriptEngine.ActiveScript { /// /// Wrapper for type, that implements interface @@ -19,8 +19,9 @@ internal sealed class HostType : HostItemBase /// /// Target type /// JS engine mode - public HostType(Type type, JsEngineMode engineMode) - : base(type, null, engineMode, false) + /// Flag for whether to allow the usage of reflection API in the script code + public HostType(Type type, JsEngineMode engineMode, bool allowReflection) + : base(type, null, engineMode, allowReflection, false) { } @@ -51,7 +52,7 @@ protected override object InnerInvokeMember(string name, BindingFlags invokeAttr processedArgs, modifiers, culture, namedParameters); } - return TypeMappingHelpers.MapToScriptType(result, _engineMode); + return TypeMappingHelpers.MapToScriptType(result, _engineMode, _allowReflection); } #endregion diff --git a/src/MsieJavaScriptEngine/ActiveScript/IActiveScript.cs b/src/MsieJavaScriptEngine/ActiveScript/IActiveScript.cs index ae0eed4..4ce72e2 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/IActiveScript.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/IActiveScript.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; @@ -84,8 +84,8 @@ [In] ScriptItemFlags flags /// /// Adds a type library to the name space for the script. This is similar to the - /// #include directive in C/C++. It allows a set of predefined items such as - /// class definitions, typedefs, and named constants to be added to the run-time + /// #include directive in C/C++. It allows a set of predefined items such as + /// class definitions, typedefs, and named constants to be added to the run-time /// environment available to the script. /// /// CLSID of the type library to add @@ -100,16 +100,16 @@ [In] ScriptTypeLibFlags typeLibFlags ); /// - /// Retrieves the IDispatch interface for the methods and properties associated + /// Retrieves the IDispatch interface for the methods and properties associated /// with the currently running script /// /// The name of the item for which the caller needs the associated - /// dispatch object. If this parameter is null, the dispatch object contains as its members + /// dispatch object. If this parameter is null, the dispatch object contains as its members /// all of the global methods and properties defined by the script. Through the - /// IDispatch interface and the associated interface, + /// IDispatch interface and the associated interface, /// the host can invoke script methods or view and modify script variables. /// The object associated with the script's global methods and - /// properties. If the scripting engine does not support such an object, null is returned. + /// properties. If the scripting engine does not support such an object, null is returned. void GetScriptDispatch( [In] [MarshalAs(UnmanagedType.LPWStr)] string itemName, [Out] [MarshalAs(UnmanagedType.IDispatch)] out object dispatch diff --git a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptError.cs b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptError.cs index 3e4d6c4..10d8244 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptError.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptError.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO; @@ -19,7 +19,7 @@ internal interface IActiveScriptError /// Retrieves information about an error that occurred while the scripting engine was running /// a script /// - /// An EXCEPINFO structure that receives error information + /// An EXCEPINFO structure that receives error information void GetExceptionInfo( [Out] out EXCEPINFO exceptionInfo ); diff --git a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptGarbageCollector.cs b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptGarbageCollector.cs index b58eeff..937e164 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptGarbageCollector.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptGarbageCollector.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript diff --git a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptParse32.cs b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptParse32.cs index 2d0360f..39c5f0f 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptParse32.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptParse32.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; @@ -13,11 +13,11 @@ namespace MsieJavaScriptEngine.ActiveScript /// /// /// Before the scripting engine can be used, one of the following methods must be called: - /// IPersist.Load, IPersist.InitNew, or . The semantics of - /// this method are identical to IPersistStreamInit.InitNew, in that this method tells the scripting - /// engine to initialize itself. Note that it is not valid to call both IPersist.InitNew or - /// and IPersist.Load, nor is it valid to call - /// IPersist.InitNew, , or IPersist.Load more than once. + /// IPersist.Load, IPersist.InitNew, or . The semantics of + /// this method are identical to IPersistStreamInit.InitNew, in that this method tells the scripting + /// engine to initialize itself. Note that it is not valid to call both IPersist.InitNew or + /// and IPersist.Load, nor is it valid to call + /// IPersist.InitNew, , or IPersist.Load more than once. /// [ComImport] [Guid("bb1a2ae2-a4f9-11cf-8f20-00805f2cd064")] @@ -32,14 +32,14 @@ internal interface IActiveScriptParse32 /// /// Adds a code scriptlet to the script. This method is used in environments where the /// persistent state of the script is intertwined with the host document and the host - /// is responsible for restoring the script, rather than through an IPersist interface. + /// is responsible for restoring the script, rather than through an IPersist interface. /// The primary examples are HTML scripting languages that allow scriptlets of code /// embedded in the HTML document to be attached to intrinsic events (for instance, - /// ONCLICK="button1.text='Exit'"). + /// ONCLICK="button1.text='Exit'"). /// /// The default name to associate with the scriptlet. If the - /// scriptlet does not contain naming information (as in the ONCLICK example above), - /// this name will be used to identify the scriptlet. If this parameter is null, the + /// scriptlet does not contain naming information (as in the ONCLICK example above), + /// this name will be used to identify the scriptlet. If this parameter is null, the /// scripting engine manufactures a unique name, if necessary. /// The scriptlet text to add. The interpretation of this string /// depends on the scripting language. @@ -48,7 +48,7 @@ internal interface IActiveScriptParse32 /// scriptlet is an event handler. /// The name of a subobject of the named item with which this /// scriptlet is associated; this name must be found in the named item's type - /// information. This parameter is null if the scriptlet is to be associated with the + /// information. This parameter is null if the scriptlet is to be associated with the /// named item instead of a subitem. This parameter, in addition to /// , identifies the specific object for which the scriptlet /// is an event handler. @@ -61,7 +61,7 @@ internal interface IActiveScriptParse32 /// provide some conditional primitive preprocessing (for example, replacing a single /// quotation mark ['] with two single quotation marks for use as a delimiter). /// Exactly how (and if) the scripting engine makes use of this information depends - /// on the scripting engine. Set this parameter to null if the host did not use a + /// on the scripting engine. Set this parameter to null if the host did not use a /// delimiter to mark the end of the scriptlet. /// Application-defined value that is used for /// debugging purposes @@ -73,7 +73,7 @@ internal interface IActiveScriptParse32 /// default name provided in , or a unique name /// synthesized by the scripting engine. /// Exception information. This structure should be - /// filled in if DISP_E_EXCEPTION is returned + /// filled in if DISP_E_EXCEPTION is returned void AddScriptlet( [In] [MarshalAs(UnmanagedType.LPWStr)] string defaultName, [In] [MarshalAs(UnmanagedType.LPWStr)] string code, @@ -95,11 +95,11 @@ [Out] out EXCEPINFO exceptionInfo /// The scriptlet text to evaluate. The interpretation of this /// string depends on the scripting language /// The item name that gives the context in which the - /// scriptlet is to be evaluated. If this parameter is null, the code is evaluated + /// scriptlet is to be evaluated. If this parameter is null, the code is evaluated /// in the scripting engine's global context /// The context object. This object is reserved for use in a /// debugging environment, where such a context may be provided by the debugger to - /// represent an active run-time context. If this parameter is null, the engine + /// represent an active run-time context. If this parameter is null, the engine /// uses to identify the context. /// The end-of-scriptlet delimiter. When /// is parsed from a stream of text, the host typically uses a delimiter, such as two @@ -108,18 +108,18 @@ [Out] out EXCEPINFO exceptionInfo /// some conditional primitive preprocessing (for example, replacing a single quotation /// mark ['] with two single quotation marks for use as a delimiter). Exactly how /// (and if) the scripting engine makes use of this information depends on the - /// scripting engine. Set this parameter to null if the host did not use a delimiter + /// scripting engine. Set this parameter to null if the host did not use a delimiter /// to mark the end of the scriptlet. /// Application-defined value that is used for /// debugging purposes /// Zero-based value that specifies which line the /// parsing will begin at /// Flags associated with the scriptlet - /// The results of scriptlet processing, or null if the caller + /// The results of scriptlet processing, or null if the caller /// expects no result (that is, the value is /// not set) /// The exception information. This structure is filled if - /// returns DISP_E_EXCEPTION. + /// returns DISP_E_EXCEPTION. void ParseScriptText( [In] [MarshalAs(UnmanagedType.LPWStr)] string code, [In] [MarshalAs(UnmanagedType.LPWStr)] string itemName, diff --git a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptParse64.cs b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptParse64.cs index 2fa9bc3..bb98f86 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptParse64.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptParse64.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; @@ -13,11 +13,11 @@ namespace MsieJavaScriptEngine.ActiveScript /// /// /// Before the scripting engine can be used, one of the following methods must be called: - /// IPersist.Load, IPersist.InitNew, or . The semantics of - /// this method are identical to IPersistStreamInit.InitNew, in that this method tells the scripting - /// engine to initialize itself. Note that it is not valid to call both IPersist.InitNew or - /// and IPersist.Load, nor is it valid to call - /// IPersist.InitNew, , or IPersist.Load more than once. + /// IPersist.Load, IPersist.InitNew, or . The semantics of + /// this method are identical to IPersistStreamInit.InitNew, in that this method tells the scripting + /// engine to initialize itself. Note that it is not valid to call both IPersist.InitNew or + /// and IPersist.Load, nor is it valid to call + /// IPersist.InitNew, , or IPersist.Load more than once. /// [ComImport] [Guid("c7ef7658-e1ee-480e-97ea-d52cb4d76d17")] @@ -32,14 +32,14 @@ internal interface IActiveScriptParse64 /// /// Adds a code scriptlet to the script. This method is used in environments where the /// persistent state of the script is intertwined with the host document and the host - /// is responsible for restoring the script, rather than through an IPersist interface. + /// is responsible for restoring the script, rather than through an IPersist interface. /// The primary examples are HTML scripting languages that allow scriptlets of code /// embedded in the HTML document to be attached to intrinsic events (for instance, - /// ONCLICK="button1.text='Exit'"). + /// ONCLICK="button1.text='Exit'"). /// /// The default name to associate with the scriptlet. If the - /// scriptlet does not contain naming information (as in the ONCLICK example above), - /// this name will be used to identify the scriptlet. If this parameter is null, the + /// scriptlet does not contain naming information (as in the ONCLICK example above), + /// this name will be used to identify the scriptlet. If this parameter is null, the /// scripting engine manufactures a unique name, if necessary. /// The scriptlet text to add. The interpretation of this string /// depends on the scripting language. @@ -48,7 +48,7 @@ internal interface IActiveScriptParse64 /// scriptlet is an event handler. /// The name of a subobject of the named item with which this /// scriptlet is associated; this name must be found in the named item's type - /// information. This parameter is null if the scriptlet is to be associated with the + /// information. This parameter is null if the scriptlet is to be associated with the /// named item instead of a subitem. This parameter, in addition to /// , identifies the specific object for which the scriptlet /// is an event handler. @@ -61,7 +61,7 @@ internal interface IActiveScriptParse64 /// provide some conditional primitive preprocessing (for example, replacing a single /// quotation mark ['] with two single quotation marks for use as a delimiter). /// Exactly how (and if) the scripting engine makes use of this information depends - /// on the scripting engine. Set this parameter to null if the host did not use a + /// on the scripting engine. Set this parameter to null if the host did not use a /// delimiter to mark the end of the scriptlet. /// Application-defined value that is used for /// debugging purposes @@ -73,7 +73,7 @@ internal interface IActiveScriptParse64 /// default name provided in , or a unique name /// synthesized by the scripting engine. /// Exception information. This structure should be - /// filled in if DISP_E_EXCEPTION is returned + /// filled in if DISP_E_EXCEPTION is returned void AddScriptlet( [In] [MarshalAs(UnmanagedType.LPWStr)] string defaultName, [In] [MarshalAs(UnmanagedType.LPWStr)] string code, @@ -95,11 +95,11 @@ [Out] out EXCEPINFO exceptionInfo /// The scriptlet text to evaluate. The interpretation of this /// string depends on the scripting language /// The item name that gives the context in which the - /// scriptlet is to be evaluated. If this parameter is null, the code is evaluated + /// scriptlet is to be evaluated. If this parameter is null, the code is evaluated /// in the scripting engine's global context /// The context object. This object is reserved for use in a /// debugging environment, where such a context may be provided by the debugger to - /// represent an active run-time context. If this parameter is null, the engine + /// represent an active run-time context. If this parameter is null, the engine /// uses to identify the context. /// The end-of-scriptlet delimiter. When /// is parsed from a stream of text, the host typically uses a delimiter, such as two @@ -108,18 +108,18 @@ [Out] out EXCEPINFO exceptionInfo /// some conditional primitive preprocessing (for example, replacing a single quotation /// mark ['] with two single quotation marks for use as a delimiter). Exactly how /// (and if) the scripting engine makes use of this information depends on the - /// scripting engine. Set this parameter to null if the host did not use a delimiter + /// scripting engine. Set this parameter to null if the host did not use a delimiter /// to mark the end of the scriptlet. /// Application-defined value that is used for /// debugging purposes /// Zero-based value that specifies which line the /// parsing will begin at /// Flags associated with the scriptlet - /// The results of scriptlet processing, or null if the caller + /// The results of scriptlet processing, or null if the caller /// expects no result (that is, the value is /// not set) /// The exception information. This structure is filled if - /// returns DISP_E_EXCEPTION. + /// returns DISP_E_EXCEPTION. void ParseScriptText( [In] [MarshalAs(UnmanagedType.LPWStr)] string code, [In] [MarshalAs(UnmanagedType.LPWStr)] string itemName, diff --git a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptProperty.cs b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptProperty.cs index f590a3e..0cc4785 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptProperty.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptProperty.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; @@ -19,7 +19,7 @@ internal interface IActiveScriptProperty /// The property value to get /// Not used /// The value of the property - /// The method returns an HRESULT + /// The method returns an HRESULT [PreserveSig] uint GetProperty( [In] uint dwProperty, @@ -33,7 +33,7 @@ [Out] out object pvarValue /// The property value to set /// Not used /// The value of the property - /// The method returns an HRESULT + /// The method returns an HRESULT [PreserveSig] uint SetProperty( [In] uint dwProperty, diff --git a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptSite.cs b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptSite.cs index d59bddd..494dff0 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptSite.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptSite.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; @@ -41,23 +41,23 @@ [Out] out int lcid /// returned. The scripting engine should request the minimum amount of information possible /// because some of the return parameters (for example, ) can take /// considerable time to load or generate. - /// A variable that receives a pointer to the IUnknown interface - /// associated with the given item. The scripting engine can use the IUnknown.QueryInterface - /// method to obtain the IDispatch interface for the item. This parameter receives null if + /// A variable that receives a pointer to the IUnknown interface + /// associated with the given item. The scripting engine can use the IUnknown.QueryInterface + /// method to obtain the IDispatch interface for the item. This parameter receives null if /// mask does not include the value. Also, it receives - /// null if there is no object associated with the item name; this mechanism is used to create + /// null if there is no object associated with the item name; this mechanism is used to create /// a simple class when the named item was added with the /// flag set in the method. /// A variable that receives a pointer to the - /// interface associated with the item. This parameter receives null if mask does not include + /// interface associated with the item. This parameter receives null if mask does not include /// the value, or if type information is not available /// for this item. If type information is not available, the object cannot source events, and - /// name binding must be realized with the IDispatch.GetIDsOfNames method. Note that the - /// interface retrieved describes the item's coclass (TKIND_COCLASS) + /// name binding must be realized with the IDispatch.GetIDsOfNames method. Note that the + /// interface retrieved describes the item's coclass (TKIND_COCLASS) /// because the object may support multiple interfaces and event interfaces. If the item supports - /// the IProvideMultipleTypeInfo interface, the interface retrieved is + /// the IProvideMultipleTypeInfo interface, the interface retrieved is /// the same as the index zero that would be obtained using the - /// IProvideMultipleTypeInfo.GetInfoOfIndex method. + /// IProvideMultipleTypeInfo.GetInfoOfIndex method. void GetItemInfo( [In] [MarshalAs(UnmanagedType.LPWStr)] string name, [In] ScriptInfoFlags mask, @@ -79,10 +79,10 @@ [Out] [MarshalAs(UnmanagedType.BStr)] out string version /// /// Informs the host that the script has completed execution /// - /// A variable that contains the script result, or null if the script + /// A variable that contains the script result, or null if the script /// produced no result /// Contains exception information generated when the script - /// terminated, or null if no exception was generated + /// terminated, or null if no exception was generated void OnScriptTerminate( [In] object result, [In] EXCEPINFO exceptionInfo diff --git a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptSiteInterruptPoll.cs b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptSiteInterruptPoll.cs index c195f10..42aeb21 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptSiteInterruptPoll.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptSiteInterruptPoll.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System.Runtime.InteropServices; namespace MsieJavaScriptEngine.ActiveScript @@ -15,7 +15,7 @@ internal interface IActiveScriptSiteInterruptPoll /// /// Allows a host to specify that a script should terminate /// - /// The method returns an HRESULT + /// The method returns an HRESULT [PreserveSig] uint QueryContinue(); } diff --git a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptWrapper.cs b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptWrapper.cs index 4a44316..fb1bcd1 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptWrapper.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptWrapper.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices.ComTypes; @@ -60,11 +60,11 @@ ScriptItemFlags flags /// The scriptlet text to evaluate. The interpretation of this /// string depends on the scripting language /// The item name that gives the context in which the - /// scriptlet is to be evaluated. If this parameter is null, the code is evaluated + /// scriptlet is to be evaluated. If this parameter is null, the code is evaluated /// in the scripting engine's global context /// The context object. This object is reserved for use in a /// debugging environment, where such a context may be provided by the debugger to - /// represent an active run-time context. If this parameter is null, the engine + /// represent an active run-time context. If this parameter is null, the engine /// uses to identify the context. /// The end-of-scriptlet delimiter. When /// is parsed from a stream of text, the host typically uses a delimiter, such as two @@ -73,14 +73,14 @@ ScriptItemFlags flags /// some conditional primitive preprocessing (for example, replacing a single quotation /// mark ['] with two single quotation marks for use as a delimiter). Exactly how /// (and if) the scripting engine makes use of this information depends on the - /// scripting engine. Set this parameter to null if the host did not use a delimiter + /// scripting engine. Set this parameter to null if the host did not use a delimiter /// to mark the end of the scriptlet. /// Application-defined value that is used for /// debugging purposes /// Zero-based value that specifies which line the /// parsing will begin at /// Flags associated with the scriptlet - /// The results of scriptlet processing, or null if the caller expects no + /// The results of scriptlet processing, or null if the caller expects no /// result (that is, the value is not set) object ParseScriptText( string code, diff --git a/src/MsieJavaScriptEngine/ActiveScript/JScriptRuntimeErrorNumber.cs b/src/MsieJavaScriptEngine/ActiveScript/JScriptRuntimeErrorNumber.cs index d65a18f..fd135a0 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/JScriptRuntimeErrorNumber.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/JScriptRuntimeErrorNumber.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript { /// @@ -23,7 +23,7 @@ internal static class JScriptRuntimeErrorNumber public const int OutOfStackSpace = 28; /// - /// Cannot assign to 'this' + /// Cannot assign to this /// public const int CannotAssignToThisKeyword = 5000; @@ -108,12 +108,12 @@ internal static class JScriptRuntimeErrorNumber public const int UnexpectedQuantifier = 5018; /// - /// Expected ']' in regular expression + /// Expected ] in regular expression /// public const int ExpectedRightSquareBracketInRegularExpression = 5019; /// - /// Expected ')' in regular expression + /// Expected ) in regular expression /// public const int ExpectedRightParenthesisInRegularExpression = 5020; diff --git a/src/MsieJavaScriptEngine/ActiveScript/JScriptSyntaxErrorNumber.cs b/src/MsieJavaScriptEngine/ActiveScript/JScriptSyntaxErrorNumber.cs index 7cf568d..76544e7 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/JScriptSyntaxErrorNumber.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/JScriptSyntaxErrorNumber.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript { /// @@ -23,37 +23,37 @@ internal static class JScriptSyntaxErrorNumber public const int SyntaxError = 1002; /// - /// Expected ':' + /// Expected : /// public const int ExpectedColon = 1003; /// - /// Expected ';' + /// Expected ; /// public const int ExpectedSemicolon = 1004; /// - /// Expected '(' + /// Expected ( /// public const int ExpectedLeftParenthesis = 1005; /// - /// Expected ')' + /// Expected ) /// public const int ExpectedRightParenthesis = 1006; /// - /// Expected ']' + /// Expected ] /// public const int ExpectedRightSquareBracket = 1007; /// - /// Expected '{' + /// Expected { /// public const int ExpectedLeftCurlyBrace = 1008; /// - /// Expected '}' + /// Expected } /// public const int ExpectedRightCurlyBrace = 1009; @@ -63,12 +63,12 @@ internal static class JScriptSyntaxErrorNumber public const int ExpectedIdentifier = 1010; /// - /// Expected '=' + /// Expected = /// public const int ExpectedEqualSign = 1011; /// - /// Expected '/' + /// Expected / /// public const int ExpectedForwardSlash = 1012; @@ -88,17 +88,17 @@ internal static class JScriptSyntaxErrorNumber public const int UnterminatedComment = 1016; /// - /// 'return' statement outside of function + /// return statement outside of function /// public const int ReturnStatementOutsideOfFunction = 1018; /// - /// Can't have 'break' outside of loop + /// Can't have break outside of loop /// public const int CannotHaveBreakStatementOutsideOfLoop = 1019; /// - /// Can't have 'continue' outside of loop + /// Can't have continue outside of loop /// public const int CannotHaveContinueStatementOutsideOfLoop = 1020; @@ -108,7 +108,7 @@ internal static class JScriptSyntaxErrorNumber public const int ExpectedHexadecimalDigit = 1023; /// - /// Expected 'while' + /// Expected while /// public const int ExpectedWhileStatement = 1024; @@ -123,7 +123,7 @@ internal static class JScriptSyntaxErrorNumber public const int LabelNotFound = 1026; /// - /// 'default' can only appear once in a 'switch' statement + /// default can only appear once in a switch statement /// public const int DefaultStatementCanOnlyAppearOnceInSwitchStatement = 1027; @@ -133,7 +133,7 @@ internal static class JScriptSyntaxErrorNumber public const int ExpectedIdentifierStringOrNumber = 1028; /// - /// Expected '@end' + /// Expected @end /// public const int ExpectedConditionalCompilationEndStatement = 1029; @@ -148,12 +148,12 @@ internal static class JScriptSyntaxErrorNumber public const int ExpectedConstant = 1031; /// - /// Expected '@' + /// Expected @ /// public const int ExpectedAtSign = 1032; /// - /// Expected 'catch' + /// Expected catch /// public const int ExpectedCatchStatement = 1033; diff --git a/src/MsieJavaScriptEngine/ActiveScript/ScriptGCType.cs b/src/MsieJavaScriptEngine/ActiveScript/ScriptGCType.cs index 5928dfc..49f816a 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ScriptGCType.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ScriptGCType.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript { /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/ScriptInfoFlags.cs b/src/MsieJavaScriptEngine/ActiveScript/ScriptInfoFlags.cs index bb97eea..26088b3 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ScriptInfoFlags.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ScriptInfoFlags.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; namespace MsieJavaScriptEngine.ActiveScript @@ -12,12 +12,12 @@ internal enum ScriptInfoFlags : uint None = 0, /// - /// Returns the IUnknown interface for this item + /// Returns the IUnknown interface for this item /// IUnknown = 1, /// - /// Returns the ITypeInfo interface for this item + /// Returns the ITypeInfo interface for this item /// ITypeInfo = 2 } diff --git a/src/MsieJavaScriptEngine/ActiveScript/ScriptInterruptFlags.cs b/src/MsieJavaScriptEngine/ActiveScript/ScriptInterruptFlags.cs index c653693..04d4bb9 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ScriptInterruptFlags.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ScriptInterruptFlags.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; namespace MsieJavaScriptEngine.ActiveScript diff --git a/src/MsieJavaScriptEngine/ActiveScript/ScriptItemFlags.cs b/src/MsieJavaScriptEngine/ActiveScript/ScriptItemFlags.cs index 5fe126f..b627cae 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ScriptItemFlags.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ScriptItemFlags.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; namespace MsieJavaScriptEngine.ActiveScript @@ -30,11 +30,11 @@ internal enum ScriptItemFlags : uint /// /// Indicates that the item is a collection of global properties and methods associated /// with the script. Normally, a scripting engine would ignore the object name (other than - /// for the purpose of using it as a cookie for the IActiveScriptSite.GetItemInfo method, + /// for the purpose of using it as a cookie for the method, /// or for resolving explicit scoping) and expose its members as global variables and /// methods. This allows the host to extend the library (run-time functions and so on) /// available to the script. It is left to the scripting engine to deal with name conflicts - /// (for example, when two ScriptItemFlags.GlobalMembers items have methods of the same + /// (for example, when two items have methods of the same /// name), although an error should not be returned because of this situation. /// GlobalMembers = 0x00000008, @@ -49,7 +49,7 @@ internal enum ScriptItemFlags : uint /// /// Indicates that the named item represents a code-only object, and that the host has no - /// IUnknown to be associated with this code-only object. The host only has a name for this + /// IUnknown to be associated with this code-only object. The host only has a name for this /// object. In object-oriented languages such as C++, this flag would create a class. /// Not all languages support this flag. /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/ScriptLanguageVersion.cs b/src/MsieJavaScriptEngine/ActiveScript/ScriptLanguageVersion.cs index 95d6cba..d4c90ca 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ScriptLanguageVersion.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ScriptLanguageVersion.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript { /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/ScriptProperty.cs b/src/MsieJavaScriptEngine/ActiveScript/ScriptProperty.cs index c274650..6d83292 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ScriptProperty.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ScriptProperty.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript { /// @@ -8,7 +8,7 @@ internal enum ScriptProperty : uint { /// /// Forces the scripting engine to divide in integer mode instead of floating point mode. - /// The default value is False. + /// The default value is false. /// IntegerMode = 0x00003000, diff --git a/src/MsieJavaScriptEngine/ActiveScript/ScriptState.cs b/src/MsieJavaScriptEngine/ActiveScript/ScriptState.cs index 3e1a775..a8b8a92 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ScriptState.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ScriptState.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript { /// @@ -7,21 +7,21 @@ namespace MsieJavaScriptEngine.ActiveScript internal enum ScriptState : uint { /// - /// Script has just been created, but has not yet been initialized using an IPersist* - /// interface and IActiveScript.SetScriptSite + /// Script has just been created, but has not yet been initialized using an IPersist* + /// interface and /// Uninitialized = 0, /// /// Script has been initialized, but is not running (connecting to other objects or /// sinking events) or executing any code. Code can be queried for execution by - /// calling the IActiveScriptParse.ParseScriptText method. + /// calling the IActiveScriptParse.ParseScriptText method. /// Initialized = 1, /// /// Script can execute code, but is not yet sinking the events of objects added by - /// the IActiveScript.AddNamedItem method + /// the IActiveScript.AddNamedItem method /// Started = 2, diff --git a/src/MsieJavaScriptEngine/ActiveScript/ScriptTextFlags.cs b/src/MsieJavaScriptEngine/ActiveScript/ScriptTextFlags.cs index 7f24c62..d8c9ba9 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ScriptTextFlags.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ScriptTextFlags.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; namespace MsieJavaScriptEngine.ActiveScript @@ -25,7 +25,7 @@ internal enum ScriptTextFlags : uint /// /// Indicates that the code added during this call should be saved if the scripting engine is saved - /// (for example, through a call to IPersist*::Save), or if the scripting engine is reset by way of + /// (for example, through a call to IPersist*.Save), or if the scripting engine is reset by way of /// a transition back to the initialized state. For more information about this state, see Script /// Engine States /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/ScriptThreadId.cs b/src/MsieJavaScriptEngine/ActiveScript/ScriptThreadId.cs index 23bb700..541f3ff 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ScriptThreadId.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ScriptThreadId.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript { /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/ScriptThreadState.cs b/src/MsieJavaScriptEngine/ActiveScript/ScriptThreadState.cs index 1567e9d..bcafbb9 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ScriptThreadState.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ScriptThreadState.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.ActiveScript { /// diff --git a/src/MsieJavaScriptEngine/ActiveScript/ScriptTypeLibFlags.cs b/src/MsieJavaScriptEngine/ActiveScript/ScriptTypeLibFlags.cs index ef91fcc..ba20786 100644 --- a/src/MsieJavaScriptEngine/ActiveScript/ScriptTypeLibFlags.cs +++ b/src/MsieJavaScriptEngine/ActiveScript/ScriptTypeLibFlags.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; namespace MsieJavaScriptEngine.ActiveScript diff --git a/src/MsieJavaScriptEngine/Constants/ClassId.cs b/src/MsieJavaScriptEngine/Constants/ClassId.cs index 535df64..715c435 100644 --- a/src/MsieJavaScriptEngine/Constants/ClassId.cs +++ b/src/MsieJavaScriptEngine/Constants/ClassId.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.Constants { /// diff --git a/src/MsieJavaScriptEngine/Constants/ComErrorCode.cs b/src/MsieJavaScriptEngine/Constants/ComErrorCode.cs index 624c09f..26b1222 100644 --- a/src/MsieJavaScriptEngine/Constants/ComErrorCode.cs +++ b/src/MsieJavaScriptEngine/Constants/ComErrorCode.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.Constants { /// diff --git a/src/MsieJavaScriptEngine/Constants/SpecialMemberName.cs b/src/MsieJavaScriptEngine/Constants/SpecialMemberName.cs index 4834591..9febe74 100644 --- a/src/MsieJavaScriptEngine/Constants/SpecialMemberName.cs +++ b/src/MsieJavaScriptEngine/Constants/SpecialMemberName.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK namespace MsieJavaScriptEngine.Constants { /// diff --git a/src/MsieJavaScriptEngine/Extensions/StringExtensions.cs b/src/MsieJavaScriptEngine/Extensions/StringExtensions.cs index 1215e0c..f6f42b1 100644 --- a/src/MsieJavaScriptEngine/Extensions/StringExtensions.cs +++ b/src/MsieJavaScriptEngine/Extensions/StringExtensions.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; namespace MsieJavaScriptEngine.Extensions { @@ -13,7 +12,7 @@ internal static class StringExtensions /// /// Instance of /// The string without quotes to seek - /// true if the quoted value occurs within this string; otherwise, false + /// true if the quoted value occurs within this string; otherwise, false public static bool ContainsQuotedValue(this string source, string value) { if (source == null) @@ -63,6 +62,7 @@ public static string TrimStart(this string source, string trimString) return result; } +#if NETFRAMEWORK /// /// Converts a first letter of string to capital @@ -83,7 +83,7 @@ public static string CapitalizeFirstLetter(this string source) } string result; - char firstCharacter = source.First(); + char firstCharacter = source[0]; if (char.IsLower(firstCharacter)) { @@ -100,6 +100,7 @@ public static string CapitalizeFirstLetter(this string source) return result; } +#endif /// /// Splits a string into lines @@ -127,7 +128,7 @@ public static string[] SplitToLines(this string source) /// When this method returns, contains the character from the string, /// if the receiving succeeded, or null character if the receiving failed. /// The receiving fails if the index out of bounds. - /// true if the character was received successfully; otherwise, false + /// true if the character was received successfully; otherwise, false public static bool TryGetChar(this string source, int index, out char result) { if (source == null) diff --git a/src/MsieJavaScriptEngine/Helpers/ComHelpers.cs b/src/MsieJavaScriptEngine/Helpers/ComHelpers.cs index f023354..525c056 100644 --- a/src/MsieJavaScriptEngine/Helpers/ComHelpers.cs +++ b/src/MsieJavaScriptEngine/Helpers/ComHelpers.cs @@ -1,4 +1,4 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; @@ -27,26 +27,6 @@ public static IntPtr CreateInstanceByClsid(Guid clsid) return pInterface; } - public static IntPtr CreateInstanceByProgId(string progId) - { - Guid clsid = ClsidFromProgId(progId); - IntPtr pInterface = CreateInstanceByClsid(clsid); - - return pInterface; - } - - private static Guid ClsidFromProgId(string progId) - { - Guid clsid; - - if (!Guid.TryParseExact(progId, "B", out clsid)) - { - HResult.Check(NativeMethods.CLSIDFromProgID(progId, out clsid)); - } - - return clsid; - } - public static bool TryCreateComObject(string progId, string serverName, out T obj) where T : class { Type type; @@ -92,14 +72,6 @@ public static IntPtr QueryInterfaceNoThrow(IntPtr pUnknown) return result == ComErrorCode.S_OK ? pInterface : IntPtr.Zero; } - public static T GetMethodDelegate(IntPtr pInterface, int methodIndex) where T : class - { - var pVTable = Marshal.ReadIntPtr(pInterface); - var pMethod = Marshal.ReadIntPtr(pVTable + methodIndex * IntPtr.Size); - - return Marshal.GetDelegateForFunctionPointer(pMethod, typeof(T)) as T; - } - public static void ReleaseAndEmpty(ref IntPtr pUnk) { if (pUnk != IntPtr.Zero) @@ -121,12 +93,6 @@ public static extern uint CoCreateInstance( [In] ref Guid iid, [Out] out IntPtr pInterface ); - - [DllImport("ole32.dll", ExactSpelling = true)] - public static extern uint CLSIDFromProgID( - [In] [MarshalAs(UnmanagedType.LPWStr)] string progId, - [Out] out Guid clsid - ); } #endregion diff --git a/src/MsieJavaScriptEngine/Helpers/NumericHelpers.cs b/src/MsieJavaScriptEngine/Helpers/NumericHelpers.cs index bd26b34..7afb9f2 100644 --- a/src/MsieJavaScriptEngine/Helpers/NumericHelpers.cs +++ b/src/MsieJavaScriptEngine/Helpers/NumericHelpers.cs @@ -12,34 +12,6 @@ internal static class NumericHelpers private const double MAX_INTEGER_IN_DOUBLE = (1L << 53) - 1; - /// - /// Gets a value indicating whether the specified type is one of the numeric types - /// - /// The type - /// true if the specified type is one of the numeric types; otherwise, false - public static bool IsNumericType(Type type) - { - TypeCode typeCode = type.GetTypeCode(); - - switch (typeCode) - { - case TypeCode.SByte: - case TypeCode.Byte: - case TypeCode.Int16: - case TypeCode.UInt16: - case TypeCode.Int32: - case TypeCode.UInt32: - case TypeCode.Int64: - case TypeCode.UInt64: - case TypeCode.Single: - case TypeCode.Double: - case TypeCode.Decimal: - return true; - default: - return false; - } - } - /// /// Casts a double value to the correct type /// diff --git a/src/MsieJavaScriptEngine/Helpers/ReflectionHelpers.cs b/src/MsieJavaScriptEngine/Helpers/ReflectionHelpers.cs index 344af4e..3331909 100644 --- a/src/MsieJavaScriptEngine/Helpers/ReflectionHelpers.cs +++ b/src/MsieJavaScriptEngine/Helpers/ReflectionHelpers.cs @@ -1,13 +1,9 @@ using System; -#if NETSTANDARD using System.Collections.Generic; using System.Linq; -#endif using System.Reflection; -#if NETSTANDARD using MsieJavaScriptEngine.Utilities; -#endif namespace MsieJavaScriptEngine.Helpers { @@ -16,6 +12,19 @@ namespace MsieJavaScriptEngine.Helpers /// internal static class ReflectionHelpers { + private static readonly PropertyInfo[] _disallowedProperties = + { + typeof(Delegate).GetProperty("Method"), + typeof(Exception).GetProperty("TargetSite") + }; + + private static readonly MethodInfo[] _disallowedMethods = + { + typeof(object).GetMethod("GetType"), + typeof(Exception).GetMethod("GetType") + }; + + public static BindingFlags GetDefaultBindingFlags(bool instance) { BindingFlags bindingFlags = BindingFlags.Public; @@ -31,6 +40,20 @@ public static BindingFlags GetDefaultBindingFlags(bool instance) return bindingFlags; } + public static bool IsAllowedProperty(PropertyInfo property) + { + bool isAllowed = !_disallowedProperties.Contains(property, MemberComparer.Instance); + + return isAllowed; + } + + public static bool IsAllowedMethod(MethodInfo method) + { + bool isAllowed = !_disallowedMethods.Contains(method, MemberComparer.Instance); + + return isAllowed; + } + public static bool IsFullyFledgedMethod(MethodInfo method) { if (!method.Attributes.HasFlag(MethodAttributes.SpecialName)) @@ -44,29 +67,6 @@ public static bool IsFullyFledgedMethod(MethodInfo method) return isFullyFledged; } -#if !NETSTANDARD - - public static MethodInfo[] GetFullyFledgedMethods(MethodInfo[] methods) - { - int methodCount = methods.Length; - var fullyFledgedMethods = new MethodInfo[methodCount]; - int fullyFledgedMethodIndex = 0; - - for (int methodIndex = 0; methodIndex < methodCount; methodIndex++) - { - MethodInfo method = methods[methodIndex]; - if (IsFullyFledgedMethod(method)) - { - fullyFledgedMethods[fullyFledgedMethodIndex] = method; - fullyFledgedMethodIndex++; - } - } - - Array.Resize(ref fullyFledgedMethods, fullyFledgedMethodIndex); - - return fullyFledgedMethods; - } -#else public static void FixFieldValueType(ref object value, FieldInfo field) { @@ -248,6 +248,47 @@ private static bool CompareParameterTypes(object[] argValues, Type[] argTypes, T } + private sealed class MemberComparer : EqualityComparer + where T : MemberInfo + { + public static MemberComparer Instance { get; } = new MemberComparer(); + + + private MemberComparer() + { } + + + #region MemberComparer overrides + + public override bool Equals(T x, T y) + { + if (x == null && y == null) + { + return true; + } + else if (x == null || y == null) + { + return false; + } + + return x.Module == y.Module +#if !NETSTANDARD1_3 + && x.MetadataToken == y.MetadataToken +#else + && x.DeclaringType == y.DeclaringType + && x.Name == y.Name +#endif + ; + } + + public override int GetHashCode(T obj) + { + return obj != null ? obj.GetHashCode() : 0; + } + + #endregion + } + private sealed class MethodWithMetadata { public MethodBase Method @@ -262,13 +303,12 @@ public Type[] ParameterTypes set; } - /// TODO: In future will need to change type to double + /// TODO: In future will need to change type to double public ushort CompatibilityScore { get; set; } } -#endif } } \ No newline at end of file diff --git a/src/MsieJavaScriptEngine/Helpers/TypeMappingHelpers.cs b/src/MsieJavaScriptEngine/Helpers/TypeMappingHelpers.cs index f5baeca..843ef9c 100644 --- a/src/MsieJavaScriptEngine/Helpers/TypeMappingHelpers.cs +++ b/src/MsieJavaScriptEngine/Helpers/TypeMappingHelpers.cs @@ -1,7 +1,8 @@ -#if !NETSTANDARD +#if NETFRAMEWORK using System; using System.Linq; +using MsieJavaScriptEngine.ActiveScript; using MsieJavaScriptEngine.Utilities; namespace MsieJavaScriptEngine.Helpers @@ -16,8 +17,9 @@ internal static class TypeMappingHelpers /// /// The source value /// JavaScript engine mode + /// Flag for whether to allow the usage of reflection API in the script code /// The mapped value - public static object MapToScriptType(object value, JsEngineMode engineMode) + public static object MapToScriptType(object value, JsEngineMode engineMode, bool allowReflection) { if (value == null) { @@ -35,7 +37,7 @@ public static object MapToScriptType(object value, JsEngineMode engineMode) return value; } - var result = new HostObject(value, engineMode); + var result = new HostObject(value, engineMode, allowReflection); return result; } @@ -45,10 +47,11 @@ public static object MapToScriptType(object value, JsEngineMode engineMode) /// /// The source array /// JavaScript engine mode + /// Flag for whether to allow the usage of reflection API in the script code /// The mapped array - public static object[] MapToScriptType(object[] args, JsEngineMode engineMode) + public static object[] MapToScriptType(object[] args, JsEngineMode engineMode, bool allowReflection) { - return args.Select(arg => MapToScriptType(arg, engineMode)).ToArray(); + return args.Select(arg => MapToScriptType(arg, engineMode, allowReflection)).ToArray(); } /// diff --git a/src/MsieJavaScriptEngine/Helpers/ValidationHelpers.cs b/src/MsieJavaScriptEngine/Helpers/ValidationHelpers.cs index b1f7511..7098a15 100644 --- a/src/MsieJavaScriptEngine/Helpers/ValidationHelpers.cs +++ b/src/MsieJavaScriptEngine/Helpers/ValidationHelpers.cs @@ -34,7 +34,7 @@ public static class ValidationHelpers /// Checks whether supports a .NET type /// /// .NET type - /// Result of check (true - is supported; false - is not supported) + /// Result of check (true - is supported; false - is not supported) public static bool IsSupportedType(Type type) { bool result = _supportedTypes.Contains(type); @@ -46,7 +46,7 @@ public static bool IsSupportedType(Type type) /// Checks whether .NET type is primitive /// /// .NET type - /// Result of check (true - is primitive; false - is not primitive) + /// Result of check (true - is primitive; false - is not primitive) public static bool IsPrimitiveType(Type type) { return TypeConverter.IsPrimitiveType(type); @@ -56,7 +56,7 @@ public static bool IsPrimitiveType(Type type) /// Checks a format of the name /// /// The name - /// Result of check (true - correct format; false - wrong format) + /// Result of check (true - correct format; false - wrong format) public static bool CheckNameFormat(string name) { return _jsNameRegex.IsMatch(name); @@ -66,7 +66,7 @@ public static bool CheckNameFormat(string name) /// Checks a format of the document name /// /// The document name - /// Result of check (true - correct format; false - wrong format) + /// Result of check (true - correct format; false - wrong format) public static bool CheckDocumentNameFormat(string name) { return _documentNameRegex.IsMatch(name); diff --git a/src/MsieJavaScriptEngine/IInnerJsEngine.cs b/src/MsieJavaScriptEngine/IInnerJsEngine.cs index 0d5ed42..6198864 100644 --- a/src/MsieJavaScriptEngine/IInnerJsEngine.cs +++ b/src/MsieJavaScriptEngine/IInnerJsEngine.cs @@ -57,10 +57,10 @@ internal interface IInnerJsEngine : IDisposable object CallFunction(string functionName, params object[] args); /// - /// Сhecks for the existence of a variable + /// Checks for the existence of a variable /// /// Name of variable - /// Result of check (true - exists; false - not exists + /// Result of check (true - exists; false - not exists bool HasVariable(string variableName); /// @@ -86,20 +86,22 @@ internal interface IInnerJsEngine : IDisposable /// /// Embeds a host object to script code /// + /// + /// Allows to embed instances of simple classes (or structures) and delegates. + /// /// The name for the new global variable or function that will represent the object /// The object to expose - /// Allows to embed instances of simple classes (or structures) and delegates. void EmbedHostObject(string itemName, object value); /// /// Embeds a host type to script code /// - /// The name for the new global variable that will represent the type - /// The type to expose /// /// Host types are exposed to script code in the form of objects whose properties and /// methods are bound to the type's static members. /// + /// The name for the new global variable that will represent the type + /// The type to expose void EmbedHostType(string itemName, Type type); /// diff --git a/src/MsieJavaScriptEngine/InnerJsEngineBase.cs b/src/MsieJavaScriptEngine/InnerJsEngineBase.cs index 2befbaf..e68123a 100644 --- a/src/MsieJavaScriptEngine/InnerJsEngineBase.cs +++ b/src/MsieJavaScriptEngine/InnerJsEngineBase.cs @@ -39,38 +39,53 @@ protected InnerJsEngineBase(JsEngineSettings settings) #region IInnerJsEngine implementation + /// public string Mode { get { return _engineModeName; } } + /// public abstract bool SupportsScriptPrecompilation { get; } + /// public abstract PrecompiledScript Precompile(string code, string documentName); + /// public abstract object Evaluate(string expression, string documentName); + /// public abstract void Execute(string code, string documentName); + /// public abstract void Execute(PrecompiledScript precompiledScript); + /// public abstract object CallFunction(string functionName, params object[] args); + /// public abstract bool HasVariable(string variableName); + /// public abstract object GetVariableValue(string variableName); + /// public abstract void SetVariableValue(string variableName, object value); + /// public abstract void RemoveVariable(string variableName); + /// public abstract void EmbedHostObject(string itemName, object value); + /// public abstract void EmbedHostType(string itemName, Type type); + /// public abstract void Interrupt(); + /// public abstract void CollectGarbage(); #endregion diff --git a/src/MsieJavaScriptEngine/JsEngineSettings.cs b/src/MsieJavaScriptEngine/JsEngineSettings.cs index e6311b8..ff92ee5 100644 --- a/src/MsieJavaScriptEngine/JsEngineSettings.cs +++ b/src/MsieJavaScriptEngine/JsEngineSettings.cs @@ -27,6 +27,19 @@ public sealed class JsEngineSettings private int _maxStackSize; #endif + /// + /// Gets or sets a flag for whether to allow the usage of reflection API in the script code + /// + /// + /// This affects , Exception.GetType, + /// Exception.TargetSite and Delegate.Method. + /// + public bool AllowReflection + { + get; + set; + } + /// /// Gets or sets a flag for whether to enable script debugging features /// @@ -50,9 +63,8 @@ public JsEngineMode EngineMode /// Gets or sets a maximum stack size in bytes /// /// - /// Set a 0 to use the default maximum stack size specified in the header + /// Set a 0 to use the default maximum stack size specified in the header /// for the executable. - /// /// public int MaxStackSize { @@ -96,6 +108,7 @@ public bool UseJson2Library /// public JsEngineSettings() { + AllowReflection = false; EnableDebugging = false; EngineMode = JsEngineMode.Auto; #if !NETSTANDARD1_3 diff --git a/src/MsieJavaScriptEngine/JsRt/Edge/ChakraEdgeJsRtJsEngine.cs b/src/MsieJavaScriptEngine/JsRt/Edge/ChakraEdgeJsRtJsEngine.cs index af448cd..7ed6c07 100644 --- a/src/MsieJavaScriptEngine/JsRt/Edge/ChakraEdgeJsRtJsEngine.cs +++ b/src/MsieJavaScriptEngine/JsRt/Edge/ChakraEdgeJsRtJsEngine.cs @@ -61,7 +61,7 @@ internal sealed class ChakraEdgeJsRtJsEngine : ChakraJsRtJsEngineBase public ChakraEdgeJsRtJsEngine(JsEngineSettings settings) : base(settings) { - _typeMapper = new EdgeTypeMapper(); + _typeMapper = new EdgeTypeMapper(settings.AllowReflection); try { @@ -121,7 +121,7 @@ private static EdgeJsRuntime CreateJsRuntime() /// /// Checks a support of the Chakra “Edge” JsRT engine /// - /// Result of check (true - supports; false - does not support) + /// Result of check (true - supports; false - does not support) public static bool IsSupported() { if (_isSupported.HasValue) @@ -191,7 +191,7 @@ private static void RemoveReferenceToValue(EdgeJsValue value) /// Checks whether the value can have references /// /// The value - /// Result of check (true - may have; false - may not have) + /// Result of check (true - may have; false - may not have) private static bool CanHaveReferences(EdgeJsValue value) { JsValueType valueType = value.ValueType; @@ -772,13 +772,12 @@ public override void Dispose() /// /// Destroys object /// - /// Flag, allowing destruction of - /// managed objects contained in fields of class + /// Flag, allowing destruction of managed objects contained in fields of class private void Dispose(bool disposing) { - if (_disposedFlag.Set()) + if (disposing) { - if (disposing) + if (_disposedFlag.Set()) { if (_dispatcher != null) { @@ -794,10 +793,10 @@ private void Dispose(bool disposing) _typeMapper = null; } } - else - { - DisposeUnmanagedResources(); - } + } + else + { + DisposeUnmanagedResources(); } } diff --git a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsContext.cs b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsContext.cs index fc91404..43027ea 100644 --- a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsContext.cs +++ b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsContext.cs @@ -164,9 +164,13 @@ public static EdgeJsValue ParseScript(string script, JsSourceContext sourceConte /// Parses a serialized script and returns a function representing the script /// /// - /// Requires an active script context. - /// The runtime will hold on to the buffer until all instances of any functions created from - /// the buffer are garbage collected. + /// + /// Requires an active script context. + /// + /// + /// The runtime will hold on to the buffer until all instances of any functions created from + /// the buffer are garbage collected. + /// /// /// The script to parse /// The serialized script @@ -208,9 +212,13 @@ public static EdgeJsValue RunScript(string script, JsSourceContext sourceContext /// Runs a serialized script /// /// - /// Requires an active script context. - /// The runtime will hold on to the buffer until all instances of any functions created from - /// the buffer are garbage collected. + /// + /// Requires an active script context. + /// + /// + /// The runtime will hold on to the buffer until all instances of any functions created from + /// the buffer are garbage collected. + /// /// /// The source code of the serialized script /// The serialized script @@ -314,7 +322,7 @@ public static void StartDebugging() /// Adds a reference to a script context /// /// - /// Calling AddRef ensures that the context will not be freed until Release is called. + /// Calling AddRef ensures that the context will not be freed until Release is called. /// /// The object's new reference count public uint AddRef() @@ -329,7 +337,7 @@ public uint AddRef() /// Releases a reference to a script context /// /// - /// Removes a reference to a context that was created by AddRef. + /// Removes a reference to a context that was created by AddRef. /// /// The object's new reference count public uint Release() diff --git a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsErrorHelpers.cs b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsErrorHelpers.cs index 9eefe16..755eaaa 100644 --- a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsErrorHelpers.cs +++ b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsErrorHelpers.cs @@ -122,7 +122,7 @@ public static void ThrowIfError(JsErrorCode errorCode) /// - /// Creates a new JavaScript error object + /// Creates a new JavaScript Error object /// /// /// Requires an active script context. @@ -138,7 +138,7 @@ public static EdgeJsValue CreateError(string message) } /// - /// Creates a new JavaScript RangeError error object + /// Creates a new JavaScript RangeError error object /// /// /// Requires an active script context. @@ -154,7 +154,7 @@ public static EdgeJsValue CreateRangeError(string message) } /// - /// Creates a new JavaScript ReferenceError error object + /// Creates a new JavaScript ReferenceError error object /// /// /// Requires an active script context. @@ -170,7 +170,7 @@ public static EdgeJsValue CreateReferenceError(string message) } /// - /// Creates a new JavaScript SyntaxError error object + /// Creates a new JavaScript SyntaxError error object /// /// /// Requires an active script context. @@ -186,7 +186,7 @@ public static EdgeJsValue CreateSyntaxError(string message) } /// - /// Creates a new JavaScript TypeError error object + /// Creates a new JavaScript TypeError error object /// /// /// Requires an active script context. @@ -202,7 +202,7 @@ public static EdgeJsValue CreateTypeError(string message) } /// - /// Creates a new JavaScript URIError error object + /// Creates a new JavaScript URIError error object /// /// /// Requires an active script context. diff --git a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsNativeFunction.cs b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsNativeFunction.cs index f3ca6a0..30f79a2 100644 --- a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsNativeFunction.cs +++ b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsNativeFunction.cs @@ -7,7 +7,7 @@ namespace MsieJavaScriptEngine.JsRt.Edge /// “Edge” function callback /// /// The Function object that represents the function being invoked - /// Indicates whether this is a regular call or a 'new' call + /// Indicates whether this is a regular call or a new call /// The arguments to the call /// The number of arguments /// Callback data, if any diff --git a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsPropertyId.cs b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsPropertyId.cs index dcceaa9..3af5b25 100644 --- a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsPropertyId.cs +++ b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsPropertyId.cs @@ -29,9 +29,7 @@ public static EdgeJsPropertyId Invalid /// Gets a name associated with the property ID /// /// - /// /// Requires an active script context. - /// /// public string Name { diff --git a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsRuntime.cs b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsRuntime.cs index 38ff239..e5f4b20 100644 --- a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsRuntime.cs +++ b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsRuntime.cs @@ -15,9 +15,9 @@ namespace MsieJavaScriptEngine.JsRt.Edge /// time. /// /// - /// NOTE: A , unlike other objects in the Chakra hosting API, is not + /// NOTE: A , unlike other objects in the Chakra hosting API, is not /// garbage collected since it contains the garbage collected heap itself. A runtime will - /// continue to exist until Dispose is called. + /// continue to exist until Dispose is called. /// /// internal struct EdgeJsRuntime : IDisposable @@ -121,7 +121,7 @@ public static EdgeJsRuntime Create(JsRuntimeAttributes attributes) /// Creates a new runtime /// /// The attributes of the runtime to be created - /// The thread service for the runtime. Can be null + /// The thread service for the runtime. Can be null /// The runtime created public static EdgeJsRuntime Create(JsRuntimeAttributes attributes, JsThreadServiceCallback threadServiceCallback) { @@ -147,7 +147,7 @@ public void CollectGarbage() /// Registering a memory allocation callback will cause the runtime to call back to the host /// whenever it acquires memory from, or releases memory to, the OS. The callback routine is /// called before the runtime memory manager allocates a block of memory. The allocation will - /// be rejected if the callback returns false. The runtime memory manager will also invoke the + /// be rejected if the callback returns false. The runtime memory manager will also invoke the /// callback routine after freeing a block of memory, as well as after allocation failures. /// /// diff --git a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsValue.cs b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsValue.cs index 2f819a2..140fa09 100644 --- a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsValue.cs +++ b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsValue.cs @@ -7,8 +7,8 @@ namespace MsieJavaScriptEngine.JsRt.Edge /// “Edge” JavaScript value /// /// - /// The JavaScript value is one of the following types of values: Undefined, Null, Boolean, - /// String, Number, or Object. + /// The JavaScript value is one of the following types of values: undefined, null, Boolean, + /// String, Number, or Object. /// internal struct EdgeJsValue { @@ -304,24 +304,6 @@ public static EdgeJsValue FromString(string value) return reference; } -#if !NETSTANDARD - - /// - /// Creates a JavaScript value that is a projection of the passed in object - /// - /// - /// Requires an active script context. - /// - /// The object to be projected - /// The JavaScript value that is a projection of the object - public static EdgeJsValue FromObject(object value) - { - EdgeJsValue reference; - EdgeJsErrorHelpers.ThrowIfError(EdgeNativeMethods.JsVariantToValue(ref value, out reference)); - - return reference; - } -#endif /// /// Creates a new Object @@ -344,8 +326,8 @@ public static EdgeJsValue CreateObject() /// /// Requires an active script context. /// - /// External data that the object will represent. May be null - /// The callback for when the object is finalized. May be null. + /// External data that the object will represent. May be null + /// The callback for when the object is finalized. May be null. /// The new Object public static EdgeJsValue CreateExternalObject(IntPtr data, JsFinalizeCallback finalizer) { @@ -405,7 +387,7 @@ public static EdgeJsValue CreateArray(uint length) } /// - /// Creates a new JavaScript error object + /// Creates a new JavaScript Error object /// /// /// Requires an active script context. @@ -421,7 +403,7 @@ public static EdgeJsValue CreateError(EdgeJsValue message) } /// - /// Creates a new JavaScript RangeError error object + /// Creates a new JavaScript RangeError error object /// /// /// Requires an active script context. @@ -437,7 +419,7 @@ public static EdgeJsValue CreateRangeError(EdgeJsValue message) } /// - /// Creates a new JavaScript ReferenceError error object + /// Creates a new JavaScript ReferenceError error object /// /// /// Requires an active script context. @@ -453,7 +435,7 @@ public static EdgeJsValue CreateReferenceError(EdgeJsValue message) } /// - /// Creates a new JavaScript SyntaxError error object + /// Creates a new JavaScript SyntaxError error object /// /// /// Requires an active script context. @@ -469,7 +451,7 @@ public static EdgeJsValue CreateSyntaxError(EdgeJsValue message) } /// - /// Creates a new JavaScript TypeError error object + /// Creates a new JavaScript TypeError error object /// /// /// Requires an active script context. @@ -485,7 +467,7 @@ public static EdgeJsValue CreateTypeError(EdgeJsValue message) } /// - /// Creates a new JavaScript URIError error object + /// Creates a new JavaScript URIError error object /// /// /// Requires an active script context. @@ -505,8 +487,8 @@ public static EdgeJsValue CreateUriError(EdgeJsValue message) /// /// /// This only needs to be called on objects that are not going to be stored somewhere on - /// the stack. Calling AddRef ensures that the JavaScript object the value refers to will not be freed - /// until Release is called. + /// the stack. Calling AddRef ensures that the JavaScript object the value refers to will not be freed + /// until Release is called. /// /// The object's new reference count public uint AddRef() @@ -521,7 +503,7 @@ public uint AddRef() /// Releases a reference to the object /// /// - /// Removes a reference that was created by AddRef. + /// Removes a reference that was created by AddRef. /// /// The object's new reference count public uint Release() @@ -552,7 +534,7 @@ public bool ToBoolean() /// /// /// - /// This function retrieves the value of a Number value. It will fail with + /// This function retrieves the value of a Number value. It will fail with /// InvalidArgument if the type of the value is not Number. /// /// @@ -611,23 +593,6 @@ public int ToInt32() return Marshal.PtrToStringUni(buffer, (int)length); } -#if !NETSTANDARD - - /// - /// Retrieves a object representation of an Object value - /// - /// - /// Requires an active script context. - /// - /// The object representation of the value - public object ToObject() - { - object value; - EdgeJsErrorHelpers.ThrowIfError(EdgeNativeMethods.JsValueToVariant(this, out value)); - - return value; - } -#endif /// /// Converts a value to Boolean using regular JavaScript semantics @@ -873,7 +838,7 @@ public void DeleteIndexedProperty(EdgeJsValue index) /// /// /// - /// This function is equivalent to the "==" operator in JavaScript. + /// This function is equivalent to the == operator in JavaScript. /// /// /// Requires an active script context. @@ -894,7 +859,7 @@ public bool Equals(EdgeJsValue other) /// /// /// - /// This function is equivalent to the "===" operator in JavaScript. + /// This function is equivalent to the === operator in JavaScript. /// /// /// Requires an active script context. @@ -917,7 +882,7 @@ public bool StrictEquals(EdgeJsValue other) /// Requires an active script context. /// /// The arguments to the call - /// The Value returned from the function invocation, if any + /// The JavaScript value returned from the function invocation, if any public EdgeJsValue CallFunction(params EdgeJsValue[] arguments) { EdgeJsValue returnReference; @@ -939,7 +904,7 @@ public EdgeJsValue CallFunction(params EdgeJsValue[] arguments) /// Requires an active script context. /// /// The arguments to the call - /// The Value returned from the function invocation + /// The JavaScript value returned from the function invocation public EdgeJsValue ConstructObject(params EdgeJsValue[] arguments) { EdgeJsValue returnReference; diff --git a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeNativeMethods.cs b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeNativeMethods.cs index e173780..0e8dd7a 100644 --- a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeNativeMethods.cs +++ b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeNativeMethods.cs @@ -148,16 +148,6 @@ internal static extern JsErrorCode JsSetRuntimeBeforeCollectCallback(EdgeJsRunti [DllImport(DllName.Chakra)] internal static extern JsErrorCode JsConvertValueToString(EdgeJsValue value, out EdgeJsValue stringValue); -#if !NETSTANDARD - - [DllImport(DllName.Chakra)] - internal static extern JsErrorCode JsVariantToValue([MarshalAs(UnmanagedType.Struct)] ref object var, - out EdgeJsValue value); - - [DllImport(DllName.Chakra)] - internal static extern JsErrorCode JsValueToVariant(EdgeJsValue obj, - [MarshalAs(UnmanagedType.Struct)] out object var); -#endif [DllImport(DllName.Chakra)] internal static extern JsErrorCode JsGetGlobalObject(out EdgeJsValue globalObject); diff --git a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeTypeMapper.cs b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeTypeMapper.cs index 6d28538..4cae2b4 100644 --- a/src/MsieJavaScriptEngine/JsRt/Edge/EdgeTypeMapper.cs +++ b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeTypeMapper.cs @@ -1,36 +1,23 @@ using System; -#if NETSTANDARD using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#endif using MsieJavaScriptEngine.Extensions; using MsieJavaScriptEngine.Helpers; -#if NETSTANDARD using MsieJavaScriptEngine.JsRt.Embedding; using MsieJavaScriptEngine.Resources; -#endif -#if !NETSTANDARD -using MsieJavaScriptEngine.Utilities; -#endif -#if NETSTANDARD using WrapperException = MsieJavaScriptEngine.JsException; -using WrapperRuntimeException = MsieJavaScriptEngine.JsRuntimeException; -using WrapperScriptException = MsieJavaScriptEngine.JsScriptException; -#endif namespace MsieJavaScriptEngine.JsRt.Edge { -#if NETSTANDARD using EdgeEmbeddedItem = EmbeddedItem; using EdgeEmbeddedObject = EmbeddedObject; using EdgeEmbeddedType = EmbeddedType; -#endif /// /// “Edge” type mapper /// @@ -39,40 +26,12 @@ internal sealed class EdgeTypeMapper : TypeMapper /// Constructs an instance of the “Edge” type mapper /// - public EdgeTypeMapper() -#if !NETSTANDARD - : base(JsEngineMode.ChakraEdgeJsRt) -#endif + /// Flag for whether to allow the usage of reflection API in the script code + public EdgeTypeMapper(bool allowReflection) + : base(allowReflection) { } -#if !NETSTANDARD - /// - /// Creates a JavaScript value from an host object if the it does not already exist - /// - /// Instance of host type - /// JavaScript value created from an host object - public override EdgeJsValue GetOrCreateScriptObject(object obj) - { - var wrappedObj = new HostObject(obj, _engineMode); - EdgeJsValue objValue = EdgeJsValue.FromObject(wrappedObj); - - return objValue; - } - - /// - /// Creates a JavaScript value from an host type if the it does not already exist - /// - /// Host type - /// JavaScript value created from an host type - public override EdgeJsValue GetOrCreateScriptType(Type type) - { - var wrappedType = new HostType(type, _engineMode); - EdgeJsValue typeValue = EdgeJsValue.FromObject(wrappedType); - - return typeValue; - } -#endif /// /// Makes a mapping of value from the host type to a script type /// @@ -148,7 +107,6 @@ public override object MapToHostType(EdgeJsValue value) case JsValueType.String: result = value.ToString(); break; -#if NETSTANDARD case JsValueType.Function: EdgeJsPropertyId externalObjectPropertyId = EdgeJsPropertyId.FromString(ExternalObjectPropertyName); if (value.HasProperty(externalObjectPropertyId)) @@ -160,23 +118,11 @@ public override object MapToHostType(EdgeJsValue value) result = result ?? value.ConvertToObject(); break; -#endif case JsValueType.Object: -#if !NETSTANDARD - case JsValueType.Function: -#endif case JsValueType.Error: case JsValueType.Array: -#if NETSTANDARD result = value.HasExternalData ? GCHandle.FromIntPtr(value.ExternalData).Target : value.ConvertToObject(); -#else - EdgeJsValue processedValue = valueType != JsValueType.Object ? - value.ConvertToObject() : value; - object obj = processedValue.ToObject(); - var hostObj = obj as HostObject; - result = hostObj != null ? hostObj.Target : obj; -#endif break; default: throw new ArgumentOutOfRangeException(); @@ -184,7 +130,6 @@ public override object MapToHostType(EdgeJsValue value) return result; } -#if NETSTANDARD protected override EdgeEmbeddedObject CreateEmbeddedObjectOrFunction(object obj) { @@ -217,7 +162,11 @@ private EdgeEmbeddedObject CreateEmbeddedFunction(Delegate del) { EdgeJsNativeFunction nativeFunction = (callee, isConstructCall, args, argCount, callbackData) => { +#if NET40 + MethodInfo method = del.Method; +#else MethodInfo method = del.GetMethodInfo(); +#endif ParameterInfo[] parameters = method.GetParameters(); object[] processedArgs = GetHostItemMemberArguments(args, parameters.Length); @@ -238,7 +187,7 @@ private EdgeEmbeddedObject CreateEmbeddedFunction(Delegate del) CreateErrorFromWrapperException(wrapperException) : EdgeJsErrorHelpers.CreateError(string.Format( - NetCoreStrings.Runtime_HostDelegateInvocationFailed, exception.Message)) + CommonStrings.Runtime_HostDelegateInvocationFailed, exception.Message)) ; EdgeJsContext.SetException(errorValue); @@ -265,7 +214,11 @@ private EdgeEmbeddedObject CreateEmbeddedFunction(Delegate del) protected override EdgeEmbeddedType CreateEmbeddedType(Type type) { +#if NET40 + Type typeInfo = type; +#else TypeInfo typeInfo = type.GetTypeInfo(); +#endif string typeName = type.FullName; BindingFlags defaultBindingFlags = ReflectionHelpers.GetDefaultBindingFlags(true); ConstructorInfo[] constructors = type.GetConstructors(defaultBindingFlags); @@ -288,7 +241,7 @@ protected override EdgeEmbeddedType CreateEmbeddedType(Type type) if (constructors.Length == 0) { - CreateAndSetError(string.Format(NetCoreStrings.Runtime_HostTypeConstructorNotFound, typeName)); + CreateAndSetError(string.Format(CommonStrings.Runtime_HostTypeConstructorNotFound, typeName)); return undefinedValue; } @@ -297,7 +250,7 @@ protected override EdgeEmbeddedType CreateEmbeddedType(Type type) if (bestFitConstructor == null) { CreateAndSetReferenceError(string.Format( - NetCoreStrings.Runtime_SuitableConstructorOfHostTypeNotFound, typeName)); + CommonStrings.Runtime_SuitableConstructorOfHostTypeNotFound, typeName)); return undefinedValue; } @@ -315,7 +268,7 @@ protected override EdgeEmbeddedType CreateEmbeddedType(Type type) CreateErrorFromWrapperException(wrapperException) : EdgeJsErrorHelpers.CreateError(string.Format( - NetCoreStrings.Runtime_HostTypeConstructorInvocationFailed, typeName, exception.Message)) + CommonStrings.Runtime_HostTypeConstructorInvocationFailed, typeName, exception.Message)) ; EdgeJsContext.SetException(errorValue); @@ -372,7 +325,7 @@ private void ProjectFields(EdgeEmbeddedItem externalItem) if (instance && obj == null) { CreateAndSetTypeError(string.Format( - NetCoreStrings.Runtime_InvalidThisContextForHostObjectField, fieldName)); + CommonStrings.Runtime_InvalidThisContextForHostObjectField, fieldName)); return undefinedValue; } @@ -395,10 +348,10 @@ private void ProjectFields(EdgeEmbeddedItem externalItem) else { string errorMessage = instance ? - string.Format(NetCoreStrings.Runtime_HostObjectFieldGettingFailed, fieldName, + string.Format(CommonStrings.Runtime_HostObjectFieldGettingFailed, fieldName, exception.Message) : - string.Format(NetCoreStrings.Runtime_HostTypeFieldGettingFailed, fieldName, typeName, + string.Format(CommonStrings.Runtime_HostTypeFieldGettingFailed, fieldName, typeName, exception.Message) ; errorValue = EdgeJsErrorHelpers.CreateError(errorMessage); @@ -424,7 +377,7 @@ private void ProjectFields(EdgeEmbeddedItem externalItem) if (instance && obj == null) { CreateAndSetTypeError(string.Format( - NetCoreStrings.Runtime_InvalidThisContextForHostObjectField, fieldName)); + CommonStrings.Runtime_InvalidThisContextForHostObjectField, fieldName)); return undefinedValue; } @@ -448,10 +401,10 @@ private void ProjectFields(EdgeEmbeddedItem externalItem) else { string errorMessage = instance ? - string.Format(NetCoreStrings.Runtime_HostObjectFieldSettingFailed, fieldName, + string.Format(CommonStrings.Runtime_HostObjectFieldSettingFailed, fieldName, exception.Message) : - string.Format(NetCoreStrings.Runtime_HostTypeFieldSettingFailed, fieldName, typeName, + string.Format(CommonStrings.Runtime_HostTypeFieldSettingFailed, fieldName, typeName, exception.Message) ; errorValue = EdgeJsErrorHelpers.CreateError(errorMessage); @@ -486,6 +439,11 @@ private void ProjectProperties(EdgeEmbeddedItem externalItem) foreach (PropertyInfo property in properties) { + if (!IsAvailableProperty(property)) + { + continue; + } + string propertyName = property.Name; EdgeJsValue descriptorValue = EdgeJsValue.CreateObject(); @@ -500,7 +458,7 @@ private void ProjectProperties(EdgeEmbeddedItem externalItem) if (instance && obj == null) { CreateAndSetTypeError(string.Format( - NetCoreStrings.Runtime_InvalidThisContextForHostObjectProperty, propertyName)); + CommonStrings.Runtime_InvalidThisContextForHostObjectProperty, propertyName)); return undefinedValue; } @@ -523,10 +481,10 @@ private void ProjectProperties(EdgeEmbeddedItem externalItem) else { string errorMessage = instance ? - string.Format(NetCoreStrings.Runtime_HostObjectPropertyGettingFailed, propertyName, + string.Format(CommonStrings.Runtime_HostObjectPropertyGettingFailed, propertyName, exception.Message) : - string.Format(NetCoreStrings.Runtime_HostTypePropertyGettingFailed, propertyName, + string.Format(CommonStrings.Runtime_HostTypePropertyGettingFailed, propertyName, typeName, exception.Message) ; errorValue = EdgeJsErrorHelpers.CreateError(errorMessage); @@ -555,7 +513,7 @@ private void ProjectProperties(EdgeEmbeddedItem externalItem) if (instance && obj == null) { CreateAndSetTypeError(string.Format( - NetCoreStrings.Runtime_InvalidThisContextForHostObjectProperty, propertyName)); + CommonStrings.Runtime_InvalidThisContextForHostObjectProperty, propertyName)); return undefinedValue; } @@ -579,10 +537,10 @@ private void ProjectProperties(EdgeEmbeddedItem externalItem) else { string errorMessage = instance ? - string.Format(NetCoreStrings.Runtime_HostObjectPropertySettingFailed, propertyName, + string.Format(CommonStrings.Runtime_HostObjectPropertySettingFailed, propertyName, exception.Message) : - string.Format(NetCoreStrings.Runtime_HostTypePropertySettingFailed, propertyName, + string.Format(CommonStrings.Runtime_HostTypePropertySettingFailed, propertyName, typeName, exception.Message) ; errorValue = EdgeJsErrorHelpers.CreateError(errorMessage); @@ -614,14 +572,13 @@ private void ProjectMethods(EdgeEmbeddedItem externalItem) string typeName = type.FullName; BindingFlags defaultBindingFlags = ReflectionHelpers.GetDefaultBindingFlags(instance); - IEnumerable methods = type.GetMethods(defaultBindingFlags) - .Where(ReflectionHelpers.IsFullyFledgedMethod); - IEnumerable> methodGroups = methods.GroupBy(m => m.Name); + MethodInfo[] methods = type.GetMethods(defaultBindingFlags); + Dictionary> availableMethodGroups = GetAvailableMethodGroups(methods); - foreach (IGrouping methodGroup in methodGroups) + foreach (KeyValuePair> methodGroup in availableMethodGroups) { string methodName = methodGroup.Key; - MethodInfo[] methodCandidates = methodGroup.ToArray(); + MethodInfo[] methodCandidates = methodGroup.Value.ToArray(); EdgeJsNativeFunction nativeFunction = (callee, isConstructCall, args, argCount, callbackData) => { @@ -630,7 +587,7 @@ private void ProjectMethods(EdgeEmbeddedItem externalItem) if (instance && obj == null) { CreateAndSetTypeError(string.Format( - NetCoreStrings.Runtime_InvalidThisContextForHostObjectMethod, methodName)); + CommonStrings.Runtime_InvalidThisContextForHostObjectMethod, methodName)); return undefinedValue; } @@ -641,7 +598,7 @@ private void ProjectMethods(EdgeEmbeddedItem externalItem) if (bestFitMethod == null) { CreateAndSetReferenceError(string.Format( - NetCoreStrings.Runtime_SuitableMethodOfHostObjectNotFound, methodName)); + CommonStrings.Runtime_SuitableMethodOfHostObjectNotFound, methodName)); return undefinedValue; } @@ -666,10 +623,10 @@ private void ProjectMethods(EdgeEmbeddedItem externalItem) else { string errorMessage = instance ? - string.Format(NetCoreStrings.Runtime_HostObjectMethodInvocationFailed, methodName, + string.Format(CommonStrings.Runtime_HostObjectMethodInvocationFailed, methodName, exception.Message) : - string.Format(NetCoreStrings.Runtime_HostTypeMethodInvocationFailed, methodName, typeName, + string.Format(CommonStrings.Runtime_HostTypeMethodInvocationFailed, methodName, typeName, exception.Message) ; errorValue = EdgeJsErrorHelpers.CreateError(errorMessage); @@ -745,6 +702,5 @@ private static EdgeJsValue CreateErrorFromWrapperException(WrapperException exce return errorValue; } -#endif } } \ No newline at end of file diff --git a/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedItem.cs b/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedItem.cs index 71c8699..8dbad02 100644 --- a/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedItem.cs +++ b/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedItem.cs @@ -1,5 +1,4 @@ -#if NETSTANDARD -using System; +using System; using System.Collections.Generic; using MsieJavaScriptEngine.Utilities; @@ -38,7 +37,7 @@ internal abstract class EmbeddedItem : IDisposable /// /// Flag indicating whether this object is disposed /// - private readonly InterlockedStatedFlag _disposedFlag = new InterlockedStatedFlag(); + private InterlockedStatedFlag _disposedFlag = new InterlockedStatedFlag(); /// /// Gets a host type @@ -121,5 +120,4 @@ public void Dispose() #endregion } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedObject.cs b/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedObject.cs index ee0bf5a..8300a73 100644 --- a/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedObject.cs +++ b/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedObject.cs @@ -1,5 +1,4 @@ -#if NETSTANDARD -using System; +using System; using System.Collections.Generic; namespace MsieJavaScriptEngine.JsRt.Embedding @@ -44,5 +43,4 @@ public override bool IsInstance #endregion } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedObjectKey.cs b/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedObjectKey.cs index 9eb2009..1bd3b1f 100644 --- a/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedObjectKey.cs +++ b/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedObjectKey.cs @@ -1,5 +1,4 @@ -#if NETSTANDARD -using System; +using System; using System.Collections; using System.Collections.Generic; @@ -84,7 +83,7 @@ int IComparable.CompareTo(object other) if (!(other is EmbeddedObjectKey)) { throw new ArgumentException( - string.Format(NetCoreStrings.Common_ArgumentHasIncorrectType, nameof(other), + string.Format(CommonStrings.Common_ArgumentHasIncorrectType, nameof(other), other.GetType().Name), nameof(other) ); @@ -122,7 +121,7 @@ int IStructuralComparable.CompareTo(object other, IComparer comparer) if (!(other is EmbeddedObjectKey)) { throw new ArgumentException( - string.Format(NetCoreStrings.Common_ArgumentHasIncorrectType, nameof(other), + string.Format(CommonStrings.Common_ArgumentHasIncorrectType, nameof(other), other.GetType().Name), nameof(other) ); @@ -161,5 +160,4 @@ public override string ToString() #endregion } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedType.cs b/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedType.cs index f29a1c1..479ce5f 100644 --- a/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedType.cs +++ b/src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedType.cs @@ -1,5 +1,4 @@ -#if NETSTANDARD -using System; +using System; using System.Collections.Generic; namespace MsieJavaScriptEngine.JsRt.Embedding @@ -44,5 +43,4 @@ public override bool IsInstance #endregion } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/MsieJavaScriptEngine/JsRt/Ie/ChakraIeJsRtJsEngine.cs b/src/MsieJavaScriptEngine/JsRt/Ie/ChakraIeJsRtJsEngine.cs index a199e1e..c405866 100644 --- a/src/MsieJavaScriptEngine/JsRt/Ie/ChakraIeJsRtJsEngine.cs +++ b/src/MsieJavaScriptEngine/JsRt/Ie/ChakraIeJsRtJsEngine.cs @@ -69,7 +69,7 @@ internal sealed class ChakraIeJsRtJsEngine : ChakraJsRtJsEngineBase public ChakraIeJsRtJsEngine(JsEngineSettings settings) : base(settings) { - _typeMapper = new IeTypeMapper(); + _typeMapper = new IeTypeMapper(settings.AllowReflection); try { @@ -137,7 +137,7 @@ private static IeJsRuntime CreateJsRuntime() /// /// Checks a support of the Chakra “IE” JsRT engine /// - /// Result of check (true - supports; false - does not support) + /// Result of check (true - supports; false - does not support) public static bool IsSupported() { if (_isSupported.HasValue) @@ -224,7 +224,7 @@ private static void RemoveReferenceToValue(IeJsValue value) /// Checks whether the value can have references /// /// The value - /// Result of check (true - may have; false - may not have) + /// Result of check (true - may have; false - may not have) private static bool CanHaveReferences(IeJsValue value) { JsValueType valueType = value.ValueType; @@ -826,13 +826,12 @@ public override void Dispose() /// /// Destroys object /// - /// Flag, allowing destruction of - /// managed objects contained in fields of class + /// Flag, allowing destruction of managed objects contained in fields of class private void Dispose(bool disposing) { - if (_disposedFlag.Set()) + if (disposing) { - if (disposing) + if (_disposedFlag.Set()) { if (_dispatcher != null) { @@ -848,10 +847,10 @@ private void Dispose(bool disposing) _typeMapper = null; } } - else - { - DisposeUnmanagedResources(); - } + } + else + { + DisposeUnmanagedResources(); } } diff --git a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsContext.cs b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsContext.cs index 0aed8ff..81dcb63 100644 --- a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsContext.cs +++ b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsContext.cs @@ -167,9 +167,13 @@ public static IeJsValue ParseScript(string script, JsSourceContext sourceContext /// Parses a serialized script and returns a function representing the script /// /// - /// Requires an active script context. - /// The runtime will hold on to the buffer until all instances of any functions created from - /// the buffer are garbage collected. + /// + /// Requires an active script context. + /// + /// + /// The runtime will hold on to the buffer until all instances of any functions created from + /// the buffer are garbage collected. + /// /// /// The script to parse /// The serialized script @@ -211,9 +215,13 @@ public static IeJsValue RunScript(string script, JsSourceContext sourceContext, /// Runs a serialized script /// /// - /// Requires an active script context. - /// The runtime will hold on to the buffer until all instances of any functions created from - /// the buffer are garbage collected. + /// + /// Requires an active script context. + /// + /// + /// The runtime will hold on to the buffer until all instances of any functions created from + /// the buffer are garbage collected. + /// /// /// The source code of the serialized script /// The serialized script @@ -360,7 +368,7 @@ public static void StartDebugging() /// Adds a reference to a script context /// /// - /// Calling AddRef ensures that the context will not be freed until Release is called. + /// Calling AddRef ensures that the context will not be freed until Release is called. /// /// The object's new reference count public uint AddRef() @@ -375,7 +383,7 @@ public uint AddRef() /// Releases a reference to a script context /// /// - /// Removes a reference to a context that was created by AddRef. + /// Removes a reference to a context that was created by AddRef. /// /// The object's new reference count public uint Release() diff --git a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsErrorHelpers.cs b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsErrorHelpers.cs index 4432941..b0346cd 100644 --- a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsErrorHelpers.cs +++ b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsErrorHelpers.cs @@ -122,7 +122,7 @@ public static void ThrowIfError(JsErrorCode errorCode) /// - /// Creates a new JavaScript error object + /// Creates a new JavaScript Error object /// /// /// Requires an active script context. @@ -138,7 +138,7 @@ public static IeJsValue CreateError(string message) } /// - /// Creates a new JavaScript RangeError error object + /// Creates a new JavaScript RangeError error object /// /// /// Requires an active script context. @@ -154,7 +154,7 @@ public static IeJsValue CreateRangeError(string message) } /// - /// Creates a new JavaScript ReferenceError error object + /// Creates a new JavaScript ReferenceError error object /// /// /// Requires an active script context. @@ -170,7 +170,7 @@ public static IeJsValue CreateReferenceError(string message) } /// - /// Creates a new JavaScript SyntaxError error object + /// Creates a new JavaScript SyntaxError error object /// /// /// Requires an active script context. @@ -186,7 +186,7 @@ public static IeJsValue CreateSyntaxError(string message) } /// - /// Creates a new JavaScript TypeError error object + /// Creates a new JavaScript TypeError error object /// /// /// Requires an active script context. @@ -202,7 +202,7 @@ public static IeJsValue CreateTypeError(string message) } /// - /// Creates a new JavaScript URIError error object + /// Creates a new JavaScript URIError error object /// /// /// Requires an active script context. diff --git a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsNativeFunction.cs b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsNativeFunction.cs index 517db1d..e7bb0a4 100644 --- a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsNativeFunction.cs +++ b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsNativeFunction.cs @@ -7,7 +7,7 @@ namespace MsieJavaScriptEngine.JsRt.Ie /// “IE” function callback /// /// The Function object that represents the function being invoked - /// Indicates whether this is a regular call or a 'new' call + /// Indicates whether this is a regular call or a new call /// The arguments to the call /// The number of arguments /// Callback data, if any diff --git a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsPropertyId.cs b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsPropertyId.cs index 12721bc..906c656 100644 --- a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsPropertyId.cs +++ b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsPropertyId.cs @@ -29,9 +29,7 @@ public static IeJsPropertyId Invalid /// Gets a name associated with the property ID /// /// - /// /// Requires an active script context. - /// /// public string Name { diff --git a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsRuntime.cs b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsRuntime.cs index bd5c95c..33d518b 100644 --- a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsRuntime.cs +++ b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsRuntime.cs @@ -18,9 +18,9 @@ namespace MsieJavaScriptEngine.JsRt.Ie /// time. /// /// - /// NOTE: A , unlike other objects in the Chakra hosting API, is not + /// NOTE: A , unlike other objects in the Chakra hosting API, is not /// garbage collected since it contains the garbage collected heap itself. A runtime will - /// continue to exist until Dispose is called. + /// continue to exist until Dispose is called. /// /// internal struct IeJsRuntime : IDisposable @@ -126,7 +126,7 @@ public static IeJsRuntime Create(JsRuntimeAttributes attributes, JsRuntimeVersio /// /// The attributes of the runtime to be created /// The version of the runtime to be created - /// The thread service for the runtime. Can be null. + /// The thread service for the runtime. Can be null. /// The runtime created public static IeJsRuntime Create(JsRuntimeAttributes attributes, JsRuntimeVersion version, JsThreadServiceCallback threadServiceCallback) { @@ -152,7 +152,7 @@ public void CollectGarbage() /// Registering a memory allocation callback will cause the runtime to call back to the host /// whenever it acquires memory from, or releases memory to, the OS. The callback routine is /// called before the runtime memory manager allocates a block of memory. The allocation will - /// be rejected if the callback returns false. The runtime memory manager will also invoke the + /// be rejected if the callback returns false. The runtime memory manager will also invoke the /// callback routine after freeing a block of memory, as well as after allocation failures. /// /// diff --git a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsValue.cs b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsValue.cs index d429422..bb6caa1 100644 --- a/src/MsieJavaScriptEngine/JsRt/Ie/IeJsValue.cs +++ b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsValue.cs @@ -8,8 +8,8 @@ namespace MsieJavaScriptEngine.JsRt.Ie /// “IE” JavaScript value /// /// - /// The JavaScript value is one of the following types of values: Undefined, Null, Boolean, - /// String, Number, or Object. + /// The JavaScript value is one of the following types of values: undefined, null, Boolean, + /// String, Number, or Object. /// internal struct IeJsValue { @@ -305,24 +305,6 @@ public static IeJsValue FromString(string value) return reference; } -#if !NETSTANDARD - - /// - /// Creates a JavaScript value that is a projection of the passed in object - /// - /// - /// Requires an active script context. - /// - /// The object to be projected - /// The JavaScript value that is a projection of the object - public static IeJsValue FromObject(object value) - { - IeJsValue reference; - IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsVariantToValue(ref value, out reference)); - - return reference; - } -#endif /// /// Creates a new Object @@ -345,8 +327,8 @@ public static IeJsValue CreateObject() /// /// Requires an active script context. /// - /// External data that the object will represent. May be null. - /// A callback for when the object is finalized. May be null. + /// External data that the object will represent. May be null. + /// A callback for when the object is finalized. May be null. /// The new Object public static IeJsValue CreateExternalObject(IntPtr data, JsFinalizeCallback finalizer) { @@ -406,7 +388,7 @@ public static IeJsValue CreateArray(uint length) } /// - /// Creates a new JavaScript error object + /// Creates a new JavaScript Error object /// /// /// Requires an active script context. @@ -422,7 +404,7 @@ public static IeJsValue CreateError(IeJsValue message) } /// - /// Creates a new JavaScript RangeError error object + /// Creates a new JavaScript RangeError error object /// /// /// Requires an active script context. @@ -438,7 +420,7 @@ public static IeJsValue CreateRangeError(IeJsValue message) } /// - /// Creates a new JavaScript ReferenceError error object + /// Creates a new JavaScript ReferenceError error object /// /// /// Requires an active script context. @@ -454,7 +436,7 @@ public static IeJsValue CreateReferenceError(IeJsValue message) } /// - /// Creates a new JavaScript SyntaxError error object + /// Creates a new JavaScript SyntaxError error object /// /// /// Requires an active script context. @@ -470,7 +452,7 @@ public static IeJsValue CreateSyntaxError(IeJsValue message) } /// - /// Creates a new JavaScript TypeError error object + /// Creates a new JavaScript TypeError error object /// /// /// Requires an active script context. @@ -486,7 +468,7 @@ public static IeJsValue CreateTypeError(IeJsValue message) } /// - /// Creates a new JavaScript URIError error object + /// Creates a new JavaScript URIError error object /// /// /// Requires an active script context. @@ -506,8 +488,8 @@ public static IeJsValue CreateUriError(IeJsValue message) /// /// /// This only needs to be called on objects that are not going to be stored somewhere on - /// the stack. Calling AddRef ensures that the JavaScript object the value refers to will not be freed - /// until Release is called + /// the stack. Calling AddRef ensures that the JavaScript object the value refers to will not be freed + /// until Release is called /// /// The object's new reference count public uint AddRef() @@ -522,7 +504,7 @@ public uint AddRef() /// Releases a reference to the object /// /// - /// Removes a reference that was created by AddRef. + /// Removes a reference that was created by AddRef. /// /// The object's new reference count public uint Release() @@ -611,23 +593,6 @@ public int ToInt32() return Marshal.PtrToStringUni(buffer, (int)length); } -#if !NETSTANDARD - - /// - /// Retrieves a object representation of an Object value - /// - /// - /// Requires an active script context. - /// - /// The object representation of the value - public object ToObject() - { - object value; - IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsValueToVariant(this, out value)); - - return value; - } -#endif /// /// Converts a value to Boolean using regular JavaScript semantics @@ -873,7 +838,7 @@ public void DeleteIndexedProperty(IeJsValue index) /// /// /// - /// This function is equivalent to the "==" operator in JavaScript. + /// This function is equivalent to the == operator in JavaScript. /// /// /// Requires an active script context. @@ -894,7 +859,7 @@ public bool Equals(IeJsValue other) /// /// /// - /// This function is equivalent to the "===" operator in JavaScript. + /// This function is equivalent to the === operator in JavaScript. /// /// /// Requires an active script context. @@ -917,7 +882,7 @@ public bool StrictEquals(IeJsValue other) /// Requires an active script context. /// /// The arguments to the call - /// The Value returned from the function invocation, if any + /// The JavaScript value returned from the function invocation, if any public IeJsValue CallFunction(params IeJsValue[] arguments) { IeJsValue returnReference; @@ -939,7 +904,7 @@ public IeJsValue CallFunction(params IeJsValue[] arguments) /// Requires an active script context. /// /// The arguments to the call - /// The Value returned from the function invocation + /// The JavaScript value returned from the function invocation public IeJsValue ConstructObject(params IeJsValue[] arguments) { IeJsValue returnReference; diff --git a/src/MsieJavaScriptEngine/JsRt/Ie/IeNativeMethods.cs b/src/MsieJavaScriptEngine/JsRt/Ie/IeNativeMethods.cs index 14a6f9d..4b9aabd 100644 --- a/src/MsieJavaScriptEngine/JsRt/Ie/IeNativeMethods.cs +++ b/src/MsieJavaScriptEngine/JsRt/Ie/IeNativeMethods.cs @@ -154,16 +154,6 @@ internal static extern JsErrorCode JsCreateContext(IeJsRuntime runtime, IDebugAp [DllImport(DllName.JScript9)] internal static extern JsErrorCode JsConvertValueToString(IeJsValue value, out IeJsValue stringValue); -#if !NETSTANDARD - - [DllImport(DllName.JScript9)] - internal static extern JsErrorCode JsVariantToValue([MarshalAs(UnmanagedType.Struct)] ref object var, - out IeJsValue value); - - [DllImport(DllName.JScript9)] - internal static extern JsErrorCode JsValueToVariant(IeJsValue obj, - [MarshalAs(UnmanagedType.Struct)] out object var); -#endif [DllImport(DllName.JScript9)] internal static extern JsErrorCode JsGetGlobalObject(out IeJsValue globalObject); diff --git a/src/MsieJavaScriptEngine/JsRt/Ie/IeTypeMapper.cs b/src/MsieJavaScriptEngine/JsRt/Ie/IeTypeMapper.cs index 00256a0..004c7e9 100644 --- a/src/MsieJavaScriptEngine/JsRt/Ie/IeTypeMapper.cs +++ b/src/MsieJavaScriptEngine/JsRt/Ie/IeTypeMapper.cs @@ -1,31 +1,23 @@ using System; -#if NETSTANDARD using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#endif using MsieJavaScriptEngine.Extensions; using MsieJavaScriptEngine.Helpers; -#if NETSTANDARD using MsieJavaScriptEngine.JsRt.Embedding; using MsieJavaScriptEngine.Resources; using WrapperException = MsieJavaScriptEngine.JsException; -using WrapperRuntimeException = MsieJavaScriptEngine.JsRuntimeException; -using WrapperScriptException = MsieJavaScriptEngine.JsScriptException; -#endif namespace MsieJavaScriptEngine.JsRt.Ie { -#if NETSTANDARD using IeEmbeddedItem = EmbeddedItem; using IeEmbeddedObject = EmbeddedObject; using IeEmbeddedType = EmbeddedType; -#endif /// /// “IE” type mapper /// @@ -34,40 +26,12 @@ internal sealed class IeTypeMapper : TypeMapper /// /// Constructs an instance of the “IE” type mapper /// - public IeTypeMapper() -#if !NETSTANDARD - : base(JsEngineMode.ChakraIeJsRt) -#endif + /// Flag for whether to allow the usage of reflection API in the script code + public IeTypeMapper(bool allowReflection) + : base(allowReflection) { } -#if !NETSTANDARD - /// - /// Creates a JavaScript value from an host object if the it does not already exist - /// - /// Instance of host type - /// JavaScript value created from an host object - public override IeJsValue GetOrCreateScriptObject(object obj) - { - var wrappedObj = new HostObject(obj, _engineMode); - IeJsValue objValue = IeJsValue.FromObject(wrappedObj); - - return objValue; - } - - /// - /// Creates a JavaScript value from an host type if the it does not already exist - /// - /// Host type - /// JavaScript value created from an host type - public override IeJsValue GetOrCreateScriptType(Type type) - { - var wrappedType = new HostType(type, _engineMode); - IeJsValue typeValue = IeJsValue.FromObject(wrappedType); - - return typeValue; - } -#endif /// /// Makes a mapping of value from the host type to a script type /// @@ -143,7 +107,6 @@ public override object MapToHostType(IeJsValue value) case JsValueType.String: result = value.ToString(); break; -#if NETSTANDARD case JsValueType.Function: IeJsPropertyId externalObjectPropertyId = IeJsPropertyId.FromString(ExternalObjectPropertyName); if (value.HasProperty(externalObjectPropertyId)) @@ -155,23 +118,11 @@ public override object MapToHostType(IeJsValue value) result = result ?? value.ConvertToObject(); break; -#endif case JsValueType.Object: -#if !NETSTANDARD - case JsValueType.Function: -#endif case JsValueType.Error: case JsValueType.Array: -#if NETSTANDARD result = value.HasExternalData ? GCHandle.FromIntPtr(value.ExternalData).Target : value.ConvertToObject(); -#else - IeJsValue processedValue = valueType != JsValueType.Object ? - value.ConvertToObject() : value; - object obj = processedValue.ToObject(); - var hostObj = obj as HostObject; - result = hostObj != null ? hostObj.Target : obj; -#endif break; default: throw new ArgumentOutOfRangeException(); @@ -179,7 +130,6 @@ public override object MapToHostType(IeJsValue value) return result; } -#if NETSTANDARD protected override IeEmbeddedObject CreateEmbeddedObjectOrFunction(object obj) { @@ -212,7 +162,11 @@ private IeEmbeddedObject CreateEmbeddedFunction(Delegate del) { IeJsNativeFunction nativeFunction = (callee, isConstructCall, args, argCount, callbackData) => { +#if NET40 + MethodInfo method = del.Method; +#else MethodInfo method = del.GetMethodInfo(); +#endif ParameterInfo[] parameters = method.GetParameters(); object[] processedArgs = GetHostItemMemberArguments(args, parameters.Length); @@ -233,7 +187,7 @@ private IeEmbeddedObject CreateEmbeddedFunction(Delegate del) CreateErrorFromWrapperException(wrapperException) : IeJsErrorHelpers.CreateError(string.Format( - NetCoreStrings.Runtime_HostDelegateInvocationFailed, exception.Message)) + CommonStrings.Runtime_HostDelegateInvocationFailed, exception.Message)) ; IeJsContext.SetException(errorValue); @@ -260,7 +214,11 @@ private IeEmbeddedObject CreateEmbeddedFunction(Delegate del) protected override IeEmbeddedType CreateEmbeddedType(Type type) { +#if NET40 + Type typeInfo = type; +#else TypeInfo typeInfo = type.GetTypeInfo(); +#endif string typeName = type.FullName; BindingFlags defaultBindingFlags = ReflectionHelpers.GetDefaultBindingFlags(true); ConstructorInfo[] constructors = type.GetConstructors(defaultBindingFlags); @@ -283,7 +241,7 @@ protected override IeEmbeddedType CreateEmbeddedType(Type type) if (constructors.Length == 0) { - CreateAndSetError(string.Format(NetCoreStrings.Runtime_HostTypeConstructorNotFound, typeName)); + CreateAndSetError(string.Format(CommonStrings.Runtime_HostTypeConstructorNotFound, typeName)); return undefinedValue; } @@ -292,7 +250,7 @@ protected override IeEmbeddedType CreateEmbeddedType(Type type) if (bestFitConstructor == null) { CreateAndSetReferenceError(string.Format( - NetCoreStrings.Runtime_SuitableConstructorOfHostTypeNotFound, typeName)); + CommonStrings.Runtime_SuitableConstructorOfHostTypeNotFound, typeName)); return undefinedValue; } @@ -310,7 +268,7 @@ protected override IeEmbeddedType CreateEmbeddedType(Type type) CreateErrorFromWrapperException(wrapperException) : IeJsErrorHelpers.CreateError(string.Format( - NetCoreStrings.Runtime_HostTypeConstructorInvocationFailed, typeName, exception.Message)) + CommonStrings.Runtime_HostTypeConstructorInvocationFailed, typeName, exception.Message)) ; IeJsContext.SetException(errorValue); @@ -367,7 +325,7 @@ private void ProjectFields(IeEmbeddedItem externalItem) if (instance && obj == null) { CreateAndSetTypeError(string.Format( - NetCoreStrings.Runtime_InvalidThisContextForHostObjectField, fieldName)); + CommonStrings.Runtime_InvalidThisContextForHostObjectField, fieldName)); return undefinedValue; } @@ -390,10 +348,10 @@ private void ProjectFields(IeEmbeddedItem externalItem) else { string errorMessage = instance ? - string.Format(NetCoreStrings.Runtime_HostObjectFieldGettingFailed, fieldName, + string.Format(CommonStrings.Runtime_HostObjectFieldGettingFailed, fieldName, exception.Message) : - string.Format(NetCoreStrings.Runtime_HostTypeFieldGettingFailed, fieldName, typeName, + string.Format(CommonStrings.Runtime_HostTypeFieldGettingFailed, fieldName, typeName, exception.Message) ; errorValue = IeJsErrorHelpers.CreateError(errorMessage); @@ -419,7 +377,7 @@ private void ProjectFields(IeEmbeddedItem externalItem) if (instance && obj == null) { CreateAndSetTypeError(string.Format( - NetCoreStrings.Runtime_InvalidThisContextForHostObjectField, fieldName)); + CommonStrings.Runtime_InvalidThisContextForHostObjectField, fieldName)); return undefinedValue; } @@ -443,10 +401,10 @@ private void ProjectFields(IeEmbeddedItem externalItem) else { string errorMessage = instance ? - string.Format(NetCoreStrings.Runtime_HostObjectFieldSettingFailed, fieldName, + string.Format(CommonStrings.Runtime_HostObjectFieldSettingFailed, fieldName, exception.Message) : - string.Format(NetCoreStrings.Runtime_HostTypeFieldSettingFailed, fieldName, typeName, + string.Format(CommonStrings.Runtime_HostTypeFieldSettingFailed, fieldName, typeName, exception.Message) ; errorValue = IeJsErrorHelpers.CreateError(errorMessage); @@ -481,6 +439,11 @@ private void ProjectProperties(IeEmbeddedItem externalItem) foreach (PropertyInfo property in properties) { + if (!IsAvailableProperty(property)) + { + continue; + } + string propertyName = property.Name; IeJsValue descriptorValue = IeJsValue.CreateObject(); @@ -495,7 +458,7 @@ private void ProjectProperties(IeEmbeddedItem externalItem) if (instance && obj == null) { CreateAndSetTypeError(string.Format( - NetCoreStrings.Runtime_InvalidThisContextForHostObjectProperty, propertyName)); + CommonStrings.Runtime_InvalidThisContextForHostObjectProperty, propertyName)); return undefinedValue; } @@ -518,10 +481,10 @@ private void ProjectProperties(IeEmbeddedItem externalItem) else { string errorMessage = instance ? - string.Format(NetCoreStrings.Runtime_HostObjectPropertyGettingFailed, propertyName, + string.Format(CommonStrings.Runtime_HostObjectPropertyGettingFailed, propertyName, exception.Message) : - string.Format(NetCoreStrings.Runtime_HostTypePropertyGettingFailed, propertyName, + string.Format(CommonStrings.Runtime_HostTypePropertyGettingFailed, propertyName, typeName, exception.Message) ; errorValue = IeJsErrorHelpers.CreateError(errorMessage); @@ -550,7 +513,7 @@ private void ProjectProperties(IeEmbeddedItem externalItem) if (instance && obj == null) { CreateAndSetTypeError(string.Format( - NetCoreStrings.Runtime_InvalidThisContextForHostObjectProperty, propertyName)); + CommonStrings.Runtime_InvalidThisContextForHostObjectProperty, propertyName)); return undefinedValue; } @@ -574,10 +537,10 @@ private void ProjectProperties(IeEmbeddedItem externalItem) else { string errorMessage = instance ? - string.Format(NetCoreStrings.Runtime_HostObjectPropertySettingFailed, propertyName, + string.Format(CommonStrings.Runtime_HostObjectPropertySettingFailed, propertyName, exception.Message) : - string.Format(NetCoreStrings.Runtime_HostTypePropertySettingFailed, propertyName, + string.Format(CommonStrings.Runtime_HostTypePropertySettingFailed, propertyName, typeName, exception.Message) ; errorValue = IeJsErrorHelpers.CreateError(errorMessage); @@ -609,14 +572,13 @@ private void ProjectMethods(IeEmbeddedItem externalItem) string typeName = type.FullName; BindingFlags defaultBindingFlags = ReflectionHelpers.GetDefaultBindingFlags(instance); - IEnumerable methods = type.GetMethods(defaultBindingFlags) - .Where(ReflectionHelpers.IsFullyFledgedMethod); - IEnumerable> methodGroups = methods.GroupBy(m => m.Name); + MethodInfo[] methods = type.GetMethods(defaultBindingFlags); + Dictionary> availableMethodGroups = GetAvailableMethodGroups(methods); - foreach (IGrouping methodGroup in methodGroups) + foreach (KeyValuePair> methodGroup in availableMethodGroups) { string methodName = methodGroup.Key; - MethodInfo[] methodCandidates = methodGroup.ToArray(); + MethodInfo[] methodCandidates = methodGroup.Value.ToArray(); IeJsNativeFunction nativeFunction = (callee, isConstructCall, args, argCount, callbackData) => { @@ -625,7 +587,7 @@ private void ProjectMethods(IeEmbeddedItem externalItem) if (instance && obj == null) { CreateAndSetTypeError(string.Format( - NetCoreStrings.Runtime_InvalidThisContextForHostObjectMethod, methodName)); + CommonStrings.Runtime_InvalidThisContextForHostObjectMethod, methodName)); return undefinedValue; } @@ -636,7 +598,7 @@ private void ProjectMethods(IeEmbeddedItem externalItem) if (bestFitMethod == null) { CreateAndSetReferenceError(string.Format( - NetCoreStrings.Runtime_SuitableMethodOfHostObjectNotFound, methodName)); + CommonStrings.Runtime_SuitableMethodOfHostObjectNotFound, methodName)); return undefinedValue; } @@ -661,10 +623,10 @@ private void ProjectMethods(IeEmbeddedItem externalItem) else { string errorMessage = instance ? - string.Format(NetCoreStrings.Runtime_HostObjectMethodInvocationFailed, methodName, + string.Format(CommonStrings.Runtime_HostObjectMethodInvocationFailed, methodName, exception.Message) : - string.Format(NetCoreStrings.Runtime_HostTypeMethodInvocationFailed, methodName, + string.Format(CommonStrings.Runtime_HostTypeMethodInvocationFailed, methodName, typeName, exception.Message) ; errorValue = IeJsErrorHelpers.CreateError(errorMessage); @@ -739,6 +701,5 @@ private static IeJsValue CreateErrorFromWrapperException(WrapperException except return errorValue; } -#endif } } \ No newline at end of file diff --git a/src/MsieJavaScriptEngine/JsRt/JsBeforeCollectCallback.cs b/src/MsieJavaScriptEngine/JsRt/JsBeforeCollectCallback.cs index dfcc3ab..a193022 100644 --- a/src/MsieJavaScriptEngine/JsRt/JsBeforeCollectCallback.cs +++ b/src/MsieJavaScriptEngine/JsRt/JsBeforeCollectCallback.cs @@ -5,6 +5,6 @@ namespace MsieJavaScriptEngine.JsRt /// /// The callback called before collection /// - /// The state passed to SetBeforeCollectCallback + /// The state passed to SetBeforeCollectCallback internal delegate void JsBeforeCollectCallback(IntPtr callbackState); } \ No newline at end of file diff --git a/src/MsieJavaScriptEngine/JsRt/JsErrorCode.cs b/src/MsieJavaScriptEngine/JsRt/JsErrorCode.cs index c747fed..b7ad833 100644 --- a/src/MsieJavaScriptEngine/JsRt/JsErrorCode.cs +++ b/src/MsieJavaScriptEngine/JsRt/JsErrorCode.cs @@ -25,7 +25,7 @@ public enum JsErrorCode : uint InvalidArgument, /// - /// An argument to a hosting API was null in a context where null is not allowed + /// An argument to a hosting API was null in a context where null is not allowed /// NullArgument, @@ -77,7 +77,7 @@ public enum JsErrorCode : uint HeapEnumInProgress, /// - /// A hosting API that operates on Object values was called with a non-Object value + /// A hosting API that operates on object values was called with a non-object value /// ArgumentNotObject, @@ -150,7 +150,7 @@ public enum JsErrorCode : uint ScriptTerminated, /// - /// A script was terminated because it tried to use "eval" or "function" and eval was disabled + /// A script was terminated because it tried to use eval or Function and eval was disabled /// [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Eval is a valid function name.")] ScriptEvalDisabled, diff --git a/src/MsieJavaScriptEngine/JsRt/JsMemoryAllocationCallback.cs b/src/MsieJavaScriptEngine/JsRt/JsMemoryAllocationCallback.cs index 4fa09cd..3e42539 100644 --- a/src/MsieJavaScriptEngine/JsRt/JsMemoryAllocationCallback.cs +++ b/src/MsieJavaScriptEngine/JsRt/JsMemoryAllocationCallback.cs @@ -5,12 +5,12 @@ namespace MsieJavaScriptEngine.JsRt /// /// User implemented callback routine for memory allocation events /// - /// The state passed to SetRuntimeMemoryAllocationCallback + /// The state passed to SetRuntimeMemoryAllocationCallback /// The type of type allocation event /// The size of the allocation /// - /// For the Allocate event, returning true allows the runtime to continue with - /// allocation. Returning false indicates the allocation request is rejected. The return value + /// For the Allocate event, returning true allows the runtime to continue with + /// allocation. Returning false indicates the allocation request is rejected. The return value /// is ignored for other allocation events. /// internal delegate bool JsMemoryAllocationCallback(IntPtr callbackState, JsMemoryEventType allocationEvent, UIntPtr allocationSize); diff --git a/src/MsieJavaScriptEngine/JsRt/JsRuntimeAttributes.cs b/src/MsieJavaScriptEngine/JsRt/JsRuntimeAttributes.cs index de0b008..a4c3536 100644 --- a/src/MsieJavaScriptEngine/JsRt/JsRuntimeAttributes.cs +++ b/src/MsieJavaScriptEngine/JsRt/JsRuntimeAttributes.cs @@ -27,7 +27,7 @@ internal enum JsRuntimeAttributes AllowScriptInterrupt = 0x00000002, /// - /// Host will call Idle, so enable idle processing. Otherwise, the runtime will manage + /// Host will call Idle, so enable idle processing. Otherwise, the runtime will manage /// memory slightly more aggressively. /// EnableIdleProcessing = 0x00000004, @@ -38,7 +38,7 @@ internal enum JsRuntimeAttributes DisableNativeCodeGeneration = 0x00000008, /// - /// Using Eval or Function constructor will throw an exception + /// Using eval or Function constructor will throw an exception /// [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Eval is a valid function name.")] DisableEval = 0x00000010 diff --git a/src/MsieJavaScriptEngine/JsRt/JsThreadServiceCallback.cs b/src/MsieJavaScriptEngine/JsRt/JsThreadServiceCallback.cs index 6f9df33..5ab1e0d 100644 --- a/src/MsieJavaScriptEngine/JsRt/JsThreadServiceCallback.cs +++ b/src/MsieJavaScriptEngine/JsRt/JsThreadServiceCallback.cs @@ -9,7 +9,7 @@ namespace MsieJavaScriptEngine.JsRt /// The host can specify a background thread service when creating a runtime. If /// specified, then background work items will be passed to the host using this callback. The /// host is expected to either begin executing the background work item immediately and return - /// true or return false and the runtime will handle the work item in-thread. + /// true or return false and the runtime will handle the work item in-thread. /// /// The callback for the background work item /// The data argument to be passed to the callback diff --git a/src/MsieJavaScriptEngine/JsRt/JsValueType.cs b/src/MsieJavaScriptEngine/JsRt/JsValueType.cs index b50cfa7..e51dcff 100644 --- a/src/MsieJavaScriptEngine/JsRt/JsValueType.cs +++ b/src/MsieJavaScriptEngine/JsRt/JsValueType.cs @@ -16,37 +16,37 @@ internal enum JsValueType Null = 1, /// - /// The value is a JavaScript number value + /// The value is a JavaScript Number value /// Number = 2, /// - /// The value is a JavaScript string value + /// The value is a JavaScript String value /// String = 3, /// - /// The value is a JavaScript Boolean value + /// The value is a JavaScript Boolean value /// Boolean = 4, /// - /// The value is a JavaScript object value + /// The value is a JavaScript Object value /// Object = 5, /// - /// The value is a JavaScript function object value + /// The value is a JavaScript Function object value /// Function = 6, /// - /// The value is a JavaScript error object value + /// The value is a JavaScript Error object value /// Error = 7, /// - /// The value is a JavaScript array object value + /// The value is a JavaScript Array object value /// Array = 8 } diff --git a/src/MsieJavaScriptEngine/JsRt/TypeMapper.cs b/src/MsieJavaScriptEngine/JsRt/TypeMapper.cs index 4297893..de3fd5a 100644 --- a/src/MsieJavaScriptEngine/JsRt/TypeMapper.cs +++ b/src/MsieJavaScriptEngine/JsRt/TypeMapper.cs @@ -1,18 +1,13 @@ using System; -#if NETSTANDARD using System.Collections.Concurrent; -#endif +using System.Collections.Generic; using System.Linq; -#if NETSTANDARD using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#endif -#if NETSTANDARD +using MsieJavaScriptEngine.Helpers; using MsieJavaScriptEngine.JsRt.Embedding; using MsieJavaScriptEngine.Utilities; -#endif namespace MsieJavaScriptEngine.JsRt { @@ -25,12 +20,16 @@ internal abstract class TypeMapper : IDisposable where TValue : struct where TFunction : Delegate { -#if NETSTANDARD /// /// Name of property to store the external object /// protected const string ExternalObjectPropertyName = "_MsieJavaScriptEngine_externalObject"; + /// + /// Flag for whether to allow the usage of reflection API in the script code + /// + protected readonly bool _allowReflection; + /// /// Storage for lazy-initialized embedded objects /// @@ -74,23 +73,17 @@ internal abstract class TypeMapper : IDisposable /// /// Flag indicating whether this object is disposed /// - private readonly InterlockedStatedFlag _disposedFlag = new InterlockedStatedFlag(); -#else - /// - /// JS engine mode - /// - protected readonly JsEngineMode _engineMode; + private InterlockedStatedFlag _disposedFlag = new InterlockedStatedFlag(); /// - /// Constructs an instance of type mapper + /// Constructs an instance of the type mapper /// - /// JS engine mode - protected TypeMapper(JsEngineMode engineMode) + /// Flag for whether to allow the usage of reflection API in the script code + protected TypeMapper(bool allowReflection) { - _engineMode = engineMode; + _allowReflection = allowReflection; } -#endif /// @@ -98,7 +91,6 @@ protected TypeMapper(JsEngineMode engineMode) /// /// Instance of host type /// JavaScript value created from an host object -#if NETSTANDARD public virtual TValue GetOrCreateScriptObject(object obj) { @@ -125,16 +117,12 @@ public virtual TValue GetOrCreateScriptObject(object obj) return embeddedObject.ScriptValue; } -#else - public abstract TValue GetOrCreateScriptObject(object obj); -#endif /// /// Creates a JavaScript value from an host type if the it does not already exist /// /// Host type /// JavaScript value created from an host type -#if NETSTANDARD public virtual TValue GetOrCreateScriptType(Type type) { if (!_embeddedTypeStorageInitialized) @@ -160,9 +148,6 @@ public virtual TValue GetOrCreateScriptType(Type type) return embeddedType.ScriptValue; } -#else - public abstract TValue GetOrCreateScriptType(Type type); -#endif /// /// Makes a mapping of value from the host type to a script type @@ -177,7 +162,6 @@ public virtual TValue GetOrCreateScriptType(Type type) /// The source value /// The mapped value public abstract object MapToHostType(TValue value); -#if NETSTANDARD protected abstract EmbeddedObject CreateEmbeddedObjectOrFunction(object obj); @@ -233,6 +217,53 @@ private void EmbeddedTypeFinalizeCallback(IntPtr ptr) embeddedTypeHandle.Free(); } + protected bool IsAvailableProperty(PropertyInfo property) + { + if (_allowReflection) + { + return true; + } + + bool isAvailable = ReflectionHelpers.IsAllowedProperty(property); + + return isAvailable; + } + + protected Dictionary> GetAvailableMethodGroups(MethodInfo[] methods) + { + int methodCount = methods.Length; + if (methodCount == 0) + { + return new Dictionary>(); + } + + var availableMethodGroups = new Dictionary>(methodCount); + + foreach (MethodInfo method in methods) + { + if (!ReflectionHelpers.IsFullyFledgedMethod(method) + || (!_allowReflection && !ReflectionHelpers.IsAllowedMethod(method))) + { + continue; + } + + string methodName = method.Name; + List methodGroup; + + if (availableMethodGroups.TryGetValue(methodName, out methodGroup)) + { + methodGroup.Add(method); + } + else + { + methodGroup = new List { method }; + availableMethodGroups.Add(methodName, methodGroup); + } + } + + return availableMethodGroups; + } + protected object[] GetHostItemMemberArguments(TValue[] args, int maxArgCount = -1) { if (args == null) @@ -282,7 +313,6 @@ protected static Exception UnwrapException(Exception exception) return originalException; } -#endif #region IDisposable implementation @@ -291,7 +321,6 @@ protected static Exception UnwrapException(Exception exception) /// public virtual void Dispose() { -#if NETSTANDARD if (_disposedFlag.Set()) { var lazyEmbeddedObjects = _lazyEmbeddedObjects; @@ -340,7 +369,6 @@ public virtual void Dispose() _embeddedTypeFinalizeCallback = null; } -#endif } #endregion diff --git a/src/MsieJavaScriptEngine/MsieJavaScriptEngine.csproj b/src/MsieJavaScriptEngine/MsieJavaScriptEngine.csproj index d86afd8..aa70849 100644 --- a/src/MsieJavaScriptEngine/MsieJavaScriptEngine.csproj +++ b/src/MsieJavaScriptEngine/MsieJavaScriptEngine.csproj @@ -1,88 +1,94 @@  - - MSIE JavaScript Engine for .NET - 3.0.7 - net40-client;net45;netstandard1.3;netstandard2.0 - 1.6.0 - 7.3 - Library - true - $(NoWarn);CS1591;NU5125 - true - true - $(Product) - Andrey Taritsyn - This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge Legacy (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). Project was based on the code of SassAndCoffee.JavaScript (http://github.com/paulcbetts/SassAndCoffee), Chakra Sample Hosts (http://github.com/panopticoncentral/chakra-host) and jsrt-dotnet (http://github.com/robpaveza/jsrt-dotnet). - LICENSE.txt - false - https://github.com/Taritsyn/MsieJavaScriptEngine - icon.png - https://github.com/Taritsyn/MsieJavaScriptEngine - git - true - true - snupkg - JavaScript;ECMAScript;MSIE;IE;Edge;Chakra - Fixed a error “Program crash after function call with too much parameters”. - en-US - ../../nuget - true - false - false - + + MSIE JavaScript Engine for .NET + 3.2.5 + net40-client;net45;netstandard1.3;netstandard2.0 + 1.6.0 + Library + true + $(NoWarn);CS1591;NU1605 + true + true + $(Product) + Andrey Taritsyn + This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge Legacy. + README.md + Apache-2.0 + https://github.com/Taritsyn/MsieJavaScriptEngine + https://raw.githubusercontent.com/Taritsyn/MsieJavaScriptEngine/master/images/MsieJavaScriptEngine_Logo_128x128.png + icon.png + https://github.com/Taritsyn/MsieJavaScriptEngine + git + true + true + snupkg + JavaScript;ECMAScript;MSIE;IE;Edge;Chakra + Added a `README.md` file to NuGet package. + en-US + ../../nuget + true + - - - + + + - - - - - - + + + + - - - - + + + + - - - + + + - - - - - + + + + + - - - $(PackageIcon) - true - false - - - $(PackageLicenseFile) - true - false - - - / - true - false - + + + $(PackageIcon) + true + false + + + / + true + false + + + / + true + false + - - readme.txt - true - - + + $(PackageReadmeFile) + true + + + / + true + + - - - + + + + + + + \ No newline at end of file diff --git a/src/MsieJavaScriptEngine/MsieJsEngine.cs b/src/MsieJavaScriptEngine/MsieJsEngine.cs index f93a473..e807c48 100644 --- a/src/MsieJavaScriptEngine/MsieJsEngine.cs +++ b/src/MsieJavaScriptEngine/MsieJsEngine.cs @@ -4,7 +4,7 @@ using System.Runtime.CompilerServices; using System.Text; -#if !NETSTANDARD +#if NETFRAMEWORK using MsieJavaScriptEngine.ActiveScript; #endif using MsieJavaScriptEngine.Helpers; @@ -93,7 +93,7 @@ public MsieJsEngine(JsEngineSettings settings) { processedEngineMode = JsEngineMode.ChakraIeJsRt; } -#if !NETSTANDARD +#if NETFRAMEWORK else if (ChakraActiveScriptJsEngine.IsSupported()) { processedEngineMode = JsEngineMode.ChakraActiveScript; @@ -106,7 +106,7 @@ public MsieJsEngine(JsEngineSettings settings) else { throw new JsEngineLoadException( -#if NETSTANDARD +#if !NETFRAMEWORK NetCoreStrings.Engine_JsEnginesNotFound #else NetFrameworkStrings.Engine_JsEnginesNotFound @@ -173,7 +173,7 @@ public MsieJsEngine(JsEngineSettings settings) break; case JsEngineMode.ChakraActiveScript: -#if !NETSTANDARD +#if NETFRAMEWORK if (previousMode != JsEngineMode.ChakraEdgeJsRt) { @@ -196,7 +196,7 @@ public MsieJsEngine(JsEngineSettings settings) string.Format(NetCoreStrings.Usage_JsEngineModeNotCompatibleWithNetCore, processedEngineMode)); #endif case JsEngineMode.Classic: -#if !NETSTANDARD +#if NETFRAMEWORK _jsEngine = new ClassicActiveScriptJsEngine(processedSettings); break; @@ -1044,10 +1044,10 @@ public T CallFunction(string functionName, params object[] args) } /// - /// Сhecks for the existence of a variable + /// Checks for the existence of a variable /// /// Name of variable - /// Result of check (true - exists; false - not exists + /// Result of check (true - exists; false - not exists /// /// /// @@ -1276,9 +1276,11 @@ public void RemoveVariable(string variableName) /// /// Embeds a host object to script code /// + /// + /// Allows to embed instances of simple classes (or structures) and delegates. + /// /// The name for the new global variable or function that will represent the object /// The object to expose - /// Allows to embed instances of simple classes (or structures) and delegates. /// /// /// @@ -1336,12 +1338,12 @@ public void EmbedHostObject(string itemName, object value) /// /// Embeds a host type to script code /// - /// The name for the new global variable that will represent the type - /// The type to expose /// /// Host types are exposed to script code in the form of objects whose properties and /// methods are bound to the type's static members. /// + /// The name for the new global variable that will represent the type + /// The type to expose /// /// /// diff --git a/src/MsieJavaScriptEngine/PACKAGE-DESCRIPTION.md b/src/MsieJavaScriptEngine/PACKAGE-DESCRIPTION.md new file mode 100644 index 0000000..85c08b4 --- /dev/null +++ b/src/MsieJavaScriptEngine/PACKAGE-DESCRIPTION.md @@ -0,0 +1,2 @@ +This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge Legacy (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). +Project was based on the code of [SassAndCoffee.JavaScript](https://github.com/anaisbetts/SassAndCoffee), [Chakra Sample Hosts](https://github.com/panopticoncentral/chakra-host) and [jsrt-dotnet](https://github.com/robpaveza/jsrt-dotnet). \ No newline at end of file diff --git a/src/MsieJavaScriptEngine/Resources/CommonStrings.Designer.cs b/src/MsieJavaScriptEngine/Resources/CommonStrings.Designer.cs index 2a1e873..07f2d33 100644 --- a/src/MsieJavaScriptEngine/Resources/CommonStrings.Designer.cs +++ b/src/MsieJavaScriptEngine/Resources/CommonStrings.Designer.cs @@ -21,7 +21,7 @@ internal class CommonStrings private static Lazy _resourceManager = new Lazy(() => new ResourceManager( "MsieJavaScriptEngine.Resources.CommonStrings", -#if NET40 +#if NET20 || NET30 || NET35 || NET40 typeof(CommonStrings).Assembly #else typeof(CommonStrings).GetTypeInfo().Assembly @@ -57,6 +57,14 @@ internal static CultureInfo Culture } } + /// + /// Looks up a localized string similar to "The parameter '{0}' must have a `{1}` type." + /// + internal static string Common_ArgumentHasIncorrectType + { + get { return GetString("Common_ArgumentHasIncorrectType"); } + } + /// /// Looks up a localized string similar to "The parameter '{0}' must be a non-empty string." /// @@ -241,6 +249,110 @@ internal static string Runtime_FunctionNotExist get { return GetString("Runtime_FunctionNotExist"); } } + /// + /// Looks up a localized string similar to "During invocation of the host delegate an error has occurred - “{0}”." + /// + internal static string Runtime_HostDelegateInvocationFailed + { + get { return GetString("Runtime_HostDelegateInvocationFailed"); } + } + + /// + /// Looks up a localized string similar to "During getting value of '{0}' field of the host object an error has occurred - “{1}”." + /// + internal static string Runtime_HostObjectFieldGettingFailed + { + get { return GetString("Runtime_HostObjectFieldGettingFailed"); } + } + + /// + /// Looks up a localized string similar to "During setting value of '{0}' field of the host object an error has occurred - “{1}”." + /// + internal static string Runtime_HostObjectFieldSettingFailed + { + get { return GetString("Runtime_HostObjectFieldSettingFailed"); } + } + + /// + /// Looks up a localized string similar to "During invocation of '{0}' method of the host object an error has occurred - “{1}”." + /// + internal static string Runtime_HostObjectMethodInvocationFailed + { + get { return GetString("Runtime_HostObjectMethodInvocationFailed"); } + } + + /// + /// Looks up a localized string similar to "During getting value of '{0}' property of the host object an error has occurred - “{1}”." + /// + internal static string Runtime_HostObjectPropertyGettingFailed + { + get { return GetString("Runtime_HostObjectPropertyGettingFailed"); } + } + + /// + /// Looks up a localized string similar to "During setting value of '{0}' property of the host object an error has occurred - “{1}”." + /// + internal static string Runtime_HostObjectPropertySettingFailed + { + get { return GetString("Runtime_HostObjectPropertySettingFailed"); } + } + + /// + /// Looks up a localized string similar to "During invocation of constructor of the `{0}` host type an error has occurred - “{1}”." + /// + internal static string Runtime_HostTypeConstructorInvocationFailed + { + get { return GetString("Runtime_HostTypeConstructorInvocationFailed"); } + } + + /// + /// Looks up a localized string similar to "Could not create instance of the `{0}` host type, because it does not have any public constructor." + /// + internal static string Runtime_HostTypeConstructorNotFound + { + get { return GetString("Runtime_HostTypeConstructorNotFound"); } + } + + /// + /// Looks up a localized string similar to "During getting value of '{0}' field of the `{1}` host type an error has occurred - “{2}”." + /// + internal static string Runtime_HostTypeFieldGettingFailed + { + get { return GetString("Runtime_HostTypeFieldGettingFailed"); } + } + + /// + /// Looks up a localized string similar to "During setting value of '{0}' field of the `{1}` host type an error has occurred - “{2}”." + /// + internal static string Runtime_HostTypeFieldSettingFailed + { + get { return GetString("Runtime_HostTypeFieldSettingFailed"); } + } + + /// + /// Looks up a localized string similar to "During invocation of '{0}' method of the `{1}` host type an error has occurred - “{2}”." + /// + internal static string Runtime_HostTypeMethodInvocationFailed + { + get { return GetString("Runtime_HostTypeMethodInvocationFailed"); } + } + + /// + /// Looks up a localized string similar to "During getting value of '{0}' property of the `{1}` host type an error has occurred - “{2}”." + /// + internal static string Runtime_HostTypePropertyGettingFailed + { + get { return GetString("Runtime_HostTypePropertyGettingFailed"); } + } + + /// + /// Looks up a localized string similar to "During setting value of '{0}' property of the host type `{1}` an error has occurred - “{2}”." + /// + internal static string Runtime_HostTypePropertySettingFailed + { + get { return GetString("Runtime_HostTypePropertySettingFailed"); } + } + /// /// Looks up a localized string similar to "The '{0}' line of the script call stack has an incorrect format." /// @@ -249,6 +361,30 @@ internal static string Runtime_InvalidCallStackLineFormat get { return GetString("Runtime_InvalidCallStackLineFormat"); } } + /// + /// Looks up a localized string similar to "Could not retrieve field '{0}' of the host object, because there was an invalid `this` context." + /// + internal static string Runtime_InvalidThisContextForHostObjectField + { + get { return GetString("Runtime_InvalidThisContextForHostObjectField"); } + } + + /// + /// Looks up a localized string similar to "Could not call method '{0}' of the host object, because there was an invalid `this` context." + /// + internal static string Runtime_InvalidThisContextForHostObjectMethod + { + get { return GetString("Runtime_InvalidThisContextForHostObjectMethod"); } + } + + /// + /// Looks up a localized string similar to "Could not retrieve property '{0}' of the host object, because there was an invalid `this` context." + /// + internal static string Runtime_InvalidThisContextForHostObjectProperty + { + get { return GetString("Runtime_InvalidThisContextForHostObjectProperty"); } + } + /// /// Looks up a localized string similar to "Script execution was interrupted." /// @@ -258,7 +394,23 @@ internal static string Runtime_ScriptInterrupted } /// - /// Looks up a localized string similar to "Сannot execute a '{0}' file, because it is empty." + /// Looks up a localized string similar to "Could not find suitable constructor or not enough arguments to invoke of constructor of the `{0}`..." + /// + internal static string Runtime_SuitableConstructorOfHostTypeNotFound + { + get { return GetString("Runtime_SuitableConstructorOfHostTypeNotFound"); } + } + + /// + /// Looks up a localized string similar to "Could not find suitable method or not enough arguments to invoke of '{0}' method of the host object." + /// + internal static string Runtime_SuitableMethodOfHostObjectNotFound + { + get { return GetString("Runtime_SuitableMethodOfHostObjectNotFound"); } + } + + /// + /// Looks up a localized string similar to "Cannot execute a '{0}' file, because it is empty." /// internal static string Usage_CannotExecuteEmptyFile { @@ -266,7 +418,7 @@ internal static string Usage_CannotExecuteEmptyFile } /// - /// Looks up a localized string similar to "Сannot execute a '{0}' resource, because it is empty." + /// Looks up a localized string similar to "Cannot execute a '{0}' resource, because it is empty." /// internal static string Usage_CannotExecuteEmptyResource { @@ -274,7 +426,7 @@ internal static string Usage_CannotExecuteEmptyResource } /// - /// Looks up a localized string similar to "Сannot execute a pre-compiled script, because it was created for another mode with name `{0}`." + /// Looks up a localized string similar to "Cannot execute a pre-compiled script, because it was created for another mode with name `{0}`." /// internal static string Usage_CannotExecutePrecompiledScriptForAnotherJsEngineMode { @@ -282,7 +434,7 @@ internal static string Usage_CannotExecutePrecompiledScriptForAnotherJsEngineMod } /// - /// Looks up a localized string similar to "Сannot pre-compile a '{0}' file, because it is empty." + /// Looks up a localized string similar to "Cannot pre-compile a '{0}' file, because it is empty." /// internal static string Usage_CannotPrecompileEmptyFile { @@ -290,7 +442,7 @@ internal static string Usage_CannotPrecompileEmptyFile } /// - /// Looks up a localized string similar to "Сannot pre-compile a '{0}' resource, because it is empty." + /// Looks up a localized string similar to "Cannot pre-compile a '{0}' resource, because it is empty." /// internal static string Usage_CannotPrecompileEmptyResource { @@ -385,14 +537,6 @@ internal static string Usage_JsEnginesConflictInProcess get { return GetString("Usage_JsEnginesConflictInProcess"); } } - /// - /// Looks up a localized string similar to "It is prohibited to use the Chakra JsRT and Chakra ActiveScript engines on one machine at a time." - /// - internal static string Usage_JsEnginesConflictOnMachine - { - get { return GetString("Usage_JsEnginesConflictOnMachine"); } - } - /// /// Looks up a localized string similar to "The type of return value `{0}` is not supported." /// diff --git a/src/MsieJavaScriptEngine/Resources/CommonStrings.resx b/src/MsieJavaScriptEngine/Resources/CommonStrings.resx index 4abc615..e950347 100644 --- a/src/MsieJavaScriptEngine/Resources/CommonStrings.resx +++ b/src/MsieJavaScriptEngine/Resources/CommonStrings.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + The parameter '{0}' must have a `{1}` type. + The parameter '{0}' must be a non-empty string. @@ -186,26 +189,80 @@ The function with the name '{0}' does not exist. + + During invocation of the host delegate an error has occurred - “{0}”. + + + During getting value of '{0}' field of the host object an error has occurred - “{1}”. + + + During setting value of '{0}' field of the host object an error has occurred - “{1}”. + + + During invocation of '{0}' method of the host object an error has occurred - “{1}”. + + + During getting value of '{0}' property of the host object an error has occurred - “{1}”. + + + During setting value of '{0}' property of the host object an error has occurred - “{1}”. + + + During invocation of constructor of the `{0}` host type an error has occurred - “{1}”. + + + Could not create instance of the `{0}` host type, because it does not have any public constructor. + + + During getting value of '{0}' field of the `{1}` host type an error has occurred - “{2}”. + + + During setting value of '{0}' field of the `{1}` host type an error has occurred - “{2}”. + + + During invocation of '{0}' method of the `{1}` host type an error has occurred - “{2}”. + + + During getting value of '{0}' property of the `{1}` host type an error has occurred - “{2}”. + + + During setting value of '{0}' property of the host type `{1}` an error has occurred - “{2}”. + The '{0}' line of the script call stack has an incorrect format. + + Could not retrieve field '{0}' of the host object, because there was an invalid `this` context. + + + Could not call method '{0}' of the host object, because there was an invalid `this` context. + + + Could not retrieve property '{0}' of the host object, because there was an invalid `this` context. + Script execution was interrupted. + + Could not find suitable constructor or not enough arguments to invoke of constructor of the `{0}` host type. + + + Could not find suitable method or not enough arguments to invoke of '{0}' method of the host object. + - Сannot execute a '{0}' file, because it is empty. + Cannot execute a '{0}' file, because it is empty. - Сannot execute a '{0}' resource, because it is empty. + Cannot execute a '{0}' resource, because it is empty. - Сannot execute a pre-compiled script, because it was created for another mode with name `{0}`. + Cannot execute a pre-compiled script, because it was created for another mode with name `{0}`. - Сannot pre-compile a '{0}' file, because it is empty. + Cannot pre-compile a '{0}' file, because it is empty. - Сannot pre-compile a '{0}' resource, because it is empty. + Cannot pre-compile a '{0}' resource, because it is empty. The embedded host object '{0}' has a type `{1}`, which is not supported. @@ -240,9 +297,6 @@ It is prohibited to use the {0} and {1} engines in one process. - - It is prohibited to use the Chakra JsRT and Chakra ActiveScript engines on one machine at a time. - The type of return value `{0}` is not supported. diff --git a/src/MsieJavaScriptEngine/Resources/CommonStrings.ru-ru.Designer.cs b/src/MsieJavaScriptEngine/Resources/CommonStrings.ru-RU.Designer.cs similarity index 100% rename from src/MsieJavaScriptEngine/Resources/CommonStrings.ru-ru.Designer.cs rename to src/MsieJavaScriptEngine/Resources/CommonStrings.ru-RU.Designer.cs diff --git a/src/MsieJavaScriptEngine/Resources/CommonStrings.ru-ru.resx b/src/MsieJavaScriptEngine/Resources/CommonStrings.ru-RU.resx similarity index 73% rename from src/MsieJavaScriptEngine/Resources/CommonStrings.ru-ru.resx rename to src/MsieJavaScriptEngine/Resources/CommonStrings.ru-RU.resx index 6e709db..76124ab 100644 --- a/src/MsieJavaScriptEngine/Resources/CommonStrings.ru-ru.resx +++ b/src/MsieJavaScriptEngine/Resources/CommonStrings.ru-RU.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Параметр с именем "{0}" должен иметь тип `{1}`! + Параметр с именем "{0}" не должен содержать пустую строку! @@ -186,12 +189,66 @@ Функция с именем "{0}" не существует! + + Во время вызова делегата хоста произошла ошибка - «{0}»! + + + Во время получения значения поля "{0}" объекта хоста произошла ошибка - «{1}»! + + + Во время присваивания значения полю "{0}" объекта хоста произошла ошибка - «{1}»! + + + Во время вызова метода "{0}" объекта хоста произошла ошибка - «{1}»! + + + Во время получения значения свойства "{0}" объекта хоста произошла ошибка - «{1}»! + + + Во время присваивания значения свойству "{0}" объекта хоста произошла ошибка - «{1}»! + + + Во время вызова конструктора типа хоста `{0}` произошла ошибка - «{1}»! + + + Не удается создать экземпляр типа хоста `{0}`, потому что он не имеет ни одного публичного конструктора! + + + Во время получения значения поля "{0}" типа хоста `{1}` произошла ошибка - «{2}»! + + + Во время присваивания значения полю "{0}" типа хоста `{1}` произошла ошибка - «{2}»! + + + Во время вызова метода "{0}" типа хоста `{1}` произошла ошибка - «{2}»! + + + Во время получения значения свойства "{0}" типа хоста `{1}` произошла ошибка - «{2}»! + + + Во время присваивания значения свойству "{0}" типа хоста `{1}` произошла ошибка - «{2}»! + Строка стека вызовов скрипта "{0}" имеет некорректный формат! + + Не удалось получить поле "{0}" объекта хоста, потому что контекст `this` недействителен! + + + Не удалось вызвать метод "{0}" объекта хоста, потому что контекст `this` недействителен! + + + Не удалось получить свойство "{0}" объекта хоста, потому что контекст `this` недействителен! + Выполнение скрипта было прервано! + + Не получается найти подходящий конструктор или не хватает аргументов для вызова конструктора `{0}` типа хоста! + + + Не получается найти подходящий метод или не хватает аргументов для вызова метода "{0}" объекта хоста! + Нельзя выполнить файл "{0}", потому что он пустой! @@ -240,9 +297,6 @@ Нельзя использовать {0} и {1} движки в одном процессе. - - Нельзя использовать Chakra JsRT и Chakra ActiveScript движки на одном компьютере одновременно. - Тип возвращаемого значения `{0}` не поддерживается! diff --git a/src/MsieJavaScriptEngine/Resources/ES5.js b/src/MsieJavaScriptEngine/Resources/ES5.js index 9ff4f4c..821c180 100644 --- a/src/MsieJavaScriptEngine/Resources/ES5.js +++ b/src/MsieJavaScriptEngine/Resources/ES5.js @@ -1,8 +1,8 @@ /*! * This polyfill based on code of the following libraries: -* 1. Douglas Crockford's ECMAScript 5 Polyfill v0.1 - http://nuget.org/packages/ES5 -* 2. MDN JavaScript Polyfills - http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference -* 3. Steven Levithan's Cross-Browser Split v1.1.1 - http://blog.stevenlevithan.com/archives/cross-browser-split +* 1. Douglas Crockford's ECMAScript 5 Polyfill v0.1 - https://www.nuget.org/packages/ES5 +* 2. MDN JavaScript Polyfills - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference +* 3. Steven Levithan's Cross-Browser Split v1.1.1 - https://blog.stevenlevithan.com/archives/cross-browser-split */ (function (undefined) { diff --git a/src/MsieJavaScriptEngine/Resources/NetCoreStrings.Designer.cs b/src/MsieJavaScriptEngine/Resources/NetCoreStrings.Designer.cs index 8941c62..21c4dc4 100644 --- a/src/MsieJavaScriptEngine/Resources/NetCoreStrings.Designer.cs +++ b/src/MsieJavaScriptEngine/Resources/NetCoreStrings.Designer.cs @@ -21,7 +21,7 @@ internal class NetCoreStrings private static Lazy _resourceManager = new Lazy(() => new ResourceManager( "MsieJavaScriptEngine.Resources.NetCoreStrings", -#if NET40 +#if NET20 || NET30 || NET35 || NET40 typeof(NetCoreStrings).Assembly #else typeof(NetCoreStrings).GetTypeInfo().Assembly @@ -57,14 +57,6 @@ internal static CultureInfo Culture } } - /// - /// Looks up a localized string similar to "The parameter '{0}' must have a `{1}` type." - /// - internal static string Common_ArgumentHasIncorrectType - { - get { return GetString("Common_ArgumentHasIncorrectType"); } - } - /// /// Looks up a localized string similar to "Could not found none of the JavaScript engines, which would be compatible with .NET Core. Perhaps..." /// @@ -73,150 +65,6 @@ internal static string Engine_JsEnginesNotFound get { return GetString("Engine_JsEnginesNotFound"); } } - /// - /// Looks up a localized string similar to "During invocation of the host delegate an error has occurred - “{0}”." - /// - internal static string Runtime_HostDelegateInvocationFailed - { - get { return GetString("Runtime_HostDelegateInvocationFailed"); } - } - - /// - /// Looks up a localized string similar to "During getting value of '{0}' field of the host object an error has occurred - “{1}”." - /// - internal static string Runtime_HostObjectFieldGettingFailed - { - get { return GetString("Runtime_HostObjectFieldGettingFailed"); } - } - - /// - /// Looks up a localized string similar to "During setting value of '{0}' field of the host object an error has occurred - “{1}”." - /// - internal static string Runtime_HostObjectFieldSettingFailed - { - get { return GetString("Runtime_HostObjectFieldSettingFailed"); } - } - - /// - /// Looks up a localized string similar to "During invocation of '{0}' method of the host object an error has occurred - “{1}”." - /// - internal static string Runtime_HostObjectMethodInvocationFailed - { - get { return GetString("Runtime_HostObjectMethodInvocationFailed"); } - } - - /// - /// Looks up a localized string similar to "During getting value of '{0}' property of the host object an error has occurred - “{1}”." - /// - internal static string Runtime_HostObjectPropertyGettingFailed - { - get { return GetString("Runtime_HostObjectPropertyGettingFailed"); } - } - - /// - /// Looks up a localized string similar to "During setting value of '{0}' property of the host object an error has occurred - “{1}”." - /// - internal static string Runtime_HostObjectPropertySettingFailed - { - get { return GetString("Runtime_HostObjectPropertySettingFailed"); } - } - - /// - /// Looks up a localized string similar to "During invocation of constructor of the `{0}` host type an error has occurred - “{1}”." - /// - internal static string Runtime_HostTypeConstructorInvocationFailed - { - get { return GetString("Runtime_HostTypeConstructorInvocationFailed"); } - } - - /// - /// Looks up a localized string similar to "Could not create instance of the `{0}` host type, because it does not have any public constructor." - /// - internal static string Runtime_HostTypeConstructorNotFound - { - get { return GetString("Runtime_HostTypeConstructorNotFound"); } - } - - /// - /// Looks up a localized string similar to "During getting value of '{0}' field of the `{1}` host type an error has occurred - “{2}”." - /// - internal static string Runtime_HostTypeFieldGettingFailed - { - get { return GetString("Runtime_HostTypeFieldGettingFailed"); } - } - - /// - /// Looks up a localized string similar to "During setting value of '{0}' field of the `{1}` host type an error has occurred - “{2}”." - /// - internal static string Runtime_HostTypeFieldSettingFailed - { - get { return GetString("Runtime_HostTypeFieldSettingFailed"); } - } - - /// - /// Looks up a localized string similar to "During invocation of '{0}' method of the `{1}` host type an error has occurred - “{2}”." - /// - internal static string Runtime_HostTypeMethodInvocationFailed - { - get { return GetString("Runtime_HostTypeMethodInvocationFailed"); } - } - - /// - /// Looks up a localized string similar to "During getting value of '{0}' property of the `{1}` host type an error has occurred - “{2}”." - /// - internal static string Runtime_HostTypePropertyGettingFailed - { - get { return GetString("Runtime_HostTypePropertyGettingFailed"); } - } - - /// - /// Looks up a localized string similar to "During setting value of '{0}' property of the host type `{1}` an error has occurred - “{2}”." - /// - internal static string Runtime_HostTypePropertySettingFailed - { - get { return GetString("Runtime_HostTypePropertySettingFailed"); } - } - - /// - /// Looks up a localized string similar to "Could not retrieve field '{0}' of the host object, because there was an invalid `this` context." - /// - internal static string Runtime_InvalidThisContextForHostObjectField - { - get { return GetString("Runtime_InvalidThisContextForHostObjectField"); } - } - - /// - /// Looks up a localized string similar to "Could not call method '{0}' of the host object, because there was an invalid `this` context." - /// - internal static string Runtime_InvalidThisContextForHostObjectMethod - { - get { return GetString("Runtime_InvalidThisContextForHostObjectMethod"); } - } - - /// - /// Looks up a localized string similar to "Could not retrieve property '{0}' of the host object, because there was an invalid `this` context." - /// - internal static string Runtime_InvalidThisContextForHostObjectProperty - { - get { return GetString("Runtime_InvalidThisContextForHostObjectProperty"); } - } - - /// - /// Looks up a localized string similar to "Could not find suitable constructor or not enough arguments to invoke of constructor of the `{0}`..." - /// - internal static string Runtime_SuitableConstructorOfHostTypeNotFound - { - get { return GetString("Runtime_SuitableConstructorOfHostTypeNotFound"); } - } - - /// - /// Looks up a localized string similar to "Could not find suitable method or not enough arguments to invoke of '{0}' method of the host object." - /// - internal static string Runtime_SuitableMethodOfHostObjectNotFound - { - get { return GetString("Runtime_SuitableMethodOfHostObjectNotFound"); } - } - /// /// Looks up a localized string similar to "The '{0}' mode of JavaScript engine is not compatible with .NET Core." /// diff --git a/src/MsieJavaScriptEngine/Resources/NetCoreStrings.resx b/src/MsieJavaScriptEngine/Resources/NetCoreStrings.resx index 532bf65..e969324 100644 --- a/src/MsieJavaScriptEngine/Resources/NetCoreStrings.resx +++ b/src/MsieJavaScriptEngine/Resources/NetCoreStrings.resx @@ -117,66 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - The parameter '{0}' must have a `{1}` type. - Could not found none of the JavaScript engines, which would be compatible with .NET Core. Perhaps you have not installed the Microsoft Edge Legacy or Internet Explorer 11 browser. - - During invocation of the host delegate an error has occurred - “{0}”. - - - During getting value of '{0}' field of the host object an error has occurred - “{1}”. - - - During setting value of '{0}' field of the host object an error has occurred - “{1}”. - - - During invocation of '{0}' method of the host object an error has occurred - “{1}”. - - - During getting value of '{0}' property of the host object an error has occurred - “{1}”. - - - During setting value of '{0}' property of the host object an error has occurred - “{1}”. - - - During invocation of constructor of the `{0}` host type an error has occurred - “{1}”. - - - Could not create instance of the `{0}` host type, because it does not have any public constructor. - - - During getting value of '{0}' field of the `{1}` host type an error has occurred - “{2}”. - - - During setting value of '{0}' field of the `{1}` host type an error has occurred - “{2}”. - - - During invocation of '{0}' method of the `{1}` host type an error has occurred - “{2}”. - - - During getting value of '{0}' property of the `{1}` host type an error has occurred - “{2}”. - - - During setting value of '{0}' property of the host type `{1}` an error has occurred - “{2}”. - - - Could not retrieve field '{0}' of the host object, because there was an invalid `this` context. - - - Could not call method '{0}' of the host object, because there was an invalid `this` context. - - - Could not retrieve property '{0}' of the host object, because there was an invalid `this` context. - - - Could not find suitable constructor or not enough arguments to invoke of constructor of the `{0}` host type. - - - Could not find suitable method or not enough arguments to invoke of '{0}' method of the host object. - The '{0}' mode of JavaScript engine is not compatible with .NET Core. diff --git a/src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-ru.Designer.cs b/src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-RU.Designer.cs similarity index 100% rename from src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-ru.Designer.cs rename to src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-RU.Designer.cs diff --git a/src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-ru.resx b/src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-RU.resx similarity index 56% rename from src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-ru.resx rename to src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-RU.resx index 4b06f90..5835a08 100644 --- a/src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-ru.resx +++ b/src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-RU.resx @@ -117,66 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Параметр с именем "{0}" должен иметь тип `{1}`! - Не удалось найти ни один из JavaScript-движков, который был бы совместим с .NET Core! Возможно, на вашем компьютере не установлен браузер Microsoft Edge Legacy или Internet Explorer 11. - - Во время вызова делегата хоста произошла ошибка - «{0}»! - - - Во время получения значения поля "{0}" объекта хоста произошла ошибка - «{1}»! - - - Во время присваивания значения полю "{0}" объекта хоста произошла ошибка - «{1}»! - - - Во время вызова метода "{0}" объекта хоста произошла ошибка - «{1}»! - - - Во время получения значения свойства "{0}" объекта хоста произошла ошибка - «{1}»! - - - Во время присваивания значения свойству "{0}" объекта хоста произошла ошибка - «{1}»! - - - Во время вызова конструктора типа хоста `{0}` произошла ошибка - «{1}»! - - - Не удается создать экземпляр типа хоста `{0}`, потому что он не имеет ни одного публичного конструктора! - - - Во время получения значения поля "{0}" типа хоста `{1}` произошла ошибка - «{2}»! - - - Во время присваивания значения полю "{0}" типа хоста `{1}` произошла ошибка - «{2}»! - - - Во время вызова метода "{0}" типа хоста `{1}` произошла ошибка - «{2}»! - - - Во время получения значения свойства "{0}" типа хоста `{1}` произошла ошибка - «{2}»! - - - Во время присваивания значения свойству "{0}" типа хоста `{1}` произошла ошибка - «{2}»! - - - Не удалось получить поле "{0}" объекта хоста, потому что контекст `this` недействителен! - - - Не удалось вызвать метод "{0}" объекта хоста, потому что контекст `this` недействителен! - - - Не удалось получить свойство "{0}" объекта хоста, потому что контекст `this` недействителен! - - - Не получается найти подходящий конструктор или не хватает аргументов для вызова конструктора `{0}` типа хоста! - - - Не получается найти подходящий метод или не хватает аргументов для вызова метода "{0}" объекта хоста! - Режим JavaScript-движка "{0}" не совместим с .NET Core! diff --git a/src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.Designer.cs b/src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.Designer.cs index feea37f..b5404bc 100644 --- a/src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.Designer.cs +++ b/src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.Designer.cs @@ -21,7 +21,7 @@ internal class NetFrameworkStrings private static Lazy _resourceManager = new Lazy(() => new ResourceManager( "MsieJavaScriptEngine.Resources.NetFrameworkStrings", -#if NET40 +#if NET20 || NET30 || NET35 || NET40 typeof(NetFrameworkStrings).Assembly #else typeof(NetFrameworkStrings).GetTypeInfo().Assembly diff --git a/src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.ru-ru.Designer.cs b/src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.ru-RU.Designer.cs similarity index 100% rename from src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.ru-ru.Designer.cs rename to src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.ru-RU.Designer.cs diff --git a/src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.ru-ru.resx b/src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.ru-RU.resx similarity index 100% rename from src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.ru-ru.resx rename to src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.ru-RU.resx diff --git a/src/MsieJavaScriptEngine/Resources/json2.js b/src/MsieJavaScriptEngine/Resources/json2.js index f6fada6..b43526d 100644 --- a/src/MsieJavaScriptEngine/Resources/json2.js +++ b/src/MsieJavaScriptEngine/Resources/json2.js @@ -1,5 +1,5 @@ // json2.js -// 2017-06-12 +// 2023-05-10 // Public Domain. // NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. diff --git a/src/MsieJavaScriptEngine/ScriptDispatcher.cs b/src/MsieJavaScriptEngine/ScriptDispatcher.cs index ad5041e..d3ba763 100644 --- a/src/MsieJavaScriptEngine/ScriptDispatcher.cs +++ b/src/MsieJavaScriptEngine/ScriptDispatcher.cs @@ -56,7 +56,7 @@ public ScriptDispatcher() /// Constructs an instance of script dispatcher /// /// The maximum stack size, in bytes, to be used by the thread, - /// or 0 to use the default maximum stack size specified in the header for the executable. + /// or 0 to use the default maximum stack size specified in the header for the executable. public ScriptDispatcher(int maxStackSize) { _thread = new Thread(StartThread, maxStackSize) @@ -150,7 +150,7 @@ private void ExecuteTask(ScriptTask task) /// /// Runs a specified delegate on the thread with modified stack size, - /// and returns its result as an . + /// and returns its result as an . /// Blocks until the invocation of delegate is completed. /// /// The type of the return value of the method, @@ -257,7 +257,7 @@ private abstract class ScriptTask : IDisposable /// /// Gets a exception, that occurred during the invocation of delegate. - /// If no exception has occurred, this will be null. + /// If no exception has occurred, this will be null. /// public Exception Exception { diff --git a/src/MsieJavaScriptEngine/Undefined.cs b/src/MsieJavaScriptEngine/Undefined.cs index f44eea9..a7097fc 100644 --- a/src/MsieJavaScriptEngine/Undefined.cs +++ b/src/MsieJavaScriptEngine/Undefined.cs @@ -1,12 +1,12 @@ namespace MsieJavaScriptEngine { /// - /// Represents an JS undefined type + /// Represents an JS undefined type /// public sealed class Undefined { /// - /// Gets a one and only undefined instance + /// Gets a one and only undefined instance /// public static readonly Undefined Value = new Undefined(); diff --git a/src/MsieJavaScriptEngine/Utilities/TypeConverter.cs b/src/MsieJavaScriptEngine/Utilities/TypeConverter.cs index e40c5ec..38bdc4a 100644 --- a/src/MsieJavaScriptEngine/Utilities/TypeConverter.cs +++ b/src/MsieJavaScriptEngine/Utilities/TypeConverter.cs @@ -64,7 +64,7 @@ public static object ConvertToType(object value, Type targetType) /// The type to convert the value to /// The value to convert /// The value that has been converted to the target type - /// Result of conversion (true - success; false - failure) + /// Result of conversion (true - success; false - failure) public static bool TryConvertToType(object value, out T convertedValue) { object resultValue; @@ -82,7 +82,7 @@ public static bool TryConvertToType(object value, out T convertedValue) /// The value to convert /// The type to convert the value to /// The value that has been converted to the target type - /// Result of conversion (true - success; false - failure) + /// Result of conversion (true - success; false - failure) public static bool TryConvertToType(object value, Type targetType, out object convertedValue) { bool result = ConvertObjectToType(value, targetType, false, out convertedValue); @@ -94,7 +94,7 @@ public static bool TryConvertToType(object value, Type targetType, out object co /// Checks whether .NET type is primitive /// /// .NET type - /// Result of check (true - is primitive; false - is not primitive) + /// Result of check (true - is primitive; false - is not primitive) internal static bool IsPrimitiveType(Type type) { TypeCode typeCode = type.GetTypeCode(); @@ -107,7 +107,7 @@ internal static bool IsPrimitiveType(Type type) /// Checks whether .NET type is primitive /// /// .NET type code - /// Result of check (true - is primitive; false - is not primitive) + /// Result of check (true - is primitive; false - is not primitive) internal static bool IsPrimitiveType(TypeCode typeCode) { bool result = _primitiveTypeCodes.Contains(typeCode); diff --git a/src/MsieJavaScriptEngine/Utilities/Utils.cs b/src/MsieJavaScriptEngine/Utilities/Utils.cs index 15979a2..0c6838a 100644 --- a/src/MsieJavaScriptEngine/Utilities/Utils.cs +++ b/src/MsieJavaScriptEngine/Utilities/Utils.cs @@ -13,7 +13,7 @@ internal static class Utils /// /// Determines whether the current process is a 64-bit process /// - /// true if the process is 64-bit; otherwise, false + /// true if the process is 64-bit; otherwise, false [MethodImpl((MethodImplOptions)256 /* AggressiveInlining */)] public static bool Is64BitProcess() { @@ -26,56 +26,12 @@ public static bool Is64BitProcess() return is64Bit; } - /// - /// Gets a content of the embedded resource as string - /// - /// The case-sensitive resource name without the namespace of the specified type - /// The type, that determines the assembly and whose namespace is used to scope - /// the resource name - /// Сontent of the embedded resource as string - public static string GetResourceAsString(string resourceName, Type type) - { - if (resourceName == null) - { - throw new ArgumentNullException( - nameof(resourceName), - string.Format(CommonStrings.Common_ArgumentIsNull, nameof(resourceName)) - ); - } - - if (type == null) - { - throw new ArgumentNullException( - nameof(type), - string.Format(CommonStrings.Common_ArgumentIsNull, nameof(type)) - ); - } - - if (string.IsNullOrWhiteSpace(resourceName)) - { - throw new ArgumentException( - string.Format(CommonStrings.Common_ArgumentIsEmpty, nameof(resourceName)), - nameof(resourceName) - ); - } - -#if NET40 - Assembly assembly = type.Assembly; -#else - Assembly assembly = type.GetTypeInfo().Assembly; -#endif - string nameSpace = type.Namespace; - string resourceFullName = nameSpace != null ? nameSpace + "." + resourceName : resourceName; - - return InnerGetResourceAsString(resourceFullName, assembly); - } - /// /// Gets a content of the embedded resource as string /// /// The case-sensitive resource name /// The assembly, which contains the embedded resource - /// Сontent of the embedded resource as string + /// Content of the embedded resource as string public static string GetResourceAsString(string resourceName, Assembly assembly) { if (resourceName == null) @@ -102,11 +58,6 @@ public static string GetResourceAsString(string resourceName, Assembly assembly) ); } - return InnerGetResourceAsString(resourceName, assembly); - } - - private static string InnerGetResourceAsString(string resourceName, Assembly assembly) - { using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { if (stream == null) diff --git a/src/MsieJavaScriptEngine/bundleconfig.json b/src/MsieJavaScriptEngine/bundleconfig.json deleted file mode 100644 index de17583..0000000 --- a/src/MsieJavaScriptEngine/bundleconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "outputFileName": "Resources/ES5.min.js", - "inputFiles": [ - "Resources/ES5.js" - ] - }, - { - "outputFileName": "Resources/json2.min.js", - "inputFiles": [ - "Resources/json2.js" - ] - } -] \ No newline at end of file diff --git a/src/MsieJavaScriptEngine/package.json b/src/MsieJavaScriptEngine/package.json new file mode 100644 index 0000000..2d65043 --- /dev/null +++ b/src/MsieJavaScriptEngine/package.json @@ -0,0 +1,12 @@ +{ + "name": "MsieJavaScriptEngine", + "version": "3.2.5", + "devDependencies": { + "uglify-js": "3.16.1" + }, + "scripts": { + "minify-es5-js": "uglifyjs ./Resources/ES5.js --output ./Resources/ES5.min.js --config-file ./.uglifyjsrc", + "minify-json2-js": "uglifyjs ./Resources/json2.js --output ./Resources/json2.min.js --config-file ./.uglifyjsrc", + "minify-js": "npm run -s minify-es5-js && npm run -s minify-json2-js" + } +} diff --git a/src/MsieJavaScriptEngine/readme.txt b/src/MsieJavaScriptEngine/readme.txt index f283212..c1ec1c6 100644 --- a/src/MsieJavaScriptEngine/readme.txt +++ b/src/MsieJavaScriptEngine/readme.txt @@ -1,11 +1,11 @@  -------------------------------------------------------------------------------- - README file for MSIE JavaScript Engine for .NET v3.0.7 + README file for MSIE JavaScript Engine for .NET v3.2.5 -------------------------------------------------------------------------------- - Copyright (c) 2012-2020 Andrey Taritsyn - http://www.taritsyn.ru + Copyright (c) 2012-2024 Andrey Taritsyn - http://www.taritsyn.ru =========== @@ -14,16 +14,16 @@ This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge Legacy (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). Project was based on the code of - SassAndCoffee.JavaScript (http://github.com/paulcbetts/SassAndCoffee), - Chakra Sample Hosts (http://github.com/panopticoncentral/chakra-host) and - jsrt-dotnet (http://github.com/robpaveza/jsrt-dotnet). + SassAndCoffee.JavaScript (https://github.com/anaisbetts/SassAndCoffee), + Chakra Sample Hosts (https://github.com/panopticoncentral/chakra-host) and + jsrt-dotnet (https://github.com/robpaveza/jsrt-dotnet). ============= RELEASE NOTES ============= - Fixed a error “Program crash after function call with too much parameters”. + Added a `README.md` file to NuGet package. ============ PROJECT SITE ============ - http://github.com/Taritsyn/MsieJavaScriptEngine \ No newline at end of file + https://github.com/Taritsyn/MsieJavaScriptEngine \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Benchmarks/HostObjectsEmbeddingBenchmark.cs b/test/MsieJavaScriptEngine.Benchmarks/HostObjectsEmbeddingBenchmark.cs index b0a91df..700a6bf 100644 --- a/test/MsieJavaScriptEngine.Benchmarks/HostObjectsEmbeddingBenchmark.cs +++ b/test/MsieJavaScriptEngine.Benchmarks/HostObjectsEmbeddingBenchmark.cs @@ -66,7 +66,11 @@ private static void EmbedAndUseHostObjects(Func createJsEngine) return result; }(someObj, log));"; +#if NET462 const string targetOutput = "RmFsc2V8MjkxNHwwLjg3Mjg1OTEwNzM4ODQyNHxBU0RG0KTQq9CS0JA="; +#else + const string targetOutput = "RmFsc2V8MjkxNHwwLjg3Mjg1OTEwNzM4ODQyMzV8QVNERtCk0KvQktCQ"; +#endif string targetLogOutput = "-= Start code execution =-" + Environment.NewLine + "-= End of code execution =-" + Environment.NewLine; @@ -89,7 +93,7 @@ private static void EmbedAndUseHostObjects(Func createJsEngine) Assert.Equal(targetOutput, output); Assert.Equal(targetLogOutput, logOutput); } -#if NET461 +#if NET462 [Benchmark] public void Classic() diff --git a/test/MsieJavaScriptEngine.Benchmarks/HostTypesEmbeddingBenchmark.cs b/test/MsieJavaScriptEngine.Benchmarks/HostTypesEmbeddingBenchmark.cs index a53ba9a..4bd965c 100644 --- a/test/MsieJavaScriptEngine.Benchmarks/HostTypesEmbeddingBenchmark.cs +++ b/test/MsieJavaScriptEngine.Benchmarks/HostTypesEmbeddingBenchmark.cs @@ -52,7 +52,11 @@ private static void EmbedAndUseHostTypes(Func createJsEngine) return result; }(SomeClass, Point, SomeOtherClass));"; +#if NET462 const string targetOutput = "RmFsc2V8MjkyMHwwLjg3Mjg1OTEwNzM4ODQyNHxBU0RG0KTQq9CS0JA="; +#else + const string targetOutput = "RmFsc2V8MjkyMHwwLjg3Mjg1OTEwNzM4ODQyMzV8QVNERtCk0KvQktCQ"; +#endif // Act string output; @@ -69,7 +73,7 @@ private static void EmbedAndUseHostTypes(Func createJsEngine) // Assert Assert.Equal(targetOutput, output); } -#if NET461 +#if NET462 [Benchmark] public void Classic() diff --git a/test/MsieJavaScriptEngine.Benchmarks/JsExecutionBenchmark.cs b/test/MsieJavaScriptEngine.Benchmarks/JsExecutionBenchmark.cs index 75f135f..633680b 100644 --- a/test/MsieJavaScriptEngine.Benchmarks/JsExecutionBenchmark.cs +++ b/test/MsieJavaScriptEngine.Benchmarks/JsExecutionBenchmark.cs @@ -182,7 +182,7 @@ private static void TransliterateStrings(Func createJsEngine, bool Assert.Equal(_targetOutputStrings[itemIndex], outputStrings[itemIndex]); } } -#if NET461 +#if NET462 [Benchmark] public void Classic() diff --git a/test/MsieJavaScriptEngine.Benchmarks/MsieJavaScriptEngine.Benchmarks.csproj b/test/MsieJavaScriptEngine.Benchmarks/MsieJavaScriptEngine.Benchmarks.csproj index 737550e..6a69fbb 100644 --- a/test/MsieJavaScriptEngine.Benchmarks/MsieJavaScriptEngine.Benchmarks.csproj +++ b/test/MsieJavaScriptEngine.Benchmarks/MsieJavaScriptEngine.Benchmarks.csproj @@ -1,24 +1,25 @@ - - MSIE JavaScript Engine: Benchmarks - 3.0.7 - net461;netcoreapp2.1;netcoreapp3.1 - Exe - true - false - + + MSIE JavaScript Engine: Benchmarks + 3.2.5 + net462;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + Exe + true + true + false + - + - - + + - - + + - - - + + + \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Auto/InteropTests.cs b/test/MsieJavaScriptEngine.Test.Auto/InteropTests.cs index c6e4def..3034802 100644 --- a/test/MsieJavaScriptEngine.Test.Auto/InteropTests.cs +++ b/test/MsieJavaScriptEngine.Test.Auto/InteropTests.cs @@ -8,5 +8,45 @@ namespace MsieJavaScriptEngine.Test.Auto public class InteropTests : InteropTestsBase { protected override JsEngineMode EngineMode => JsEngineMode.Auto; + + + #region Embedding of objects + + #region Objects with methods + + public override void EmbeddingOfInstanceOfCustomValueTypeAndCallingOfItsGetTypeMethod() + { } + + public override void EmbeddingOfInstanceOfCustomReferenceTypeAndCallingOfItsGetTypeMethod() + { } + + #endregion + + #region Delegates + + public override void EmbeddingOfInstanceOfDelegateAndCheckingItsPrototype() + { } + + public override void EmbeddingOfInstanceOfDelegateAndGettingItsMethodProperty() + { } + + #endregion + + #endregion + + + #region Embedding of types + + #region Creating of instances + + public override void CreatingAnInstanceOfEmbeddedBuiltinExceptionAndGettingItsTargetSiteProperty() + { } + + public override void CreatingAnInstanceOfEmbeddedCustomExceptionAndCallingOfItsGetTypeMethod() + { } + + #endregion + + #endregion } } \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Auto/MsieJavaScriptEngine.Test.Auto.csproj b/test/MsieJavaScriptEngine.Test.Auto/MsieJavaScriptEngine.Test.Auto.csproj index 3097fec..59d8bc1 100644 --- a/test/MsieJavaScriptEngine.Test.Auto/MsieJavaScriptEngine.Test.Auto.csproj +++ b/test/MsieJavaScriptEngine.Test.Auto/MsieJavaScriptEngine.Test.Auto.csproj @@ -1,22 +1,21 @@  - - MSIE JavaScript Engine: Tests for Auto Mode - 3.0.7 - net40;net451;netcoreapp1.0;netcoreapp2.1;netcoreapp3.1 - 1.0.16 - Library - true - true - false - + + MSIE JavaScript Engine: Tests for Auto Mode + 3.2.5 + net462;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + Library + true + true + false + - + - - + + - - + + \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.ChakraActiveScript/CommonTests.cs b/test/MsieJavaScriptEngine.Test.ChakraActiveScript/CommonTests.cs index e7a0e0d..b33e52e 100644 --- a/test/MsieJavaScriptEngine.Test.ChakraActiveScript/CommonTests.cs +++ b/test/MsieJavaScriptEngine.Test.ChakraActiveScript/CommonTests.cs @@ -17,7 +17,7 @@ public class CommonTests : CommonTestsBase #region Mapping of errors [Test] - public void MappingCompilationErrorDuringEvaluationOfExpressionIsCorrect() + public void MappingCompilationErrorDuringEvaluationOfExpression() { // Arrange const string input = @"var $variable1 = 611; @@ -53,7 +53,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionIsCorrect() } [Test] - public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorrect() + public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugMode() { // Arrange const string input = @"var $variable1 = 611; @@ -65,7 +65,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorr JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -89,7 +89,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorr } [Test] - public void MappingRuntimeErrorDuringEvaluationOfExpressionIsCorrect() + public void MappingRuntimeErrorDuringEvaluationOfExpression() { // Arrange const string input = @"var $variable1 = 611; @@ -126,7 +126,7 @@ public void MappingRuntimeErrorDuringEvaluationOfExpressionIsCorrect() } [Test] - public void MappingCompilationErrorDuringExecutionOfCodeIsCorrect() + public void MappingCompilationErrorDuringExecutionOfCode() { // Arrange const string input = @"function factorial(value) { @@ -168,7 +168,7 @@ public void MappingCompilationErrorDuringExecutionOfCodeIsCorrect() } [Test] - public void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCorrect() + public void MappingCompilationErrorDuringExecutionOfCodeInDebugMode() { // Arrange const string input = @"function factorial(value) { @@ -186,7 +186,7 @@ public void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCorrect() JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -210,7 +210,7 @@ public void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCorrect() } [Test] - public void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect() + public void MappingRuntimeErrorDuringExecutionOfCode() { // Arrange const string input = @"function factorial(value) { @@ -257,7 +257,7 @@ public void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect() #region Generation of error messages [Test] - public void GenerationOfCompilationErrorMessageIsCorrect() + public void GenerationOfCompilationErrorMessage() { // Arrange const string input = @"var arr = []; @@ -287,7 +287,7 @@ public void GenerationOfCompilationErrorMessageIsCorrect() } [Test] - public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() + public void GenerationOfCompilationErrorMessageInDebugMode() { // Arrange const string input = @"var arr = []; @@ -300,7 +300,7 @@ public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -317,7 +317,7 @@ public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() } [Test] - public void GenerationOfRuntimeErrorMessageIsCorrect() + public void GenerationOfRuntimeErrorMessage() { // Arrange const string input = @"function foo(x, y) { diff --git a/test/MsieJavaScriptEngine.Test.ChakraActiveScript/InteropTests.cs b/test/MsieJavaScriptEngine.Test.ChakraActiveScript/InteropTests.cs index 27b4b4c..432f127 100644 --- a/test/MsieJavaScriptEngine.Test.ChakraActiveScript/InteropTests.cs +++ b/test/MsieJavaScriptEngine.Test.ChakraActiveScript/InteropTests.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using MsieJavaScriptEngine.Test.Common; +using MsieJavaScriptEngine.Test.Common.Interop.Animals; namespace MsieJavaScriptEngine.Test.ChakraActiveScript { @@ -15,12 +16,41 @@ public class InteropTests : InteropTestsBase #region Embedding of objects + #region Delegates + + [Test] + public override void EmbeddingOfInstanceOfDelegateAndCheckingItsPrototype() + { } + + [Test] + public override void EmbeddingOfInstanceOfDelegateAndGettingItsMethodProperty() + { + // Arrange + string TestAllowReflectionSetting(bool allowReflection) + { + var cat = new Cat(); + var cryFunc = new Func(cat.Cry); + + using (var jsEngine = CreateJsEngine(allowReflection: allowReflection)) + { + jsEngine.EmbedHostObject("cry", cryFunc); + return jsEngine.Evaluate("cry.Method;"); + } + } + + // Act and Assert + Assert.AreEqual("System.String Cry()", TestAllowReflectionSetting(true)); + Assert.AreEqual("undefined", TestAllowReflectionSetting(false)); + } + + #endregion + #region Recursive calls #region Mapping of errors [Test] - public void MappingRuntimeErrorDuringRecursiveEvaluationOfFilesIsCorrect() + public void MappingRuntimeErrorDuringRecursiveEvaluationOfFiles() { // Arrange string directoryPath = GetAbsolutePath("SharedFiles/recursiveEvaluation/runtimeError"); diff --git a/test/MsieJavaScriptEngine.Test.ChakraActiveScript/MsieJavaScriptEngine.Test.ChakraActiveScript.csproj b/test/MsieJavaScriptEngine.Test.ChakraActiveScript/MsieJavaScriptEngine.Test.ChakraActiveScript.csproj index 9d3949e..45a6f86 100644 --- a/test/MsieJavaScriptEngine.Test.ChakraActiveScript/MsieJavaScriptEngine.Test.ChakraActiveScript.csproj +++ b/test/MsieJavaScriptEngine.Test.ChakraActiveScript/MsieJavaScriptEngine.Test.ChakraActiveScript.csproj @@ -1,21 +1,21 @@  - - MSIE JavaScript Engine: Tests for Chakra ActiveScript Mode - 3.0.7 - net40;net451 - Library - true - true - false - + + MSIE JavaScript Engine: Tests for Chakra ActiveScript Mode + 3.2.5 + net462 + Library + true + true + false + - + - - + + - - + + \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/CommonTests.cs b/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/CommonTests.cs index 0afc7e8..09acc27 100644 --- a/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/CommonTests.cs +++ b/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/CommonTests.cs @@ -18,7 +18,7 @@ public class CommonTests : CommonTestsBase #region Mapping of errors [Test] - public void MappingCompilationErrorDuringEvaluationOfExpressionIsCorrect() + public void MappingCompilationErrorDuringEvaluationOfExpression() { // Arrange const string input = @"var $variable1 = 611; @@ -54,7 +54,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionIsCorrect() } [Test] - public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorrect() + public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugMode() { // Arrange const string input = @"var $variable1 = 611; @@ -66,7 +66,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorr JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -90,7 +90,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorr } [Test] - public void MappingRuntimeErrorDuringEvaluationOfExpressionIsCorrect() + public void MappingRuntimeErrorDuringEvaluationOfExpression() { // Arrange const string input = @"var $variable1 = 611; @@ -127,7 +127,7 @@ public void MappingRuntimeErrorDuringEvaluationOfExpressionIsCorrect() } [Test] - public void MappingCompilationErrorDuringExecutionOfCodeIsCorrect() + public void MappingCompilationErrorDuringExecutionOfCode() { // Arrange const string input = @"function factorial(value) { @@ -169,7 +169,7 @@ public void MappingCompilationErrorDuringExecutionOfCodeIsCorrect() } [Test] - public virtual void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCorrect() + public virtual void MappingCompilationErrorDuringExecutionOfCodeInDebugMode() { // Arrange const string input = @"function factorial(value) { @@ -187,7 +187,7 @@ public virtual void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCor JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -211,7 +211,7 @@ public virtual void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCor } [Test] - public void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect() + public void MappingRuntimeErrorDuringExecutionOfCode() { // Arrange const string input = @"function factorial(value) { @@ -262,7 +262,7 @@ public void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect() #region Generation of error messages [Test] - public void GenerationOfCompilationErrorMessageIsCorrect() + public void GenerationOfCompilationErrorMessage() { // Arrange const string input = @"var arr = []; @@ -292,7 +292,7 @@ public void GenerationOfCompilationErrorMessageIsCorrect() } [Test] - public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() + public void GenerationOfCompilationErrorMessageInDebugMode() { // Arrange const string input = @"var arr = []; @@ -305,7 +305,7 @@ public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -322,7 +322,7 @@ public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() } [Test] - public void GenerationOfRuntimeErrorMessageIsCorrect() + public void GenerationOfRuntimeErrorMessage() { // Arrange const string input = @"function foo(x, y) { diff --git a/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/InteropTests.cs b/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/InteropTests.cs index 6cbb8fb..14eefa0 100644 --- a/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/InteropTests.cs +++ b/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/InteropTests.cs @@ -14,39 +14,13 @@ public class InteropTests : InteropTestsBase #region Embedding of objects -#if NETCOREAPP - - #region Delegates - - [Test] - public void EmbeddedInstanceOfDelegateHasFunctionPrototype() - { - // Arrange - var someFunc = new Func(() => 42); - - const string input = "Object.getPrototypeOf(embeddedFunc) === Function.prototype"; - - // Act - bool output; - - using (var jsEngine = CreateJsEngine()) - { - jsEngine.EmbedHostObject("embeddedFunc", someFunc); - output = jsEngine.Evaluate(input); - } - - // Assert - Assert.True(output); - } - - #endregion #region Recursive calls #region Mapping of errors [Test] - public void MappingRuntimeErrorDuringRecursiveEvaluationOfFilesIsCorrect() + public void MappingRuntimeErrorDuringRecursiveEvaluationOfFiles() { // Arrange string directoryPath = GetAbsolutePath("SharedFiles/recursiveEvaluation/runtimeError"); @@ -97,7 +71,6 @@ public void MappingRuntimeErrorDuringRecursiveEvaluationOfFilesIsCorrect() #endregion -#endif #endregion } } \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/MsieJavaScriptEngine.Test.ChakraEdgeJsRt.csproj b/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/MsieJavaScriptEngine.Test.ChakraEdgeJsRt.csproj index 15bd8e3..db28d38 100644 --- a/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/MsieJavaScriptEngine.Test.ChakraEdgeJsRt.csproj +++ b/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/MsieJavaScriptEngine.Test.ChakraEdgeJsRt.csproj @@ -1,22 +1,21 @@  - - MSIE JavaScript Engine: Tests for Chakra Edge JsRT Mode - 3.0.7 - net40;net451;netcoreapp1.0;netcoreapp2.1;netcoreapp3.1 - 1.0.16 - Library - true - true - false - + + MSIE JavaScript Engine: Tests for Chakra Edge JsRT Mode + 3.2.5 + net462;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + Library + true + true + false + - + - - + + - - + + \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/PrecompilationTests.cs b/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/PrecompilationTests.cs index 94a1c6d..2b0bd53 100644 --- a/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/PrecompilationTests.cs +++ b/test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/PrecompilationTests.cs @@ -18,7 +18,7 @@ public class PrecompilationTests : PrecompilationTestsBase #region Mapping of errors [Test] - public void MappingCompilationErrorDuringPrecompilationOfCodeIsCorrect() + public void MappingCompilationErrorDuringPrecompilationOfCode() { // Arrange const string input = @"function guid() { @@ -63,7 +63,7 @@ function s4() { } [Test] - public void MappingRuntimeErrorDuringExecutionOfPrecompiledCodeIsCorrect() + public void MappingRuntimeErrorDuringExecutionOfPrecompiledCode() { // Arrange const string input = @"function getItem(items, itemIndex) { @@ -118,7 +118,7 @@ public void MappingRuntimeErrorDuringExecutionOfPrecompiledCodeIsCorrect() #region Generation of error messages [Test] - public void GenerationOfCompilationErrorMessageIsCorrect() + public void GenerationOfCompilationErrorMessage() { // Arrange const string input = @"function makeId(length) { @@ -127,7 +127,7 @@ public void GenerationOfCompilationErrorMessageIsCorrect() charIndex ; - for (charIndex = 0; charIndex < length; charIndex++) + for (charIndex = 0; charIndex < length; charIndex++) result += possible.charAt(Math.floor(Math.random() * possible.length)); } @@ -159,7 +159,7 @@ public void GenerationOfCompilationErrorMessageIsCorrect() } [Test] - public void GenerationOfRuntimeErrorMessageIsCorrect() + public void GenerationOfRuntimeErrorMessage() { // Arrange const string input = @"function getFullName(firstName, lastName) { diff --git a/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/CommonTests.cs b/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/CommonTests.cs index 770e9a4..9983e4a 100644 --- a/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/CommonTests.cs +++ b/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/CommonTests.cs @@ -17,7 +17,7 @@ public class CommonTests : CommonTestsBase #region Mapping of errors [Test] - public void MappingCompilationErrorDuringEvaluationOfExpressionIsCorrect() + public void MappingCompilationErrorDuringEvaluationOfExpression() { // Arrange const string input = @"var $variable1 = 611; @@ -53,7 +53,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionIsCorrect() } [Test] - public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorrect() + public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugMode() { // Arrange const string input = @"var $variable1 = 611; @@ -65,7 +65,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorr JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -89,7 +89,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorr } [Test] - public void MappingRuntimeErrorDuringEvaluationOfExpressionIsCorrect() + public void MappingRuntimeErrorDuringEvaluationOfExpression() { // Arrange const string input = @"var $variable1 = 611; @@ -126,7 +126,7 @@ public void MappingRuntimeErrorDuringEvaluationOfExpressionIsCorrect() } [Test] - public void MappingCompilationErrorDuringExecutionOfCodeIsCorrect() + public void MappingCompilationErrorDuringExecutionOfCode() { // Arrange const string input = @"function factorial(value) { @@ -168,7 +168,7 @@ public void MappingCompilationErrorDuringExecutionOfCodeIsCorrect() } [Test] - public virtual void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCorrect() + public virtual void MappingCompilationErrorDuringExecutionOfCodeInDebugMode() { // Arrange const string input = @"function factorial(value) { @@ -186,7 +186,7 @@ public virtual void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCor JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -210,7 +210,7 @@ public virtual void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCor } [Test] - public void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect() + public void MappingRuntimeErrorDuringExecutionOfCode() { // Arrange const string input = @"function factorial(value) { @@ -261,7 +261,7 @@ public void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect() #region Generation of error messages [Test] - public void GenerationOfCompilationErrorMessageIsCorrect() + public void GenerationOfCompilationErrorMessage() { // Arrange const string input = @"var arr = []; @@ -291,7 +291,7 @@ public void GenerationOfCompilationErrorMessageIsCorrect() } [Test] - public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() + public void GenerationOfCompilationErrorMessageInDebugMode() { // Arrange const string input = @"var arr = []; @@ -304,7 +304,7 @@ public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -321,7 +321,7 @@ public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() } [Test] - public void GenerationOfRuntimeErrorMessageIsCorrect() + public void GenerationOfRuntimeErrorMessage() { // Arrange const string input = @"function foo(x, y) { diff --git a/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/InteropTests.cs b/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/InteropTests.cs index e55b5e6..15ee2c5 100644 --- a/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/InteropTests.cs +++ b/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/InteropTests.cs @@ -14,39 +14,13 @@ public class InteropTests : InteropTestsBase #region Embedding of objects -#if NETCOREAPP - - #region Delegates - - [Test] - public void EmbeddedInstanceOfDelegateHasFunctionPrototype() - { - // Arrange - var someFunc = new Func(() => 42); - - const string input = "Object.getPrototypeOf(embeddedFunc) === Function.prototype"; - - // Act - bool output; - - using (var jsEngine = CreateJsEngine()) - { - jsEngine.EmbedHostObject("embeddedFunc", someFunc); - output = jsEngine.Evaluate(input); - } - - // Assert - Assert.True(output); - } - - #endregion #region Recursive calls #region Mapping of errors [Test] - public void MappingRuntimeErrorDuringRecursiveEvaluationOfFilesIsCorrect() + public void MappingRuntimeErrorDuringRecursiveEvaluationOfFiles() { // Arrange string directoryPath = GetAbsolutePath("SharedFiles/recursiveEvaluation/runtimeError"); @@ -97,7 +71,6 @@ public void MappingRuntimeErrorDuringRecursiveEvaluationOfFilesIsCorrect() #endregion -#endif #endregion } } \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/MsieJavaScriptEngine.Test.ChakraIeJsRt.csproj b/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/MsieJavaScriptEngine.Test.ChakraIeJsRt.csproj index f9a0d9c..816d0c4 100644 --- a/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/MsieJavaScriptEngine.Test.ChakraIeJsRt.csproj +++ b/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/MsieJavaScriptEngine.Test.ChakraIeJsRt.csproj @@ -1,22 +1,21 @@  - - MSIE JavaScript Engine: Tests for Chakra IE JsRT Mode - 3.0.7 - net40;net451;netcoreapp1.0;netcoreapp2.1;netcoreapp3.1 - 1.0.16 - Library - true - true - false - + + MSIE JavaScript Engine: Tests for Chakra IE JsRT Mode + 3.2.5 + net462;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + Library + true + true + false + - + - - + + - - + + \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/PrecompilationTests.cs b/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/PrecompilationTests.cs index 53eda79..b9f9b7c 100644 --- a/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/PrecompilationTests.cs +++ b/test/MsieJavaScriptEngine.Test.ChakraIeJsRt/PrecompilationTests.cs @@ -17,7 +17,7 @@ public class PrecompilationTests : PrecompilationTestsBase #region Mapping of errors [Test] - public void MappingCompilationErrorDuringPrecompilationOfCodeIsCorrect() + public void MappingCompilationErrorDuringPrecompilationOfCode() { // Arrange const string input = @"function guid() { @@ -62,7 +62,7 @@ function s4() { } [Test] - public void MappingRuntimeErrorDuringExecutionOfPrecompiledCodeIsCorrect() + public void MappingRuntimeErrorDuringExecutionOfPrecompiledCode() { // Arrange const string input = @"function getItem(items, itemIndex) { @@ -117,7 +117,7 @@ public void MappingRuntimeErrorDuringExecutionOfPrecompiledCodeIsCorrect() #region Generation of error messages [Test] - public void GenerationOfCompilationErrorMessageIsCorrect() + public void GenerationOfCompilationErrorMessage() { // Arrange const string input = @"function makeId(length) { @@ -126,7 +126,7 @@ public void GenerationOfCompilationErrorMessageIsCorrect() charIndex ; - for (charIndex = 0; charIndex < length; charIndex++) + for (charIndex = 0; charIndex < length; charIndex++) result += possible.charAt(Math.floor(Math.random() * possible.length)); } @@ -158,7 +158,7 @@ public void GenerationOfCompilationErrorMessageIsCorrect() } [Test] - public void GenerationOfRuntimeErrorMessageIsCorrect() + public void GenerationOfRuntimeErrorMessage() { // Arrange const string input = @"function getFullName(firstName, lastName) { diff --git a/test/MsieJavaScriptEngine.Test.Classic/CommonTests.cs b/test/MsieJavaScriptEngine.Test.Classic/CommonTests.cs index f070a05..45a5ac3 100644 --- a/test/MsieJavaScriptEngine.Test.Classic/CommonTests.cs +++ b/test/MsieJavaScriptEngine.Test.Classic/CommonTests.cs @@ -17,7 +17,7 @@ public class CommonTests : CommonTestsBase #region Mapping of errors [Test] - public void MappingCompilationErrorDuringEvaluationOfExpressionIsCorrect() + public void MappingCompilationErrorDuringEvaluationOfExpression() { // Arrange const string input = @"var $variable1 = 611; @@ -53,7 +53,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionIsCorrect() } [Test] - public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorrect() + public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugMode() { // Arrange const string input = @"var $variable1 = 611; @@ -65,7 +65,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorr JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -89,7 +89,7 @@ public void MappingCompilationErrorDuringEvaluationOfExpressionInDebugModeIsCorr } [Test] - public void MappingRuntimeErrorDuringEvaluationOfExpressionIsCorrect() + public void MappingRuntimeErrorDuringEvaluationOfExpression() { // Arrange const string input = @"var $variable1 = 611; @@ -126,7 +126,7 @@ public void MappingRuntimeErrorDuringEvaluationOfExpressionIsCorrect() } [Test] - public void MappingCompilationErrorDuringExecutionOfCodeIsCorrect() + public void MappingCompilationErrorDuringExecutionOfCode() { // Arrange const string input = @"function factorial(value) { @@ -168,7 +168,7 @@ public void MappingCompilationErrorDuringExecutionOfCodeIsCorrect() } [Test] - public void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCorrect() + public void MappingCompilationErrorDuringExecutionOfCodeInDebugMode() { // Arrange const string input = @"function factorial(value) { @@ -186,7 +186,7 @@ public void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCorrect() JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -210,7 +210,7 @@ public void MappingCompilationErrorDuringExecutionOfCodeInDebugModeIsCorrect() } [Test] - public void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect() + public void MappingRuntimeErrorDuringExecutionOfCode() { // Arrange const string input = @"function factorial(value) { @@ -257,7 +257,7 @@ public void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect() #region Generation of error messages [Test] - public void GenerationOfCompilationErrorMessageIsCorrect() + public void GenerationOfCompilationErrorMessage() { // Arrange const string input = @"var arr = []; @@ -287,7 +287,7 @@ public void GenerationOfCompilationErrorMessageIsCorrect() } [Test] - public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() + public void GenerationOfCompilationErrorMessageInDebugMode() { // Arrange const string input = @"var arr = []; @@ -300,7 +300,7 @@ public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() JsCompilationException exception = null; // Act - using (var jsEngine = CreateJsEngine(true)) + using (var jsEngine = CreateJsEngine(enableDebugging: true)) { try { @@ -317,7 +317,7 @@ public void GenerationOfCompilationErrorMessageInDebugModeIsCorrect() } [Test] - public void GenerationOfRuntimeErrorMessageIsCorrect() + public void GenerationOfRuntimeErrorMessage() { // Arrange const string input = @"function foo(x, y) { diff --git a/test/MsieJavaScriptEngine.Test.Classic/Es5Tests.cs b/test/MsieJavaScriptEngine.Test.Classic/Es5Tests.cs index b447707..9ab2544 100644 --- a/test/MsieJavaScriptEngine.Test.Classic/Es5Tests.cs +++ b/test/MsieJavaScriptEngine.Test.Classic/Es5Tests.cs @@ -15,7 +15,7 @@ public class Es5Tests : Es5TestsBase #region Object methods [Test] - public override void ObjectKeysMethodIsSupported() + public override void SupportsObjectKeysMethod() { // Arrange const string input1 = "Object.keys(['a', 'b', 'c']).toString();"; diff --git a/test/MsieJavaScriptEngine.Test.Classic/InteropTests.cs b/test/MsieJavaScriptEngine.Test.Classic/InteropTests.cs index 23997cc..48763b5 100644 --- a/test/MsieJavaScriptEngine.Test.Classic/InteropTests.cs +++ b/test/MsieJavaScriptEngine.Test.Classic/InteropTests.cs @@ -4,6 +4,8 @@ using NUnit.Framework; using MsieJavaScriptEngine.Test.Common; +using MsieJavaScriptEngine.Test.Common.Interop; +using MsieJavaScriptEngine.Test.Common.Interop.Animals; namespace MsieJavaScriptEngine.Test.Classic { @@ -15,12 +17,91 @@ public class InteropTests : InteropTestsBase #region Embedding of objects + #region Objects with methods + + [Test] + public override void EmbeddingOfInstanceOfCustomValueTypeAndCallingOfItsGetTypeMethod() + { + // Arrange + string TestAllowReflectionSetting(bool allowReflection) + { + var date = new Date(); + + using (var jsEngine = CreateJsEngine(allowReflection: allowReflection)) + { + jsEngine.EmbedHostObject("date", date); + return jsEngine.Evaluate("date.GetType();"); + } + } + + // Act and Assert + Assert.AreEqual(typeof(Date).FullName, TestAllowReflectionSetting(true)); + + var exception = Assert.Throws(() => TestAllowReflectionSetting(false)); + Assert.AreEqual("Runtime error", exception.Category); + Assert.AreEqual("Object doesn't support this property or method", exception.Description); + } + + [Test] + public override void EmbeddingOfInstanceOfCustomReferenceTypeAndCallingOfItsGetTypeMethod() + { + // Arrange + string TestAllowReflectionSetting(bool allowReflection) + { + var cat = new Cat(); + + using (var jsEngine = CreateJsEngine(allowReflection: allowReflection)) + { + jsEngine.EmbedHostObject("cat", cat); + return jsEngine.Evaluate("cat.GetType();"); + } + } + + // Act and Assert + Assert.AreEqual(typeof(Cat).FullName, TestAllowReflectionSetting(true)); + + var exception = Assert.Throws(() => TestAllowReflectionSetting(false)); + Assert.AreEqual("Runtime error", exception.Category); + Assert.AreEqual("Object doesn't support this property or method", exception.Description); + } + + #endregion + + #region Delegates + + [Test] + public override void EmbeddingOfInstanceOfDelegateAndCheckingItsPrototype() + { } + + [Test] + public override void EmbeddingOfInstanceOfDelegateAndGettingItsMethodProperty() + { + // Arrange + string TestAllowReflectionSetting(bool allowReflection) + { + var cat = new Cat(); + var cryFunc = new Func(cat.Cry); + + using (var jsEngine = CreateJsEngine(allowReflection: allowReflection)) + { + jsEngine.EmbedHostObject("cry", cryFunc); + return jsEngine.Evaluate("cry.Method;"); + } + } + + // Act and Assert + Assert.AreEqual("System.String Cry()", TestAllowReflectionSetting(true)); + Assert.AreEqual("undefined", TestAllowReflectionSetting(false)); + } + + #endregion + #region Recursive calls #region Mapping of errors [Test] - public void MappingRuntimeErrorDuringRecursiveEvaluationOfFilesIsCorrect() + public void MappingRuntimeErrorDuringRecursiveEvaluationOfFiles() { // Arrange string directoryPath = GetAbsolutePath("SharedFiles/recursiveEvaluation/runtimeError"); @@ -67,5 +148,37 @@ public void MappingRuntimeErrorDuringRecursiveEvaluationOfFilesIsCorrect() #endregion #endregion + + + #region Embedding of types + + #region Creating of instances + + [Test] + public override void CreatingAnInstanceOfEmbeddedCustomExceptionAndCallingOfItsGetTypeMethod() + { + // Arrange + string TestAllowReflectionSetting(bool allowReflection) + { + Type loginFailedExceptionType = typeof(LoginFailedException); + + using (var jsEngine = CreateJsEngine(allowReflection: allowReflection)) + { + jsEngine.EmbedHostType("LoginFailedError", loginFailedExceptionType); + return jsEngine.Evaluate("new LoginFailedError(\"Wrong password entered!\").GetType();"); + } + } + + // Act and Assert + Assert.AreEqual(typeof(LoginFailedException).FullName, TestAllowReflectionSetting(true)); + + var exception = Assert.Throws(() => TestAllowReflectionSetting(false)); + Assert.AreEqual("Runtime error", exception.Category); + Assert.AreEqual("Object doesn't support this property or method", exception.Description); + } + + #endregion + + #endregion } } \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Classic/MsieJavaScriptEngine.Test.Classic.csproj b/test/MsieJavaScriptEngine.Test.Classic/MsieJavaScriptEngine.Test.Classic.csproj index 4f2026f..b14413f 100644 --- a/test/MsieJavaScriptEngine.Test.Classic/MsieJavaScriptEngine.Test.Classic.csproj +++ b/test/MsieJavaScriptEngine.Test.Classic/MsieJavaScriptEngine.Test.Classic.csproj @@ -1,21 +1,21 @@  - - MSIE JavaScript Engine: Tests for Classic Mode - 3.0.7 - net40;net451 - Library - true - true - false - + + MSIE JavaScript Engine: Tests for Classic Mode + 3.2.5 + net462 + Library + true + true + false + - + - - + + - - + + \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Common/CommonTestsBase.cs b/test/MsieJavaScriptEngine.Test.Common/CommonTestsBase.cs index 71485fc..76ee95e 100644 --- a/test/MsieJavaScriptEngine.Test.Common/CommonTestsBase.cs +++ b/test/MsieJavaScriptEngine.Test.Common/CommonTestsBase.cs @@ -1,8 +1,6 @@ using System; using System.IO; -#if !NET40 using System.Reflection; -#endif using System.Threading; using NUnit.Framework; @@ -15,7 +13,7 @@ public abstract class CommonTestsBase : FileSystemTestsBase #region Creation of engines [Test] - public virtual void CreationOfEngineWithoutDisposingIsCorrect() + public virtual void CreationOfEngineWithoutDisposing() { MsieJsEngine jsEngine = CreateJsEngine(); jsEngine.Execute("var a = 1 + 1;"); @@ -26,7 +24,7 @@ public virtual void CreationOfEngineWithoutDisposingIsCorrect() #region Evaluation of scripts [Test] - public virtual void EvaluationOfExpressionWithUndefinedResultIsCorrect() + public virtual void EvaluationOfExpressionWithUndefinedResult() { // Arrange const string input = "undefined"; @@ -45,7 +43,7 @@ public virtual void EvaluationOfExpressionWithUndefinedResultIsCorrect() } [Test] - public virtual void EvaluationOfExpressionWithNullResultIsCorrect() + public virtual void EvaluationOfExpressionWithNullResult() { // Arrange const string input = "null"; @@ -64,7 +62,7 @@ public virtual void EvaluationOfExpressionWithNullResultIsCorrect() } [Test] - public virtual void EvaluationOfExpressionWithBooleanResultIsCorrect() + public virtual void EvaluationOfExpressionWithBooleanResult() { // Arrange const string input1 = "7 > 5"; @@ -89,7 +87,7 @@ public virtual void EvaluationOfExpressionWithBooleanResultIsCorrect() } [Test] - public virtual void EvaluationOfExpressionWithIntegerResultIsCorrect() + public virtual void EvaluationOfExpressionWithIntegerResult() { // Arrange const string input = "7 * 8 - 20"; @@ -108,7 +106,7 @@ public virtual void EvaluationOfExpressionWithIntegerResultIsCorrect() } [Test] - public virtual void EvaluationOfExpressionWithDoubleResultIsCorrect() + public virtual void EvaluationOfExpressionWithDoubleResult() { // Arrange const string input = "Math.PI + 0.22"; @@ -127,7 +125,7 @@ public virtual void EvaluationOfExpressionWithDoubleResultIsCorrect() } [Test] - public virtual void EvaluationOfExpressionWithStringResultIsCorrect() + public virtual void EvaluationOfExpressionWithStringResult() { // Arrange const string input = "'Hello, ' + \"Vasya\" + '?';"; @@ -146,7 +144,7 @@ public virtual void EvaluationOfExpressionWithStringResultIsCorrect() } [Test] - public virtual void EvaluationOfExpressionWithUnicodeStringResultIsCorrect() + public virtual void EvaluationOfExpressionWithUnicodeStringResult() { // Arrange const string input = "'Привет, ' + \"Вася\" + '?';"; @@ -169,7 +167,7 @@ public virtual void EvaluationOfExpressionWithUnicodeStringResultIsCorrect() #region Execution of scripts [Test] - public virtual void ExecutionOfCodeIsCorrect() + public virtual void ExecutionOfCode() { // Arrange const string functionCode = @"function add(num1, num2) { @@ -192,7 +190,7 @@ public virtual void ExecutionOfCodeIsCorrect() } [Test] - public virtual void ExecutionOfFileIsCorrect() + public virtual void ExecutionOfFile() { // Arrange string filePath = GetAbsolutePath("SharedFiles/square.js"); @@ -213,7 +211,7 @@ public virtual void ExecutionOfFileIsCorrect() } [Test] - public virtual void ExecutionOfResourceByNameAndTypeIsCorrect() + public virtual void ExecutionOfResourceByNameAndType() { // Arrange const string resourceName = "Resources.cube.js"; @@ -234,7 +232,7 @@ public virtual void ExecutionOfResourceByNameAndTypeIsCorrect() } [Test] - public virtual void ExecutionOfResourceByNameAndAssemblyIsCorrect() + public virtual void ExecutionOfResourceByNameAndAssembly() { // Arrange const string resourceName = "MsieJavaScriptEngine.Test.Common.Resources.power.js"; @@ -247,9 +245,7 @@ public virtual void ExecutionOfResourceByNameAndAssemblyIsCorrect() using (var jsEngine = CreateJsEngine()) { jsEngine.ExecuteResource(resourceName, typeof(CommonTestsBase) -#if !NET40 .GetTypeInfo() -#endif .Assembly ); output = jsEngine.Evaluate(input); @@ -264,7 +260,7 @@ public virtual void ExecutionOfResourceByNameAndAssemblyIsCorrect() #region Calling of functions [Test] - public virtual void CallingOfFunctionWithoutParametersIsCorrect() + public virtual void CallingOfFunctionWithoutParameters() { // Arrange const string functionCode = @"function hooray() { @@ -286,7 +282,7 @@ public virtual void CallingOfFunctionWithoutParametersIsCorrect() } [Test] - public virtual void CallingOfFunctionWithUndefinedResultIsCorrect() + public virtual void CallingOfFunctionWithUndefinedResult() { // Arrange const string functionCode = @"function testUndefined(value) { @@ -312,7 +308,7 @@ public virtual void CallingOfFunctionWithUndefinedResultIsCorrect() } [Test] - public virtual void CallingOfFunctionWithNullResultIsCorrect() + public virtual void CallingOfFunctionWithNullResult() { // Arrange const string functionCode = @"function testNull(value) { @@ -338,7 +334,7 @@ public virtual void CallingOfFunctionWithNullResultIsCorrect() } [Test] - public virtual void CallingOfFunctionWithBooleanResultIsCorrect() + public virtual void CallingOfFunctionWithBooleanResult() { // Arrange const string functionCode = @"function inverse(value) { @@ -361,7 +357,7 @@ public virtual void CallingOfFunctionWithBooleanResultIsCorrect() } [Test] - public virtual void CallingOfFunctionWithIntegerResultIsCorrect() + public virtual void CallingOfFunctionWithIntegerResult() { // Arrange const string functionCode = @"function negate(value) { @@ -384,7 +380,7 @@ public virtual void CallingOfFunctionWithIntegerResultIsCorrect() } [Test] - public virtual void CallingOfFunctionWithDoubleResultIsCorrect() + public virtual void CallingOfFunctionWithDoubleResult() { // Arrange const string functionCode = @"function triple(value) { @@ -407,7 +403,7 @@ public virtual void CallingOfFunctionWithDoubleResultIsCorrect() } [Test] - public virtual void CallingOfFunctionWithStringResultIsCorrect() + public virtual void CallingOfFunctionWithStringResult() { // Arrange const string functionCode = @"function greeting(name) { @@ -430,7 +426,7 @@ public virtual void CallingOfFunctionWithStringResultIsCorrect() } [Test] - public virtual void CallingOfFunctionWithUnicodeStringResultIsCorrect() + public virtual void CallingOfFunctionWithUnicodeStringResult() { // Arrange const string functionCode = @"function privet(name) { @@ -453,7 +449,7 @@ public virtual void CallingOfFunctionWithUnicodeStringResultIsCorrect() } [Test] - public virtual void CallingOfFunctionWithManyParametersIsCorrect() + public virtual void CallingOfFunctionWithManyParameters() { // Arrange const string functionCode = @"function determineArgumentsTypes() { @@ -487,7 +483,7 @@ public virtual void CallingOfFunctionWithManyParametersIsCorrect() } [Test] - public virtual void CallingOfFunctionWithManyParametersAndBooleanResultIsCorrect() + public virtual void CallingOfFunctionWithManyParametersAndBooleanResult() { // Arrange const string functionCode = @"function and() { @@ -525,7 +521,7 @@ public virtual void CallingOfFunctionWithManyParametersAndBooleanResultIsCorrect } [Test] - public virtual void CallingOfFunctionWithManyParametersAndIntegerResultIsCorrect() + public virtual void CallingOfFunctionWithManyParametersAndIntegerResult() { // Arrange const string functionCode = @"function sum() { @@ -555,7 +551,7 @@ public virtual void CallingOfFunctionWithManyParametersAndIntegerResultIsCorrect } [Test] - public virtual void CallingOfFunctionWithManyParametersAndDoubleResultIsCorrect() + public virtual void CallingOfFunctionWithManyParametersAndDoubleResult() { // Arrange const string functionCode = @"function sum() { @@ -585,7 +581,7 @@ public virtual void CallingOfFunctionWithManyParametersAndDoubleResultIsCorrect( } [Test] - public virtual void CallingOfFunctionWithManyParametersAndStringResultIsCorrect() + public virtual void CallingOfFunctionWithManyParametersAndStringResult() { // Arrange const string functionCode = @"function concatenate() { @@ -615,7 +611,7 @@ public virtual void CallingOfFunctionWithManyParametersAndStringResultIsCorrect( } [Test] - public virtual void CallingOfFunctionWithManyParametersAndUnicodeStringResultIsCorrect() + public virtual void CallingOfFunctionWithManyParametersAndUnicodeStringResult() { // Arrange const string functionCode = @"function obedinit() { @@ -645,7 +641,7 @@ public virtual void CallingOfFunctionWithManyParametersAndUnicodeStringResultIsC } [Test] - public virtual void CallingOfFunctionWithNameContainingUnicodeCharactersIsCorrect() + public virtual void CallingOfFunctionWithNameContainingUnicodeCharacters() { // Arrange const string functionCode = @"function сумма(число1, число2) { @@ -672,7 +668,7 @@ public virtual void CallingOfFunctionWithNameContainingUnicodeCharactersIsCorrec #region Getting, setting and removing variables [Test] - public virtual void SettingAndGettingVariableWithUndefinedValueIsCorrect() + public virtual void SettingAndGettingVariableWithUndefinedValue() { // Arrange const string variableName = "myVar1"; @@ -695,7 +691,7 @@ public virtual void SettingAndGettingVariableWithUndefinedValueIsCorrect() } [Test] - public virtual void SettingAndGettingVariableWithNullValueIsCorrect() + public virtual void SettingAndGettingVariableWithNullValue() { // Arrange const string variableName = "myVar2"; @@ -718,7 +714,7 @@ public virtual void SettingAndGettingVariableWithNullValueIsCorrect() } [Test] - public virtual void SettingAndGettingVariableWithBooleanValueIsCorrect() + public virtual void SettingAndGettingVariableWithBooleanValue() { // Arrange const string variableName = "isVisible"; @@ -752,7 +748,7 @@ public virtual void SettingAndGettingVariableWithBooleanValueIsCorrect() } [Test] - public virtual void SettingAndGettingVariableWithIntegerValueIsCorrect() + public virtual void SettingAndGettingVariableWithIntegerValue() { // Arrange const string variableName = "amount"; @@ -786,7 +782,7 @@ public virtual void SettingAndGettingVariableWithIntegerValueIsCorrect() } [Test] - public virtual void SettingAndGettingVariableWithDoubleValueIsCorrect() + public virtual void SettingAndGettingVariableWithDoubleValue() { // Arrange const string variableName = "price"; @@ -820,7 +816,7 @@ public virtual void SettingAndGettingVariableWithDoubleValueIsCorrect() } [Test] - public virtual void SettingAndGettingVariableWithStringValueIsCorrect() + public virtual void SettingAndGettingVariableWithStringValue() { // Arrange const string variableName = "word"; @@ -854,7 +850,7 @@ public virtual void SettingAndGettingVariableWithStringValueIsCorrect() } [Test] - public virtual void SettingAndGettingVariableWithUnicodeStringValueIsCorrect() + public virtual void SettingAndGettingVariableWithUnicodeStringValue() { // Arrange const string variableName = "slovo"; @@ -888,7 +884,7 @@ public virtual void SettingAndGettingVariableWithUnicodeStringValueIsCorrect() } [Test] - public virtual void SettingAndGettingVariableWithNameContainingUnicodeCharactersIsCorrect() + public virtual void SettingAndGettingVariableWithNameContainingUnicodeCharacters() { // Arrange const string variableName = "слово"; @@ -922,7 +918,7 @@ public virtual void SettingAndGettingVariableWithNameContainingUnicodeCharacters } [Test] - public virtual void RemovingVariableIsCorrect() + public virtual void RemovingVariable() { // Arrange const string variableName = "price"; @@ -946,7 +942,7 @@ public virtual void RemovingVariableIsCorrect() } [Test] - public virtual void RemovingVariableWithNameContainingUnicodeCharactersIsCorrect() + public virtual void RemovingVariableWithNameContainingUnicodeCharacters() { // Arrange const string variableName = "цена"; @@ -974,10 +970,10 @@ public virtual void RemovingVariableWithNameContainingUnicodeCharactersIsCorrect #region Script interruption [Test] - public virtual void ScriptInterruptionIsCorrect() + public virtual void ScriptInterruption() { // Arrange - const string sleepyСode = @"function sleep(millisecondsTimeout) { + const string sleepyCode = @"function sleep(millisecondsTimeout) { var totalMilliseconds = new Date().getTime() + millisecondsTimeout; while (new Date() < totalMilliseconds) @@ -1008,7 +1004,7 @@ public virtual void ScriptInterruptionIsCorrect() try { - jsEngine.Execute(sleepyСode); + jsEngine.Execute(sleepyCode); } catch (Exception e) { @@ -1029,7 +1025,7 @@ public virtual void ScriptInterruptionIsCorrect() #region Garbage collection [Test] - public virtual void GarbageCollectionIsCorrect() + public virtual void GarbageCollection() { // Arrange const string input = @"arr = []; for (i = 0; i < 1000000; i++) { arr.push(arr); }"; diff --git a/test/MsieJavaScriptEngine.Test.Common/ErrorFormattingTests.cs b/test/MsieJavaScriptEngine.Test.Common/ErrorFormattingTests.cs index bcd0519..b3551c0 100644 --- a/test/MsieJavaScriptEngine.Test.Common/ErrorFormattingTests.cs +++ b/test/MsieJavaScriptEngine.Test.Common/ErrorFormattingTests.cs @@ -8,7 +8,7 @@ namespace MsieJavaScriptEngine.Test.Common public class ErrorFormattingTests { [Test] - public void GettingSourceFragmentFromLineIsCorrect() + public void GettingSourceFragmentFromLine() { // Arrange const string input1 = ""; diff --git a/test/MsieJavaScriptEngine.Test.Common/Es5TestsBase.cs b/test/MsieJavaScriptEngine.Test.Common/Es5TestsBase.cs index 327f0eb..762cf9a 100644 --- a/test/MsieJavaScriptEngine.Test.Common/Es5TestsBase.cs +++ b/test/MsieJavaScriptEngine.Test.Common/Es5TestsBase.cs @@ -10,7 +10,7 @@ public abstract class Es5TestsBase : TestsBase #region Array methods [Test] - public virtual void ArrayEveryMethodIsSupported() + public virtual void SupportsArrayEveryMethod() { // Arrange const string initCode = "var engines = ['Chakra', 'V8', 'SpiderMonkey', 'Jurassic'];"; @@ -39,7 +39,7 @@ public virtual void ArrayEveryMethodIsSupported() } [Test] - public virtual void ArrayFilterMethodIsSupported() + public virtual void SupportsArrayFilterMethod() { // Arrange const string initCode = "var engines = ['Chakra', 'V8', 'SpiderMonkey', 'Jurassic'];"; @@ -65,7 +65,7 @@ public virtual void ArrayFilterMethodIsSupported() } [Test] - public virtual void ArrayForEachMethodIsSupported() + public virtual void SupportsArrayForEachMethod() { // Arrange const string resultVariableName = "enginesString"; @@ -95,7 +95,7 @@ public virtual void ArrayForEachMethodIsSupported() } [Test] - public virtual void ArrayIndexOfMethodIsSupported() + public virtual void SupportsArrayIndexOfMethod() { // Arrange const string initCode = "var arr = [2, 5, 9, 2]"; @@ -154,7 +154,7 @@ public virtual void ArrayIndexOfMethodIsSupported() } [Test] - public virtual void ArrayIsArrayMethodIsSupported() + public virtual void SupportsArrayIsArrayMethod() { // Arrange const string input1 = "Array.isArray({ length: 0 });"; @@ -179,7 +179,7 @@ public virtual void ArrayIsArrayMethodIsSupported() } [Test] - public virtual void ArrayLastIndexOfMethodIsSupported() + public virtual void SupportsArrayLastIndexOfMethod() { // Arrange const string initCode = "var arr = [2, 5, 9, 2]"; @@ -238,7 +238,7 @@ public virtual void ArrayLastIndexOfMethodIsSupported() } [Test] - public virtual void ArrayMapMethodIsSupported() + public virtual void SupportsArrayMapMethod() { // Arrange const string initCode = "var engines = ['Chakra', 'V8', 'SpiderMonkey', 'Jurassic'];"; @@ -264,7 +264,7 @@ public virtual void ArrayMapMethodIsSupported() } [Test] - public virtual void ArrayReduceMethodIsSupported() + public virtual void SupportsArrayReduceMethod() { // Arrange const string input1 = @"[1, 2, 3, 4, 5].reduce(function (accum, value, index, array) { @@ -293,7 +293,7 @@ public virtual void ArrayReduceMethodIsSupported() } [Test] - public virtual void ArrayReduceRightMethodIsSupported() + public virtual void SupportsArrayReduceRightMethod() { // Arrange const string input1 = @"[1, 2, 3, 4, 5].reduceRight(function (accum, value, index, array) { @@ -322,7 +322,7 @@ public virtual void ArrayReduceRightMethodIsSupported() } [Test] - public virtual void ArraySomeMethodIsSupported() + public virtual void SupportsArraySomeMethod() { // Arrange const string initCode = "var engines = ['Chakra', 'V8', 'SpiderMonkey', 'Jurassic'];"; @@ -348,7 +348,7 @@ public virtual void ArraySomeMethodIsSupported() #region Date methods [Test] - public virtual void DateNowMethodIsSupported() + public virtual void SupportsDateNowMethod() { // Arrange const string input = "Date.now();"; @@ -367,7 +367,7 @@ public virtual void DateNowMethodIsSupported() } [Test] - public virtual void DateToIsoStringMethodIsSupported() + public virtual void SupportsDateToIsoStringMethod() { // Arrange const string input = @"(new Date(1386696984000)).toISOString();"; @@ -390,21 +390,28 @@ public virtual void DateToIsoStringMethodIsSupported() #region Function methods [Test] - public virtual void FunctionBindIsSupported() + public virtual void SupportsFunctionBindMethod() { // Arrange - const string initCode = @"var a = 5, - module = { - a: 12, - getA: function() { return this.a; } - }, - getA = module.getA + const string initCode = @"var A = (function () { + function A(a) { + this.a = a; + } + + A.prototype.getA = function() { + return this.a; + }; + + return A; + })(), + a = new A(5), + otherContext = { a: 12 } ;"; - const string input1 = "getA();"; + const string input1 = "a.getA();"; const int targetOutput1 = 5; - const string input2 = "getA.bind(module)();"; + const string input2 = "a.getA.bind(otherContext)();"; const int targetOutput2 = 12; // Act @@ -429,7 +436,7 @@ public virtual void FunctionBindIsSupported() #region JSON methods [Test] - public virtual void JsonParseMethodIsSupported() + public virtual void SupportsJsonParseMethod() { // Arrange const string initCode = "var obj = JSON.parse('{ \"foo\": \"bar\" }');"; @@ -450,7 +457,7 @@ public virtual void JsonParseMethodIsSupported() } [Test] - public virtual void JsonStringifyMethodIsSupported() + public virtual void SupportsJsonStringifyMethod() { // Arrange const string initCode = @"var obj = new Object(); @@ -476,7 +483,7 @@ public virtual void JsonStringifyMethodIsSupported() #region Object methods [Test] - public virtual void ObjectCreateMethodIsSupported() + public virtual void SupportsObjectCreateMethod() { // Arrange const string initCode1 = "var obj1 = Object.create(null);"; @@ -531,7 +538,7 @@ public virtual void ObjectCreateMethodIsSupported() } [Test] - public virtual void ObjectKeysMethodIsSupported() + public virtual void SupportsObjectKeysMethod() { // Arrange const string input1 = "Object.keys(['a', 'b', 'c']).toString();"; @@ -578,7 +585,7 @@ public virtual void ObjectKeysMethodIsSupported() #region String methods [Test] - public virtual void StringSplitMethodIsCorrect() + public virtual void SupportsStringSplitMethod() { // Arrange const string input1 = "'aaaa'.split(/a/).length;"; @@ -609,7 +616,7 @@ public virtual void StringSplitMethodIsCorrect() } [Test] - public virtual void StringTrimMethodIsSupported() + public virtual void SupportsStringTrimMethod() { // Arrange const string input = "' foo '.trim();"; diff --git a/test/MsieJavaScriptEngine.Test.Common/FileSystemTestsBase.cs b/test/MsieJavaScriptEngine.Test.Common/FileSystemTestsBase.cs index bb8bfa6..cd82ffe 100644 --- a/test/MsieJavaScriptEngine.Test.Common/FileSystemTestsBase.cs +++ b/test/MsieJavaScriptEngine.Test.Common/FileSystemTestsBase.cs @@ -1,9 +1,5 @@ using System; using System.IO; -#if NETCOREAPP1_0 - -using Microsoft.Extensions.PlatformAbstractions; -#endif namespace MsieJavaScriptEngine.Test.Common { @@ -14,12 +10,7 @@ public abstract class FileSystemTestsBase : TestsBase protected FileSystemTestsBase() { -#if NETCOREAPP1_0 - var appEnv = PlatformServices.Default.Application; - string appDirectoryPath = appEnv.ApplicationBasePath; -#else string appDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; -#endif _baseDirectoryPath = Path.Combine(appDirectoryPath, "../../../../"); } diff --git a/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/Color.cs b/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/Color.cs deleted file mode 100644 index ecf6dc1..0000000 --- a/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/Color.cs +++ /dev/null @@ -1,387 +0,0 @@ -#if NETCOREAPP1_0 -using System; -using System.Text; - -namespace MsieJavaScriptEngine.Test.Common.Interop.Drawing -{ - /// - /// Represents an ARGB (alpha, red, green, blue) color - /// - public struct Color - { - private readonly string _name; - private readonly long _value; - private readonly short _knownColor; - private readonly short _state; - - private static short StateKnownColorValid = 1; - private static short StateARGBValueValid = 2; - private static short StateValueMask = StateARGBValueValid; - private static short StateNameValid = 8; - private static long NotDefinedValue = 0L; - public static readonly Color Empty = new Color(); - - /// - /// Gets a value indicating whether this structure is a predefined color. - /// Predefined colors are represented by the elements of the enumeration. - /// - /// true if this was created from a predefined color by using either - /// the FromName method or the FromKnownColor method; otherwise, false. - public bool IsKnownColor - { - get - { - return ((uint)_state & (uint)StateKnownColorValid) > 0U; - } - } - - /// - /// Gets a name of this - /// - /// The name of this - public string Name - { - get - { - if ((_state & StateNameValid) != 0) - { - return _name; - } - - if (IsKnownColor) - { - var knownColor = (KnownColor)_knownColor; - return KnownColorTable.KnownColorToName(knownColor) ?? knownColor.ToString(); - } - - return Convert.ToString(_value, 16); - } - } - - private long Value - { - get - { - if ((_state & StateValueMask) != 0) - { - return _value; - } - - if (IsKnownColor) - { - var knownColor = (KnownColor)_knownColor; - return KnownColorTable.KnownColorToArgb(knownColor); - } - - return NotDefinedValue; - } - } - - /// - /// Gets a system-defined color that has an ARGB value of #FFFF4500 - /// - /// A representing a system-defined color - public static Color OrangeRed - { - get - { - return new Color(KnownColor.OrangeRed); - } - } - - /// - /// Gets a red component value of this structure - /// - /// The red component value of this - public byte R - { - get - { - return (byte)((ulong)(Value >> 16) & byte.MaxValue); - } - } - - /// - /// Gets a green component value of this structure - /// - /// The green component value of this - public byte G - { - get - { - return (byte)((ulong)(Value >> 8) & byte.MaxValue); - } - } - - /// - /// Gets a blue component value of this structure - /// - /// The blue component value of this - public byte B - { - get - { - return (byte)((ulong)Value & byte.MaxValue); - } - } - - /// - /// Gets a alpha component value of this structure - /// - /// The alpha component value of this - public byte A - { - get - { - return (byte)((ulong)(Value >> 24) & byte.MaxValue); - } - } - - - internal Color(KnownColor knownColor) - { - _value = 0L; - _state = StateKnownColorValid; - _name = null; - _knownColor = (short)knownColor; - } - - private Color(long value, short state, string name, KnownColor knownColor) - { - _value = value; - _state = state; - _name = name; - _knownColor = (short)knownColor; - } - - - private static void CheckByte(int value, string name) - { - if (value < 0 || value > byte.MaxValue) - { - throw new ArgumentException(string.Format( - "Value of '{1}' is not valid for '{0}'. '{0}' should be greater than or equal to {2} and less than or equal to {3}.", - name, value, 0, (int)byte.MaxValue - )); - } - } - - private static long MakeArgb(byte alpha, byte red, byte green, byte blue) - { - return (uint)(red << 16 | green << 8 | blue | alpha << 24) & (long)uint.MaxValue; - } - - /// - /// Creates a structure from the specified 8-bit color values (red, green, and blue). - /// The alpha value is implicitly 255 (fully opaque). - /// Although this method allows a 32-bit value to be passed for each color component, the value - /// of each component is limited to 8 bits. - /// - /// The red component value for the new . - /// Valid values are 0 through 255. - /// The green component value for the new . - /// Valid values are 0 through 255. - /// The blue component value for the new . - /// Valid values are 0 through 255. - /// The that this method creates - /// , , or - /// is less than 0 or greater than 255. - public static Color FromArgb(int red, int green, int blue) - { - return FromArgb(byte.MaxValue, red, green, blue); - } - - /// - /// Creates a structure from the four ARGB component (alpha, red, green, and blue) values. - /// Although this method allows a 32-bit value to be passed for each component, the value of - /// each component is limited to 8 bits. - /// - /// The alpha component. Valid values are 0 through 255. - /// The red component. Valid values are 0 through 255. - /// The green component. Valid values are 0 through 255. - /// The blue component. Valid values are 0 through 255. - /// The that this method creates - /// , , - /// , or is less than 0 or greater than 255. - public static Color FromArgb(int alpha, int red, int green, int blue) - { - CheckByte(alpha, "alpha"); - CheckByte(red, "red"); - CheckByte(green, "green"); - CheckByte(blue, "blue"); - - return new Color(MakeArgb((byte)alpha, (byte)red, (byte)green, (byte)blue), - StateARGBValueValid, null, 0); - } - - /// - /// Gets a hue-saturation-brightness (HSB) brightness value for this structure - /// - /// The brightness of this . - /// The brightness ranges from 0.0 through 1.0, where 0.0 represents black and 1.0 represents white. - public float GetBrightness() - { - double num1 = R / (double)byte.MaxValue; - float num2 = G / (float)byte.MaxValue; - float num3 = B / (float)byte.MaxValue; - float num4 = (float)num1; - float num5 = (float)num1; - if (num2 > num4) - { - num4 = num2; - } - if (num3 > num4) - { - num4 = num3; - } - if (num2 < num5) - { - num5 = num2; - } - if (num3 < num5) - { - num5 = num3; - } - - return (float)((num4 + num5) / 2.0); - } - - /// - /// Gets a hue-saturation-brightness (HSB) hue value, in degrees, for this structure - /// - /// The hue, in degrees, of this . - /// The hue is measured in degrees, ranging from 0.0 through 360.0, in HSB color space. - public float GetHue() - { - if (R == G && G == B) - { - return 0.0f; - } - float num1 = R / (float)byte.MaxValue; - float num2 = G / (float)byte.MaxValue; - float num3 = B / (float)byte.MaxValue; - float num4 = 0.0f; - float num5 = num1; - float num6 = num1; - if (num2 > num5) - { - num5 = num2; - } - if (num3 > num5) - { - num5 = num3; - } - if (num2 < num6) - { - num6 = num2; - } - if (num3 < num6) - { - num6 = num3; - } - float num7 = num5 - num6; - if (num1 == num5) - { - num4 = (num2 - num3)/num7; - } - else if (num2 == num5) - { - num4 = (float)(2.0 + (num3 - num1) / num7); - } - else if (num3 == num5) - { - num4 = (float)(4.0 + (num1 - num2) / (double)num7); - } - float num8 = num4 * 60f; - if (num8 < 0.0) - { - num8 += 360f; - } - - return num8; - } - - /// - /// Gets a hue-saturation-brightness (HSB) saturation value for this structure - /// - /// The saturation of this . - /// The saturation ranges from 0.0 through 1.0, where 0.0 is grayscale and 1.0 is the most saturated. - public float GetSaturation() - { - double num1 = R / (double)byte.MaxValue; - float num2 = G / (float)byte.MaxValue; - float num3 = B / (float)byte.MaxValue; - float num4 = 0.0f; - float num5 = (float)num1; - float num6 = (float)num1; - if (num2 > num5) - { - num5 = num2; - } - if (num3 > num5) - { - num5 = num3; - } - if (num2 < num6) - { - num6 = num2; - } - if (num3 < num6) - { - num6 = num3; - } - if (num5 != num6) - { - num4 = (num5 + num6) / 2.0 > 0.5 ? - (float)((num5 -num6) / (2.0 - num5 - num6)) - : - (num5 - num6) / (num5 + num6) - ; - } - - return num4; - } - - /// - /// Converts this structure to a human-readable string - /// - /// A string that is the name of this , if the - /// is created from a predefined color by using either the FromName method - /// or the FromKnownColor method; - /// otherwise, a string that consists of the ARGB component names and their values. - /// - public override string ToString() - { - var sb = new StringBuilder(32); - sb.Append(GetType().Name); - sb.Append(" ["); - if ((_state & StateNameValid) != 0) - { - sb.Append(Name); - } - else if ((_state & StateKnownColorValid) != 0) - { - sb.Append(Name); - } - else if ((_state & StateValueMask) != 0) - { - sb.Append("A="); - sb.Append(A); - sb.Append(", R="); - sb.Append(R); - sb.Append(", G="); - sb.Append(G); - sb.Append(", B="); - sb.Append(B); - } - else - { - sb.Append("Empty"); - } - sb.Append("]"); - - return sb.ToString(); - } - } -} -#endif \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/KnownColor.cs b/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/KnownColor.cs deleted file mode 100644 index 09a59e5..0000000 --- a/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/KnownColor.cs +++ /dev/null @@ -1,12 +0,0 @@ -#if NETCOREAPP1_0 -namespace MsieJavaScriptEngine.Test.Common.Interop.Drawing -{ - /// - /// Specifies the known system colors - /// - public enum KnownColor - { - OrangeRed = 128 - } -} -#endif \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/KnownColorTable.cs b/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/KnownColorTable.cs deleted file mode 100644 index 162ad55..0000000 --- a/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/KnownColorTable.cs +++ /dev/null @@ -1,27 +0,0 @@ -#if NETCOREAPP1_0 -namespace MsieJavaScriptEngine.Test.Common.Interop.Drawing -{ - internal static class KnownColorTable - { - public static int KnownColorToArgb(KnownColor color) - { - if (color == KnownColor.OrangeRed) - { - return -1286; - } - - return 0; - } - - public static string KnownColorToName(KnownColor color) - { - if (color == KnownColor.OrangeRed) - { - return "OrangeRed"; - } - - return null; - } - } -} -#endif \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/Point.cs b/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/Point.cs deleted file mode 100644 index 1af2144..0000000 --- a/test/MsieJavaScriptEngine.Test.Common/Interop/Drawing/Point.cs +++ /dev/null @@ -1,79 +0,0 @@ -#if NETCOREAPP1_0 -using System.Globalization; - -namespace MsieJavaScriptEngine.Test.Common.Interop.Drawing -{ - /// - /// Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional plane - /// - public struct Point - { - private int _x; - private int _y; - - /// - /// Represents a that has X and Y values set to zero - /// - public static readonly Point Empty; - - /// - /// Gets or sets the x-coordinate of this - /// - public int X - { - get { return _x; } - set { _x = value; } - } - - /// - /// Gets or sets the y-coordinate of this - /// - public int Y - { - get { return _y; } - set { _y = value; } - } - - /// - /// Gets a value indicating whether this is empty - /// - /// true if both X and Y are 0; otherwise, false - public bool IsEmpty - { - get - { - if (_x == 0 && _y == 0) - { - return true; - } - - return false; - } - } - - - /// - /// Constructs an instance of the class with the specified coordinates - /// - /// The horizontal position of the point - /// The vertical position of the point - public Point(int x, int y) - { - _x = x; - _y = y; - } - - - /// - /// Converts this to a human-readable string - /// - /// A string that represents this - public override string ToString() - { - return "{X=" + _x.ToString(CultureInfo.CurrentCulture) + - ",Y=" + _y.ToString(CultureInfo.CurrentCulture) + "}" - ; - } - } -} -#endif \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Common/Interop/LoginFailedException.cs b/test/MsieJavaScriptEngine.Test.Common/Interop/LoginFailedException.cs new file mode 100644 index 0000000..85f1f40 --- /dev/null +++ b/test/MsieJavaScriptEngine.Test.Common/Interop/LoginFailedException.cs @@ -0,0 +1,54 @@ +using System; +#if !NET8_0_OR_GREATER +using System.Runtime.Serialization; +#endif + +namespace MsieJavaScriptEngine.Test.Common.Interop +{ + [Serializable] + public class LoginFailedException : Exception + { + private string _userName; + + public string UserName + { + get { return _userName; } + set { _userName = value; } + } + + + public LoginFailedException() + { } + + public LoginFailedException(string message) + : base(message) + { } + + public LoginFailedException(string message, Exception innerException) + : base(message, innerException) + { } +#if !NET8_0_OR_GREATER + + protected LoginFailedException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + if (info != null) + { + _userName = info.GetString("UserName"); + } + } + + + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + if (info == null) + { + throw new ArgumentNullException(nameof(info)); + } + + base.GetObjectData(info, context); + info.AddValue("UserName", this._userName); + } +#endif + } +} \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Common/Interop/SomeClass.cs b/test/MsieJavaScriptEngine.Test.Common/Interop/SomeClass.cs new file mode 100644 index 0000000..8a85635 --- /dev/null +++ b/test/MsieJavaScriptEngine.Test.Common/Interop/SomeClass.cs @@ -0,0 +1,10 @@ +namespace MsieJavaScriptEngine.Test.Common.Interop +{ + public class SomeClass + { + public int SomeProperty { get; set; } = 123; + public string SomeOtherProperty { get; set; } = "abc"; + + public static SomeClass Instance { get; } = new SomeClass(); + } +} \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Common/InteropTestsBase.cs b/test/MsieJavaScriptEngine.Test.Common/InteropTestsBase.cs index d708214..8cbb90a 100644 --- a/test/MsieJavaScriptEngine.Test.Common/InteropTestsBase.cs +++ b/test/MsieJavaScriptEngine.Test.Common/InteropTestsBase.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -#if !NETCOREAPP1_0 using System.Drawing; -#endif using System.IO; using System.Linq; using System.Text; @@ -11,9 +9,6 @@ using MsieJavaScriptEngine.Test.Common.Interop; using MsieJavaScriptEngine.Test.Common.Interop.Animals; -#if NETCOREAPP1_0 -using MsieJavaScriptEngine.Test.Common.Interop.Drawing; -#endif using MsieJavaScriptEngine.Test.Common.Interop.Logging; namespace MsieJavaScriptEngine.Test.Common @@ -26,7 +21,7 @@ public abstract class InteropTestsBase : FileSystemTestsBase #region Objects with fields [Test] - public virtual void EmbeddingOfInstanceOfCustomValueTypeWithFieldsIsCorrect() + public virtual void EmbeddingOfInstanceOfCustomValueTypeWithFields() { // Arrange var date = new Date(2015, 12, 29); @@ -63,7 +58,7 @@ public virtual void EmbeddingOfInstanceOfCustomValueTypeWithFieldsIsCorrect() } [Test] - public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithFieldsIsCorrect() + public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithFields() { // Arrange var product = new Product @@ -111,7 +106,7 @@ public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithFieldsIsCorrect( #region Objects with properties [Test] - public virtual void EmbeddingOfInstanceOfBuiltinValueTypeWithPropertiesIsCorrect() + public virtual void EmbeddingOfInstanceOfBuiltinValueTypeWithProperties() { // Arrange var timeSpan = new TimeSpan(4840780000000); @@ -152,7 +147,7 @@ public virtual void EmbeddingOfInstanceOfBuiltinValueTypeWithPropertiesIsCorrect } [Test] - public virtual void EmbeddingOfInstanceOfBuiltinReferenceTypeWithPropertiesIsCorrect() + public virtual void EmbeddingOfInstanceOfBuiltinReferenceTypeWithProperties() { // Arrange var uri = new Uri("https://github.com/Taritsyn/MsieJavaScriptEngine"); @@ -187,7 +182,7 @@ public virtual void EmbeddingOfInstanceOfBuiltinReferenceTypeWithPropertiesIsCor } [Test] - public virtual void EmbeddingOfInstanceOfCustomValueTypeWithPropertiesIsCorrect() + public virtual void EmbeddingOfInstanceOfCustomValueTypeWithProperties() { // Arrange var temperature = new Temperature(-17.3, TemperatureUnits.Celsius); @@ -222,7 +217,7 @@ public virtual void EmbeddingOfInstanceOfCustomValueTypeWithPropertiesIsCorrect( } [Test] - public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithPropertiesIsCorrect() + public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithProperties() { // Arrange var person = new Person("Vanya", "Ivanov"); @@ -260,7 +255,7 @@ public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithPropertiesIsCorr } [Test] - public virtual void EmbeddingOfInstanceOfAnonymousTypeWithPropertiesIsCorrect() + public virtual void EmbeddingOfInstanceOfAnonymousTypeWithProperties() { // Arrange var person = new @@ -328,7 +323,7 @@ public virtual void EmbeddingOfInstanceOfAnonymousTypeWithPropertiesIsCorrect() #region Objects with methods [Test] - public virtual void EmbeddingOfInstanceOfBuiltinValueTypeWithMethodsIsCorrect() + public virtual void EmbeddingOfInstanceOfBuiltinValueTypeWithMethods() { // Arrange var color = Color.FromArgb(84, 139, 212); @@ -363,7 +358,7 @@ public virtual void EmbeddingOfInstanceOfBuiltinValueTypeWithMethodsIsCorrect() } [Test] - public virtual void EmbeddingOfInstanceOfBuiltinReferenceTypeWithMethodIsCorrect() + public virtual void EmbeddingOfInstanceOfBuiltinReferenceTypeWithMethod() { // Arrange var random = new Random(); @@ -385,7 +380,7 @@ public virtual void EmbeddingOfInstanceOfBuiltinReferenceTypeWithMethodIsCorrect } [Test] - public virtual void EmbeddingOfInstanceOfCustomValueTypeWithMethodsIsCorrect() + public virtual void EmbeddingOfInstanceOfCustomValueTypeWithMethods() { // Arrange var programmerDayDate = new Date(2015, 9, 13); @@ -414,7 +409,7 @@ public virtual void EmbeddingOfInstanceOfCustomValueTypeWithMethodsIsCorrect() } [Test] - public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithMethodIsCorrect() + public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithMethod() { // Arrange var fileManager = new FileManager(); @@ -437,7 +432,7 @@ public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithMethodIsCorrect( } [Test] - public virtual void CallingOfMethodOfCustomReferenceTypeWithInterfaceParameterIsCorrect() + public virtual void EmbeddingOfInstancesOfCustomReferenceTypesAndCallingOfMethodOfWithInterfaceParameter() { // Arrange var animalTrainer = new AnimalTrainer(); @@ -468,12 +463,58 @@ public virtual void CallingOfMethodOfCustomReferenceTypeWithInterfaceParameterIs Assert.AreEqual(targetOutput2, output2); } + [Test] + public virtual void EmbeddingOfInstanceOfCustomValueTypeAndCallingOfItsGetTypeMethod() + { + // Arrange + string TestAllowReflectionSetting(bool allowReflection) + { + var date = new Date(); + + using (var jsEngine = CreateJsEngine(allowReflection: allowReflection)) + { + jsEngine.EmbedHostObject("date", date); + return jsEngine.Evaluate("date.GetType();"); + } + } + + // Act and Assert + Assert.AreEqual(typeof(Date).FullName, TestAllowReflectionSetting(true)); + + var exception = Assert.Throws(() => TestAllowReflectionSetting(false)); + Assert.AreEqual("Runtime error", exception.Category); + Assert.AreEqual("Object doesn't support property or method 'GetType'", exception.Description); + } + + [Test] + public virtual void EmbeddingOfInstanceOfCustomReferenceTypeAndCallingOfItsGetTypeMethod() + { + // Arrange + string TestAllowReflectionSetting(bool allowReflection) + { + var cat = new Cat(); + + using (var jsEngine = CreateJsEngine(allowReflection: allowReflection)) + { + jsEngine.EmbedHostObject("cat", cat); + return jsEngine.Evaluate("cat.GetType();"); + } + } + + // Act and Assert + Assert.AreEqual(typeof(Cat).FullName, TestAllowReflectionSetting(true)); + + var exception = Assert.Throws(() => TestAllowReflectionSetting(false)); + Assert.AreEqual("Runtime error", exception.Category); + Assert.AreEqual("Object doesn't support property or method 'GetType'", exception.Description); + } + #endregion #region Delegates [Test] - public virtual void EmbeddingOfInstanceOfDelegateWithoutParametersIsCorrect() + public virtual void EmbeddingOfInstanceOfDelegateWithoutParameters() { // Arrange var generateRandomStringFunc = new Func(() => @@ -512,7 +553,7 @@ public virtual void EmbeddingOfInstanceOfDelegateWithoutParametersIsCorrect() } [Test] - public virtual void EmbeddingOfInstanceOfDelegateWithOneParameterIsCorrect() + public virtual void EmbeddingOfInstanceOfDelegateWithOneParameter() { // Arrange var squareFunc = new Func(a => a * a); @@ -534,7 +575,7 @@ public virtual void EmbeddingOfInstanceOfDelegateWithOneParameterIsCorrect() } [Test] - public virtual void EmbeddingOfInstanceOfDelegateWithTwoParametersIsCorrect() + public virtual void EmbeddingOfInstanceOfDelegateWithTwoParameters() { // Arrange var sumFunc = new Func((a, b) => a + b); @@ -556,7 +597,7 @@ public virtual void EmbeddingOfInstanceOfDelegateWithTwoParametersIsCorrect() } [Test] - public virtual void EmbeddingOfInstanceOfDelegateWithoutResultIsCorrect() + public virtual void EmbeddingOfInstanceOfDelegateWithoutResult() { // Arrange var logBuilder = new StringBuilder(); @@ -602,7 +643,28 @@ public virtual void EmbeddingOfInstanceOfDelegateWithoutResultIsCorrect() } [Test] - public virtual void CallingOfEmbeddedDelegateWithMissingParameter() + public virtual void EmbeddingOfInstanceOfDelegateAndCheckingItsPrototype() + { + // Arrange + var someFunc = new Func(() => 42); + + const string input = "Object.getPrototypeOf(embeddedFunc) === Function.prototype"; + + // Act + bool output; + + using (var jsEngine = CreateJsEngine()) + { + jsEngine.EmbedHostObject("embeddedFunc", someFunc); + output = jsEngine.Evaluate(input); + } + + // Assert + Assert.True(output); + } + + [Test] + public virtual void EmbeddingOfInstanceOfDelegateAndCallingItWithMissingParameter() { // Arrange var sumFunc = new Func((a, b) => a + b); @@ -630,7 +692,7 @@ public virtual void CallingOfEmbeddedDelegateWithMissingParameter() } [Test] - public virtual void CallingOfEmbeddedDelegateWithExtraParameter() + public virtual void EmbeddingOfInstanceOfDelegateAndCallingItWithExtraParameter() { // Arrange var sumFunc = new Func((a, b) => a + b); @@ -651,12 +713,33 @@ public virtual void CallingOfEmbeddedDelegateWithExtraParameter() Assert.AreEqual(targetOutput, output); } + [Test] + public virtual void EmbeddingOfInstanceOfDelegateAndGettingItsMethodProperty() + { + // Arrange + string TestAllowReflectionSetting(bool allowReflection) + { + var cat = new Cat(); + var cryFunc = new Func(cat.Cry); + + using (var jsEngine = CreateJsEngine(allowReflection: allowReflection)) + { + jsEngine.EmbedHostObject("cry", cryFunc); + return jsEngine.Evaluate("cry.Method;"); + } + } + + // Act and Assert + Assert.AreEqual("undefined", TestAllowReflectionSetting(true)); + Assert.AreEqual("undefined", TestAllowReflectionSetting(false)); + } + #endregion #region Integration [Test] - public virtual void InteractionOfEmbeddedCustomValueTypeAndDelegateInstancesIsCorrect() + public virtual void InteractionOfEmbeddedCustomValueTypeAndDelegateInstances() { // Arrange var informaticsDayDate = new Date(2015, 12, 4); @@ -707,7 +790,7 @@ public virtual void InteractionOfEmbeddedCustomValueTypeAndDelegateInstancesIsCo #region Recursive calls [Test] - public virtual void RecursiveEvaluationOfFilesIsCorrect() + public virtual void RecursiveEvaluationOfFiles() { // Arrange string directoryPath = GetAbsolutePath("SharedFiles/recursiveEvaluation/noError"); @@ -736,7 +819,7 @@ public virtual void RecursiveEvaluationOfFilesIsCorrect() } [Test] - public virtual void RecursiveExecutionOfFilesIsCorrect() + public virtual void RecursiveExecutionOfFiles() { // Arrange string directoryPath = GetAbsolutePath("SharedFiles/recursiveExecution/noError"); @@ -766,7 +849,7 @@ public virtual void RecursiveExecutionOfFilesIsCorrect() #region Removal [Test] - public virtual void RemovingOfEmbeddedInstanceOfCustomReferenceTypeIsCorrect() + public virtual void RemovingOfEmbeddedInstanceOfCustomReferenceType() { // Arrange var person = new Person("Vasya", "Pupkin"); @@ -794,6 +877,41 @@ public virtual void RemovingOfEmbeddedInstanceOfCustomReferenceTypeIsCorrect() #endregion + #region Special cases + + [Test] + public virtual void EmbeddingOfInstanceOfCustomReferenceTypeAndModificationOfGlobalObject() + { + // Arrange + var someObj = new SomeClass(); + + const string modifyingCode = @"(function () { + 'use strict'; + + var global = typeof self != 'undefined' && self.Math == Math ? + self : Function('return this')(); + + global['foo'] = 'bar'; +})();"; + const string variableName = "foo"; + const string targetOutput = "bar"; + + // Act + string output; + + using (var jsEngine = CreateJsEngine()) + { + jsEngine.EmbedHostObject("someObj", someObj); + jsEngine.Execute(modifyingCode); + output = jsEngine.GetVariableValue(variableName); + } + + // Assert + Assert.AreEqual(targetOutput, output); + } + + #endregion + #endregion @@ -802,7 +920,7 @@ public virtual void RemovingOfEmbeddedInstanceOfCustomReferenceTypeIsCorrect() #region Creating of instances [Test] - public virtual void CreatingAnInstanceOfEmbeddedBuiltinValueTypeIsCorrect() + public virtual void CreatingAnInstanceOfEmbeddedBuiltinValueType() { // Arrange Type pointType = typeof(Point); @@ -824,7 +942,7 @@ public virtual void CreatingAnInstanceOfEmbeddedBuiltinValueTypeIsCorrect() } [Test] - public virtual void CreatingAnInstanceOfEmbeddedBuiltinReferenceTypeIsCorrect() + public virtual void CreatingAnInstanceOfEmbeddedBuiltinReferenceType() { // Arrange Type uriType = typeof(Uri); @@ -850,7 +968,7 @@ public virtual void CreatingAnInstanceOfEmbeddedBuiltinReferenceTypeIsCorrect() } [Test] - public virtual void CreatingAnInstanceOfEmbeddedCustomValueTypeIsCorrect() + public virtual void CreatingAnInstanceOfEmbeddedCustomValueType() { // Arrange Type point3DType = typeof(Point3D); @@ -872,7 +990,7 @@ public virtual void CreatingAnInstanceOfEmbeddedCustomValueTypeIsCorrect() } [Test] - public virtual void CreatingAnInstanceOfEmbeddedCustomReferenceTypeIsCorrect() + public virtual void CreatingAnInstanceOfEmbeddedCustomReferenceType() { // Arrange Type personType = typeof(Person); @@ -893,12 +1011,55 @@ public virtual void CreatingAnInstanceOfEmbeddedCustomReferenceTypeIsCorrect() Assert.AreEqual(targetOutput, output); } + [Test] + public virtual void CreatingAnInstanceOfEmbeddedBuiltinExceptionAndGettingItsTargetSiteProperty() + { + // Arrange + string TestAllowReflectionSetting(bool allowReflection) + { + Type invalidOperationExceptionType = typeof(InvalidOperationException); + + using (var jsEngine = CreateJsEngine(allowReflection: allowReflection)) + { + jsEngine.EmbedHostType("InvalidOperationError", invalidOperationExceptionType); + return jsEngine.Evaluate("new InvalidOperationError(\"A terrible thing happened!\").TargetSite;"); + } + } + + // Act and Assert + Assert.AreEqual(null, TestAllowReflectionSetting(true)); + Assert.AreEqual("undefined", TestAllowReflectionSetting(false)); + } + + [Test] + public virtual void CreatingAnInstanceOfEmbeddedCustomExceptionAndCallingOfItsGetTypeMethod() + { + // Arrange + string TestAllowReflectionSetting(bool allowReflection) + { + Type loginFailedExceptionType = typeof(LoginFailedException); + + using (var jsEngine = CreateJsEngine(allowReflection: allowReflection)) + { + jsEngine.EmbedHostType("LoginFailedError", loginFailedExceptionType); + return jsEngine.Evaluate("new LoginFailedError(\"Wrong password entered!\").GetType();"); + } + } + + // Act and Assert + Assert.AreEqual(typeof(LoginFailedException).FullName, TestAllowReflectionSetting(true)); + + var exception = Assert.Throws(() => TestAllowReflectionSetting(false)); + Assert.AreEqual("Runtime error", exception.Category); + Assert.AreEqual("Object doesn't support property or method 'GetType'", exception.Description); + } + #endregion #region Types with constants [Test] - public virtual void EmbeddingOfBuiltinReferenceTypeWithConstantsIsCorrect() + public virtual void EmbeddingOfBuiltinReferenceTypeWithConstants() { // Arrange Type mathType = typeof(Math); @@ -927,7 +1088,7 @@ public virtual void EmbeddingOfBuiltinReferenceTypeWithConstantsIsCorrect() } [Test] - public virtual void EmbeddingOfCustomValueTypeWithConstantsIsCorrect() + public virtual void EmbeddingOfCustomValueTypeWithConstants() { // Arrange Type predefinedStringsType = typeof(PredefinedStrings); @@ -962,7 +1123,7 @@ public virtual void EmbeddingOfCustomValueTypeWithConstantsIsCorrect() } [Test] - public virtual void EmbeddingOfCustomReferenceTypeWithConstantIsCorrect() + public virtual void EmbeddingOfCustomReferenceTypeWithConstant() { // Arrange Type base64EncoderType = typeof(Base64Encoder); @@ -988,7 +1149,7 @@ public virtual void EmbeddingOfCustomReferenceTypeWithConstantIsCorrect() #region Types with fields [Test] - public virtual void EmbeddingOfBuiltinValueTypeWithFieldIsCorrect() + public virtual void EmbeddingOfBuiltinValueTypeWithField() { // Arrange Type guidType = typeof(Guid); @@ -1010,7 +1171,7 @@ public virtual void EmbeddingOfBuiltinValueTypeWithFieldIsCorrect() } [Test] - public virtual void EmbeddingOfBuiltinReferenceTypeWithFieldIsCorrect() + public virtual void EmbeddingOfBuiltinReferenceTypeWithField() { // Arrange Type bitConverterType = typeof(BitConverter); @@ -1032,7 +1193,7 @@ public virtual void EmbeddingOfBuiltinReferenceTypeWithFieldIsCorrect() } [Test] - public virtual void EmbeddingOfCustomValueTypeWithFieldIsCorrect() + public virtual void EmbeddingOfCustomValueTypeWithField() { // Arrange Type point3DType = typeof(Point3D); @@ -1054,7 +1215,7 @@ public virtual void EmbeddingOfCustomValueTypeWithFieldIsCorrect() } [Test] - public virtual void EmbeddingOfCustomReferenceTypeWithFieldIsCorrect() + public virtual void EmbeddingOfCustomReferenceTypeWithField() { // Arrange Type defaultLoggerType = typeof(DefaultLogger); @@ -1085,7 +1246,7 @@ public virtual void EmbeddingOfCustomReferenceTypeWithFieldIsCorrect() #region Types with properties [Test] - public virtual void EmbeddingOfBuiltinValueTypeWithPropertyIsCorrect() + public virtual void EmbeddingOfBuiltinValueTypeWithProperty() { // Arrange Type colorType = typeof(Color); @@ -1107,7 +1268,7 @@ public virtual void EmbeddingOfBuiltinValueTypeWithPropertyIsCorrect() } [Test] - public virtual void EmbeddingOfBuiltinReferenceTypeWithPropertyIsCorrect() + public virtual void EmbeddingOfBuiltinReferenceTypeWithProperty() { // Arrange Type environmentType = typeof(Environment); @@ -1129,7 +1290,7 @@ public virtual void EmbeddingOfBuiltinReferenceTypeWithPropertyIsCorrect() } [Test] - public virtual void EmbeddingOfCustomValueTypeWithPropertyIsCorrect() + public virtual void EmbeddingOfCustomValueTypeWithProperty() { // Arrange Type dateType = typeof(Date); @@ -1162,7 +1323,7 @@ public virtual void EmbeddingOfCustomValueTypeWithPropertyIsCorrect() } [Test] - public virtual void EmbeddingOfCustomReferenceTypeWithPropertyIsCorrect() + public virtual void EmbeddingOfCustomReferenceTypeWithProperty() { // Arrange Type bundleTableType = typeof(BundleTable); @@ -1191,7 +1352,7 @@ public virtual void EmbeddingOfCustomReferenceTypeWithPropertyIsCorrect() #region Types with methods [Test] - public virtual void EmbeddingOfBuiltinValueTypeWithMethodIsCorrect() + public virtual void EmbeddingOfBuiltinValueTypeWithMethod() { // Arrange Type dateTimeType = typeof(DateTime); @@ -1213,7 +1374,7 @@ public virtual void EmbeddingOfBuiltinValueTypeWithMethodIsCorrect() } [Test] - public virtual void EmbeddingOfBuiltinReferenceTypeWithMethodsIsCorrect() + public virtual void EmbeddingOfBuiltinReferenceTypeWithMethods() { // Arrange Type mathType = typeof(Math); @@ -1241,7 +1402,7 @@ public virtual void EmbeddingOfBuiltinReferenceTypeWithMethodsIsCorrect() } [Test] - public virtual void EmbeddingOfCustomValueTypeWithMethodIsCorrect() + public virtual void EmbeddingOfCustomValueTypeWithMethod() { // Arrange var dateType = typeof(Date); @@ -1263,7 +1424,7 @@ public virtual void EmbeddingOfCustomValueTypeWithMethodIsCorrect() } [Test] - public virtual void EmbeddingOfCustomReferenceTypeWithMethodIsCorrect() + public virtual void EmbeddingOfCustomReferenceTypeWithMethod() { // Arrange Type base64EncoderType = typeof(Base64Encoder); @@ -1289,7 +1450,7 @@ public virtual void EmbeddingOfCustomReferenceTypeWithMethodIsCorrect() #region Removal [Test] - public virtual void RemovingOfEmbeddedCustomReferenceTypeIsCorrect() + public virtual void RemovingOfEmbeddedCustomReferenceType() { // Arrange Type personType = typeof(Person); @@ -1317,6 +1478,41 @@ public virtual void RemovingOfEmbeddedCustomReferenceTypeIsCorrect() #endregion + #region Special cases + + [Test] + public virtual void EmbeddingOfCustomReferenceTypeAndModificationOfGlobalObject() + { + // Arrange + var someType = typeof(SomeClass); + + const string modifyingCode = @"(function () { + 'use strict'; + + var global = typeof self != 'undefined' && self.Math == Math ? + self : Function('return this')(); + + global.foo = 'baz'; +})();"; + const string variableName = "foo"; + const string targetOutput = "baz"; + + // Act + string output; + + using (var jsEngine = CreateJsEngine()) + { + jsEngine.EmbedHostType("SomeType", someType); + jsEngine.Execute(modifyingCode); + output = jsEngine.GetVariableValue(variableName); + } + + // Assert + Assert.AreEqual(targetOutput, output); + } + + #endregion + #endregion } } \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Common/MsieJavaScriptEngine.Test.Common.csproj b/test/MsieJavaScriptEngine.Test.Common/MsieJavaScriptEngine.Test.Common.csproj index c0989f1..826f89d 100644 --- a/test/MsieJavaScriptEngine.Test.Common/MsieJavaScriptEngine.Test.Common.csproj +++ b/test/MsieJavaScriptEngine.Test.Common/MsieJavaScriptEngine.Test.Common.csproj @@ -1,37 +1,32 @@  - - MSIE JavaScript Engine: Common Tests - 3.0.7 - net40;net451;netcoreapp1.0;netcoreapp2.1;netcoreapp3.1 - 1.0.16 - Library - true - true - false - - - - - - - - - - - - - - - - - - - - - - - - + + MSIE JavaScript Engine: Common Tests + 3.2.5 + net462;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + Library + true + true + false + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/MsieJavaScriptEngine.Test.Common/MultithreadingTestsBase.cs b/test/MsieJavaScriptEngine.Test.Common/MultithreadingTestsBase.cs index 8849530..2b1311c 100644 --- a/test/MsieJavaScriptEngine.Test.Common/MultithreadingTestsBase.cs +++ b/test/MsieJavaScriptEngine.Test.Common/MultithreadingTestsBase.cs @@ -8,7 +8,7 @@ namespace MsieJavaScriptEngine.Test.Common public abstract class MultithreadingTestsBase : TestsBase { [Test] - public virtual void ExecutionOfCodeFromDifferentThreadsIsCorrect() + public virtual void ExecutionOfCodeFromDifferentThreads() { // Arrange const string variableName = "foo"; diff --git a/test/MsieJavaScriptEngine.Test.Common/PrecompilationTestsBase.cs b/test/MsieJavaScriptEngine.Test.Common/PrecompilationTestsBase.cs index 60fe323..772e218 100644 --- a/test/MsieJavaScriptEngine.Test.Common/PrecompilationTestsBase.cs +++ b/test/MsieJavaScriptEngine.Test.Common/PrecompilationTestsBase.cs @@ -1,7 +1,5 @@ using System.IO; -#if !NET40 using System.Reflection; -#endif using System.Threading.Tasks; using NUnit.Framework; @@ -14,7 +12,7 @@ public abstract class PrecompilationTestsBase : FileSystemTestsBase #region Execution of precompiled scripts [Test] - public virtual void ExecutionOfPrecompiledCodeIsCorrect() + public virtual void ExecutionOfPrecompiledCode() { // Arrange const string libraryCode = @"function declensionOfNumerals(number, titles) { @@ -86,7 +84,7 @@ function declinationOfSeconds(number) { } [Test] - public virtual void ExecutionOfPrecompiledFileIsCorrect() + public virtual void ExecutionOfPrecompiledFile() { // Arrange string filePath = GetAbsolutePath("SharedFiles/declinationOfMinutes.js"); @@ -136,7 +134,7 @@ public virtual void ExecutionOfPrecompiledFileIsCorrect() } [Test] - public virtual void ExecutionOfPrecompiledResourceByNameAndTypeIsCorrect() + public virtual void ExecutionOfPrecompiledResourceByNameAndType() { // Arrange const string resourceName = "Resources.declinationOfHours.js"; @@ -186,7 +184,7 @@ public virtual void ExecutionOfPrecompiledResourceByNameAndTypeIsCorrect() } [Test] - public virtual void ExecutionOfPrecompiledResourceByNameAndAssemblyIsCorrect() + public virtual void ExecutionOfPrecompiledResourceByNameAndAssembly() { // Arrange const string resourceName = "MsieJavaScriptEngine.Test.Common.Resources.declinationOfDays.js"; @@ -207,9 +205,7 @@ public virtual void ExecutionOfPrecompiledResourceByNameAndAssemblyIsCorrect() if (supportsScriptPrecompilation) { precompiledResource = jsEngine.PrecompileResource(resourceName, typeof(PrecompilationTestsBase) -#if !NET40 .GetTypeInfo() -#endif .Assembly ); diff --git a/test/MsieJavaScriptEngine.Test.Common/TestsBase.cs b/test/MsieJavaScriptEngine.Test.Common/TestsBase.cs index 81c99f7..6854dfb 100644 --- a/test/MsieJavaScriptEngine.Test.Common/TestsBase.cs +++ b/test/MsieJavaScriptEngine.Test.Common/TestsBase.cs @@ -18,15 +18,11 @@ public abstract class TestsBase protected virtual bool UseJson2Library => false; - protected MsieJsEngine CreateJsEngine() - { - return CreateJsEngine(false); - } - - protected MsieJsEngine CreateJsEngine(bool enableDebugging) + protected MsieJsEngine CreateJsEngine(bool allowReflection = false, bool enableDebugging = false) { var jsEngine = new MsieJsEngine(new JsEngineSettings { + AllowReflection = allowReflection, EnableDebugging = enableDebugging, EngineMode = EngineMode, UseEcmaScript5Polyfill = UseEcmaScript5Polyfill, diff --git a/test/MsieJavaScriptEngine.Test.Common/ValidationTests.cs b/test/MsieJavaScriptEngine.Test.Common/ValidationTests.cs index 7acc226..a9c90a5 100644 --- a/test/MsieJavaScriptEngine.Test.Common/ValidationTests.cs +++ b/test/MsieJavaScriptEngine.Test.Common/ValidationTests.cs @@ -8,7 +8,7 @@ namespace MsieJavaScriptEngine.Test.Common public class ValidationTests { [Test] - public void NameFormatIsCorrect() + public void CheckingOfCorrectNameFormat() { // Arrange @@ -30,7 +30,7 @@ public void NameFormatIsCorrect() } [Test] - public void NameFormatIsWrong() + public void CheckingOfWrongNameFormat() { // Arrange @@ -50,7 +50,7 @@ public void NameFormatIsWrong() } [Test] - public void DocumentNameFormatIsCorrect() + public void CheckingOfCorrectDocumentNameFormat() { // Arrange @@ -74,7 +74,7 @@ public void DocumentNameFormatIsCorrect() } [Test] - public void DocumentNameFormatIsWrong() + public void CheckingOfWrongDocumentNameFormat() { // Arrange