├── .editorconfig ├── .gitattributes ├── .gitignore ├── CHANGELOG.md ├── LICENSE.txt ├── Licenses ├── chakra-host-license.txt ├── cross-browser-split-license.txt ├── jsrt-dotnet-license.txt ├── sass-and-coffee-license.txt └── uglify-js-license.txt ├── MsieJavaScriptEngine.sln ├── README.md ├── build-js.cmd ├── build ├── Key.snk ├── common.props ├── net40-client-target.props └── strong-name-signing.props ├── global.json ├── images └── MsieJavaScriptEngine_Logo_128x128.png ├── run-tests.cmd ├── src └── MsieJavaScriptEngine │ ├── .uglifyjsrc │ ├── ActiveScript │ ├── ActiveScriptException.cs │ ├── ActiveScriptJsEngineBase.ScriptSiteBase.cs │ ├── ActiveScriptJsEngineBase.cs │ ├── ActiveScriptJsErrorHelpers.cs │ ├── ActiveScriptWrapper32.cs │ ├── ActiveScriptWrapper64.cs │ ├── ActiveScriptWrapperBase.cs │ ├── ChakraActiveScriptJsEngine.ScriptSite.cs │ ├── ChakraActiveScriptJsEngine.cs │ ├── ClassicActiveScriptJsEngine.ScriptSite.cs │ ├── ClassicActiveScriptJsEngine.cs │ ├── Debugging │ │ ├── AppBreakFlags.cs │ │ ├── BreakReason.cs │ │ ├── BreakResumeAction.cs │ │ ├── BreakpointState.cs │ │ ├── DebugApplicationWrapper.cs │ │ ├── DebugDocument.cs │ │ ├── DebugDocumentContext.cs │ │ ├── DebugLineInfo.cs │ │ ├── DebugStackFrameDescriptor.cs │ │ ├── DocumentNameType.cs │ │ ├── ErrorResumeAction.cs │ │ ├── IActiveScriptDebug32.cs │ │ ├── IActiveScriptDebug64.cs │ │ ├── IActiveScriptErrorDebug.cs │ │ ├── IActiveScriptSiteDebug32.cs │ │ ├── IActiveScriptSiteDebug64.cs │ │ ├── IActiveScriptSiteDebugEx.cs │ │ ├── IApplicationDebugger.cs │ │ ├── IDebugApplication32.cs │ │ ├── IDebugApplication64.cs │ │ ├── IDebugApplicationNode.cs │ │ ├── IDebugApplicationThread.cs │ │ ├── IDebugAsyncOperation.cs │ │ ├── IDebugCodeContext.cs │ │ ├── IDebugDocument.cs │ │ ├── IDebugDocumentContext.cs │ │ ├── IDebugDocumentHelper32.cs │ │ ├── IDebugDocumentHelper64.cs │ │ ├── IDebugDocumentInfo.cs │ │ ├── IDebugDocumentProvider.cs │ │ ├── IDebugDocumentText.cs │ │ ├── IDebugProperty.cs │ │ ├── IDebugStackFrame.cs │ │ ├── IDebugStackFrameSniffer.cs │ │ ├── IDebugStackFrameSnifferEx32.cs │ │ ├── IDebugStackFrameSnifferEx64.cs │ │ ├── IDebugSyncOperation.cs │ │ ├── IDebugThreadCall32.cs │ │ ├── IDebugThreadCall64.cs │ │ ├── IEnumDebugApplicationNodes.cs │ │ ├── IEnumDebugCodeContexts.cs │ │ ├── IEnumDebugExpressionContexts.cs │ │ ├── IEnumDebugStackFrames.cs │ │ ├── IEnumRemoteDebugApplicationThreads.cs │ │ ├── IProcessDebugManager32.cs │ │ ├── IProcessDebugManager64.cs │ │ ├── IProvideExpressionContexts.cs │ │ ├── IRemoteDebugApplicationThread.cs │ │ ├── NullEnumDebugStackFrames.cs │ │ ├── ProcessDebugManager.cs │ │ ├── ProcessDebugManagerWrapper.cs │ │ ├── SourceTextAttrs.cs │ │ └── TextDocAttrs.cs │ ├── HostItemBase.cs │ ├── HostObject.cs │ ├── HostType.cs │ ├── IActiveScript.cs │ ├── IActiveScriptError.cs │ ├── IActiveScriptGarbageCollector.cs │ ├── IActiveScriptParse32.cs │ ├── IActiveScriptParse64.cs │ ├── IActiveScriptProperty.cs │ ├── IActiveScriptSite.cs │ ├── IActiveScriptSiteInterruptPoll.cs │ ├── IActiveScriptWrapper.cs │ ├── JScriptRuntimeErrorNumber.cs │ ├── JScriptSyntaxErrorNumber.cs │ ├── ScriptGCType.cs │ ├── ScriptInfoFlags.cs │ ├── ScriptInterruptFlags.cs │ ├── ScriptItemFlags.cs │ ├── ScriptLanguageVersion.cs │ ├── ScriptProperty.cs │ ├── ScriptState.cs │ ├── ScriptTextFlags.cs │ ├── ScriptThreadId.cs │ ├── ScriptThreadState.cs │ └── ScriptTypeLibFlags.cs │ ├── Constants │ ├── ClassId.cs │ ├── ComErrorCode.cs │ ├── DllName.cs │ ├── JsErrorCategory.cs │ ├── JsErrorType.cs │ └── SpecialMemberName.cs │ ├── Extensions │ ├── ExceptionExtensions.cs │ ├── StringExtensions.cs │ └── TypeExtensions.cs │ ├── Helpers │ ├── CallStackItem.cs │ ├── ComHelpers.cs │ ├── CommonRegExps.cs │ ├── JsEngineModeHelpers.cs │ ├── JsErrorHelpers.cs │ ├── NumericHelpers.cs │ ├── ReflectionHelpers.cs │ ├── TextHelpers.cs │ ├── TypeMappingHelpers.cs │ └── ValidationHelpers.cs │ ├── IInnerJsEngine.cs │ ├── InnerJsEngineBase.cs │ ├── JsCompilationException.cs │ ├── JsEngineException.cs │ ├── JsEngineLoadException.cs │ ├── JsEngineMode.cs │ ├── JsEngineSettings.cs │ ├── JsException.cs │ ├── JsFatalException.cs │ ├── JsInterruptedException.cs │ ├── JsRt │ ├── ChakraJsRtJsEngineBase.cs │ ├── Edge │ │ ├── ChakraEdgeJsRtJsEngine.cs │ │ ├── EdgeJsContext.cs │ │ ├── EdgeJsErrorHelpers.cs │ │ ├── EdgeJsNativeFunction.cs │ │ ├── EdgeJsPropertyId.cs │ │ ├── EdgeJsRuntime.cs │ │ ├── EdgeJsScope.cs │ │ ├── EdgeJsScriptException.cs │ │ ├── EdgeJsValue.cs │ │ ├── EdgeJsValueExtensions.cs │ │ ├── EdgeNativeMethods.cs │ │ └── EdgeTypeMapper.cs │ ├── Embedding │ │ ├── EmbeddedItem.cs │ │ ├── EmbeddedObject.cs │ │ ├── EmbeddedObjectKey.cs │ │ └── EmbeddedType.cs │ ├── Ie │ │ ├── ChakraIeJsRtJsEngine.cs │ │ ├── IeJsContext.cs │ │ ├── IeJsErrorHelpers.cs │ │ ├── IeJsNativeFunction.cs │ │ ├── IeJsPropertyId.cs │ │ ├── IeJsRuntime.cs │ │ ├── IeJsScope.cs │ │ ├── IeJsScriptException.cs │ │ ├── IeJsValue.cs │ │ ├── IeJsValueExtensions.cs │ │ ├── IeNativeMethods.cs │ │ └── IeTypeMapper.cs │ ├── JsBackgroundWorkItemCallback.cs │ ├── JsBeforeCollectCallback.cs │ ├── JsEngineException.cs │ ├── JsErrorCode.cs │ ├── JsException.cs │ ├── JsFatalException.cs │ ├── JsFinalizeCallback.cs │ ├── JsMemoryAllocationCallback.cs │ ├── JsMemoryEventType.cs │ ├── JsRuntimeAttributes.cs │ ├── JsRuntimeVersion.cs │ ├── JsSourceContext.cs │ ├── JsThreadServiceCallback.cs │ ├── JsUsageException.cs │ ├── JsValueType.cs │ └── TypeMapper.cs │ ├── JsRuntimeException.cs │ ├── JsScriptException.cs │ ├── JsUsageException.cs │ ├── MsieJavaScriptEngine.csproj │ ├── MsieJsEngine.cs │ ├── PACKAGE-DESCRIPTION.md │ ├── Polyfills │ └── System │ │ └── Reflection │ │ └── TypeInfoExtensions.cs │ ├── PrecompiledScript.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Resources │ ├── CommonStrings.Designer.cs │ ├── CommonStrings.resx │ ├── CommonStrings.ru-RU.Designer.cs │ ├── CommonStrings.ru-RU.resx │ ├── ES5.js │ ├── NetCoreStrings.Designer.cs │ ├── NetCoreStrings.resx │ ├── NetCoreStrings.ru-RU.Designer.cs │ ├── NetCoreStrings.ru-RU.resx │ ├── NetFrameworkStrings.Designer.cs │ ├── NetFrameworkStrings.resx │ ├── NetFrameworkStrings.ru-RU.Designer.cs │ ├── NetFrameworkStrings.ru-RU.resx │ └── json2.js │ ├── ScriptDispatcher.cs │ ├── Undefined.cs │ ├── Utilities │ ├── InterlockedStatedFlag.cs │ ├── StatedFlag.cs │ ├── TypeConverter.cs │ ├── UniqueDocumentNameManager.cs │ └── Utils.cs │ ├── package.json │ └── readme.txt └── test ├── MsieJavaScriptEngine.Benchmarks ├── Assert.cs ├── HostObjectsEmbeddingBenchmark.cs ├── HostTypesEmbeddingBenchmark.cs ├── Interop │ ├── ObjectsEmbedding │ │ ├── SomeClass.cs │ │ ├── SomeClassBase.cs │ │ └── SomeOtherClass.cs │ └── TypesEmbedding │ │ ├── SomeClass.cs │ │ └── SomeOtherClass.cs ├── JsExecutionBenchmark.cs ├── MsieJavaScriptEngine.Benchmarks.csproj ├── Program.cs └── Resources │ └── russian-translit.js ├── MsieJavaScriptEngine.Test.Auto ├── CommonTests.cs ├── Es5Tests.cs ├── InteropTests.cs ├── MsieJavaScriptEngine.Test.Auto.csproj ├── MultithreadingTests.cs └── PrecompilationTests.cs ├── MsieJavaScriptEngine.Test.ChakraActiveScript ├── CommonTests.cs ├── Es5Tests.cs ├── InteropTests.cs ├── MsieJavaScriptEngine.Test.ChakraActiveScript.csproj ├── MultithreadingTests.cs └── PrecompilationTests.cs ├── MsieJavaScriptEngine.Test.ChakraEdgeJsRt ├── CommonTests.cs ├── Es5Tests.cs ├── InteropTests.cs ├── MsieJavaScriptEngine.Test.ChakraEdgeJsRt.csproj ├── MultithreadingTests.cs └── PrecompilationTests.cs ├── MsieJavaScriptEngine.Test.ChakraIeJsRt ├── CommonTests.cs ├── Es5Tests.cs ├── InteropTests.cs ├── MsieJavaScriptEngine.Test.ChakraIeJsRt.csproj ├── MultithreadingTests.cs └── PrecompilationTests.cs ├── MsieJavaScriptEngine.Test.Classic ├── CommonTests.cs ├── Es5Tests.cs ├── InteropTests.cs ├── MsieJavaScriptEngine.Test.Classic.csproj ├── MultithreadingTests.cs └── PrecompilationTests.cs ├── MsieJavaScriptEngine.Test.Common ├── CommonTestsBase.cs ├── ErrorFormattingTests.cs ├── Es5TestsBase.cs ├── FileSystemTestsBase.cs ├── Interop │ ├── Animals │ │ ├── AnimalTrainer.cs │ │ ├── Cat.cs │ │ ├── Dog.cs │ │ └── IAnimal.cs │ ├── Base64Encoder.cs │ ├── BundleTable.cs │ ├── Date.cs │ ├── FileManager.cs │ ├── Logging │ │ ├── DefaultLogger.cs │ │ ├── ILogger.cs │ │ ├── NullLogger.cs │ │ └── ThrowExceptionLogger.cs │ ├── LoginFailedException.cs │ ├── Person.cs │ ├── Point3D.cs │ ├── PredefinedStrings.cs │ ├── Product.cs │ ├── SomeClass.cs │ └── Temperature.cs ├── InteropTestsBase.cs ├── MsieJavaScriptEngine.Test.Common.csproj ├── MultithreadingTestsBase.cs ├── PrecompilationTestsBase.cs ├── Resources │ ├── cube.js │ ├── declinationOfDays.js │ ├── declinationOfHours.js │ └── power.js ├── TestsBase.cs └── ValidationTests.cs └── SharedFiles ├── declinationOfMinutes.js ├── link.txt ├── recursiveEvaluation ├── noError │ ├── index.js │ └── math.js └── runtimeError │ ├── index.js │ └── math.js ├── recursiveExecution └── noError │ ├── firstFile.js │ ├── mainFile.js │ └── secondFile.js └── square.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # Top-most EditorConfig file 2 | root = true 3 | 4 | [*] 5 | end_of_line = crlf 6 | indent_style = tab 7 | tab_width = 4 8 | trim_trailing_whitespace = true 9 | insert_final_newline = false 10 | 11 | [*.json] 12 | indent_style = space 13 | indent_size = 2 14 | insert_final_newline = true 15 | 16 | [*.cmd] 17 | indent_style = space 18 | indent_size = 4 19 | 20 | [*.{xml,config,csproj,props,targets}] 21 | indent_style = space 22 | indent_size = 2 23 | 24 | [*.sln] 25 | insert_final_newline = true 26 | 27 | [*.{txt,md}] 28 | indent_style = space 29 | indent_size = unset 30 | 31 | [**/Resources/**] 32 | charset = unset 33 | end_of_line = unset 34 | indent_style = unset 35 | indent_size = unset 36 | trim_trailing_whitespace = unset 37 | insert_final_newline = unset -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | 9 | # Standard to msysgit 10 | *.doc diff=astextplain 11 | *.DOC diff=astextplain 12 | *.docx diff=astextplain 13 | *.DOCX diff=astextplain 14 | *.dot diff=astextplain 15 | *.DOT diff=astextplain 16 | *.pdf diff=astextplain 17 | *.PDF diff=astextplain 18 | *.rtf diff=astextplain 19 | *.RTF diff=astextplain -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | 5 | # Node.js tools 6 | node_modules/ 7 | package-lock.json 8 | 9 | # NUnit test results 10 | TestResult.xml 11 | 12 | # BenchmarkDotNet artifacts 13 | BenchmarkDotNet.Artifacts/ 14 | 15 | ## Ignore Visual Studio temporary files, build results, and 16 | ## files generated by popular Visual Studio add-ons. 17 | 18 | # User-specific files 19 | .vs/ 20 | .vscode/ 21 | .idea/ 22 | *.sln.docstates 23 | *.suo 24 | *.user 25 | *.userprefs 26 | 27 | # Build results 28 | artifacts/ 29 | *.FileListAbsolute.txt 30 | *.ilk 31 | *.log 32 | *.meta 33 | *.obj 34 | *.pch 35 | *.pdb 36 | *.pgc 37 | *.pgd 38 | *.rsp 39 | *.sbr 40 | *.tlb 41 | *.tlh 42 | *.tli 43 | *.tmp 44 | *.vspscc 45 | *.vssscc 46 | *_i.c 47 | *_p.c 48 | 49 | # Visual Studio profiler 50 | *.psess 51 | *.vsp 52 | *.vspx 53 | 54 | # ReSharper is a .NET coding add-in 55 | _ReSharper.*/ 56 | 57 | # Publishing 58 | PublishProfiles/ 59 | *.Publish.xml 60 | 61 | # NuGet Packages 62 | packages/ 63 | *.nupkg 64 | *.snupkg 65 | 66 | # Others 67 | .build/ 68 | .nuget/ 69 | *.bak 70 | *.[Cc]ache 71 | *.dbmdl 72 | *.docstates 73 | *.orig 74 | *.scc 75 | *DS_Store 76 | 77 | # Backup & report files from converting an old project file to a newer 78 | # Visual Studio version. Backup files are not needed, because we have git ;-) 79 | _UpgradeReport_Files/ 80 | Backup*/ 81 | UpgradeLog.htm 82 | UpgradeLog*.XML 83 | 84 | # Current project-specific folders and files 85 | nuget/ 86 | **/Resources/*.min.js -------------------------------------------------------------------------------- /Licenses/cross-browser-split-license.txt: -------------------------------------------------------------------------------- 1 | Cross-Browser Split 1.1.1 2 | Copyright 2007-2012 Steven Levithan 3 | Available under the MIT License 4 | ECMAScript compliant, uniform cross-browser split method -------------------------------------------------------------------------------- /Licenses/jsrt-dotnet-license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Rob Paveza 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Licenses/sass-and-coffee-license.txt: -------------------------------------------------------------------------------- 1 | Microsoft Public License (Ms-PL) 2 | 3 | This license governs use of the accompanying software. If you use the software, 4 | you accept this license. If you do not accept the license, do not use the 5 | software. 6 | 7 | 1. Definitions 8 | The terms "reproduce," "reproduction," "derivative works," and "distribution" 9 | have the same meaning here as under U.S. copyright law. A "contribution" is the 10 | original software, or any additions or changes to the software. A "contributor" 11 | is any person that distributes its contribution under this license. "Licensed 12 | patents" are a contributor's patent claims that read directly on its 13 | contribution. 14 | 15 | 2. Grant of Rights 16 | 17 | (A) Copyright Grant- Subject to the terms of this license, including the license 18 | conditions and limitations in section 3, each contributor grants you a 19 | non-exclusive, worldwide, royalty-free copyright license to reproduce its 20 | contribution, prepare derivative works of its contribution, and distribute its 21 | contribution or any derivative works that you create. 22 | 23 | (B) Patent Grant- Subject 24 | to the terms of this license, including the license conditions and limitations 25 | in section 3, each contributor grants you a non-exclusive, worldwide, 26 | royalty-free license under its licensed patents to make, have made, use, sell, 27 | offer for sale, import, and/or otherwise dispose of its contribution in the 28 | software or derivative works of the contribution in the software. 29 | 30 | 3. Conditions and Limitations 31 | 32 | (A) No Trademark License- This license does not grant you rights to use any 33 | contributors' name, logo, or trademarks. 34 | (B) If you bring a patent claim against any contributor over patents that you 35 | claim are infringed by the software, your patent license from such contributor 36 | to the software ends automatically. 37 | (C) If you distribute any portion of the software, you must retain all 38 | copyright, patent, trademark, and attribution notices that are present in the 39 | software. 40 | (D) If you distribute any portion of the software in source code form, you may 41 | do so only under this license by including a complete copy of this license with 42 | your distribution. If you distribute any portion of the software in compiled or 43 | object code form, you may only do so under a license that complies with this 44 | license. 45 | (E) The software is licensed "as-is." You bear the risk of using it. The 46 | contributors give no express warranties, guarantees or conditions. You may have 47 | additional consumer rights under your local laws which this license cannot 48 | change. To the extent permitted under your local laws, the contributors exclude 49 | the implied warranties of merchantability, fitness for a particular purpose and 50 | non-infringement. -------------------------------------------------------------------------------- /Licenses/uglify-js-license.txt: -------------------------------------------------------------------------------- 1 | UglifyJS is released under the BSD license: 2 | 3 | Copyright 2012-2019 (c) Mihai Bazon 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | * Redistributions of source code must retain the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above 14 | copyright notice, this list of conditions and the following 15 | disclaimer in the documentation and/or other materials 16 | provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY 19 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 23 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 27 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 28 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | SUCH DAMAGE. -------------------------------------------------------------------------------- /build-js.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | cd ./src/MsieJavaScriptEngine/ 5 | 6 | ::-------------------------------------------------------------------------------- 7 | :: Build 8 | ::-------------------------------------------------------------------------------- 9 | 10 | echo Installing Node.js packages ... 11 | echo. 12 | call npm install 13 | if errorlevel 1 goto error 14 | echo. 15 | 16 | echo Minifying JS files ... 17 | echo. 18 | call npm run -s minify-js 19 | if errorlevel 1 goto error 20 | echo. 21 | 22 | ::-------------------------------------------------------------------------------- 23 | :: Exit 24 | ::-------------------------------------------------------------------------------- 25 | 26 | echo Succeeded! 27 | goto exit 28 | 29 | :error 30 | echo *** Error: The previous step failed! 31 | 32 | :exit 33 | cd ../../ 34 | endlocal -------------------------------------------------------------------------------- /build/Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Taritsyn/MsieJavaScriptEngine/7c2dcede7cd2d18f5b5940d84f59f0823df3817b/build/Key.snk -------------------------------------------------------------------------------- /build/common.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | Copyright © 2012-2024 Andrey Taritsyn 4 | false 5 | false 6 | 7 | -------------------------------------------------------------------------------- /build/net40-client-target.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | .NETFramework 4 | v4.0 5 | client 6 | 7 | -------------------------------------------------------------------------------- /build/strong-name-signing.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | ../../build/Key.snk 4 | true 5 | true 6 | 7 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "8.0.200" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /images/MsieJavaScriptEngine_Logo_128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Taritsyn/MsieJavaScriptEngine/7c2dcede7cd2d18f5b5940d84f59f0823df3817b/images/MsieJavaScriptEngine_Logo_128x128.png -------------------------------------------------------------------------------- /run-tests.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | set common_test_project_name=MsieJavaScriptEngine.Test.Common 5 | set auto_test_project_name=MsieJavaScriptEngine.Test.Auto 6 | set chakra_edge_jsrt_test_project_name=MsieJavaScriptEngine.Test.ChakraEdgeJsRt 7 | set chakra_ie_jsrt_test_project_name=MsieJavaScriptEngine.Test.ChakraIeJsRt 8 | set chakra_activescript_test_project_name=MsieJavaScriptEngine.Test.ChakraActiveScript 9 | set classic_test_project_name=MsieJavaScriptEngine.Test.Classic 10 | 11 | set common-args=%* 12 | set test_dir_path=test 13 | set common_test_project_file_path=%test_dir_path%\%common_test_project_name%\%common_test_project_name%.csproj 14 | set auto_test_project_file_path=%test_dir_path%\%auto_test_project_name%\%auto_test_project_name%.csproj 15 | set chakra_edge_jsrt_test_project_file_path=%test_dir_path%\%chakra_edge_jsrt_test_project_name%\%chakra_edge_jsrt_test_project_name%.csproj 16 | set chakra_ie_jsrt_test_project_file_path=%test_dir_path%\%chakra_ie_jsrt_test_project_name%\%chakra_ie_jsrt_test_project_name%.csproj 17 | set chakra_activescript_test_project_file_path=%test_dir_path%\%chakra_activescript_test_project_name%\%chakra_activescript_test_project_name%.csproj 18 | set classic_test_project_file_path=%test_dir_path%\%classic_test_project_name%\%classic_test_project_name%.csproj 19 | 20 | @echo Run unit tests... 21 | @echo. 22 | 23 | dotnet test %common-args% "%common_test_project_file_path%" 24 | @echo. 25 | 26 | dotnet test %common-args% "%auto_test_project_file_path%" 27 | @echo. 28 | 29 | dotnet test %common-args% "%chakra_edge_jsrt_test_project_file_path%" 30 | @echo. 31 | 32 | dotnet test %common-args% "%chakra_ie_jsrt_test_project_file_path%" 33 | @echo. 34 | 35 | dotnet test %common-args% "%chakra_activescript_test_project_file_path%" 36 | @echo. 37 | 38 | dotnet test %common-args% "%classic_test_project_file_path%" 39 | @echo. -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/.uglifyjsrc: -------------------------------------------------------------------------------- 1 | { 2 | "compress": { 3 | "hoist_funs": true, 4 | "hoist_vars": true, 5 | "passes": 2 6 | }, 7 | "mangle": {}, 8 | "output": { 9 | "comments": "/^!/" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/ChakraActiveScriptJsEngine.ScriptSite.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using MsieJavaScriptEngine.Constants; 3 | using MsieJavaScriptEngine.Helpers; 4 | using MsieJavaScriptEngine.Resources; 5 | 6 | namespace MsieJavaScriptEngine.ActiveScript 7 | { 8 | internal sealed partial class ChakraActiveScriptJsEngine 9 | { 10 | /// 11 | /// Chakra Active Script site 12 | /// 13 | private sealed class ScriptSite : ScriptSiteBase, IActiveScriptSiteInterruptPoll 14 | { 15 | /// 16 | /// Constructs an instance of the Chakra Active Script site 17 | /// 18 | /// Instance of the Active Script JS engine 19 | public ScriptSite(ChakraActiveScriptJsEngine jsEngine) 20 | : base(jsEngine) 21 | { } 22 | 23 | 24 | #region IActiveScriptSiteInterruptPoll implementation 25 | 26 | public uint QueryContinue() 27 | { 28 | int hResult; 29 | 30 | if (InterruptRequested) 31 | { 32 | hResult = ComErrorCode.E_ABORT; 33 | string category = JsErrorCategory.Interrupted; 34 | string description = CommonStrings.Runtime_ScriptInterrupted; 35 | string message = description; 36 | 37 | var activeScriptException = new ActiveScriptException(message) 38 | { 39 | ErrorCode = hResult, 40 | Category = category, 41 | Description = description 42 | }; 43 | 44 | LastException = activeScriptException; 45 | } 46 | else 47 | { 48 | hResult = ComErrorCode.S_OK; 49 | } 50 | 51 | return NumericHelpers.SignedAsUnsigned(hResult); 52 | } 53 | 54 | #endregion 55 | } 56 | } 57 | } 58 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/AppBreakFlags.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Indicate the current debug state for applications and threads 8 | /// 9 | [Flags] 10 | internal enum AppBreakFlags : uint 11 | { 12 | None = 0, 13 | 14 | /// 15 | /// Language engine should break immediately on all threads with 16 | /// 17 | /// 18 | DebuggerBlock = 0x00000001, 19 | 20 | /// 21 | /// Language engine should break immediately with 22 | /// 23 | DebuggerHalt = 0x00000002, 24 | 25 | /// 26 | /// Language engine should break immediately in the stepping thread with 27 | /// 28 | /// 29 | Step = 0x00010000, 30 | 31 | /// 32 | /// The application is in nested execution on a breakpoint 33 | /// 34 | Nested = 0x00020000, 35 | 36 | /// 37 | /// The debugger is stepping at the source level 38 | /// 39 | StepTypeSource = 0x00000000, 40 | 41 | /// 42 | /// The debugger is stepping at the byte code level 43 | /// 44 | StepTypeByteCode = 0x00100000, 45 | 46 | /// 47 | /// The debugger is stepping at the machine level 48 | /// 49 | StepTypeMachine = 0x00200000, 50 | 51 | /// 52 | /// Mask for factoring out the step types 53 | /// 54 | StepTypeMask = 0x00F00000, 55 | 56 | /// 57 | /// A breakpoint is in progress 58 | /// 59 | InBreakpoint = 0x80000000 60 | } 61 | } 62 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakReason.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 3 | { 4 | /// 5 | /// Indicates what caused the break 6 | /// 7 | internal enum BreakReason 8 | { 9 | /// 10 | /// The language engine is in the stepping mode 11 | /// 12 | Step, 13 | 14 | /// 15 | /// The language engine encountered an explicit breakpoint 16 | /// 17 | Breakpoint, 18 | 19 | /// 20 | /// The language engine encountered a debugger block on another thread 21 | /// 22 | DebuggerBlock, 23 | 24 | /// 25 | /// The host requested a break 26 | /// 27 | HostInitiated, 28 | 29 | /// 30 | /// The language engine requested a break 31 | /// 32 | LanguageInitiated, 33 | 34 | /// 35 | /// The debugger IDE requested a break 36 | /// 37 | DebuggerHalt, 38 | 39 | /// 40 | /// An execution error caused the break 41 | /// 42 | Error, 43 | 44 | /// 45 | /// Caused by JIT Debugging startup 46 | /// 47 | Jit 48 | } 49 | } 50 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakResumeAction.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 3 | { 4 | /// 5 | /// Describes ways to continue from a breakpoint 6 | /// 7 | internal enum BreakResumeAction 8 | { 9 | /// 10 | /// Aborts the application 11 | /// 12 | Abort, 13 | 14 | /// 15 | /// Continues running 16 | /// 17 | Continue, 18 | 19 | /// 20 | /// Steps into a procedure 21 | /// 22 | StepInto, 23 | 24 | /// 25 | /// Steps over a procedure 26 | /// 27 | StepOver, 28 | 29 | /// 30 | /// Steps out of the current procedure 31 | /// 32 | StepOut, 33 | 34 | /// 35 | /// Continues running with state 36 | /// 37 | Ignore, 38 | 39 | /// 40 | /// Steps to the next document 41 | /// 42 | StepDocument 43 | } 44 | } 45 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/BreakpointState.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 3 | { 4 | /// 5 | /// Indicates the state of a breakpoint 6 | /// 7 | internal enum BreakpointState 8 | { 9 | /// 10 | /// The breakpoint no longer exists, but there are still references to it 11 | /// 12 | Deleted, 13 | 14 | /// 15 | /// The breakpoint exists but is disabled 16 | /// 17 | Disabled, 18 | 19 | /// 20 | /// The breakpoint exists and is enabled 21 | /// 22 | Enabled 23 | } 24 | } 25 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugDocumentContext.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 3 | { 4 | /// 5 | /// Debug document context 6 | /// 7 | internal sealed class DebugDocumentContext : IDebugDocumentContext 8 | { 9 | /// 10 | /// Debug document 11 | /// 12 | private readonly DebugDocument _document; 13 | 14 | /// 15 | /// Position 16 | /// 17 | private readonly uint _position; 18 | 19 | /// 20 | /// Length 21 | /// 22 | private readonly uint _length; 23 | 24 | /// 25 | /// Code context enumerator 26 | /// 27 | private readonly IEnumDebugCodeContexts _enumCodeContexts; 28 | 29 | /// 30 | /// Gets a position 31 | /// 32 | public uint Position 33 | { 34 | get { return _position; } 35 | } 36 | 37 | /// 38 | /// Gets a length 39 | /// 40 | public uint Length 41 | { 42 | get { return _length; } 43 | } 44 | 45 | 46 | /// 47 | /// Constructs an instance of the debug document context 48 | /// 49 | /// Debug document 50 | /// Position 51 | /// Length 52 | /// Code context enumerator 53 | public DebugDocumentContext(DebugDocument document, uint position, uint length, 54 | IEnumDebugCodeContexts enumCodeContexts) 55 | { 56 | _document = document; 57 | _position = position; 58 | _length = length; 59 | _enumCodeContexts = enumCodeContexts; 60 | } 61 | 62 | 63 | #region IDebugDocumentContext implementation 64 | 65 | public void GetDocument(out IDebugDocument debugDocument) 66 | { 67 | debugDocument = _document; 68 | } 69 | 70 | public void EnumCodeContexts(out IEnumDebugCodeContexts enumContexts) 71 | { 72 | _enumCodeContexts.Clone(out enumContexts); 73 | } 74 | 75 | #endregion 76 | } 77 | } 78 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugLineInfo.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 3 | { 4 | /// 5 | /// Information about line of source code 6 | /// 7 | internal struct DebugLineInfo 8 | { 9 | /// 10 | /// Gets a line number 11 | /// 12 | public readonly uint Number; 13 | 14 | /// 15 | /// Gets a position of line 16 | /// 17 | public readonly uint Position; 18 | 19 | /// 20 | /// Gets a length of line 21 | /// 22 | public readonly uint Length; 23 | 24 | /// 25 | /// Gets a length of line break 26 | /// 27 | public readonly uint BreakLength; 28 | 29 | 30 | /// 31 | /// Constructs an instance of the information about line of source code 32 | /// 33 | /// Line number 34 | /// Position of line 35 | /// Length of line 36 | /// Length of line break 37 | public DebugLineInfo(uint number, uint position, uint length, uint breakLength) 38 | { 39 | Number = number; 40 | Position = position; 41 | Length = length; 42 | BreakLength = breakLength; 43 | } 44 | } 45 | } 46 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugStackFrameDescriptor.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 6 | { 7 | /// 8 | /// Enumerates stack frames and merges output from several enumerators on the same thread 9 | /// 10 | /// 11 | /// The process debug manager uses this structure to sort the stack frames from 12 | /// multiple script engines. By convention, stacks grow down. Consequently, on architectures 13 | /// where stacks grow up, the addresses should be twos-complemented. 14 | /// 15 | [StructLayout(LayoutKind.Sequential)] 16 | internal struct DebugStackFrameDescriptor 17 | { 18 | /// 19 | /// The stack frame object 20 | /// 21 | [MarshalAs(UnmanagedType.Interface)] 22 | public IDebugStackFrame Frame; 23 | 24 | /// 25 | /// A machine-dependent representation of the lower range of physical addresses 26 | /// associated with this stack frame 27 | /// 28 | public uint Minimum; 29 | 30 | /// 31 | /// A machine-dependent representation of the upper range of physical addresses 32 | /// associated with this stack frame 33 | /// 34 | public uint Limit; 35 | 36 | /// 37 | /// Flag that indicates that the frame is being processed 38 | /// 39 | [MarshalAs(UnmanagedType.Bool)] 40 | public bool IsFinal; 41 | 42 | /// 43 | /// If this parameter is not null, the current enumerator merging should stop and 44 | /// a new one should be started. The object indicates how to start the new enumeration. 45 | /// 46 | public IntPtr pFinalObject; 47 | } 48 | } 49 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/DocumentNameType.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 3 | { 4 | /// 5 | /// Describes which type to get for a document 6 | /// 7 | internal enum DocumentNameType 8 | { 9 | /// 10 | /// Gets the name as it appears in the application tree 11 | /// 12 | AppNode, 13 | 14 | /// 15 | /// Gets the name as it appears on the viewer title bar 16 | /// 17 | Title, 18 | 19 | /// 20 | /// Gets the file name without a path 21 | /// 22 | FileTail, 23 | 24 | /// 25 | /// Gets the URL of the document 26 | /// 27 | Url, 28 | 29 | /// 30 | /// Gets the title appended with enumeration for identification 31 | /// 32 | UniqueTitle 33 | } 34 | } 35 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/ErrorResumeAction.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 3 | { 4 | /// 5 | /// Describes how to continue from a runtime error 6 | /// 7 | internal enum ErrorResumeAction 8 | { 9 | /// 10 | /// Re-executes the statement that produced the error 11 | /// 12 | ReexecuteErrorStatement, 13 | 14 | /// 15 | /// Lets the language engine handle the error 16 | /// 17 | AbortCallAndReturnErrorToCaller, 18 | 19 | /// 20 | /// Resumes execution in the code following the statement that produced the error 21 | /// 22 | SkipErrorStatement 23 | } 24 | } 25 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptDebug32.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 6 | { 7 | /// 8 | /// Implemented by script engines that support debugging 9 | /// 10 | [ComImport] 11 | [Guid("51973c10-cb0c-11d0-b5c9-00a0244a0e7a")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IActiveScriptDebug32 14 | { 15 | /// 16 | /// Returns the text attributes for an arbitrary block of script text 17 | /// 18 | /// The script block text 19 | /// The number of characters in the script block text 20 | /// End of script block delimiter 21 | /// Flags associated with the script block 22 | /// Buffer to contain the returned attributes 23 | void GetScriptTextAttributes( 24 | [In] [MarshalAs(UnmanagedType.LPWStr)] string code, 25 | [In] uint length, 26 | [In] [MarshalAs(UnmanagedType.LPWStr)] string delimiter, 27 | [In] ScriptTextFlags flags, 28 | [In] [Out] ref IntPtr pAttrs 29 | ); 30 | 31 | /// 32 | /// Returns the text attributes for an arbitrary scriptlet 33 | /// 34 | /// The scriptlet text 35 | /// The number of characters in the scriptlet text 36 | /// End of scriptlet delimiter 37 | /// Flags associated with the scriptlet 38 | /// Buffer to contain the returned attributes 39 | void GetScriptletTextAttributes( 40 | [In] [MarshalAs(UnmanagedType.LPWStr)] string code, 41 | [In] uint length, 42 | [In] [MarshalAs(UnmanagedType.LPWStr)] string delimiter, 43 | [In] ScriptTextFlags flags, 44 | [In] [Out] ref IntPtr pAttrs 45 | ); 46 | 47 | /// 48 | /// Used by a smart host to delegate the method 49 | /// 50 | /// The source context as provided to 51 | /// or 52 | /// 53 | /// Character offset relative to start of script text 54 | /// Number of characters in this context 55 | /// An enumerator of the code contexts in the specified range 56 | /// The method returns an HRESULT 57 | [PreserveSig] 58 | uint EnumCodeContextsOfPosition( 59 | [In] uint sourceContext, 60 | [In] uint offset, 61 | [In] uint length, 62 | [Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugCodeContexts enumContexts 63 | ); 64 | } 65 | } 66 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptDebug64.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 6 | { 7 | /// 8 | /// Implemented by script engines that support debugging 9 | /// 10 | [ComImport] 11 | [Guid("bc437e23-f5b8-47f4-bb79-7d1ce5483b86")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IActiveScriptDebug64 14 | { 15 | /// 16 | /// Returns the text attributes for an arbitrary block of script text 17 | /// 18 | /// The script block text 19 | /// The number of characters in the script block text 20 | /// End of script block delimiter 21 | /// Flags associated with the script block 22 | /// Buffer to contain the returned attributes 23 | void GetScriptTextAttributes( 24 | [In] [MarshalAs(UnmanagedType.LPWStr)] string code, 25 | [In] uint length, 26 | [In] [MarshalAs(UnmanagedType.LPWStr)] string delimiter, 27 | [In] ScriptTextFlags flags, 28 | [In] [Out] ref IntPtr pAttrs 29 | ); 30 | 31 | /// 32 | /// Returns the text attributes for an arbitrary scriptlet 33 | /// 34 | /// The scriptlet text 35 | /// The number of characters in the scriptlet text 36 | /// End of scriptlet delimiter 37 | /// Flags associated with the scriptlet 38 | /// Buffer to contain the returned attributes 39 | void GetScriptletTextAttributes( 40 | [In] [MarshalAs(UnmanagedType.LPWStr)] string code, 41 | [In] uint length, 42 | [In] [MarshalAs(UnmanagedType.LPWStr)] string delimiter, 43 | [In] ScriptTextFlags flags, 44 | [In] [Out] ref IntPtr pAttrs 45 | ); 46 | 47 | /// 48 | /// Used by a smart host to delegate the method 49 | /// 50 | /// The source context as provided to 51 | /// or 52 | /// 53 | /// Character offset relative to start of script text 54 | /// Number of characters in this context 55 | /// An enumerator of the code contexts in the specified range 56 | /// The method returns an HRESULT 57 | [PreserveSig] 58 | uint EnumCodeContextsOfPosition( 59 | [In] ulong sourceContext, 60 | [In] uint offset, 61 | [In] uint length, 62 | [Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugCodeContexts enumContexts 63 | ); 64 | } 65 | } 66 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptErrorDebug.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO; 5 | 6 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 7 | { 8 | /// 9 | /// Provides document context information for compile-time errors and run-time exceptions 10 | /// 11 | [ComImport] 12 | [Guid("51973c12-cb0c-11d0-b5c9-00a0244a0e7a")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | internal interface IActiveScriptErrorDebug // : IActiveScriptError 15 | { 16 | #region IActiveScriptError methods 17 | 18 | /// 19 | /// Retrieves information about an error that occurred while the scripting engine was running a script 20 | /// 21 | /// An EXCEPINFO structure that receives error information 22 | void GetExceptionInfo( 23 | [Out] out EXCEPINFO exceptionInfo 24 | ); 25 | 26 | /// 27 | /// Retrieves the location in the source code where an error occurred while the scripting engine 28 | /// was running a script 29 | /// 30 | /// A cookie that identifies the context. The interpretation of 31 | /// this parameter depends on the host application. 32 | /// The line number in the source file where the error occurred 33 | /// The character position in the line where the error occurred 34 | void GetSourcePosition( 35 | [Out] out uint sourceContext, 36 | [Out] out uint lineNumber, 37 | [Out] out int characterPosition 38 | ); 39 | 40 | /// 41 | /// Retrieves the line in the source file where an error occurred while a scripting engine 42 | /// was running a script 43 | /// 44 | /// The line of source code in which the error occurred 45 | void GetSourceLineText( 46 | [Out] [MarshalAs(UnmanagedType.BStr)] out string sourceLine 47 | ); 48 | 49 | #endregion 50 | } 51 | } 52 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebug32.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Smart hosts implement the interface to perform document management 8 | /// and to participate in debugging 9 | /// 10 | [ComImport] 11 | [Guid("51973c11-cb0c-11d0-b5c9-00a0244a0e7a")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IActiveScriptSiteDebug32 14 | { 15 | /// 16 | /// Used by the language engine to delegate 17 | /// 18 | /// The source context as provided to 19 | /// or 20 | /// 21 | /// Character offset relative to start of script block or scriptlet 22 | /// Number of characters in this context 23 | /// The document context corresponding to this character-position 24 | /// range 25 | void GetDocumentContextFromPosition( 26 | [In] uint sourceContext, 27 | [In] uint offset, 28 | [In] uint length, 29 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugDocumentContext documentContext 30 | ); 31 | 32 | /// 33 | /// Returns the debug application object associated with this script site 34 | /// 35 | /// The debug application object associated with the script site 36 | void GetApplication( 37 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugApplication32 application 38 | ); 39 | 40 | /// 41 | /// Gets the application node under which script documents should be added 42 | /// 43 | /// The debug application node that holds script documents 44 | void GetRootApplicationNode( 45 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugApplicationNode node 46 | ); 47 | 48 | /// 49 | /// Allows a smart host to determine how to handle run-time errors 50 | /// 51 | /// The run-time error that occurred 52 | /// Flag indicating whether to pass the error to the debugger to 53 | /// do JIT debugging 54 | /// Flag indicating whether to call 55 | /// when the user decides to continue without 56 | /// debugging 57 | void OnScriptErrorDebug( 58 | [In] [MarshalAs(UnmanagedType.Interface)] IActiveScriptErrorDebug errorDebug, 59 | [Out] [MarshalAs(UnmanagedType.Bool)] out bool enterDebugger, 60 | [Out] [MarshalAs(UnmanagedType.Bool)] out bool callOnScriptErrorWhenContinuing 61 | ); 62 | } 63 | } 64 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebug64.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Smart hosts implement the interface to perform document management 8 | /// and to participate in debugging 9 | /// 10 | [ComImport] 11 | [Guid("d6b96b0a-7463-402c-92ac-89984226942f")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IActiveScriptSiteDebug64 14 | { 15 | /// 16 | /// Used by the language engine to delegate IDebugCodeContext.GetSourceContext 17 | /// 18 | /// The source context as provided to 19 | /// or 20 | /// 21 | /// Character offset relative to start of script block or scriptlet 22 | /// Number of characters in this context 23 | /// The document context corresponding to this character-position 24 | /// range 25 | void GetDocumentContextFromPosition( 26 | [In] ulong sourceContext, 27 | [In] uint offset, 28 | [In] uint length, 29 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugDocumentContext documentContext 30 | ); 31 | 32 | /// 33 | /// Returns the debug application object associated with this script site 34 | /// 35 | /// The debug application object associated with the script site 36 | void GetApplication( 37 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugApplication64 application 38 | ); 39 | 40 | /// 41 | /// Gets the application node under which script documents should be added 42 | /// 43 | /// The debug application node that holds script documents 44 | void GetRootApplicationNode( 45 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugApplicationNode node 46 | ); 47 | 48 | /// 49 | /// Allows a smart host to determine how to handle run-time errors 50 | /// 51 | /// The run-time error that occurred 52 | /// Flag indicating whether to pass the error to the debugger to 53 | /// do JIT debugging 54 | /// Flag indicating whether to call 55 | /// when the user decides to continue without 56 | /// debugging 57 | void OnScriptErrorDebug( 58 | [In] [MarshalAs(UnmanagedType.Interface)] IActiveScriptErrorDebug errorDebug, 59 | [Out] [MarshalAs(UnmanagedType.Bool)] out bool enterDebugger, 60 | [Out] [MarshalAs(UnmanagedType.Bool)] out bool callOnScriptErrorWhenContinuing 61 | ); 62 | } 63 | } 64 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IActiveScriptSiteDebugEx.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Implement this interface along with the 8 | /// or interface if you are writing a host that needs 9 | /// to get a notification of a run-time error in an application and optionally attach to 10 | /// the application for debugging. The Process Debug Manager provides notification through 11 | /// or if a Just-In-Time 12 | /// script debugger is found on the computer. If no Just-In-Time script debugger is found, 13 | /// the PDM provides notification through instead. 14 | /// 15 | [ComImport] 16 | [Guid("bb722ccb-6ad2-41c6-b780-af9c03ee69f5")] 17 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 18 | internal interface IActiveScriptSiteDebugEx 19 | { 20 | /// 21 | /// Informs the host about a script run-time error when the Process Debug Manager does not 22 | /// find a Just In Time script debugger 23 | /// 24 | /// The run-time error that occurred 25 | /// Whether to call 26 | /// or 27 | /// if the user decides to 28 | /// continue without debugging 29 | void OnCanNotJitScriptErrorDebug( 30 | [In] [MarshalAs(UnmanagedType.Interface)] IActiveScriptErrorDebug errorDebug, 31 | [Out] [MarshalAs(UnmanagedType.Bool)] out bool callOnScriptErrorWhenContinuing 32 | ); 33 | } 34 | } 35 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IApplicationDebugger.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// The primary interface exposed by a debugger 8 | /// 9 | [ComImport] 10 | [Guid("51973c2a-cb0c-11d0-b5c9-00a0244a0e7a")] 11 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 12 | internal interface IApplicationDebugger 13 | { } 14 | } 15 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugApplicationThread.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Allows language engines and hosts to provide thread synchronization and to maintain 8 | /// thread-specific debug state information. This interface extends 9 | /// the interface to provide non-remote access to the thread. 10 | /// 11 | [ComImport] 12 | [Guid("51973c38-cb0c-11d0-b5c9-00a0244a0e7a")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | internal interface IDebugApplicationThread // : IRemoteDebugApplicationThread 15 | { } 16 | } 17 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugAsyncOperation.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// The Process Debug Manager implements the interface. 8 | /// A language engine calls the IDebugApplication.CreateAsyncDebugOperation method 9 | /// to obtain a reference to this interface. The language engine can use 10 | /// the interface to provide asynchronous access to a synchronous 11 | /// debug operation. 12 | /// 13 | [ComImport] 14 | [Guid("51973c1b-cb0c-11d0-b5c9-00a0244a0e7a")] 15 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 16 | internal interface IDebugAsyncOperation 17 | { } 18 | } 19 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugCodeContext.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// An abstraction that represents a position in executable code 8 | /// 9 | [ComImport] 10 | [Guid("51973c13-cb0c-11d0-b5c9-00a0244a0e7a")] 11 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 12 | internal interface IDebugCodeContext 13 | { 14 | /// 15 | /// Returns the document context associated with this code context 16 | /// 17 | /// The document context associated with this code context 18 | void GetDocumentContext( 19 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugDocumentContext context 20 | ); 21 | 22 | /// 23 | /// Sets or clears a breakpoint at this code context 24 | /// 25 | /// Specifies the breakpoint state for this code context 26 | void SetBreakPoint( 27 | [In] BreakpointState state 28 | ); 29 | } 30 | } 31 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocument.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 6 | { 7 | /// 8 | /// The base interface for all debug documents 9 | /// 10 | [ComImport] 11 | [Guid("51973c21-cb0c-11d0-b5c9-00a0244a0e7a")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IDebugDocument // : IDebugDocumentInfo 14 | { 15 | #region IDebugDocumentInfo methods 16 | 17 | /// 18 | /// Returns the specified document name 19 | /// 20 | /// The type of document name to return 21 | /// String containing the name 22 | void GetName( 23 | [In] DocumentNameType type, 24 | [Out] [MarshalAs(UnmanagedType.BStr)] out string name 25 | ); 26 | 27 | /// 28 | /// Returns a CLSID identifying the document type 29 | /// 30 | /// A CLSID identifying the document type 31 | void GetDocumentClassId( 32 | [Out] out Guid clsid 33 | ); 34 | 35 | #endregion 36 | } 37 | } 38 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentContext.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Provides an abstract representation of a portion of the document being debugged. 8 | /// For text documents, this representation consists of a character-position range 9 | /// 10 | [ComImport] 11 | [Guid("51973c28-cb0c-11d0-b5c9-00a0244a0e7a")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IDebugDocumentContext 14 | { 15 | /// 16 | /// Returns the document that contains this context 17 | /// 18 | /// The document that contains this context 19 | void GetDocument( 20 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugDocument document 21 | ); 22 | 23 | /// 24 | /// Enumerates the code contexts associated with this document context 25 | /// 26 | /// The code contexts associated with this document context 27 | void EnumCodeContexts( 28 | [Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugCodeContexts enumContexts 29 | ); 30 | } 31 | } 32 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentHelper32.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 4 | { 5 | /// 6 | /// Provide implementations for many interfaces necessary for smart hosting, such as 7 | /// the IDebugDocument, IDebugDocumentContext, IDebugDocumentProvider, 8 | /// IDebugDocumentText and IDebugDocumentTextEvents interfaces 9 | /// 10 | [ComImport] 11 | [Guid("51973C26-CB0C-11d0-B5C9-00A0244A0E7A")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IDebugDocumentHelper32 14 | { } 15 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentHelper64.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 4 | { 5 | /// 6 | /// Provide implementations for many interfaces necessary for smart hosting, such as 7 | /// the IDebugDocument, IDebugDocumentContext, IDebugDocumentProvider, 8 | /// IDebugDocumentText and IDebugDocumentTextEvents interfaces 9 | /// 10 | [ComImport] 11 | [Guid("c4c7363c-20fd-47f9-bd82-4855e0150871")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IDebugDocumentHelper64 14 | { } 15 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentInfo.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 6 | { 7 | /// 8 | /// Provides information on a document, which may or may not be instantiated 9 | /// 10 | [ComImport] 11 | [Guid("51973c1f-cb0c-11d0-b5c9-00a0244a0e7a")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IDebugDocumentInfo 14 | { 15 | /// 16 | /// Returns the specified document name 17 | /// 18 | /// The type of document name to return 19 | /// String containing the name 20 | void GetName( 21 | [In] DocumentNameType type, 22 | [Out] [MarshalAs(UnmanagedType.BStr)] out string name 23 | ); 24 | 25 | /// 26 | /// Returns a CLSID identifying the document type 27 | /// 28 | /// A CLSID identifying the document type 29 | void GetDocumentClassId( 30 | [Out] out Guid clsid 31 | ); 32 | } 33 | } 34 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugDocumentProvider.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 6 | { 7 | /// 8 | /// Provides the means for instantiating a document on demand 9 | /// 10 | [ComImport] 11 | [Guid("51973c20-cb0c-11d0-b5c9-00a0244a0e7a")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IDebugDocumentProvider // : IDebugDocumentInfo 14 | { 15 | #region IDebugDocumentInfo methods 16 | 17 | /// 18 | /// Returns the specified document name 19 | /// 20 | /// The type of document name to return 21 | /// String containing the name 22 | void GetName( 23 | [In] DocumentNameType type, 24 | [Out] [MarshalAs(UnmanagedType.BStr)] out string name 25 | ); 26 | 27 | /// 28 | /// Returns a CLSID identifying the document type 29 | /// 30 | /// A CLSID identifying the document type 31 | void GetDocumentClassId( 32 | [Out] out Guid clsid 33 | ); 34 | 35 | #endregion 36 | 37 | /// 38 | /// Causes the document to be instantiated if it does not already exist 39 | /// 40 | /// The debug document corresponding to the document 41 | void GetDocument( 42 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugDocument document 43 | ); 44 | } 45 | } 46 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugProperty.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Used to describe any hierarchical property of the entity being debugged that has a name, type, and value. 8 | /// Most commonly, is used to describe the result of expression evaluation, 9 | /// statement evaluation, or register evaluation. 10 | /// 11 | [ComImport] 12 | [Guid("51973c50-cb0c-11d0-b5c9-00a0244a0e7a")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | internal interface IDebugProperty 15 | { } 16 | } 17 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrame.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Represents a logical stack frame on the thread stack 8 | /// 9 | [ComImport] 10 | [Guid("51973c17-cb0c-11d0-b5c9-00a0244a0e7a")] 11 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 12 | internal interface IDebugStackFrame 13 | { 14 | /// 15 | /// Returns the current code context associated with the stack frame 16 | /// 17 | /// The code context associated with the stack frame 18 | void GetCodeContext( 19 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugCodeContext context 20 | ); 21 | 22 | /// 23 | /// Returns a short or long textual description of the stack frame 24 | /// 25 | /// Flag, where true returns a long description and 26 | /// false returns a short description 27 | /// The description of the stack frame 28 | void GetDescriptionString( 29 | [In] [MarshalAs(UnmanagedType.Bool)] bool longString, 30 | [Out] [MarshalAs(UnmanagedType.BStr)] out string description 31 | ); 32 | 33 | /// 34 | /// Returns a short or long textual description of the language 35 | /// 36 | /// Flag, where true returns a long description and 37 | /// false returns a short description 38 | /// The description of the language 39 | void GetLanguageString( 40 | [In] [MarshalAs(UnmanagedType.Bool)] bool longString, 41 | [Out] [MarshalAs(UnmanagedType.BStr)] out string language 42 | ); 43 | 44 | /// 45 | /// Returns the thread associated with this stack frame 46 | /// 47 | /// The thread associated with this stack frame 48 | void GetThread( 49 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugApplicationThread thread 50 | ); 51 | 52 | /// 53 | /// Returns a property browser for the current frame 54 | /// 55 | /// A property browser for the current frame 56 | void GetDebugProperty( 57 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugProperty property 58 | ); 59 | } 60 | } 61 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSniffer.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Provides a way to enumerate the logical stack frames known by a component. Script engines typically 8 | /// implement this interface. The process debug manager uses this interface to find all stack frames 9 | /// associated with a given thread. 10 | /// 11 | [ComImport] 12 | [Guid("51973c18-cb0c-11d0-b5c9-00a0244a0e7a")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | internal interface IDebugStackFrameSniffer 15 | { 16 | /// 17 | /// Returns an enumerator of stack frames for the current thread 18 | /// 19 | /// Enumerator of stack frames for the current thread 20 | void EnumStackFrames( 21 | [Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames 22 | ); 23 | } 24 | } 25 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSnifferEx32.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Provides a way to enumerate the logical stack frames known by a component. Script engines typically 8 | /// implement this interface. The process debug manager uses this interface to find all stack frames 9 | /// associated with a given thread. 10 | /// 11 | [ComImport] 12 | [Guid("51973c19-cb0c-11d0-b5c9-00a0244a0e7a")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | internal interface IDebugStackFrameSnifferEx32 // : IDebugStackFrameSniffer 15 | { 16 | #region IDebugStackFrameSniffer methods 17 | 18 | /// 19 | /// Returns an enumerator of stack frames for the current thread 20 | /// 21 | /// Enumerator of stack frames for the current thread 22 | void EnumStackFrames( 23 | [Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames 24 | ); 25 | 26 | #endregion 27 | 28 | void EnumStackFramesEx32( 29 | [In] uint minimum, 30 | [Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames 31 | ); 32 | } 33 | } 34 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugStackFrameSnifferEx64.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Provides a way to enumerate the logical stack frames known by a component. Script engines typically 8 | /// implement this interface. The process debug manager uses this interface to find all stack frames 9 | /// associated with a given thread. 10 | /// 11 | [ComImport] 12 | [Guid("8cd12af4-49c1-4d52-8d8a-c146f47581aa")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | internal interface IDebugStackFrameSnifferEx64 // : IDebugStackFrameSniffer 15 | { 16 | #region IDebugStackFrameSniffer methods 17 | 18 | /// 19 | /// Returns an enumerator of stack frames for the current thread 20 | /// 21 | /// Enumerator of stack frames for the current thread 22 | void EnumStackFrames( 23 | [Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames 24 | ); 25 | 26 | #endregion 27 | 28 | void EnumStackFramesEx64( 29 | [In] ulong minimum, 30 | [Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames 31 | ); 32 | } 33 | } 34 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugSyncOperation.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Allows a script engine to abstract an operation (such as expression evaluation) that needs to be 8 | /// performed while nested in a particular blocked thread. The interface also provides a mechanism for 9 | /// canceling unresponsive operations. 10 | /// 11 | [ComImport] 12 | [Guid("51973c1a-cb0c-11d0-b5c9-00a0244a0e7a")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | internal interface IDebugSyncOperation 15 | { } 16 | } 17 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugThreadCall32.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// The interface is typically implemented by a component that makes 8 | /// cross-thread calls with the IDebugThread marshalling implementation provided by 9 | /// the process debug manager (PDM). 10 | /// 11 | [ComImport] 12 | [Guid("51973c36-cb0c-11d0-b5c9-00a0244a0e7a")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | internal interface IDebugThreadCall32 15 | { } 16 | } 17 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IDebugThreadCall64.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// The interface is typically implemented by a component that makes 8 | /// cross-thread calls with the IDebugThread marshalling implementation provided by 9 | /// the process debug manager (PDM). 10 | /// 11 | [ComImport] 12 | [Guid("cb3fa335-e979-42fd-9fcf-a7546a0f3905")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | internal interface IDebugThreadCall64 15 | { } 16 | } 17 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugApplicationNodes.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Enumerates child nodes of a node associated with an application 8 | /// 9 | [ComImport] 10 | [Guid("51973c3a-cb0c-11d0-b5c9-00a0244a0e7a")] 11 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 12 | internal interface IEnumDebugApplicationNodes 13 | { } 14 | } 15 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugCodeContexts.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Enumerates the code contexts that correspond to a document context 8 | /// 9 | [ComImport] 10 | [Guid("51973c1d-cb0c-11d0-b5c9-00a0244a0e7a")] 11 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 12 | internal interface IEnumDebugCodeContexts 13 | { 14 | /// 15 | /// Retrieves a specified number of segments in the enumeration sequence 16 | /// 17 | /// The number of segments to retrieve 18 | /// Returns an array of interfaces that 19 | /// represents the segments being retrieved 20 | /// The actual number of segments fetched by the enumerator 21 | void Next( 22 | [In] uint count, 23 | [Out] [MarshalAs(UnmanagedType.Interface)] out IDebugCodeContext[] contexts, 24 | [Out] out uint countFetched 25 | ); 26 | 27 | /// 28 | /// Skips a specified number of segments in an enumeration sequence 29 | /// 30 | /// Number of segments in the enumeration sequence to skip 31 | void Skip( 32 | [In] uint count 33 | ); 34 | 35 | /// 36 | /// Resets an enumeration sequence to the beginning 37 | /// 38 | void Reset(); 39 | 40 | /// 41 | /// Creates an enumerator that contains the same state as the current enumerator 42 | /// 43 | /// Returns the interface of 44 | /// the clone of the enumerator 45 | void Clone( 46 | [Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugCodeContexts enumContexts 47 | ); 48 | } 49 | } 50 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugExpressionContexts.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Enumerates a collection of IDebugExpressionContexts objects 8 | /// 9 | [ComImport] 10 | [Guid("51973c40-cb0c-11d0-b5c9-00a0244a0e7a")] 11 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 12 | internal interface IEnumDebugExpressionContexts 13 | { } 14 | } 15 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumDebugStackFrames.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Enumerates the stack frames corresponding to a thread 8 | /// 9 | [ComImport] 10 | [Guid("51973c1e-cb0c-11d0-b5c9-00a0244a0e7a")] 11 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 12 | internal interface IEnumDebugStackFrames 13 | { 14 | /// 15 | /// Retrieves a specified number of segments in the enumeration sequence 16 | /// 17 | /// The number of segments to retrieve 18 | /// Returns an array of 19 | /// interfaces that represents the segments being retrieved 20 | /// The actual number of segments fetched by the enumerator 21 | void Next( 22 | [In] uint count, 23 | [Out] out DebugStackFrameDescriptor descriptor, 24 | [Out] out uint countFetched 25 | ); 26 | 27 | /// 28 | /// Skips a specified number of segments in an enumeration sequence 29 | /// 30 | /// Number of segments in the enumeration sequence to skip 31 | void Skip( 32 | [In] uint count 33 | ); 34 | 35 | /// 36 | /// Resets an enumeration sequence to the beginning 37 | /// 38 | void Reset(); 39 | 40 | /// 41 | /// Creates an enumerator that contains the same state as the current enumerator 42 | /// 43 | /// Returns the interface of 44 | /// the clone of the enumerator 45 | void Clone( 46 | [Out] [MarshalAs(UnmanagedType.Interface)] out IEnumDebugStackFrames enumFrames 47 | ); 48 | } 49 | } 50 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IEnumRemoteDebugApplicationThreads.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Enumerates the running threads in an application 8 | /// 9 | [ComImport] 10 | [Guid("51973c3c-cb0c-11d0-b5c9-00a0244a0e7a")] 11 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 12 | internal interface IEnumRemoteDebugApplicationThreads 13 | { } 14 | } 15 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IProcessDebugManager32.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 4 | { 5 | /// 6 | /// Primary interface to the process debug manager. This interface can create, add, or 7 | /// remove a virtual application from a process. It can enumerate stack frames and 8 | /// application threads. 9 | /// 10 | [ComImport] 11 | [Guid("51973C2f-CB0C-11d0-B5C9-00A0244A0E7A")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IProcessDebugManager32 14 | { 15 | /// 16 | /// Creates a new debug application 17 | /// 18 | /// The new debug application 19 | void CreateApplication(out IDebugApplication32 debugApplication); 20 | 21 | /// 22 | /// Gets a default debug application 23 | /// 24 | /// The default debug application 25 | void GetDefaultApplication(out IDebugApplication32 debugApplication); 26 | 27 | /// 28 | /// Adds a new debug application 29 | /// 30 | /// The new debug application 31 | /// An engine-defined cookie 32 | uint AddApplication(IDebugApplication32 debugApplication, out uint cookie); 33 | 34 | /// 35 | /// Removes a debug application 36 | /// 37 | /// The cookie of the debug application to remove 38 | void RemoveApplication(uint cookie); 39 | 40 | /// 41 | /// Creates a debug document helper 42 | /// 43 | /// The outer unknown 44 | /// The new debug document helper 45 | void CreateDebugDocumentHelper(object outerUnknown, out IDebugDocumentHelper32 helper); 46 | } 47 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IProcessDebugManager64.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 4 | { 5 | /// 6 | /// Primary interface to the process debug manager. This interface can create, add, or 7 | /// remove a virtual application from a process. It can enumerate stack frames and 8 | /// application threads. 9 | /// 10 | [ComImport] 11 | [Guid("56b9fC1C-63A9-4CC1-AC21-087D69A17FAB")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IProcessDebugManager64 14 | { 15 | /// 16 | /// Creates a new debug application 17 | /// 18 | /// The new debug application 19 | void CreateApplication(out IDebugApplication64 debugApplication); 20 | 21 | /// 22 | /// Gets a default debug application 23 | /// 24 | /// The default debug application 25 | void GetDefaultApplication(out IDebugApplication64 debugApplication); 26 | 27 | /// 28 | /// Adds a new debug application 29 | /// 30 | /// The new debug application 31 | /// An engine-defined cookie 32 | uint AddApplication(IDebugApplication64 debugApplication, out uint cookie); 33 | 34 | /// 35 | /// Removes a debug application 36 | /// 37 | /// The cookie of the debug application to remove 38 | void RemoveApplication(uint cookie); 39 | 40 | /// 41 | /// Creates a debug document helper 42 | /// 43 | /// The outer unknown 44 | /// The new debug document helper 45 | void CreateDebugDocumentHelper(object outerUnknown, out IDebugDocumentHelper64 helper); 46 | } 47 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IProvideExpressionContexts.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Provides a way to enumerate expression contexts known by a certain component 8 | /// 9 | [ComImport] 10 | [Guid("51973c41-cb0c-11d0-b5c9-00a0244a0e7a")] 11 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 12 | internal interface IProvideExpressionContexts 13 | { } 14 | } 15 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/IRemoteDebugApplicationThread.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Represents a thread of execution within a particular application 8 | /// 9 | [ComImport] 10 | [Guid("51973c37-cb0c-11d0-b5c9-00a0244a0e7a")] 11 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 12 | internal interface IRemoteDebugApplicationThread 13 | { } 14 | } 15 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/NullEnumDebugStackFrames.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | internal class NullEnumDebugStackFrames : IEnumDebugStackFrames 7 | { 8 | #region IEnumDebugStackFrames implementation 9 | 10 | public void Next(uint count, out DebugStackFrameDescriptor descriptor, out uint countFetched) 11 | { 12 | descriptor = default(DebugStackFrameDescriptor); 13 | countFetched = 0; 14 | } 15 | 16 | public void Skip(uint count) 17 | { } 18 | 19 | public void Reset() 20 | { } 21 | 22 | public void Clone(out IEnumDebugStackFrames enumFrames) 23 | { 24 | throw new NotImplementedException(); 25 | } 26 | 27 | #endregion 28 | } 29 | } 30 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/ProcessDebugManager.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 4 | { 5 | /// 6 | /// Process debug manager 7 | /// 8 | [ComImport] 9 | [Guid("78A51822-51F4-11D0-8F20-00805F2CD064")] 10 | internal class ProcessDebugManager 11 | { } 12 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/SourceTextAttrs.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Describe the attributes of a single character of source text 8 | /// 9 | [Flags] 10 | internal enum SourceTextAttrs : ushort 11 | { 12 | None = 0, 13 | 14 | /// 15 | /// The character is part of a language keyword 16 | /// (for example, the JavaScript keyword while) 17 | /// 18 | Keyword = 0x0001, 19 | 20 | /// 21 | /// The character is part of a comment block 22 | /// 23 | Comment = 0x0002, 24 | 25 | /// 26 | /// The character is not part of compiled language source text 27 | /// (for example, the HTML surrounding a script block) 28 | /// 29 | NonSource = 0x0004, 30 | 31 | /// 32 | /// The character is part of a language operator 33 | /// (for example, the arithmetic operator +) 34 | /// 35 | Operator = 0x0008, 36 | 37 | /// 38 | /// The character is part of a language numeric constant 39 | /// (for example, the constant 3.14159) 40 | /// 41 | Number = 0x0010, 42 | 43 | /// 44 | /// The character is part of a language string constant 45 | /// (for example, the string "Hello World") 46 | /// 47 | String = 0x0020, 48 | 49 | /// 50 | /// The character indicates the start of a function block 51 | /// 52 | FunctionStart = 0x0040 53 | } 54 | } 55 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/Debugging/TextDocAttrs.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript.Debugging 5 | { 6 | /// 7 | /// Describe the attributes of the document 8 | /// 9 | [Flags] 10 | internal enum TextDocAttrs : uint 11 | { 12 | None = 0, 13 | 14 | /// 15 | /// The document is read-only 16 | /// 17 | ReadOnly = 0x00000001, 18 | 19 | /// 20 | /// The document is the primary file of this document tree 21 | /// 22 | TypePrimary = 0x00000002, 23 | 24 | /// 25 | /// The document is a worker 26 | /// 27 | TypeWorker = 0x00000004, 28 | 29 | /// 30 | /// The document is a script file 31 | /// 32 | TypeScript = 0x00000008 33 | } 34 | } 35 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/HostType.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Reflection; 6 | 7 | using MsieJavaScriptEngine.Constants; 8 | using MsieJavaScriptEngine.Helpers; 9 | 10 | namespace MsieJavaScriptEngine.ActiveScript 11 | { 12 | /// 13 | /// Wrapper for type, that implements interface 14 | /// 15 | internal sealed class HostType : HostItemBase 16 | { 17 | /// 18 | /// Constructs an instance of the wrapper for type, that implements interface 19 | /// 20 | /// Target type 21 | /// JS engine mode 22 | /// Flag for whether to allow the usage of reflection API in the script code 23 | public HostType(Type type, JsEngineMode engineMode, bool allowReflection) 24 | : base(type, null, engineMode, allowReflection, false) 25 | { } 26 | 27 | 28 | #region HostItemBase overrides 29 | 30 | protected override object InnerInvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, 31 | object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) 32 | { 33 | object result; 34 | 35 | if (name == SpecialMemberName.Default && invokeAttr.HasFlag(BindingFlags.CreateInstance)) 36 | { 37 | object[] processedArgs = args; 38 | 39 | if (_engineMode != JsEngineMode.Classic && processedArgs.Length > 0) 40 | { 41 | processedArgs = processedArgs.Skip(1).ToArray(); 42 | } 43 | processedArgs = TypeMappingHelpers.MapToHostType(processedArgs); 44 | 45 | result = Activator.CreateInstance(_type, processedArgs); 46 | } 47 | else 48 | { 49 | object[] processedArgs = TypeMappingHelpers.MapToHostType(args); 50 | 51 | result = InvokeStandardMember(name, invokeAttr, binder, target, 52 | processedArgs, modifiers, culture, namedParameters); 53 | } 54 | 55 | return TypeMappingHelpers.MapToScriptType(result, _engineMode, _allowReflection); 56 | } 57 | 58 | #endregion 59 | } 60 | } 61 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/IActiveScriptError.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO; 5 | 6 | namespace MsieJavaScriptEngine.ActiveScript 7 | { 8 | /// 9 | /// An object implementing this interface is passed to the method 10 | /// whenever the scripting engine encounters an unhandled error. The host then calls methods on 11 | /// this object to obtain information about the error that occurred. 12 | /// 13 | [ComImport] 14 | [Guid("eae1ba61-a4ed-11cf-8f20-00805f2cd064")] 15 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 16 | internal interface IActiveScriptError 17 | { 18 | /// 19 | /// Retrieves information about an error that occurred while the scripting engine was running 20 | /// a script 21 | /// 22 | /// An EXCEPINFO structure that receives error information 23 | void GetExceptionInfo( 24 | [Out] out EXCEPINFO exceptionInfo 25 | ); 26 | 27 | /// 28 | /// Retrieves the location in the source code where an error occurred while the scripting engine 29 | /// was running a script 30 | /// 31 | /// A cookie that identifies the context. The interpretation of 32 | /// this parameter depends on the host application. 33 | /// The line number in the source file where the error occurred 34 | /// The character position in the line where the error occurred 35 | void GetSourcePosition( 36 | [Out] out uint sourceContext, 37 | [Out] out uint lineNumber, 38 | [Out] out int characterPosition 39 | ); 40 | 41 | /// 42 | /// Retrieves the line in the source file where an error occurred while a scripting engine 43 | /// was running a script 44 | /// 45 | /// The line of source code in which the error occurred 46 | void GetSourceLineText( 47 | [Out] [MarshalAs(UnmanagedType.BStr)] out string sourceLine 48 | ); 49 | } 50 | } 51 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/IActiveScriptGarbageCollector.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript 5 | { 6 | /// 7 | /// Provides a method to start garbage collection. This interface should be implemented by 8 | /// Active Script engines that want to clean up their resources. 9 | /// 10 | [ComImport] 11 | [Guid("6aa2c4a0-2b53-11d4-a2a0-00104bd35090")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IActiveScriptGarbageCollector 14 | { 15 | /// 16 | /// The Active Script host calls this method to start garbage collection 17 | /// 18 | /// The type of garbage collection 19 | void CollectGarbage( 20 | [In] ScriptGCType type 21 | ); 22 | } 23 | } 24 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/IActiveScriptProperty.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MsieJavaScriptEngine.ActiveScript 6 | { 7 | /// 8 | /// The interface is used to get and set 9 | /// configuration properties 10 | /// 11 | [ComImport] 12 | [Guid("4954e0d0-fbc7-11d1-8410-006008c3fbfc")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | internal interface IActiveScriptProperty 15 | { 16 | /// 17 | /// Gets the property that is specified by the parameter 18 | /// 19 | /// The property value to get 20 | /// Not used 21 | /// The value of the property 22 | /// The method returns an HRESULT 23 | [PreserveSig] 24 | uint GetProperty( 25 | [In] uint dwProperty, 26 | [In] IntPtr pvarIndex, 27 | [Out] out object pvarValue 28 | ); 29 | 30 | /// 31 | /// Sets the property that is specified by the parameter 32 | /// 33 | /// The property value to set 34 | /// Not used 35 | /// The value of the property 36 | /// The method returns an HRESULT 37 | [PreserveSig] 38 | uint SetProperty( 39 | [In] uint dwProperty, 40 | [In] IntPtr pvarIndex, 41 | [In] [Out] ref object pvarValue 42 | ); 43 | } 44 | } 45 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/IActiveScriptSiteInterruptPoll.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript 5 | { 6 | /// 7 | /// The interface allows a host to specify 8 | /// that ascript should terminate 9 | /// 10 | [ComImport] 11 | [Guid("539698a0-cdca-11cf-a5eb-00aa0047a063")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IActiveScriptSiteInterruptPoll 14 | { 15 | /// 16 | /// Allows a host to specify that a script should terminate 17 | /// 18 | /// The method returns an HRESULT 19 | [PreserveSig] 20 | uint QueryContinue(); 21 | } 22 | } 23 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/ScriptGCType.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript 3 | { 4 | /// 5 | /// The type of garbage collection to perform 6 | /// 7 | internal enum ScriptGCType 8 | { 9 | /// 10 | /// Do normal garbage collection 11 | /// 12 | Normal = 0, 13 | 14 | /// 15 | /// Do exhaustive garbage collection 16 | /// 17 | Exhaustive = 1 18 | } 19 | } 20 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/ScriptInfoFlags.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript 5 | { 6 | [Flags] 7 | internal enum ScriptInfoFlags : uint 8 | { 9 | /// 10 | /// Not a valid option 11 | /// 12 | None = 0, 13 | 14 | /// 15 | /// Returns the IUnknown interface for this item 16 | /// 17 | IUnknown = 1, 18 | 19 | /// 20 | /// Returns the ITypeInfo interface for this item 21 | /// 22 | ITypeInfo = 2 23 | } 24 | } 25 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/ScriptInterruptFlags.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript 5 | { 6 | /// 7 | /// Thread interruption options 8 | /// 9 | [Flags] 10 | internal enum ScriptInterruptFlags : uint 11 | { 12 | /// 13 | /// No flags 14 | /// 15 | None = 0, 16 | 17 | /// 18 | /// If supported, enter the scripting engine's debugger at the current script execution point 19 | /// 20 | Debug = 1, 21 | 22 | /// 23 | /// If supported by the scripting engine's language, let the script handle the exception. 24 | /// Otherwise, the script method is aborted and the error code is returned to the caller; that 25 | /// is, the event source or macro invoker. 26 | /// 27 | RaiseException = 2 28 | } 29 | } 30 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/ScriptLanguageVersion.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript 3 | { 4 | /// 5 | /// Specifies the possible scripting versions 6 | /// 7 | internal enum ScriptLanguageVersion 8 | { 9 | /// 10 | /// Version not selected 11 | /// 12 | None = -1, 13 | 14 | /// 15 | /// Default version 16 | /// 17 | Default = 0, 18 | 19 | /// 20 | /// Windows Scripting version 5.7 21 | /// 22 | WindowsScripting57 = 1, 23 | 24 | /// 25 | /// Windows Scripting version 5.8 26 | /// 27 | WindowsScripting58 = 2, 28 | 29 | /// 30 | /// ECMAScript 5 31 | /// 32 | EcmaScript5 = 3 33 | } 34 | } 35 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/ScriptProperty.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript 3 | { 4 | /// 5 | /// Script property (see https://msdn.microsoft.com/en-us/subscriptions/downloads/cc512774(v=vs.94).aspx) 6 | /// 7 | internal enum ScriptProperty : uint 8 | { 9 | /// 10 | /// Forces the scripting engine to divide in integer mode instead of floating point mode. 11 | /// The default value is false. 12 | /// 13 | IntegerMode = 0x00003000, 14 | 15 | /// 16 | /// Allows the string compare function of the scripting engine to be replaced 17 | /// 18 | StringCompareInstance = 0x00003001, 19 | 20 | /// 21 | /// Informs the scripting engine that no other scripting engines exist to contribute 22 | /// to the global object 23 | /// 24 | AbbreviateGlobalNameResolution = 0x70000002, 25 | 26 | /// 27 | /// Forces the JavaScript scripting engine to select a set of language features to be supported. 28 | /// The default set of language features supported by the JavaScript scripting engine is equivalent 29 | /// to the language feature set that appeared in version 5.7 of the JavaScript scripting engine. 30 | /// 31 | InvokeVersioning = 0x00004000 32 | } 33 | } 34 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/ScriptState.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript 3 | { 4 | /// 5 | /// Specifies the state of a scripting engine 6 | /// 7 | internal enum ScriptState : uint 8 | { 9 | /// 10 | /// Script has just been created, but has not yet been initialized using an IPersist* 11 | /// interface and 12 | /// 13 | Uninitialized = 0, 14 | 15 | /// 16 | /// Script has been initialized, but is not running (connecting to other objects or 17 | /// sinking events) or executing any code. Code can be queried for execution by 18 | /// calling the IActiveScriptParse.ParseScriptText method. 19 | /// 20 | Initialized = 1, 21 | 22 | /// 23 | /// Script can execute code, but is not yet sinking the events of objects added by 24 | /// the IActiveScript.AddNamedItem method 25 | /// 26 | Started = 2, 27 | 28 | /// 29 | /// Script is loaded and connected for sinking events 30 | /// 31 | Connected = 3, 32 | 33 | /// 34 | /// Script is loaded and has a run-time execution state, but is temporarily 35 | /// disconnected from sinking events 36 | /// 37 | Disconnected = 4, 38 | 39 | /// 40 | /// Script has been closed. The scripting engine no longer works and returns errors 41 | /// for most methods 42 | /// 43 | Closed = 5 44 | } 45 | } 46 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/ScriptTextFlags.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript 5 | { 6 | [Flags] 7 | internal enum ScriptTextFlags : uint 8 | { 9 | DelayExecution = 0x00000001, 10 | 11 | /// 12 | /// Indicates that the script text should be visible (and, therefore, callable by name) as a global 13 | /// method in the name space of the script 14 | /// 15 | IsVisible = 0x00000002, 16 | 17 | /// 18 | /// If the distinction between a computational expression and a statement is important but 19 | /// syntactically ambiguous in the script language, this flag specifies that the scriptlet is to be 20 | /// interpreted as an expression, rather than as a statement or list of statements. By default, 21 | /// statements are assumed unless the correct choice can be determined from the syntax of the 22 | /// scriptlet text 23 | /// 24 | IsExpression = 0x00000020, 25 | 26 | /// 27 | /// Indicates that the code added during this call should be saved if the scripting engine is saved 28 | /// (for example, through a call to IPersist*.Save), or if the scripting engine is reset by way of 29 | /// a transition back to the initialized state. For more information about this state, see Script 30 | /// Engine States 31 | /// 32 | IsPersistent = 0x00000040, 33 | 34 | HostManagesSource = 0x00000080, 35 | 36 | IsCrossDomain = 0x00000100 37 | } 38 | } 39 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/ScriptThreadId.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript 3 | { 4 | /// 5 | /// Used to specify the type of thread 6 | /// 7 | internal static class ScriptThreadId 8 | { 9 | /// 10 | /// The currently executing thread 11 | /// 12 | public const uint Current = 0xFFFFFFFD; 13 | 14 | /// 15 | /// The base thread; that is, the thread in which the scripting engine was instantiated 16 | /// 17 | public const uint Base = 0xFFFFFFFE; 18 | 19 | /// 20 | /// All threads 21 | /// 22 | public const uint All = 0xFFFFFFFF; 23 | } 24 | } 25 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/ScriptThreadState.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.ActiveScript 3 | { 4 | /// 5 | /// Specifies the state of a thread in a scripting engine 6 | /// 7 | internal enum ScriptThreadState : uint 8 | { 9 | /// 10 | /// Specified thread is not currently servicing a scripted event, processing 11 | /// immediately executed script text, or running a script macro 12 | /// 13 | NotInScript = 0, 14 | 15 | /// 16 | /// Specified thread is actively servicing a scripted event, processing 17 | /// immediately executed script text, or running a script macro 18 | /// 19 | Running = 1 20 | } 21 | } 22 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/ActiveScript/ScriptTypeLibFlags.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | 4 | namespace MsieJavaScriptEngine.ActiveScript 5 | { 6 | [Flags] 7 | internal enum ScriptTypeLibFlags : uint 8 | { 9 | /// 10 | /// No flags 11 | /// 12 | None = 0, 13 | 14 | /// 15 | /// The type library describes an ActiveX control used by the host 16 | /// 17 | IsControl = 0x00000010, 18 | 19 | /// 20 | /// Not documented 21 | /// 22 | IsPersistent = 0x00000040 23 | } 24 | } 25 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Constants/ClassId.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.Constants 3 | { 4 | /// 5 | /// Class identifiers 6 | /// 7 | internal static class ClassId 8 | { 9 | public const string Classic = "{f414c260-6ac0-11cf-b6d1-00aa00bbbb58}"; 10 | 11 | public const string Chakra = "{16d51579-a30b-4c8b-a276-0ff4dc41e755}"; 12 | } 13 | } 14 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Constants/ComErrorCode.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.Constants 3 | { 4 | /// 5 | /// COM error codes 6 | /// 7 | internal static class ComErrorCode 8 | { 9 | // ReSharper disable InconsistentNaming 10 | public const int SEVERITY_SUCCESS = 0; 11 | public const int SEVERITY_ERROR = 1; 12 | 13 | public const int FACILITY_NULL = 0; 14 | public const int FACILITY_RPC = 1; 15 | public const int FACILITY_DISPATCH = 2; 16 | public const int FACILITY_STORAGE = 3; 17 | public const int FACILITY_ITF = 4; 18 | public const int FACILITY_WIN32 = 7; 19 | public const int FACILITY_WINDOWS = 8; 20 | public const int FACILITY_CONTROL = 10; 21 | public const int FACILITY_INTERNET = 12; 22 | public const int FACILITY_URT = 19; 23 | 24 | public const int S_OK = 0; 25 | public const int S_FALSE = 1; 26 | 27 | public const int E_ABORT = unchecked((int)0x80004004); 28 | public const int E_ELEMENT_NOT_FOUND = unchecked((int)0x8002802B); 29 | public const int E_CLASS_NOT_REGISTERED = unchecked((int)0x80040154); 30 | // ReSharper restore InconsistentNaming 31 | } 32 | } 33 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Constants/DllName.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Constants 2 | { 3 | /// 4 | /// DLL names 5 | /// 6 | internal static class DllName 7 | { 8 | public const string JScript = "jscript.dll"; 9 | 10 | public const string JScript9 = "jscript9.dll"; 11 | 12 | public const string Chakra = "chakra.dll"; 13 | } 14 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Constants/JsErrorCategory.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Constants 2 | { 3 | internal static class JsErrorCategory 4 | { 5 | public const string Unknown = "Unknown error"; 6 | public const string Compilation = "Compilation error"; 7 | public const string Runtime = "Runtime error"; 8 | public const string Interrupted = "Interrupted error"; 9 | public const string Usage = "Usage error"; 10 | public const string Engine = "Engine error"; 11 | public const string EngineLoad = "Engine load error"; 12 | public const string Fatal = "Fatal error"; 13 | } 14 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Constants/JsErrorType.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Constants 2 | { 3 | internal static class JsErrorType 4 | { 5 | public const string Common = "Error"; 6 | public const string Eval = "EvalError"; 7 | public const string Internal = "InternalError"; 8 | public const string Range = "RangeError"; 9 | public const string Reference = "ReferenceError"; 10 | public const string RegExp = "RegExpError"; 11 | public const string Syntax = "SyntaxError"; 12 | public const string Type = "TypeError"; 13 | public const string URI = "URIError"; 14 | } 15 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Constants/SpecialMemberName.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | namespace MsieJavaScriptEngine.Constants 3 | { 4 | /// 5 | /// Special member names 6 | /// 7 | internal static class SpecialMemberName 8 | { 9 | public const string Default = "[DISPID=0]"; 10 | } 11 | } 12 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Extensions/ExceptionExtensions.cs: -------------------------------------------------------------------------------- 1 | #if NET40 2 | using System; 3 | using System.Reflection; 4 | 5 | namespace MsieJavaScriptEngine.Extensions 6 | { 7 | /// 8 | /// Exception extensions 9 | /// 10 | internal static class ExceptionExtensions 11 | { 12 | /// 13 | /// Preserves a stack trace of exception 14 | /// 15 | /// The exception 16 | public static void PreserveStackTrace(this Exception source) 17 | { 18 | if (source == null) 19 | { 20 | throw new ArgumentNullException(nameof(source)); 21 | } 22 | 23 | MethodInfo preserveStackTraceMethodInfo = typeof(Exception).GetMethod("InternalPreserveStackTrace", 24 | BindingFlags.Instance | BindingFlags.NonPublic); 25 | preserveStackTraceMethodInfo.Invoke(source, null); 26 | } 27 | } 28 | } 29 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Extensions/TypeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | #if NETSTANDARD1_3 3 | using System.Reflection; 4 | #endif 5 | 6 | namespace MsieJavaScriptEngine.Extensions 7 | { 8 | /// 9 | /// Type extensions 10 | /// 11 | internal static class TypeExtensions 12 | { 13 | /// 14 | /// Gets a underlying type code of the specified 15 | /// 16 | /// The type whose underlying type code to get 17 | /// The code of the underlying type 18 | public static TypeCode GetTypeCode(this Type source) 19 | { 20 | TypeCode typeCode; 21 | 22 | #if NETSTANDARD1_3 23 | if (source == null) 24 | { 25 | typeCode = TypeCode.Empty; 26 | } 27 | else if (source == typeof(bool)) 28 | { 29 | typeCode = TypeCode.Boolean; 30 | } 31 | else if (source == typeof(char)) 32 | { 33 | typeCode = TypeCode.Char; 34 | } 35 | else if (source == typeof(sbyte)) 36 | { 37 | typeCode = TypeCode.SByte; 38 | } 39 | else if (source == typeof(byte)) 40 | { 41 | typeCode = TypeCode.Byte; 42 | } 43 | else if (source == typeof(short)) 44 | { 45 | typeCode = TypeCode.Int16; 46 | } 47 | else if (source == typeof(ushort)) 48 | { 49 | typeCode = TypeCode.UInt16; 50 | } 51 | else if (source == typeof(int)) 52 | { 53 | typeCode = TypeCode.Int32; 54 | } 55 | else if (source == typeof(uint)) 56 | { 57 | typeCode = TypeCode.UInt32; 58 | } 59 | else if (source == typeof(long)) 60 | { 61 | typeCode = TypeCode.Int64; 62 | } 63 | else if (source == typeof(ulong)) 64 | { 65 | typeCode = TypeCode.UInt64; 66 | } 67 | else if (source == typeof(float)) 68 | { 69 | typeCode = TypeCode.Single; 70 | } 71 | else if (source == typeof(double)) 72 | { 73 | typeCode = TypeCode.Double; 74 | } 75 | else if (source == typeof(decimal)) 76 | { 77 | typeCode = TypeCode.Decimal; 78 | } 79 | else if (source == typeof(DateTime)) 80 | { 81 | typeCode = TypeCode.DateTime; 82 | } 83 | else if (source == typeof(string)) 84 | { 85 | typeCode = TypeCode.String; 86 | } 87 | else if (source.GetTypeInfo().IsEnum) 88 | { 89 | typeCode = GetTypeCode(Enum.GetUnderlyingType(source)); 90 | } 91 | else 92 | { 93 | typeCode = TypeCode.Object; 94 | } 95 | #else 96 | typeCode = Type.GetTypeCode(source); 97 | #endif 98 | 99 | return typeCode; 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Helpers/CallStackItem.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Helpers 2 | { 3 | /// 4 | /// Script call stack item 5 | /// 6 | internal sealed class CallStackItem 7 | { 8 | /// 9 | /// Gets or sets a function name 10 | /// 11 | public string FunctionName 12 | { 13 | get; 14 | set; 15 | } 16 | 17 | /// 18 | /// Gets or sets a document name 19 | /// 20 | public string DocumentName 21 | { 22 | get; 23 | set; 24 | } 25 | 26 | /// 27 | /// Gets or sets a line number 28 | /// 29 | public int LineNumber 30 | { 31 | get; 32 | set; 33 | } 34 | 35 | /// 36 | /// Gets or sets a column number 37 | /// 38 | public int ColumnNumber 39 | { 40 | get; 41 | set; 42 | } 43 | 44 | 45 | /// 46 | /// Constructs an instance of the script call stack item 47 | /// 48 | public CallStackItem() 49 | { 50 | FunctionName = string.Empty; 51 | DocumentName = string.Empty; 52 | LineNumber = 0; 53 | ColumnNumber = 0; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Helpers/CommonRegExps.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Helpers 2 | { 3 | /// 4 | /// Common regular expressions 5 | /// 6 | internal static class CommonRegExps 7 | { 8 | /// 9 | /// Pattern for working with JS names 10 | /// 11 | public const string JsNamePattern = @"[$_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}]" + 12 | @"[$_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\u200C\u200D\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*"; 13 | 14 | /// 15 | /// Pattern for working with JS full names 16 | /// 17 | public const string JsFullNamePattern = JsNamePattern + @"(?:\." + JsNamePattern + @")*"; 18 | 19 | /// 20 | /// Pattern for working with document names 21 | /// 22 | public const string DocumentNamePattern = @"[^\s*?""<>|][^\t\n\r*?""<>|]*?"; 23 | } 24 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Helpers/JsEngineModeHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MsieJavaScriptEngine.Helpers 4 | { 5 | internal static class JsEngineModeHelpers 6 | { 7 | public static string GetModeName(JsEngineMode mode) 8 | { 9 | string modeName; 10 | 11 | switch (mode) 12 | { 13 | case JsEngineMode.Classic: 14 | modeName = "Classic"; 15 | break; 16 | case JsEngineMode.ChakraActiveScript: 17 | modeName = "Chakra ActiveScript"; 18 | break; 19 | case JsEngineMode.ChakraIeJsRt: 20 | modeName = "Chakra IE JsRT"; 21 | break; 22 | case JsEngineMode.ChakraEdgeJsRt: 23 | modeName = "Chakra Edge JsRT"; 24 | break; 25 | default: 26 | throw new NotSupportedException(); 27 | } 28 | 29 | return modeName; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Helpers/NumericHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using MsieJavaScriptEngine.Extensions; 4 | 5 | namespace MsieJavaScriptEngine.Helpers 6 | { 7 | /// 8 | /// Numeric helpers 9 | /// 10 | internal static class NumericHelpers 11 | { 12 | private const double MAX_INTEGER_IN_DOUBLE = (1L << 53) - 1; 13 | 14 | 15 | /// 16 | /// Casts a double value to the correct type 17 | /// 18 | /// Double value 19 | /// Numeric value with the correct type 20 | public static object CastDoubleValueToCorrectType(double value) 21 | { 22 | if (Math.Round(value) == value) 23 | { 24 | if (Math.Abs(value) <= MAX_INTEGER_IN_DOUBLE) 25 | { 26 | long longValue = Convert.ToInt64(value); 27 | if (longValue >= int.MinValue && longValue <= int.MaxValue) 28 | { 29 | return (int)longValue; 30 | } 31 | 32 | return longValue; 33 | } 34 | } 35 | else 36 | { 37 | float floatValue = Convert.ToSingle(value); 38 | if (value == floatValue) 39 | { 40 | return floatValue; 41 | } 42 | } 43 | 44 | return value; 45 | } 46 | 47 | internal static int UnsignedAsSigned(uint value) 48 | { 49 | return BitConverter.ToInt32(BitConverter.GetBytes(value), 0); 50 | } 51 | 52 | internal static uint SignedAsUnsigned(int value) 53 | { 54 | return BitConverter.ToUInt32(BitConverter.GetBytes(value), 0); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Helpers/TypeMappingHelpers.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | using System.Linq; 4 | 5 | using MsieJavaScriptEngine.ActiveScript; 6 | using MsieJavaScriptEngine.Utilities; 7 | 8 | namespace MsieJavaScriptEngine.Helpers 9 | { 10 | /// 11 | /// Type mapping helpers 12 | /// 13 | internal static class TypeMappingHelpers 14 | { 15 | /// 16 | /// Makes a mapping of value from the host type to a script type 17 | /// 18 | /// The source value 19 | /// JavaScript engine mode 20 | /// Flag for whether to allow the usage of reflection API in the script code 21 | /// The mapped value 22 | public static object MapToScriptType(object value, JsEngineMode engineMode, bool allowReflection) 23 | { 24 | if (value == null) 25 | { 26 | return DBNull.Value; 27 | } 28 | 29 | if (value is Undefined) 30 | { 31 | return null; 32 | } 33 | 34 | Type type = value.GetType(); 35 | if (TypeConverter.IsPrimitiveType(type) || type.FullName == "System.__ComObject") 36 | { 37 | return value; 38 | } 39 | 40 | var result = new HostObject(value, engineMode, allowReflection); 41 | 42 | return result; 43 | } 44 | 45 | /// 46 | /// Makes a mapping of array items from the host type to a script type 47 | /// 48 | /// The source array 49 | /// JavaScript engine mode 50 | /// Flag for whether to allow the usage of reflection API in the script code 51 | /// The mapped array 52 | public static object[] MapToScriptType(object[] args, JsEngineMode engineMode, bool allowReflection) 53 | { 54 | return args.Select(arg => MapToScriptType(arg, engineMode, allowReflection)).ToArray(); 55 | } 56 | 57 | /// 58 | /// Makes a mapping of value from the script type to a host type 59 | /// 60 | /// The source value 61 | /// The mapped value 62 | public static object MapToHostType(object value) 63 | { 64 | if (value == null) 65 | { 66 | return Undefined.Value; 67 | } 68 | 69 | if (value is DBNull) 70 | { 71 | return null; 72 | } 73 | 74 | if (TypeConverter.IsPrimitiveType(value.GetType())) 75 | { 76 | return value; 77 | } 78 | 79 | var hostObj = value as HostObject; 80 | object result = hostObj != null ? hostObj.Target : value; 81 | 82 | return result; 83 | } 84 | 85 | /// 86 | /// Makes a mapping of array itemp from the script type to a host type 87 | /// 88 | /// The source array 89 | /// The mapped array 90 | public static object[] MapToHostType(object[] args) 91 | { 92 | return args.Select(MapToHostType).ToArray(); 93 | } 94 | } 95 | } 96 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Helpers/ValidationHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text.RegularExpressions; 4 | 5 | using MsieJavaScriptEngine.Utilities; 6 | 7 | namespace MsieJavaScriptEngine.Helpers 8 | { 9 | /// 10 | /// Validation helpers 11 | /// 12 | public static class ValidationHelpers 13 | { 14 | /// 15 | /// List of supported types 16 | /// 17 | private static readonly Type[] _supportedTypes = 18 | { 19 | typeof(Undefined), typeof(Boolean), typeof(Int32), typeof(Double), typeof(String) 20 | }; 21 | 22 | /// 23 | /// Regular expression for working with JS names 24 | /// 25 | private static readonly Regex _jsNameRegex = new Regex("^" + CommonRegExps.JsNamePattern + "$"); 26 | 27 | /// 28 | /// Regular expression for working with document names 29 | /// 30 | private static readonly Regex _documentNameRegex = new Regex("^" + CommonRegExps.DocumentNamePattern + "$"); 31 | 32 | 33 | /// 34 | /// Checks whether supports a .NET type 35 | /// 36 | /// .NET type 37 | /// Result of check (true - is supported; false - is not supported) 38 | public static bool IsSupportedType(Type type) 39 | { 40 | bool result = _supportedTypes.Contains(type); 41 | 42 | return result; 43 | } 44 | 45 | /// 46 | /// Checks whether .NET type is primitive 47 | /// 48 | /// .NET type 49 | /// Result of check (true - is primitive; false - is not primitive) 50 | public static bool IsPrimitiveType(Type type) 51 | { 52 | return TypeConverter.IsPrimitiveType(type); 53 | } 54 | 55 | /// 56 | /// Checks a format of the name 57 | /// 58 | /// The name 59 | /// Result of check (true - correct format; false - wrong format) 60 | public static bool CheckNameFormat(string name) 61 | { 62 | return _jsNameRegex.IsMatch(name); 63 | } 64 | 65 | /// 66 | /// Checks a format of the document name 67 | /// 68 | /// The document name 69 | /// Result of check (true - correct format; false - wrong format) 70 | public static bool CheckDocumentNameFormat(string name) 71 | { 72 | return _documentNameRegex.IsMatch(name); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/InnerJsEngineBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using MsieJavaScriptEngine.Helpers; 4 | using MsieJavaScriptEngine.Utilities; 5 | 6 | namespace MsieJavaScriptEngine 7 | { 8 | /// 9 | /// Base class of the inner JS engine 10 | /// 11 | internal abstract class InnerJsEngineBase : IInnerJsEngine 12 | { 13 | /// 14 | /// JS engine settings 15 | /// 16 | protected JsEngineSettings _settings; 17 | 18 | /// 19 | /// Name of JS engine mode 20 | /// 21 | protected readonly string _engineModeName; 22 | 23 | /// 24 | /// Flag that object is destroyed 25 | /// 26 | protected StatedFlag _disposedFlag = new StatedFlag(); 27 | 28 | 29 | /// 30 | /// Constructs an instance of the inner JS engine 31 | /// 32 | /// JS engine settings 33 | protected InnerJsEngineBase(JsEngineSettings settings) 34 | { 35 | _settings = settings; 36 | _engineModeName = JsEngineModeHelpers.GetModeName(_settings.EngineMode); 37 | } 38 | 39 | 40 | #region IInnerJsEngine implementation 41 | 42 | /// 43 | public string Mode 44 | { 45 | get { return _engineModeName; } 46 | } 47 | 48 | /// 49 | public abstract bool SupportsScriptPrecompilation { get; } 50 | 51 | 52 | /// 53 | public abstract PrecompiledScript Precompile(string code, string documentName); 54 | 55 | /// 56 | public abstract object Evaluate(string expression, string documentName); 57 | 58 | /// 59 | public abstract void Execute(string code, string documentName); 60 | 61 | /// 62 | public abstract void Execute(PrecompiledScript precompiledScript); 63 | 64 | /// 65 | public abstract object CallFunction(string functionName, params object[] args); 66 | 67 | /// 68 | public abstract bool HasVariable(string variableName); 69 | 70 | /// 71 | public abstract object GetVariableValue(string variableName); 72 | 73 | /// 74 | public abstract void SetVariableValue(string variableName, object value); 75 | 76 | /// 77 | public abstract void RemoveVariable(string variableName); 78 | 79 | /// 80 | public abstract void EmbedHostObject(string itemName, object value); 81 | 82 | /// 83 | public abstract void EmbedHostType(string itemName, Type type); 84 | 85 | /// 86 | public abstract void Interrupt(); 87 | 88 | /// 89 | public abstract void CollectGarbage(); 90 | 91 | #endregion 92 | 93 | #region IDisposable implementation 94 | 95 | public abstract void Dispose(); 96 | 97 | #endregion 98 | } 99 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsEngineException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | #if !NETSTANDARD1_3 3 | using System.Runtime.Serialization; 4 | #endif 5 | 6 | using MsieJavaScriptEngine.Constants; 7 | 8 | namespace MsieJavaScriptEngine 9 | { 10 | /// 11 | /// The exception that occurred in the workings of the JS engine itself 12 | /// 13 | #if !NETSTANDARD1_3 14 | [Serializable] 15 | #endif 16 | public class JsEngineException : JsException 17 | { 18 | /// 19 | /// Initializes a new instance of the class 20 | /// with a specified error message 21 | /// 22 | /// The message that describes the error 23 | public JsEngineException(string message) 24 | : base(message) 25 | { 26 | Category = JsErrorCategory.Engine; 27 | } 28 | 29 | /// 30 | /// Initializes a new instance of the class 31 | /// with a specified error message and a reference to the inner exception 32 | /// that is the cause of this exception 33 | /// 34 | /// The error message that explains the reason for the exception 35 | /// The exception that is the cause of the current exception 36 | public JsEngineException(string message, Exception innerException) 37 | : base(message, innerException) 38 | { 39 | Category = JsErrorCategory.Engine; 40 | } 41 | 42 | /// 43 | /// Initializes a new instance of the class 44 | /// 45 | /// The error message that explains the reason for the exception 46 | /// Name of JS engine mode 47 | public JsEngineException(string message, string engineMode) 48 | : base(message, engineMode) 49 | { 50 | Category = JsErrorCategory.Engine; 51 | } 52 | 53 | /// 54 | /// Initializes a new instance of the class 55 | /// 56 | /// The error message that explains the reason for the exception 57 | /// Name of JS engine mode 58 | /// The exception that is the cause of the current exception 59 | public JsEngineException(string message, string engineMode, Exception innerException) 60 | : base(message, engineMode, innerException) 61 | { 62 | Category = JsErrorCategory.Engine; 63 | } 64 | #if !NETSTANDARD1_3 65 | 66 | /// 67 | /// Initializes a new instance of the class with serialized data 68 | /// 69 | /// The object that holds the serialized data 70 | /// The contextual information about the source or destination 71 | protected JsEngineException(SerializationInfo info, StreamingContext context) 72 | : base(info, context) 73 | { } 74 | #endif 75 | } 76 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsEngineLoadException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | #if !NETSTANDARD1_3 3 | using System.Runtime.Serialization; 4 | #endif 5 | 6 | using MsieJavaScriptEngine.Constants; 7 | 8 | namespace MsieJavaScriptEngine 9 | { 10 | /// 11 | /// The exception that is thrown when a loading of JS engine is failed 12 | /// 13 | #if !NETSTANDARD1_3 14 | [Serializable] 15 | #endif 16 | public sealed class JsEngineLoadException : JsEngineException 17 | { 18 | /// 19 | /// Initializes a new instance of the class 20 | /// with a specified error message 21 | /// 22 | /// The message that describes the error 23 | public JsEngineLoadException(string message) 24 | : base(message) 25 | { 26 | Category = JsErrorCategory.EngineLoad; 27 | } 28 | 29 | /// 30 | /// Initializes a new instance of the class 31 | /// with a specified error message and a reference to the inner exception 32 | /// that is the cause of this exception 33 | /// 34 | /// The error message that explains the reason for the exception 35 | /// The exception that is the cause of the current exception 36 | public JsEngineLoadException(string message, Exception innerException) 37 | : base(message, innerException) 38 | { 39 | Category = JsErrorCategory.EngineLoad; 40 | } 41 | 42 | /// 43 | /// Initializes a new instance of the class 44 | /// 45 | /// The error message that explains the reason for the exception 46 | /// Name of JS engine mode 47 | public JsEngineLoadException(string message, string engineMode) 48 | : base(message, engineMode) 49 | { 50 | Category = JsErrorCategory.EngineLoad; 51 | } 52 | 53 | /// 54 | /// Initializes a new instance of the class 55 | /// 56 | /// The error message that explains the reason for the exception 57 | /// Name of JS engine mode 58 | /// The exception that is the cause of the current exception 59 | public JsEngineLoadException(string message, string engineMode, Exception innerException) 60 | : base(message, engineMode, innerException) 61 | { 62 | Category = JsErrorCategory.EngineLoad; 63 | } 64 | #if !NETSTANDARD1_3 65 | 66 | /// 67 | /// Initializes a new instance of the class with serialized data 68 | /// 69 | /// The object that holds the serialized data 70 | /// The contextual information about the source or destination 71 | private JsEngineLoadException(SerializationInfo info, StreamingContext context) 72 | : base(info, context) 73 | { } 74 | #endif 75 | } 76 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsEngineMode.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine 2 | { 3 | /// 4 | /// JS engine modes 5 | /// 6 | public enum JsEngineMode 7 | { 8 | /// 9 | /// Automatically selects the most modern JS engine from available on the machine 10 | /// 11 | Auto = 0, 12 | 13 | /// 14 | /// Classic MSIE JS engine (supports ECMAScript 3 with possibility of using 15 | /// the ECMAScript 5 Polyfill and the JSON2 library). 16 | /// Requires Internet Explorer 6 or higher on the machine. 17 | /// Not supported in version for .NET Core. 18 | /// 19 | Classic, 20 | 21 | /// 22 | /// ActiveScript version of Chakra JS engine (supports ECMAScript 5). 23 | /// Requires Internet Explorer 9 or higher on the machine. 24 | /// Not supported in version for .NET Core. 25 | /// 26 | ChakraActiveScript, 27 | 28 | /// 29 | /// “IE” JsRT version of Chakra JS engine (supports ECMAScript 5). 30 | /// Requires Internet Explorer 11 or Microsoft Edge on the machine. 31 | /// 32 | ChakraIeJsRt, 33 | 34 | /// 35 | /// “Edge” JsRT version of Chakra JS engine (supports ECMAScript 5). 36 | /// Requires Microsoft Edge on the machine. 37 | /// 38 | ChakraEdgeJsRt 39 | } 40 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsFatalException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | #if !NETSTANDARD1_3 3 | using System.Runtime.Serialization; 4 | #endif 5 | 6 | using MsieJavaScriptEngine.Constants; 7 | 8 | namespace MsieJavaScriptEngine 9 | { 10 | /// 11 | /// The fatal exception occurred 12 | /// 13 | #if !NETSTANDARD1_3 14 | [Serializable] 15 | #endif 16 | public sealed class JsFatalException : JsException 17 | { 18 | /// 19 | /// Initializes a new instance of the class 20 | /// with a specified error message 21 | /// 22 | /// The message that describes the error 23 | public JsFatalException(string message) 24 | : base(message) 25 | { 26 | Category = JsErrorCategory.Fatal; 27 | } 28 | 29 | /// 30 | /// Initializes a new instance of the class 31 | /// with a specified error message and a reference to the inner exception 32 | /// that is the cause of this exception 33 | /// 34 | /// The error message that explains the reason for the exception 35 | /// The exception that is the cause of the current exception 36 | public JsFatalException(string message, Exception innerException) 37 | : base(message, innerException) 38 | { 39 | Category = JsErrorCategory.Fatal; 40 | } 41 | 42 | /// 43 | /// Initializes a new instance of the class 44 | /// 45 | /// The error message that explains the reason for the exception 46 | /// Name of JS engine mode 47 | public JsFatalException(string message, string engineMode) 48 | : base(message, engineMode) 49 | { 50 | Category = JsErrorCategory.Fatal; 51 | } 52 | 53 | /// 54 | /// Initializes a new instance of the class 55 | /// 56 | /// The error message that explains the reason for the exception 57 | /// Name of JS engine mode 58 | /// The exception that is the cause of the current exception 59 | public JsFatalException(string message, string engineMode, Exception innerException) 60 | : base(message, engineMode, innerException) 61 | { 62 | Category = JsErrorCategory.Fatal; 63 | } 64 | #if !NETSTANDARD1_3 65 | 66 | /// 67 | /// Initializes a new instance of the class with serialized data 68 | /// 69 | /// The object that holds the serialized data 70 | /// The contextual information about the source or destination 71 | private JsFatalException(SerializationInfo info, StreamingContext context) 72 | : base(info, context) 73 | { } 74 | #endif 75 | } 76 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/ChakraJsRtJsEngineBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MsieJavaScriptEngine.JsRt 4 | { 5 | /// 6 | /// JsRT version of Chakra JS engine 7 | /// 8 | internal abstract class ChakraJsRtJsEngineBase : InnerJsEngineBase 9 | { 10 | /// 11 | /// JS source context 12 | /// 13 | protected JsSourceContext _jsSourceContext = JsSourceContext.FromIntPtr(IntPtr.Zero); 14 | 15 | /// 16 | /// Script dispatcher 17 | /// 18 | protected ScriptDispatcher _dispatcher; 19 | 20 | 21 | /// 22 | /// Constructs an instance of the Chakra JsRT engine 23 | /// 24 | /// JS engine settings 25 | protected ChakraJsRtJsEngineBase(JsEngineSettings settings) 26 | : base(settings) 27 | { 28 | #if NETSTANDARD1_3 29 | _dispatcher = new ScriptDispatcher(); 30 | #else 31 | _dispatcher = new ScriptDispatcher(settings.MaxStackSize); 32 | #endif 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsNativeFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.JsRt.Edge 5 | { 6 | /// 7 | /// “Edge” function callback 8 | /// 9 | /// The Function object that represents the function being invoked 10 | /// Indicates whether this is a regular call or a new call 11 | /// The arguments to the call 12 | /// The number of arguments 13 | /// Callback data, if any 14 | /// The result of the call, if any 15 | internal delegate EdgeJsValue EdgeJsNativeFunction(EdgeJsValue callee, bool isConstructCall, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] EdgeJsValue[] arguments, ushort argumentCount, IntPtr callbackData); 16 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsScope.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MsieJavaScriptEngine.JsRt.Edge 4 | { 5 | /// 6 | /// “Edge” scope automatically sets a context to current and resets the original context 7 | /// when disposed 8 | /// 9 | internal struct EdgeJsScope : IDisposable 10 | { 11 | /// 12 | /// The previous context 13 | /// 14 | private readonly EdgeJsContext _previousContext; 15 | 16 | /// 17 | /// Whether the structure has been disposed 18 | /// 19 | private bool _disposed; 20 | 21 | 22 | /// 23 | /// Initializes a new instance of the struct 24 | /// 25 | /// The context to create the scope for 26 | public EdgeJsScope(EdgeJsContext context) 27 | { 28 | _disposed = false; 29 | _previousContext = EdgeJsContext.Current; 30 | EdgeJsContext.Current = context; 31 | } 32 | 33 | #region IDisposable implementation 34 | 35 | /// 36 | /// Disposes the scope and sets the previous context to current 37 | /// 38 | public void Dispose() 39 | { 40 | if (_disposed) 41 | { 42 | return; 43 | } 44 | 45 | EdgeJsContext.Current = _previousContext; 46 | _disposed = true; 47 | } 48 | 49 | #endregion 50 | } 51 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsScriptException.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Taritsyn/MsieJavaScriptEngine/7c2dcede7cd2d18f5b5940d84f59f0823df3817b/src/MsieJavaScriptEngine/JsRt/Edge/EdgeJsScriptException.cs -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace MsieJavaScriptEngine.JsRt.Embedding 5 | { 6 | /// 7 | /// Embedded object 8 | /// 9 | /// The type of the JavaScript value 10 | /// The type of the native function 11 | internal sealed class EmbeddedObject : EmbeddedItem 12 | where TValue : struct 13 | where TFunction : Delegate 14 | { 15 | /// 16 | /// Constructs an instance of the embedded object 17 | /// 18 | /// Instance of host type 19 | /// JavaScript value created from an host object 20 | public EmbeddedObject(object hostObject, TValue scriptValue) 21 | : base(hostObject.GetType(), hostObject, scriptValue, new List()) 22 | { } 23 | 24 | /// 25 | /// Constructs an instance of the embedded object 26 | /// 27 | /// Instance of host type 28 | /// JavaScript value created from an host object 29 | /// List of native functions, that used to access to members of host object 30 | public EmbeddedObject(object hostObject, TValue scriptValue, IList nativeFunctions) 31 | : base(hostObject.GetType(), hostObject, scriptValue, nativeFunctions) 32 | { } 33 | 34 | #region EmbeddedItem overrides 35 | 36 | /// 37 | /// Gets a value that indicates if the host item is an instance 38 | /// 39 | public override bool IsInstance 40 | { 41 | get { return true; } 42 | } 43 | 44 | #endregion 45 | } 46 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/Embedding/EmbeddedType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace MsieJavaScriptEngine.JsRt.Embedding 5 | { 6 | /// 7 | /// Embedded type 8 | /// 9 | /// The type of the JavaScript value 10 | /// The type of the native function 11 | internal sealed class EmbeddedType : EmbeddedItem 12 | where TValue : struct 13 | where TFunction : Delegate 14 | { 15 | /// 16 | /// Constructs an instance of the embedded type 17 | /// 18 | /// Host type 19 | /// JavaScript value created from an host type 20 | public EmbeddedType(Type hostType, TValue scriptValue) 21 | : base(hostType, null, scriptValue, new List()) 22 | { } 23 | 24 | /// 25 | /// Constructs an instance of the embedded type 26 | /// 27 | /// Host type 28 | /// JavaScript value created from an host type 29 | /// List of native functions, that used to access to members of type 30 | public EmbeddedType(Type hostType, TValue scriptValue, IList nativeFunctions) 31 | : base(hostType, null, scriptValue, nativeFunctions) 32 | { } 33 | 34 | #region EmbeddedItem overrides 35 | 36 | /// 37 | /// Gets a value that indicates if the host item is an instance 38 | /// 39 | public override bool IsInstance 40 | { 41 | get { return false; } 42 | } 43 | 44 | #endregion 45 | } 46 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/Ie/IeJsNativeFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MsieJavaScriptEngine.JsRt.Ie 5 | { 6 | /// 7 | /// “IE” function callback 8 | /// 9 | /// The Function object that represents the function being invoked 10 | /// Indicates whether this is a regular call or a new call 11 | /// The arguments to the call 12 | /// The number of arguments 13 | /// Callback data, if any 14 | /// The result of the call, if any 15 | internal delegate IeJsValue IeJsNativeFunction(IeJsValue callee, bool isConstructCall, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] IeJsValue[] arguments, ushort argumentCount, IntPtr callbackData); 16 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/Ie/IeJsScope.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MsieJavaScriptEngine.JsRt.Ie 4 | { 5 | /// 6 | /// “IE” scope automatically sets a context to current and resets the original context 7 | /// when disposed 8 | /// 9 | internal struct IeJsScope : IDisposable 10 | { 11 | /// 12 | /// The previous context 13 | /// 14 | private readonly IeJsContext _previousContext; 15 | 16 | /// 17 | /// Whether the structure has been disposed 18 | /// 19 | private bool _disposed; 20 | 21 | 22 | /// 23 | /// Initializes a new instance of the struct 24 | /// 25 | /// The context to create the scope for 26 | public IeJsScope(IeJsContext context) 27 | { 28 | _disposed = false; 29 | _previousContext = IeJsContext.Current; 30 | IeJsContext.Current = context; 31 | } 32 | 33 | #region IDisposable implementation 34 | 35 | /// 36 | /// Disposes the scope and sets the previous context to current 37 | /// 38 | public void Dispose() 39 | { 40 | if (_disposed) 41 | { 42 | return; 43 | } 44 | 45 | IeJsContext.Current = _previousContext; 46 | _disposed = true; 47 | } 48 | 49 | #endregion 50 | } 51 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/Ie/IeJsScriptException.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Taritsyn/MsieJavaScriptEngine/7c2dcede7cd2d18f5b5940d84f59f0823df3817b/src/MsieJavaScriptEngine/JsRt/Ie/IeJsScriptException.cs -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsBackgroundWorkItemCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MsieJavaScriptEngine.JsRt 4 | { 5 | /// 6 | /// The background work item callback 7 | /// 8 | /// 9 | /// This is passed to the host's thread service (if provided) to allow the host to 10 | /// invoke the work item callback on the background thread of its choice. 11 | /// 12 | /// Data argument passed to the thread service 13 | internal delegate void JsBackgroundWorkItemCallback(IntPtr callbackData); 14 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsBeforeCollectCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MsieJavaScriptEngine.JsRt 4 | { 5 | /// 6 | /// The callback called before collection 7 | /// 8 | /// The state passed to SetBeforeCollectCallback 9 | internal delegate void JsBeforeCollectCallback(IntPtr callbackState); 10 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsEngineException.cs: -------------------------------------------------------------------------------- 1 | #if !NETSTANDARD1_3 2 | using System; 3 | using System.Runtime.Serialization; 4 | 5 | #endif 6 | namespace MsieJavaScriptEngine.JsRt 7 | { 8 | /// 9 | /// The exception that occurred in the workings of the JS engine itself 10 | /// 11 | #if !NETSTANDARD1_3 12 | [Serializable] 13 | #endif 14 | public sealed class JsEngineException : JsException 15 | { 16 | /// 17 | /// Initializes a new instance of the class 18 | /// 19 | /// The error code returned 20 | public JsEngineException(JsErrorCode errorCode) 21 | : base(errorCode) 22 | { } 23 | 24 | /// 25 | /// Initializes a new instance of the class 26 | /// with a specified error message 27 | /// 28 | /// The error code returned 29 | /// The error message 30 | public JsEngineException(JsErrorCode errorCode, string message) 31 | : base(errorCode, message) 32 | { } 33 | #if !NETSTANDARD1_3 34 | 35 | /// 36 | /// Initializes a new instance of the class with serialized data 37 | /// 38 | /// The object that holds the serialized data 39 | /// The contextual information about the source or destination 40 | private JsEngineException(SerializationInfo info, StreamingContext context) 41 | : base(info, context) 42 | { } 43 | #endif 44 | } 45 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | #if !NETSTANDARD1_3 3 | using System.Runtime.Serialization; 4 | using System.Security.Permissions; 5 | #endif 6 | 7 | namespace MsieJavaScriptEngine.JsRt 8 | { 9 | /// 10 | /// The exception returned from the Chakra engine 11 | /// 12 | #if !NETSTANDARD1_3 13 | [Serializable] 14 | #endif 15 | public class JsException : Exception 16 | { 17 | /// 18 | /// The error code 19 | /// 20 | private readonly JsErrorCode _errorCode; 21 | 22 | /// 23 | /// Gets a error code 24 | /// 25 | public JsErrorCode ErrorCode 26 | { 27 | get { return _errorCode; } 28 | } 29 | 30 | 31 | /// 32 | /// Initializes a new instance of the class 33 | /// 34 | /// The error code returned 35 | public JsException(JsErrorCode errorCode) 36 | : this(errorCode, "A fatal exception has occurred in a JavaScript runtime") 37 | { } 38 | 39 | /// 40 | /// Initializes a new instance of the class 41 | /// with a specified error message 42 | /// 43 | /// The error code returned 44 | /// The error message 45 | public JsException(JsErrorCode errorCode, string message) 46 | : base(message) 47 | { 48 | _errorCode = errorCode; 49 | } 50 | #if !NETSTANDARD1_3 51 | 52 | /// 53 | /// Initializes a new instance of the class with serialized data 54 | /// 55 | /// The object that holds the serialized data 56 | /// The contextual information about the source or destination 57 | protected JsException(SerializationInfo info, StreamingContext context) 58 | : base(info, context) 59 | { 60 | if (info != null) 61 | { 62 | _errorCode = (JsErrorCode)info.GetUInt32("ErrorCode"); 63 | } 64 | } 65 | 66 | 67 | #region Exception overrides 68 | 69 | /// 70 | /// Populates a with the data needed to serialize the target object 71 | /// 72 | /// The to populate with data 73 | /// The destination (see ) for this serialization 74 | [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)] 75 | public override void GetObjectData(SerializationInfo info, StreamingContext context) 76 | { 77 | if (info == null) 78 | { 79 | throw new ArgumentNullException(nameof(info)); 80 | } 81 | 82 | base.GetObjectData(info, context); 83 | info.AddValue("ErrorCode", (uint)_errorCode); 84 | } 85 | 86 | #endregion 87 | #endif 88 | } 89 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsFatalException.cs: -------------------------------------------------------------------------------- 1 | #if !NETSTANDARD1_3 2 | using System; 3 | using System.Runtime.Serialization; 4 | 5 | #endif 6 | namespace MsieJavaScriptEngine.JsRt 7 | { 8 | /// 9 | /// The fatal exception occurred 10 | /// 11 | #if !NETSTANDARD1_3 12 | [Serializable] 13 | #endif 14 | public sealed class JsFatalException : JsException 15 | { 16 | /// 17 | /// Initializes a new instance of the class 18 | /// 19 | /// The error code returned 20 | public JsFatalException(JsErrorCode errorCode) 21 | : base(errorCode) 22 | { } 23 | 24 | /// 25 | /// Initializes a new instance of the class 26 | /// with a specified error message 27 | /// 28 | /// The error code returned 29 | /// The error message 30 | public JsFatalException(JsErrorCode errorCode, string message) 31 | : base(errorCode, message) 32 | { } 33 | #if !NETSTANDARD1_3 34 | 35 | /// 36 | /// Initializes a new instance of the class with serialized data 37 | /// 38 | /// The object that holds the serialized data 39 | /// The contextual information about the source or destination 40 | private JsFatalException(SerializationInfo info, StreamingContext context) 41 | : base(info, context) 42 | { } 43 | #endif 44 | } 45 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsFinalizeCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MsieJavaScriptEngine.JsRt 4 | { 5 | /// 6 | /// The finalization callback 7 | /// 8 | /// The external data that was passed in when creating the object being finalized 9 | internal delegate void JsFinalizeCallback(IntPtr data); 10 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsMemoryAllocationCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MsieJavaScriptEngine.JsRt 4 | { 5 | /// 6 | /// User implemented callback routine for memory allocation events 7 | /// 8 | /// The state passed to SetRuntimeMemoryAllocationCallback 9 | /// The type of type allocation event 10 | /// The size of the allocation 11 | /// 12 | /// For the Allocate event, returning true allows the runtime to continue with 13 | /// allocation. Returning false indicates the allocation request is rejected. The return value 14 | /// is ignored for other allocation events. 15 | /// 16 | internal delegate bool JsMemoryAllocationCallback(IntPtr callbackState, JsMemoryEventType allocationEvent, UIntPtr allocationSize); 17 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsMemoryEventType.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.JsRt 2 | { 3 | /// 4 | /// Allocation callback event type 5 | /// 6 | internal enum JsMemoryEventType 7 | { 8 | /// 9 | /// Indicates a request for memory allocation 10 | /// 11 | Allocate = 0, 12 | 13 | /// 14 | /// Indicates a memory freeing event 15 | /// 16 | Free = 1, 17 | 18 | /// 19 | /// Indicates a failed allocation event 20 | /// 21 | Failure = 2 22 | } 23 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsRuntimeAttributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.CodeAnalysis; 3 | 4 | namespace MsieJavaScriptEngine.JsRt 5 | { 6 | /// 7 | /// Attributes of a runtime 8 | /// 9 | [Flags] 10 | internal enum JsRuntimeAttributes 11 | { 12 | /// 13 | /// No special attributes 14 | /// 15 | None = 0x00000000, 16 | 17 | /// 18 | /// The runtime will not do any work (such as garbage collection) on background threads 19 | /// 20 | DisableBackgroundWork = 0x00000001, 21 | 22 | /// 23 | /// The runtime should support reliable script interruption. This increases the number of 24 | /// places where the runtime will check for a script interrupt request at the cost of a 25 | /// small amount of runtime performance. 26 | /// 27 | AllowScriptInterrupt = 0x00000002, 28 | 29 | /// 30 | /// Host will call Idle, so enable idle processing. Otherwise, the runtime will manage 31 | /// memory slightly more aggressively. 32 | /// 33 | EnableIdleProcessing = 0x00000004, 34 | 35 | /// 36 | /// Runtime will not generate native code 37 | /// 38 | DisableNativeCodeGeneration = 0x00000008, 39 | 40 | /// 41 | /// Using eval or Function constructor will throw an exception 42 | /// 43 | [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Eval is a valid function name.")] 44 | DisableEval = 0x00000010 45 | } 46 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsRuntimeVersion.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.JsRt 2 | { 3 | /// 4 | /// Version of the runtime 5 | /// 6 | internal enum JsRuntimeVersion 7 | { 8 | /// 9 | /// Create runtime with IE10 version 10 | /// 11 | Version10 = 0, 12 | 13 | /// 14 | /// Create runtime with IE11 version 15 | /// 16 | Version11 = 1, 17 | 18 | /// 19 | /// Create runtime with highest version present on the machine at runtime 20 | /// 21 | VersionEdge = -1 22 | } 23 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsThreadServiceCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MsieJavaScriptEngine.JsRt 4 | { 5 | /// 6 | /// The thread service callback 7 | /// 8 | /// 9 | /// The host can specify a background thread service when creating a runtime. If 10 | /// specified, then background work items will be passed to the host using this callback. The 11 | /// host is expected to either begin executing the background work item immediately and return 12 | /// true or return false and the runtime will handle the work item in-thread. 13 | /// 14 | /// The callback for the background work item 15 | /// The data argument to be passed to the callback 16 | /// Whether the thread service will execute the callback 17 | internal delegate bool JsThreadServiceCallback(JsBackgroundWorkItemCallback callbackFunction, IntPtr callbackData); 18 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsUsageException.cs: -------------------------------------------------------------------------------- 1 | #if !NETSTANDARD1_3 2 | using System; 3 | using System.Runtime.Serialization; 4 | 5 | #endif 6 | namespace MsieJavaScriptEngine.JsRt 7 | { 8 | /// 9 | /// The API usage exception occurred 10 | /// 11 | #if !NETSTANDARD1_3 12 | [Serializable] 13 | #endif 14 | public sealed class JsUsageException : JsException 15 | { 16 | /// 17 | /// Initializes a new instance of the class 18 | /// 19 | /// The error code returned 20 | public JsUsageException(JsErrorCode errorCode) 21 | : base(errorCode) 22 | { } 23 | 24 | /// 25 | /// Initializes a new instance of the class 26 | /// with a specified error message 27 | /// 28 | /// The error code returned 29 | /// The error message 30 | public JsUsageException(JsErrorCode errorCode, string message) 31 | : base(errorCode, message) 32 | { } 33 | #if !NETSTANDARD1_3 34 | 35 | /// 36 | /// Initializes a new instance of the class with serialized data 37 | /// 38 | /// The object that holds the serialized data 39 | /// The contextual information about the source or destination 40 | private JsUsageException(SerializationInfo info, StreamingContext context) 41 | : base(info, context) 42 | { } 43 | #endif 44 | } 45 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsRt/JsValueType.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.JsRt 2 | { 3 | /// 4 | /// The JavaScript type of a JavaScript value 5 | /// 6 | internal enum JsValueType 7 | { 8 | /// 9 | /// The value is the undefined value 10 | /// 11 | Undefined = 0, 12 | 13 | /// 14 | /// The value is the null value 15 | /// 16 | Null = 1, 17 | 18 | /// 19 | /// The value is a JavaScript Number value 20 | /// 21 | Number = 2, 22 | 23 | /// 24 | /// The value is a JavaScript String value 25 | /// 26 | String = 3, 27 | 28 | /// 29 | /// The value is a JavaScript Boolean value 30 | /// 31 | Boolean = 4, 32 | 33 | /// 34 | /// The value is a JavaScript Object value 35 | /// 36 | Object = 5, 37 | 38 | /// 39 | /// The value is a JavaScript Function object value 40 | /// 41 | Function = 6, 42 | 43 | /// 44 | /// The value is a JavaScript Error object value 45 | /// 46 | Error = 7, 47 | 48 | /// 49 | /// The value is a JavaScript Array object value 50 | /// 51 | Array = 8 52 | } 53 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/JsUsageException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | #if !NETSTANDARD1_3 3 | using System.Runtime.Serialization; 4 | #endif 5 | 6 | using MsieJavaScriptEngine.Constants; 7 | 8 | namespace MsieJavaScriptEngine 9 | { 10 | /// 11 | /// The API usage exception occurred 12 | /// 13 | #if !NETSTANDARD1_3 14 | [Serializable] 15 | #endif 16 | public sealed class JsUsageException : JsException 17 | { 18 | /// 19 | /// Initializes a new instance of the class 20 | /// with a specified error message 21 | /// 22 | /// The message that describes the error 23 | public JsUsageException(string message) 24 | : base(message) 25 | { 26 | Category = JsErrorCategory.Usage; 27 | } 28 | 29 | /// 30 | /// Initializes a new instance of the class 31 | /// with a specified error message and a reference to the inner exception 32 | /// that is the cause of this exception 33 | /// 34 | /// The error message that explains the reason for the exception 35 | /// The exception that is the cause of the current exception 36 | public JsUsageException(string message, Exception innerException) 37 | : base(message, innerException) 38 | { 39 | Category = JsErrorCategory.Usage; 40 | } 41 | 42 | /// 43 | /// Initializes a new instance of the class 44 | /// 45 | /// The error message that explains the reason for the exception 46 | /// Name of JS engine mode 47 | public JsUsageException(string message, string engineMode) 48 | : base(message, engineMode) 49 | { 50 | Category = JsErrorCategory.Usage; 51 | } 52 | 53 | /// 54 | /// Initializes a new instance of the class 55 | /// 56 | /// The error message that explains the reason for the exception 57 | /// Name of JS engine mode 58 | /// The exception that is the cause of the current exception 59 | public JsUsageException(string message, string engineMode, Exception innerException) 60 | : base(message, engineMode, innerException) 61 | { 62 | Category = JsErrorCategory.Usage; 63 | } 64 | #if !NETSTANDARD1_3 65 | 66 | /// 67 | /// Initializes a new instance of the class with serialized data 68 | /// 69 | /// The object that holds the serialized data 70 | /// The contextual information about the source or destination 71 | private JsUsageException(SerializationInfo info, StreamingContext context) 72 | : base(info, context) 73 | { } 74 | #endif 75 | } 76 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/PACKAGE-DESCRIPTION.md: -------------------------------------------------------------------------------- 1 | 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). 2 | 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). -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Polyfills/System/Reflection/TypeInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | #if NETSTANDARD1_3 2 | using System; 3 | using System.Reflection; 4 | 5 | namespace MsieJavaScriptEngine.Polyfills.System.Reflection 6 | { 7 | internal static class TypeInfoExtensions 8 | { 9 | public static bool IsInstanceOfType(this TypeInfo source, object o) 10 | { 11 | if (source == null) 12 | { 13 | throw new ArgumentNullException(nameof(source)); 14 | } 15 | 16 | if (o == null) 17 | { 18 | return false; 19 | } 20 | 21 | return source.IsAssignableFrom(o.GetType().GetTypeInfo()); 22 | } 23 | } 24 | } 25 | #endif -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/PrecompiledScript.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine 2 | { 3 | /// 4 | /// Represents a pre-compiled script that can be executed by different instances of the MSIE JS engine 5 | /// 6 | public sealed class PrecompiledScript 7 | { 8 | /// 9 | /// Gets a name of JS engine mode 10 | /// 11 | public string EngineMode 12 | { 13 | get; 14 | private set; 15 | } 16 | 17 | /// 18 | /// Gets a source code of the script 19 | /// 20 | internal string Code 21 | { 22 | get; 23 | private set; 24 | } 25 | 26 | /// 27 | /// Gets a cached data for accelerated recompilation 28 | /// 29 | internal byte[] CachedBytes 30 | { 31 | get; 32 | private set; 33 | } 34 | 35 | /// 36 | /// Gets a document name 37 | /// 38 | internal string DocumentName 39 | { 40 | get; 41 | private set; 42 | } 43 | 44 | 45 | /// 46 | /// Constructs an instance of pre-compiled script 47 | /// 48 | /// Name of JS engine mode 49 | /// The source code of the script 50 | /// Cached data for accelerated recompilation 51 | /// Document name 52 | internal PrecompiledScript(string engineMode, string code, byte[] cachedBytes, string documentName) 53 | { 54 | EngineMode = engineMode; 55 | Code = code; 56 | CachedBytes = cachedBytes; 57 | DocumentName = documentName; 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | // Unit tests need access to internal members 4 | [assembly: InternalsVisibleTo("MsieJavaScriptEngine.Test.Common, PublicKey=002400000480000094000000060200000024000052534131000400000100010031605c3b70d76b" + 5 | "bb7e2afeccded26c52f66c4c7047c7a5b6a88301f54f1e91d5e5a08a9e36b0ad18a403f7894eda" + 6 | "d58b014576963d6c6073e3df92eebadd1e9c6bc6c8fb3ad8b95e6358a0948a2fc5df0fa76553b5" + 7 | "63c7584fc6fa22952bd24965f64877622d14559a3603879f8a746eaed0f2cb009dec5537770d94" + 8 | "83e629a9")] -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Resources/CommonStrings.ru-RU.Designer.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Taritsyn/MsieJavaScriptEngine/7c2dcede7cd2d18f5b5940d84f59f0823df3817b/src/MsieJavaScriptEngine/Resources/CommonStrings.ru-RU.Designer.cs -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Resources/NetCoreStrings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // 5 | // Changes to this file may cause incorrect behavior and will be lost if 6 | // the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | namespace MsieJavaScriptEngine.Resources 10 | { 11 | using System; 12 | using System.Globalization; 13 | using System.Reflection; 14 | using System.Resources; 15 | 16 | /// 17 | /// A strongly-typed resource class, for looking up localized strings, etc. 18 | /// 19 | internal class NetCoreStrings 20 | { 21 | private static Lazy _resourceManager = 22 | new Lazy(() => new ResourceManager( 23 | "MsieJavaScriptEngine.Resources.NetCoreStrings", 24 | #if NET20 || NET30 || NET35 || NET40 25 | typeof(NetCoreStrings).Assembly 26 | #else 27 | typeof(NetCoreStrings).GetTypeInfo().Assembly 28 | #endif 29 | )); 30 | 31 | private static CultureInfo _resourceCulture; 32 | 33 | /// 34 | /// Returns a cached ResourceManager instance used by this class 35 | /// 36 | internal static ResourceManager ResourceManager 37 | { 38 | get 39 | { 40 | return _resourceManager.Value; 41 | } 42 | } 43 | 44 | /// 45 | /// Overrides a current thread's CurrentUICulture property for all 46 | /// resource lookups using this strongly typed resource class 47 | /// 48 | internal static CultureInfo Culture 49 | { 50 | get 51 | { 52 | return _resourceCulture; 53 | } 54 | set 55 | { 56 | _resourceCulture = value; 57 | } 58 | } 59 | 60 | /// 61 | /// Looks up a localized string similar to "Could not found none of the JavaScript engines, which would be compatible with .NET Core. Perhaps..." 62 | /// 63 | internal static string Engine_JsEnginesNotFound 64 | { 65 | get { return GetString("Engine_JsEnginesNotFound"); } 66 | } 67 | 68 | /// 69 | /// Looks up a localized string similar to "The '{0}' mode of JavaScript engine is not compatible with .NET Core." 70 | /// 71 | internal static string Usage_JsEngineModeNotCompatibleWithNetCore 72 | { 73 | get { return GetString("Usage_JsEngineModeNotCompatibleWithNetCore"); } 74 | } 75 | 76 | private static string GetString(string name) 77 | { 78 | string value = ResourceManager.GetString(name, _resourceCulture); 79 | 80 | return value; 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-RU.Designer.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Taritsyn/MsieJavaScriptEngine/7c2dcede7cd2d18f5b5940d84f59f0823df3817b/src/MsieJavaScriptEngine/Resources/NetCoreStrings.ru-RU.Designer.cs -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.ru-RU.Designer.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Taritsyn/MsieJavaScriptEngine/7c2dcede7cd2d18f5b5940d84f59f0823df3817b/src/MsieJavaScriptEngine/Resources/NetFrameworkStrings.ru-RU.Designer.cs -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Undefined.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine 2 | { 3 | /// 4 | /// Represents an JS undefined type 5 | /// 6 | public sealed class Undefined 7 | { 8 | /// 9 | /// Gets a one and only undefined instance 10 | /// 11 | public static readonly Undefined Value = new Undefined(); 12 | 13 | private Undefined() 14 | { } 15 | 16 | /// 17 | /// Returns a string that represents the current object 18 | /// 19 | /// A string that represents the current object 20 | public override string ToString() 21 | { 22 | return "undefined"; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Utilities/InterlockedStatedFlag.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | 3 | namespace MsieJavaScriptEngine.Utilities 4 | { 5 | internal struct InterlockedStatedFlag 6 | { 7 | private int _counter; 8 | 9 | 10 | public bool IsSet() 11 | { 12 | return _counter != 0; 13 | } 14 | 15 | public bool Set() 16 | { 17 | return Interlocked.Exchange(ref _counter, 1) == 0; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Utilities/StatedFlag.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Utilities 2 | { 3 | internal struct StatedFlag 4 | { 5 | private bool _isSet; 6 | 7 | 8 | public bool IsSet() 9 | { 10 | return _isSet; 11 | } 12 | 13 | public bool Set() 14 | { 15 | if (!_isSet) 16 | { 17 | _isSet = true; 18 | return true; 19 | } 20 | 21 | return false; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/Utilities/UniqueDocumentNameManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | 5 | using MsieJavaScriptEngine.Resources; 6 | 7 | namespace MsieJavaScriptEngine.Utilities 8 | { 9 | /// 10 | /// Unique document name manager 11 | /// 12 | internal sealed class UniqueDocumentNameManager 13 | { 14 | /// 15 | /// Default document name 16 | /// 17 | private readonly string _defaultName; 18 | 19 | /// 20 | /// Storage of unique names 21 | /// 22 | private readonly Dictionary _storage = new Dictionary(); 23 | 24 | /// 25 | /// Synchronizer of unique name storage 26 | /// 27 | private readonly object _storageSynchronizer = new object(); 28 | 29 | 30 | /// 31 | /// Constructs an instance of the unique document name manager 32 | /// 33 | /// Default document name 34 | public UniqueDocumentNameManager(string defaultName) 35 | { 36 | if (defaultName == null) 37 | { 38 | throw new ArgumentNullException( 39 | nameof(defaultName), 40 | string.Format(CommonStrings.Common_ArgumentIsNull, nameof(defaultName)) 41 | ); 42 | } 43 | 44 | if (string.IsNullOrWhiteSpace(defaultName)) 45 | { 46 | throw new ArgumentException( 47 | string.Format(CommonStrings.Common_ArgumentIsEmpty, nameof(defaultName)), 48 | nameof(defaultName) 49 | ); 50 | } 51 | 52 | _defaultName = defaultName; 53 | } 54 | 55 | 56 | /// 57 | /// Gets a unique document name 58 | /// 59 | /// Document name 60 | /// Unique document name 61 | public string GetUniqueName(string name) 62 | { 63 | string appropriateName = !string.IsNullOrWhiteSpace(name) ? 64 | Path.GetFileNameWithoutExtension(name) : _defaultName; 65 | string extension = Path.GetExtension(name); 66 | 67 | lock (_storageSynchronizer) 68 | { 69 | uint count; 70 | _storage.TryGetValue(appropriateName, out count); 71 | _storage[appropriateName] = ++count; 72 | 73 | string uniqueName = count > 1 ? 74 | string.Concat(appropriateName, " [", count, "]", extension) 75 | : 76 | string.Concat(appropriateName, extension) 77 | ; 78 | 79 | return uniqueName; 80 | } 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MsieJavaScriptEngine", 3 | "version": "3.2.5", 4 | "devDependencies": { 5 | "uglify-js": "3.16.1" 6 | }, 7 | "scripts": { 8 | "minify-es5-js": "uglifyjs ./Resources/ES5.js --output ./Resources/ES5.min.js --config-file ./.uglifyjsrc", 9 | "minify-json2-js": "uglifyjs ./Resources/json2.js --output ./Resources/json2.min.js --config-file ./.uglifyjsrc", 10 | "minify-js": "npm run -s minify-es5-js && npm run -s minify-json2-js" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/MsieJavaScriptEngine/readme.txt: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- 4 | README file for MSIE JavaScript Engine for .NET v3.2.5 5 | 6 | -------------------------------------------------------------------------------- 7 | 8 | Copyright (c) 2012-2024 Andrey Taritsyn - http://www.taritsyn.ru 9 | 10 | 11 | =========== 12 | DESCRIPTION 13 | =========== 14 | This library is a .NET wrapper for working with the JavaScript engines of 15 | Internet Explorer and Edge Legacy (JsRT versions of Chakra, ActiveScript version 16 | of Chakra and Classic JavaScript Engine). Project was based on the code of 17 | SassAndCoffee.JavaScript (https://github.com/anaisbetts/SassAndCoffee), 18 | Chakra Sample Hosts (https://github.com/panopticoncentral/chakra-host) and 19 | jsrt-dotnet (https://github.com/robpaveza/jsrt-dotnet). 20 | 21 | ============= 22 | RELEASE NOTES 23 | ============= 24 | Added a `README.md` file to NuGet package. 25 | 26 | ============ 27 | PROJECT SITE 28 | ============ 29 | https://github.com/Taritsyn/MsieJavaScriptEngine -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Benchmarks/Assert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace MsieJavaScriptEngine.Benchmarks 5 | { 6 | internal static class Assert 7 | { 8 | public static void Equal(string expected, string actual) 9 | { 10 | if (actual != expected) 11 | { 12 | var messageBuilder = new StringBuilder(); 13 | messageBuilder.AppendLine("Assert.Equal() Failure"); 14 | messageBuilder.AppendLine(); 15 | messageBuilder.AppendLine($"Expected: {expected}"); 16 | messageBuilder.Append($"Actual: {actual}"); 17 | 18 | string errorMessage = messageBuilder.ToString(); 19 | 20 | throw new InvalidOperationException(errorMessage); 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Benchmarks/Interop/ObjectsEmbedding/SomeClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace MsieJavaScriptEngine.Benchmarks.Interop.ObjectsEmbedding 7 | { 8 | public class SomeClass : SomeClassBase 9 | { 10 | public Point Field5; 11 | 12 | public SomeOtherClass Property5 { get; set; } 13 | 14 | 15 | public SomeClass() 16 | { 17 | Field5 = new Point(); 18 | 19 | Property5 = new SomeOtherClass(); 20 | } 21 | 22 | 23 | public int DoSomething(bool arg1, int arg2, double arg3, string arg4) 24 | { 25 | int result = Convert.ToInt32(arg1) + 26 | arg2 + 27 | (int)Math.Round(arg3) + 28 | Encoding.UTF8.GetBytes(arg4).Sum(x => x); 29 | ; 30 | 31 | return result; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Benchmarks/Interop/ObjectsEmbedding/SomeClassBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MsieJavaScriptEngine.Benchmarks.Interop.ObjectsEmbedding 8 | { 9 | public abstract class SomeClassBase 10 | { 11 | public bool Field1; 12 | public int Field2; 13 | public double Field3; 14 | public string Field4; 15 | 16 | public bool Property1 { get; set; } 17 | public int Property2 { get; set; } 18 | public double Property3 { get; set; } 19 | public string Property4 { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Benchmarks/Interop/ObjectsEmbedding/SomeOtherClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Text; 4 | 5 | namespace MsieJavaScriptEngine.Benchmarks.Interop.ObjectsEmbedding 6 | { 7 | public class SomeOtherClass : SomeClassBase 8 | { 9 | public string DoSomething(bool arg1, int arg2, double arg3, string arg4) 10 | { 11 | string rawResult = arg1.ToString(CultureInfo.InvariantCulture) + "|" + 12 | arg2.ToString(CultureInfo.InvariantCulture) + "|" + 13 | arg3.ToString(CultureInfo.InvariantCulture) + "|" + 14 | arg4 15 | ; 16 | string result = Convert.ToBase64String(Encoding.UTF8.GetBytes(rawResult)); 17 | 18 | return result; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Benchmarks/Interop/TypesEmbedding/SomeClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace MsieJavaScriptEngine.Benchmarks.Interop.TypesEmbedding 7 | { 8 | public static class SomeClass 9 | { 10 | public static bool Field1; 11 | public static int Field2; 12 | public static double Field3; 13 | public static string Field4; 14 | public static Point Field5; 15 | 16 | public static bool Property1 { get; set; } 17 | public static int Property2 { get; set; } 18 | public static double Property3 { get; set; } 19 | public static string Property4 { get; set; } 20 | public static SomeOtherClass Property5 { get; set; } 21 | 22 | 23 | public static int DoSomething(bool arg1, int arg2, double arg3, string arg4) 24 | { 25 | int result = Convert.ToInt32(arg1) + 26 | arg2 + 27 | (int)Math.Round(arg3) + 28 | Encoding.UTF8.GetBytes(arg4).Sum(x => x); 29 | ; 30 | 31 | return result; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Benchmarks/Interop/TypesEmbedding/SomeOtherClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Text; 4 | 5 | namespace MsieJavaScriptEngine.Benchmarks.Interop.TypesEmbedding 6 | { 7 | public class SomeOtherClass 8 | { 9 | public bool Field1; 10 | public int Field2; 11 | public double Field3; 12 | public string Field4; 13 | 14 | public bool Property1 { get; set; } 15 | public int Property2 { get; set; } 16 | public double Property3 { get; set; } 17 | public string Property4 { get; set; } 18 | 19 | 20 | public SomeOtherClass(bool field1, int field2, double field3, string field4, 21 | bool property1, int property2, double property3, string property4) 22 | { 23 | Field1 = field1; 24 | Field2 = field2; 25 | Field3 = field3; 26 | Field4 = field4; 27 | 28 | Property1 = property1; 29 | Property2 = property2; 30 | Property3 = property3; 31 | Property4 = property4; 32 | } 33 | 34 | 35 | public static string DoSomething(bool arg1, int arg2, double arg3, string arg4) 36 | { 37 | string rawResult = arg1.ToString(CultureInfo.InvariantCulture) + "|" + 38 | arg2.ToString(CultureInfo.InvariantCulture) + "|" + 39 | arg3.ToString(CultureInfo.InvariantCulture) + "|" + 40 | arg4 41 | ; 42 | string result = Convert.ToBase64String(Encoding.UTF8.GetBytes(rawResult)); 43 | 44 | return result; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Benchmarks/MsieJavaScriptEngine.Benchmarks.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | MSIE JavaScript Engine: Benchmarks 5 | 3.2.5 6 | net462;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 7 | Exe 8 | true 9 | true 10 | false 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Benchmarks/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | using BenchmarkDotNet.Running; 4 | 5 | namespace MsieJavaScriptEngine.Benchmarks 6 | { 7 | public static class Program 8 | { 9 | public static void Main(string[] args) 10 | { 11 | BenchmarkSwitcher.FromAssembly(typeof(Program).GetTypeInfo().Assembly).Run(args); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Auto/CommonTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using MsieJavaScriptEngine.Test.Common; 4 | 5 | namespace MsieJavaScriptEngine.Test.Auto 6 | { 7 | [TestFixture] 8 | public class CommonTests : CommonTestsBase 9 | { 10 | protected override JsEngineMode EngineMode => JsEngineMode.Auto; 11 | } 12 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Auto/Es5Tests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using MsieJavaScriptEngine.Test.Common; 4 | 5 | namespace MsieJavaScriptEngine.Test.Auto 6 | { 7 | [TestFixture] 8 | public class Es5Tests : Es5TestsBase 9 | { 10 | protected override JsEngineMode EngineMode => JsEngineMode.Auto; 11 | protected override bool UseEcmaScript5Polyfill => true; 12 | protected override bool UseJson2Library => true; 13 | } 14 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Auto/InteropTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using MsieJavaScriptEngine.Test.Common; 4 | 5 | namespace MsieJavaScriptEngine.Test.Auto 6 | { 7 | [TestFixture] 8 | public class InteropTests : InteropTestsBase 9 | { 10 | protected override JsEngineMode EngineMode => JsEngineMode.Auto; 11 | 12 | 13 | #region Embedding of objects 14 | 15 | #region Objects with methods 16 | 17 | public override void EmbeddingOfInstanceOfCustomValueTypeAndCallingOfItsGetTypeMethod() 18 | { } 19 | 20 | public override void EmbeddingOfInstanceOfCustomReferenceTypeAndCallingOfItsGetTypeMethod() 21 | { } 22 | 23 | #endregion 24 | 25 | #region Delegates 26 | 27 | public override void EmbeddingOfInstanceOfDelegateAndCheckingItsPrototype() 28 | { } 29 | 30 | public override void EmbeddingOfInstanceOfDelegateAndGettingItsMethodProperty() 31 | { } 32 | 33 | #endregion 34 | 35 | #endregion 36 | 37 | 38 | #region Embedding of types 39 | 40 | #region Creating of instances 41 | 42 | public override void CreatingAnInstanceOfEmbeddedBuiltinExceptionAndGettingItsTargetSiteProperty() 43 | { } 44 | 45 | public override void CreatingAnInstanceOfEmbeddedCustomExceptionAndCallingOfItsGetTypeMethod() 46 | { } 47 | 48 | #endregion 49 | 50 | #endregion 51 | } 52 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Auto/MsieJavaScriptEngine.Test.Auto.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | MSIE JavaScript Engine: Tests for Auto Mode 5 | 3.2.5 6 | net462;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 7 | Library 8 | true 9 | true 10 | false 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Auto/MultithreadingTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using MsieJavaScriptEngine.Test.Common; 4 | 5 | namespace MsieJavaScriptEngine.Test.Auto 6 | { 7 | [TestFixture] 8 | public class MultithreadingTests : MultithreadingTestsBase 9 | { 10 | protected override JsEngineMode EngineMode => JsEngineMode.Auto; 11 | } 12 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Auto/PrecompilationTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using MsieJavaScriptEngine.Test.Common; 4 | 5 | namespace MsieJavaScriptEngine.Test.Auto 6 | { 7 | [TestFixture] 8 | public class PrecompilationTests : PrecompilationTestsBase 9 | { 10 | protected override JsEngineMode EngineMode => JsEngineMode.Auto; 11 | } 12 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraActiveScript/Es5Tests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using MsieJavaScriptEngine.Test.Common; 4 | 5 | namespace MsieJavaScriptEngine.Test.ChakraActiveScript 6 | { 7 | [TestFixture] 8 | public class Es5Tests : Es5TestsBase 9 | { 10 | protected override JsEngineMode EngineMode => JsEngineMode.ChakraActiveScript; 11 | } 12 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraActiveScript/MsieJavaScriptEngine.Test.ChakraActiveScript.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | MSIE JavaScript Engine: Tests for Chakra ActiveScript Mode 5 | 3.2.5 6 | net462 7 | Library 8 | true 9 | true 10 | false 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraActiveScript/MultithreadingTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using NUnit.Framework; 4 | 5 | using MsieJavaScriptEngine.Test.Common; 6 | 7 | namespace MsieJavaScriptEngine.Test.ChakraActiveScript 8 | { 9 | [TestFixture] 10 | public class MultithreadingTests : MultithreadingTestsBase 11 | { 12 | protected override JsEngineMode EngineMode => JsEngineMode.ChakraActiveScript; 13 | } 14 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraActiveScript/PrecompilationTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using MsieJavaScriptEngine.Test.Common; 4 | 5 | namespace MsieJavaScriptEngine.Test.ChakraActiveScript 6 | { 7 | [TestFixture] 8 | public class PrecompilationTests : PrecompilationTestsBase 9 | { 10 | protected override JsEngineMode EngineMode => JsEngineMode.ChakraActiveScript; 11 | } 12 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/Es5Tests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using MsieJavaScriptEngine.Test.Common; 4 | 5 | namespace MsieJavaScriptEngine.Test.ChakraEdgeJsRt 6 | { 7 | [TestFixture] 8 | public class Es5Tests : Es5TestsBase 9 | { 10 | protected override JsEngineMode EngineMode => JsEngineMode.ChakraEdgeJsRt; 11 | } 12 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/InteropTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | using NUnit.Framework; 5 | 6 | using MsieJavaScriptEngine.Test.Common; 7 | 8 | namespace MsieJavaScriptEngine.Test.ChakraEdgeJsRt 9 | { 10 | [TestFixture] 11 | public class InteropTests : InteropTestsBase 12 | { 13 | protected override JsEngineMode EngineMode => JsEngineMode.ChakraEdgeJsRt; 14 | 15 | 16 | #region Embedding of objects 17 | 18 | #region Recursive calls 19 | 20 | #region Mapping of errors 21 | 22 | [Test] 23 | public void MappingRuntimeErrorDuringRecursiveEvaluationOfFiles() 24 | { 25 | // Arrange 26 | string directoryPath = GetAbsolutePath("SharedFiles/recursiveEvaluation/runtimeError"); 27 | const string input = "require('index').calculateResult();"; 28 | 29 | // Act 30 | JsRuntimeException exception = null; 31 | 32 | using (var jsEngine = CreateJsEngine()) 33 | { 34 | try 35 | { 36 | Func loadModule = path => { 37 | string absolutePath = Path.Combine(directoryPath, $"{path}.js"); 38 | string code = File.ReadAllText(absolutePath); 39 | object result = jsEngine.Evaluate(code, absolutePath); 40 | 41 | return result; 42 | }; 43 | 44 | jsEngine.EmbedHostObject("require", loadModule); 45 | double output = jsEngine.Evaluate(input); 46 | } 47 | catch (JsRuntimeException e) 48 | { 49 | exception = e; 50 | } 51 | } 52 | 53 | // Assert 54 | Assert.NotNull(exception); 55 | Assert.AreEqual("Runtime error", exception.Category); 56 | Assert.AreEqual("'argumens' is not defined", exception.Description); 57 | Assert.AreEqual("ReferenceError", exception.Type); 58 | Assert.AreEqual("math.js", exception.DocumentName); 59 | Assert.AreEqual(10, exception.LineNumber); 60 | Assert.AreEqual(4, exception.ColumnNumber); 61 | Assert.IsEmpty(exception.SourceFragment); 62 | Assert.AreEqual( 63 | " at sum (math.js:10:4)" + Environment.NewLine + 64 | " at calculateResult (index.js:7:4)" + Environment.NewLine + 65 | " at Global code (Script Document:1:1)", 66 | exception.CallStack 67 | ); 68 | } 69 | 70 | #endregion 71 | 72 | #endregion 73 | 74 | #endregion 75 | } 76 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/MsieJavaScriptEngine.Test.ChakraEdgeJsRt.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | MSIE JavaScript Engine: Tests for Chakra Edge JsRT Mode 5 | 3.2.5 6 | net462;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 7 | Library 8 | true 9 | true 10 | false 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/MultithreadingTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.RegularExpressions; 3 | 4 | using NUnit.Framework; 5 | 6 | using MsieJavaScriptEngine.Test.Common; 7 | 8 | namespace MsieJavaScriptEngine.Test.ChakraEdgeJsRt 9 | { 10 | [TestFixture] 11 | public class MultithreadingTests : MultithreadingTestsBase 12 | { 13 | protected override JsEngineMode EngineMode => JsEngineMode.ChakraEdgeJsRt; 14 | } 15 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraIeJsRt/Es5Tests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using MsieJavaScriptEngine.Test.Common; 4 | 5 | namespace MsieJavaScriptEngine.Test.ChakraIeJsRt 6 | { 7 | [TestFixture] 8 | public class Es5Tests : Es5TestsBase 9 | { 10 | protected override JsEngineMode EngineMode => JsEngineMode.ChakraIeJsRt; 11 | } 12 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraIeJsRt/InteropTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | using NUnit.Framework; 5 | 6 | using MsieJavaScriptEngine.Test.Common; 7 | 8 | namespace MsieJavaScriptEngine.Test.ChakraIeJsRt 9 | { 10 | [TestFixture] 11 | public class InteropTests : InteropTestsBase 12 | { 13 | protected override JsEngineMode EngineMode => JsEngineMode.ChakraIeJsRt; 14 | 15 | 16 | #region Embedding of objects 17 | 18 | #region Recursive calls 19 | 20 | #region Mapping of errors 21 | 22 | [Test] 23 | public void MappingRuntimeErrorDuringRecursiveEvaluationOfFiles() 24 | { 25 | // Arrange 26 | string directoryPath = GetAbsolutePath("SharedFiles/recursiveEvaluation/runtimeError"); 27 | const string input = "require('index').calculateResult();"; 28 | 29 | // Act 30 | JsRuntimeException exception = null; 31 | 32 | using (var jsEngine = CreateJsEngine()) 33 | { 34 | try 35 | { 36 | Func loadModule = path => { 37 | string absolutePath = Path.Combine(directoryPath, $"{path}.js"); 38 | string code = File.ReadAllText(absolutePath); 39 | object result = jsEngine.Evaluate(code, absolutePath); 40 | 41 | return result; 42 | }; 43 | 44 | jsEngine.EmbedHostObject("require", loadModule); 45 | double output = jsEngine.Evaluate(input); 46 | } 47 | catch (JsRuntimeException e) 48 | { 49 | exception = e; 50 | } 51 | } 52 | 53 | // Assert 54 | Assert.NotNull(exception); 55 | Assert.AreEqual("Runtime error", exception.Category); 56 | Assert.AreEqual("'argumens' is undefined", exception.Description); 57 | Assert.AreEqual("ReferenceError", exception.Type); 58 | Assert.AreEqual("math.js", exception.DocumentName); 59 | Assert.AreEqual(10, exception.LineNumber); 60 | Assert.AreEqual(4, exception.ColumnNumber); 61 | Assert.IsEmpty(exception.SourceFragment); 62 | Assert.AreEqual( 63 | " at sum (math.js:10:4)" + Environment.NewLine + 64 | " at calculateResult (index.js:7:4)" + Environment.NewLine + 65 | " at Global code (Script Document:1:1)", 66 | exception.CallStack 67 | ); 68 | } 69 | 70 | #endregion 71 | 72 | #endregion 73 | 74 | #endregion 75 | } 76 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraIeJsRt/MsieJavaScriptEngine.Test.ChakraIeJsRt.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | MSIE JavaScript Engine: Tests for Chakra IE JsRT Mode 5 | 3.2.5 6 | net462;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 7 | Library 8 | true 9 | true 10 | false 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.ChakraIeJsRt/MultithreadingTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using NUnit.Framework; 4 | 5 | using MsieJavaScriptEngine.Test.Common; 6 | 7 | namespace MsieJavaScriptEngine.Test.ChakraIeJsRt 8 | { 9 | [TestFixture] 10 | public class MultithreadingTests : MultithreadingTestsBase 11 | { 12 | protected override JsEngineMode EngineMode => JsEngineMode.ChakraIeJsRt; 13 | } 14 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Classic/Es5Tests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using MsieJavaScriptEngine.Test.Common; 4 | 5 | namespace MsieJavaScriptEngine.Test.Classic 6 | { 7 | [TestFixture] 8 | public class Es5Tests : Es5TestsBase 9 | { 10 | protected override JsEngineMode EngineMode => JsEngineMode.Classic; 11 | protected override bool UseEcmaScript5Polyfill => true; 12 | protected override bool UseJson2Library => true; 13 | 14 | 15 | #region Object methods 16 | 17 | [Test] 18 | public override void SupportsObjectKeysMethod() 19 | { 20 | // Arrange 21 | const string input1 = "Object.keys(['a', 'b', 'c']).toString();"; 22 | const string targetOutput1 = "0,1,2"; 23 | 24 | const string input2 = "Object.keys({ 0: 'a', 1: 'b', 2: 'c' }).toString();"; 25 | const string targetOutput2 = "0,1,2"; 26 | 27 | const string input3 = "Object.keys({ 100: 'a', 2: 'b', 7: 'c' }).toString();"; 28 | const string targetOutput3 = "100,2,7"; 29 | 30 | const string initCode4 = @"var myObj = function() { }; 31 | myObj.prototype = { getFoo: { value: function () { return this.foo } } };; 32 | myObj.foo = 1; 33 | "; 34 | const string input4 = "Object.keys(myObj).toString();"; 35 | const string targetOutput4 = "foo"; 36 | 37 | // Act 38 | string output1; 39 | string output2; 40 | string output3; 41 | string output4; 42 | 43 | using (var jsEngine = CreateJsEngine()) 44 | { 45 | output1 = jsEngine.Evaluate(input1); 46 | output2 = jsEngine.Evaluate(input2); 47 | output3 = jsEngine.Evaluate(input3); 48 | 49 | jsEngine.Execute(initCode4); 50 | output4 = jsEngine.Evaluate(input4); 51 | } 52 | 53 | // Assert 54 | Assert.AreEqual(targetOutput1, output1); 55 | Assert.AreEqual(targetOutput2, output2); 56 | Assert.AreEqual(targetOutput3, output3); 57 | Assert.AreEqual(targetOutput4, output4); 58 | } 59 | 60 | #endregion 61 | } 62 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Classic/MsieJavaScriptEngine.Test.Classic.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | MSIE JavaScript Engine: Tests for Classic Mode 5 | 3.2.5 6 | net462 7 | Library 8 | true 9 | true 10 | false 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Classic/MultithreadingTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using NUnit.Framework; 4 | 5 | using MsieJavaScriptEngine.Test.Common; 6 | 7 | namespace MsieJavaScriptEngine.Test.Classic 8 | { 9 | [TestFixture] 10 | public class MultithreadingTests : MultithreadingTestsBase 11 | { 12 | protected override JsEngineMode EngineMode => JsEngineMode.Classic; 13 | } 14 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Classic/PrecompilationTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using MsieJavaScriptEngine.Test.Common; 4 | 5 | namespace MsieJavaScriptEngine.Test.Classic 6 | { 7 | [TestFixture] 8 | public class PrecompilationTests : PrecompilationTestsBase 9 | { 10 | protected override JsEngineMode EngineMode => JsEngineMode.Classic; 11 | } 12 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/FileSystemTestsBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace MsieJavaScriptEngine.Test.Common 5 | { 6 | public abstract class FileSystemTestsBase : TestsBase 7 | { 8 | private string _baseDirectoryPath; 9 | 10 | 11 | protected FileSystemTestsBase() 12 | { 13 | string appDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; 14 | _baseDirectoryPath = Path.Combine(appDirectoryPath, "../../../../"); 15 | } 16 | 17 | 18 | protected string GetAbsolutePath(string relativePath) 19 | { 20 | string absolutePath = Path.GetFullPath(Path.Combine(_baseDirectoryPath, relativePath)); 21 | 22 | return absolutePath; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Animals/AnimalTrainer.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop.Animals 2 | { 3 | public sealed class AnimalTrainer 4 | { 5 | public string ExecuteVoiceCommand(IAnimal animal) 6 | { 7 | return animal.Cry(); 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Animals/Cat.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop.Animals 2 | { 3 | public sealed class Cat : IAnimal 4 | { 5 | public string Cry() 6 | { 7 | return "Meow!"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Animals/Dog.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop.Animals 2 | { 3 | public sealed class Dog : IAnimal 4 | { 5 | public string Cry() 6 | { 7 | return "Woof!"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Animals/IAnimal.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop.Animals 2 | { 3 | public interface IAnimal 4 | { 5 | string Cry(); 6 | } 7 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Base64Encoder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace MsieJavaScriptEngine.Test.Common.Interop 5 | { 6 | public static class Base64Encoder 7 | { 8 | public const int DATA_URI_MAX = 32768; 9 | 10 | 11 | public static string Encode(string value) 12 | { 13 | return Convert.ToBase64String(Encoding.GetEncoding(0).GetBytes(value)); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/BundleTable.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop 2 | { 3 | public static class BundleTable 4 | { 5 | private static bool _enableOptimizations = true; 6 | 7 | public static bool EnableOptimizations 8 | { 9 | get 10 | { 11 | return _enableOptimizations; 12 | } 13 | set 14 | { 15 | _enableOptimizations = value; 16 | } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Date.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MsieJavaScriptEngine.Test.Common.Interop 4 | { 5 | public struct Date 6 | { 7 | private static readonly int[] _cumulativeDays = { 0, 31, 59, 90, 120, 151, 181, 8 | 212, 243, 273, 304, 334 }; 9 | 10 | public int Year; 11 | public int Month; 12 | public int Day; 13 | 14 | public static Date Today 15 | { 16 | get 17 | { 18 | DateTime currentDateTime = DateTime.Today; 19 | var currentDate = new Date(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day); 20 | 21 | return currentDate; 22 | } 23 | } 24 | 25 | 26 | public Date(int year, int month, int day) 27 | { 28 | Year = year; 29 | Month = month; 30 | Day = day; 31 | } 32 | 33 | 34 | public static bool IsLeapYear(int year) 35 | { 36 | return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); 37 | } 38 | 39 | public int GetDayOfYear() 40 | { 41 | return _cumulativeDays[Month - 1] + 42 | Day + 43 | (Month > 2 && IsLeapYear(Year) ? 1 : 0) 44 | ; 45 | } 46 | 47 | public Date AddDays(double value) 48 | { 49 | var dateTime = new DateTime(Year, Month, Day); 50 | DateTime newDateTime = dateTime.AddDays(value); 51 | 52 | return new Date(newDateTime.Year, newDateTime.Month, newDateTime.Day); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/FileManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | namespace MsieJavaScriptEngine.Test.Common.Interop 6 | { 7 | public sealed class FileManager 8 | { 9 | public string ReadFile(string path) 10 | { 11 | return ReadFile(path, null); 12 | } 13 | 14 | public string ReadFile(string path, Encoding encoding) 15 | { 16 | if (path == null) 17 | { 18 | throw new ArgumentNullException("path"); 19 | } 20 | 21 | encoding = encoding ?? Encoding.UTF8; 22 | 23 | string content = File.ReadAllText(path, encoding); 24 | 25 | return content; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Logging/DefaultLogger.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop.Logging 2 | { 3 | public class DefaultLogger 4 | { 5 | public static ILogger Current = new NullLogger(); 6 | } 7 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Logging/ILogger.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop.Logging 2 | { 3 | public interface ILogger 4 | { 5 | void Error(string category, string message, 6 | string filePath = "", int lineNumber = 0, int columnNumber = 0, 7 | string sourceFragment = ""); 8 | 9 | void Warn(string category, string message, 10 | string filePath = "", int lineNumber = 0, int columnNumber = 0, 11 | string sourceFragment = ""); 12 | 13 | void Debug(string category, string message, string filePath = ""); 14 | 15 | void Info(string category, string message, string filePath = ""); 16 | } 17 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Logging/NullLogger.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop.Logging 2 | { 3 | public sealed class NullLogger : ILogger 4 | { 5 | public void Error(string category, string message, 6 | string filePath = "", int lineNumber = 0, int columnNumber = 0, 7 | string sourceFragment = "") 8 | { } 9 | 10 | public void Warn(string category, string message, 11 | string filePath = "", int lineNumber = 0, int columnNumber = 0, 12 | string sourceFragment = "") 13 | { } 14 | 15 | public void Debug(string category, string message, string filePath = "") 16 | { } 17 | 18 | public void Info(string category, string message, string filePath = "") 19 | { } 20 | 21 | public override string ToString() 22 | { 23 | return "[null logger]"; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Logging/ThrowExceptionLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace MsieJavaScriptEngine.Test.Common.Interop.Logging 5 | { 6 | public sealed class ThrowExceptionLogger : ILogger 7 | { 8 | public void Error(string category, string message, string filePath = "", 9 | int lineNumber = 0, int columnNumber = 0, string sourceFragment = "") 10 | { 11 | var errorBuilder = new StringBuilder(); 12 | errorBuilder.AppendLine("Category: " + category); 13 | errorBuilder.AppendLine("Message: " + message); 14 | 15 | if (!string.IsNullOrWhiteSpace(filePath)) 16 | { 17 | errorBuilder.AppendLine("File: " + filePath); 18 | } 19 | 20 | if (lineNumber > 0) 21 | { 22 | errorBuilder.AppendLine("Line number: " + lineNumber); 23 | } 24 | 25 | if (columnNumber > 0) 26 | { 27 | errorBuilder.AppendLine("Column number: " + columnNumber); 28 | } 29 | 30 | if (!string.IsNullOrWhiteSpace(sourceFragment)) 31 | { 32 | errorBuilder.AppendLine("Source fragment:" + Environment.NewLine + sourceFragment); 33 | } 34 | 35 | string errorMessage = errorBuilder.ToString(); 36 | errorBuilder.Clear(); 37 | 38 | throw new InvalidOperationException(errorMessage); 39 | } 40 | 41 | public void Warn(string category, string message, 42 | string filePath = "", int lineNumber = 0, int columnNumber = 0, 43 | string sourceFragment = "") 44 | { } 45 | 46 | public void Debug(string category, string message, string filePath = "") 47 | { } 48 | 49 | public void Info(string category, string message, string filePath = "") 50 | { } 51 | 52 | public override string ToString() 53 | { 54 | return "[throw exception logger]"; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/LoginFailedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | #if !NET8_0_OR_GREATER 3 | using System.Runtime.Serialization; 4 | #endif 5 | 6 | namespace MsieJavaScriptEngine.Test.Common.Interop 7 | { 8 | [Serializable] 9 | public class LoginFailedException : Exception 10 | { 11 | private string _userName; 12 | 13 | public string UserName 14 | { 15 | get { return _userName; } 16 | set { _userName = value; } 17 | } 18 | 19 | 20 | public LoginFailedException() 21 | { } 22 | 23 | public LoginFailedException(string message) 24 | : base(message) 25 | { } 26 | 27 | public LoginFailedException(string message, Exception innerException) 28 | : base(message, innerException) 29 | { } 30 | #if !NET8_0_OR_GREATER 31 | 32 | protected LoginFailedException(SerializationInfo info, StreamingContext context) 33 | : base(info, context) 34 | { 35 | if (info != null) 36 | { 37 | _userName = info.GetString("UserName"); 38 | } 39 | } 40 | 41 | 42 | public override void GetObjectData(SerializationInfo info, StreamingContext context) 43 | { 44 | if (info == null) 45 | { 46 | throw new ArgumentNullException(nameof(info)); 47 | } 48 | 49 | base.GetObjectData(info, context); 50 | info.AddValue("UserName", this._userName); 51 | } 52 | #endif 53 | } 54 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Person.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop 2 | { 3 | public sealed class Person 4 | { 5 | public string FirstName 6 | { 7 | get; 8 | set; 9 | } 10 | 11 | public string LastName 12 | { 13 | get; 14 | set; 15 | } 16 | 17 | public string Patronymic 18 | { 19 | get; 20 | set; 21 | } 22 | 23 | 24 | public Person() 25 | : this(string.Empty, string.Empty) 26 | { } 27 | 28 | public Person(string firstName, string lastName) 29 | : this(firstName, lastName, string.Empty) 30 | { } 31 | 32 | public Person(string firstName, string lastName, string patronymic) 33 | { 34 | FirstName = firstName; 35 | LastName = lastName; 36 | Patronymic = patronymic; 37 | } 38 | 39 | 40 | public override string ToString() 41 | { 42 | return string.Format("{{FirstName={0},LastName={1}}}", FirstName, LastName); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Point3D.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop 2 | { 3 | public struct Point3D 4 | { 5 | public int X; 6 | public int Y; 7 | public int Z; 8 | 9 | public static readonly Point3D Empty = new Point3D(); 10 | 11 | 12 | public Point3D(int x, int y, int z) 13 | { 14 | X = x; 15 | Y = y; 16 | Z = z; 17 | } 18 | 19 | 20 | public override string ToString() 21 | { 22 | return string.Format("{{X={0},Y={1},Z={2}}}", X, Y, Z); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/PredefinedStrings.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop 2 | { 3 | public struct PredefinedStrings 4 | { 5 | public const string VeryLongName = "Very Long Name"; 6 | public const string AnotherVeryLongName = "Another Very Long Name"; 7 | public const string TheLastVeryLongName = "The Last Very Long Name"; 8 | } 9 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Product.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop 2 | { 3 | public sealed class Product 4 | { 5 | public string Name; 6 | public string Description; 7 | public double Price; 8 | } 9 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/SomeClass.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common.Interop 2 | { 3 | public class SomeClass 4 | { 5 | public int SomeProperty { get; set; } = 123; 6 | public string SomeOtherProperty { get; set; } = "abc"; 7 | 8 | public static SomeClass Instance { get; } = new SomeClass(); 9 | } 10 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Interop/Temperature.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MsieJavaScriptEngine.Test.Common.Interop 4 | { 5 | public struct Temperature 6 | { 7 | double _celsius; 8 | 9 | public double Celsius 10 | { 11 | get 12 | { 13 | return _celsius; 14 | } 15 | set 16 | { 17 | _celsius = value; 18 | } 19 | } 20 | 21 | public double Kelvin 22 | { 23 | get 24 | { 25 | return _celsius + 273.15; 26 | } 27 | set 28 | { 29 | if (value < 0) 30 | { 31 | throw new ArgumentOutOfRangeException(); 32 | } 33 | 34 | _celsius = value - 273.15; 35 | } 36 | } 37 | 38 | public double Fahrenheit 39 | { 40 | get 41 | { 42 | return 9 * _celsius / 5 + 32; 43 | } 44 | set 45 | { 46 | _celsius = 5 * (value - 32) / 9; 47 | } 48 | } 49 | 50 | public Temperature(double degree, TemperatureUnits units) 51 | { 52 | _celsius = 0; 53 | 54 | switch (units) 55 | { 56 | case TemperatureUnits.Celsius: 57 | Celsius = degree; 58 | break; 59 | case TemperatureUnits.Kelvin: 60 | Kelvin = degree; 61 | break; 62 | case TemperatureUnits.Fahrenheit: 63 | Fahrenheit = degree; 64 | break; 65 | default: 66 | throw new NotSupportedException(); 67 | } 68 | } 69 | 70 | public override string ToString() 71 | { 72 | return ToString(TemperatureUnits.Celsius); 73 | } 74 | 75 | public string ToString(TemperatureUnits units) 76 | { 77 | string formattedValue; 78 | 79 | switch (units) 80 | { 81 | case TemperatureUnits.Celsius: 82 | formattedValue = String.Format("{0}\u00B0 C", Celsius); 83 | break; 84 | case TemperatureUnits.Kelvin: 85 | formattedValue = String.Format("{0}\u00B0 K", Kelvin); 86 | break; 87 | case TemperatureUnits.Fahrenheit: 88 | formattedValue = String.Format("{0}\u00B0 F", Fahrenheit); 89 | break; 90 | default: 91 | formattedValue = string.Empty; 92 | break; 93 | } 94 | 95 | return formattedValue; 96 | } 97 | } 98 | 99 | public enum TemperatureUnits 100 | { 101 | Celsius, 102 | Kelvin, 103 | Fahrenheit 104 | } 105 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/MsieJavaScriptEngine.Test.Common.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | MSIE JavaScript Engine: Common Tests 5 | 3.2.5 6 | net462;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 7 | Library 8 | true 9 | true 10 | false 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/MultithreadingTestsBase.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | 3 | using NUnit.Framework; 4 | 5 | namespace MsieJavaScriptEngine.Test.Common 6 | { 7 | [TestFixture] 8 | public abstract class MultithreadingTestsBase : TestsBase 9 | { 10 | [Test] 11 | public virtual void ExecutionOfCodeFromDifferentThreads() 12 | { 13 | // Arrange 14 | const string variableName = "foo"; 15 | string inputCode1 = string.Format("var {0} = 'bar';", variableName); 16 | string inputCode2 = string.Format("{0} = 'baz';", variableName); 17 | const string targetOutput = "baz"; 18 | 19 | // Act 20 | string output; 21 | 22 | using (var jsEngine = CreateJsEngine()) 23 | { 24 | jsEngine.Execute(inputCode1); 25 | 26 | var thread = new Thread(() => jsEngine.Execute(inputCode2)); 27 | thread.Start(); 28 | thread.Join(); 29 | 30 | output = jsEngine.GetVariableValue(variableName); 31 | } 32 | 33 | // Assert 34 | Assert.AreEqual(targetOutput, output); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Resources/cube.js: -------------------------------------------------------------------------------- 1 | function cube(num) { 2 | return num * num * num; 3 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Resources/declinationOfDays.js: -------------------------------------------------------------------------------- 1 | function declensionOfNumerals(number, titles) { 2 | var result, 3 | titleIndex, 4 | cases = [2, 0, 1, 1, 1, 2], 5 | caseIndex 6 | ; 7 | 8 | if (number % 100 > 4 && number % 100 < 20) { 9 | titleIndex = 2; 10 | } 11 | else { 12 | caseIndex = number % 10 < 5 ? number % 10 : 5; 13 | titleIndex = cases[caseIndex]; 14 | } 15 | 16 | result = titles[titleIndex]; 17 | 18 | return result; 19 | } 20 | 21 | function declinationOfDays(number) { 22 | return declensionOfNumerals(number, ['день', 'дня', 'дней']); 23 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Resources/declinationOfHours.js: -------------------------------------------------------------------------------- 1 | function declensionOfNumerals(number, titles) { 2 | var result, 3 | titleIndex, 4 | cases = [2, 0, 1, 1, 1, 2], 5 | caseIndex 6 | ; 7 | 8 | if (number % 100 > 4 && number % 100 < 20) { 9 | titleIndex = 2; 10 | } 11 | else { 12 | caseIndex = number % 10 < 5 ? number % 10 : 5; 13 | titleIndex = cases[caseIndex]; 14 | } 15 | 16 | result = titles[titleIndex]; 17 | 18 | return result; 19 | } 20 | 21 | function declinationOfHours(number) { 22 | return declensionOfNumerals(number, ['час', 'часа', 'часов']); 23 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/Resources/power.js: -------------------------------------------------------------------------------- 1 | function power(x, y) { 2 | var result = x; 3 | 4 | for (var i = 2; i <= y; i++) { 5 | result *= x; 6 | } 7 | 8 | return result; 9 | } -------------------------------------------------------------------------------- /test/MsieJavaScriptEngine.Test.Common/TestsBase.cs: -------------------------------------------------------------------------------- 1 | namespace MsieJavaScriptEngine.Test.Common 2 | { 3 | public abstract class TestsBase 4 | { 5 | /// 6 | /// Gets a JS engine mode 7 | /// 8 | protected abstract JsEngineMode EngineMode { get; } 9 | 10 | /// 11 | /// Gets a flag for whether to use the ECMAScript 5 Polyfill 12 | /// 13 | protected virtual bool UseEcmaScript5Polyfill => false; 14 | 15 | /// 16 | /// Gets a flag for whether to use the JSON2 library 17 | /// 18 | protected virtual bool UseJson2Library => false; 19 | 20 | 21 | protected MsieJsEngine CreateJsEngine(bool allowReflection = false, bool enableDebugging = false) 22 | { 23 | var jsEngine = new MsieJsEngine(new JsEngineSettings 24 | { 25 | AllowReflection = allowReflection, 26 | EnableDebugging = enableDebugging, 27 | EngineMode = EngineMode, 28 | UseEcmaScript5Polyfill = UseEcmaScript5Polyfill, 29 | UseJson2Library = UseJson2Library 30 | }); 31 | 32 | return jsEngine; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /test/SharedFiles/declinationOfMinutes.js: -------------------------------------------------------------------------------- 1 | function declensionOfNumerals(number, titles) { 2 | var result, 3 | titleIndex, 4 | cases = [2, 0, 1, 1, 1, 2], 5 | caseIndex 6 | ; 7 | 8 | if (number % 100 > 4 && number % 100 < 20) { 9 | titleIndex = 2; 10 | } 11 | else { 12 | caseIndex = number % 10 < 5 ? number % 10 : 5; 13 | titleIndex = cases[caseIndex]; 14 | } 15 | 16 | result = titles[titleIndex]; 17 | 18 | return result; 19 | } 20 | 21 | function declinationOfMinutes(number) { 22 | return declensionOfNumerals(number, ['минута', 'минуты', 'минут']); 23 | } -------------------------------------------------------------------------------- /test/SharedFiles/link.txt: -------------------------------------------------------------------------------- 1 | http://www.panopticoncentral.net/2015/09/09/the-two-faces-of-jsrt-in-windows-10/ -------------------------------------------------------------------------------- /test/SharedFiles/recursiveEvaluation/noError/index.js: -------------------------------------------------------------------------------- 1 | /*global require */ 2 | (function () { 3 | 'use strict'; 4 | 5 | function calculateResult() { 6 | var math = require('./math'), 7 | result = math.sum(math.cube(5), math.square(2), math.PI) 8 | ; 9 | 10 | return result; 11 | } 12 | 13 | var exports = { 14 | calculateResult: calculateResult 15 | }; 16 | 17 | return exports; 18 | }()); -------------------------------------------------------------------------------- /test/SharedFiles/recursiveEvaluation/noError/math.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 'use strict'; 3 | 4 | function sum() { 5 | var result = 0, 6 | i 7 | ; 8 | 9 | for (i = 0; i < arguments.length; i++) { 10 | result += arguments[i]; 11 | } 12 | 13 | return result; 14 | } 15 | 16 | function square(num) { 17 | return num * num; 18 | } 19 | 20 | function cube(num) { 21 | return num * num * num; 22 | } 23 | 24 | var exports = { 25 | PI: 3.14, 26 | sum: sum, 27 | square: square, 28 | cube: cube 29 | }; 30 | 31 | return exports; 32 | }()); -------------------------------------------------------------------------------- /test/SharedFiles/recursiveEvaluation/runtimeError/index.js: -------------------------------------------------------------------------------- 1 | /*global require */ 2 | (function () { 3 | 'use strict'; 4 | 5 | function calculateResult() { 6 | var math = require('./math'), 7 | result = math.sum(math.cube(5), math.square(2), math.PI) 8 | ; 9 | 10 | return result; 11 | } 12 | 13 | var exports = { 14 | calculateResult: calculateResult 15 | }; 16 | 17 | return exports; 18 | }()); -------------------------------------------------------------------------------- /test/SharedFiles/recursiveEvaluation/runtimeError/math.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 'use strict'; 3 | 4 | function sum() { 5 | var result = 0, 6 | i 7 | ; 8 | 9 | for (i = 0; i < arguments.length; i++) { 10 | result += argumens[i]; 11 | } 12 | 13 | return result; 14 | } 15 | 16 | function square(num) { 17 | return num * num; 18 | } 19 | 20 | function cube(num) { 21 | return num * num * num; 22 | } 23 | 24 | var exports = { 25 | PI: 3.14, 26 | sum: sum, 27 | square: square, 28 | cube: cube 29 | }; 30 | 31 | return exports; 32 | }()); -------------------------------------------------------------------------------- /test/SharedFiles/recursiveExecution/noError/firstFile.js: -------------------------------------------------------------------------------- 1 | num = num * 3; 2 | executeFile(directoryPath + "/secondFile.js"); -------------------------------------------------------------------------------- /test/SharedFiles/recursiveExecution/noError/mainFile.js: -------------------------------------------------------------------------------- 1 | var num = 5; 2 | executeFile(directoryPath + "/firstFile.js"); -------------------------------------------------------------------------------- /test/SharedFiles/recursiveExecution/noError/secondFile.js: -------------------------------------------------------------------------------- 1 | num -= 3; -------------------------------------------------------------------------------- /test/SharedFiles/square.js: -------------------------------------------------------------------------------- 1 | function square(num) { 2 | return num * num; 3 | } --------------------------------------------------------------------------------