From 9824bbb4fbc90e24962b3fed5cec8339dabe31c0 Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Tue, 7 Mar 2023 08:58:28 +0100 Subject: [PATCH 1/4] Update V8 to 10.0.139.9 --- .../Noesis.Javascript/JavaScript.Net.vcxproj | 18 +++++++++--------- Source/Noesis.Javascript/JavascriptContext.cpp | 2 +- Source/Noesis.Javascript/packages.config | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/Noesis.Javascript/JavaScript.Net.vcxproj b/Source/Noesis.Javascript/JavaScript.Net.vcxproj index 196e601..527d153 100644 --- a/Source/Noesis.Javascript/JavaScript.Net.vcxproj +++ b/Source/Noesis.Javascript/JavaScript.Net.vcxproj @@ -1,9 +1,9 @@ - - - - + + + + Debug @@ -28,7 +28,7 @@ v4.7.2 ManagedCProj JavaScriptNet - 10.0.18362.0 + 10.0 @@ -183,9 +183,9 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - + + + + \ No newline at end of file diff --git a/Source/Noesis.Javascript/JavascriptContext.cpp b/Source/Noesis.Javascript/JavascriptContext.cpp index 61cb676..126bd18 100644 --- a/Source/Noesis.Javascript/JavascriptContext.cpp +++ b/Source/Noesis.Javascript/JavascriptContext.cpp @@ -558,7 +558,7 @@ CompileScript(v8::Isolate *isolate, wchar_t const *source_code, wchar_t const *r else { Local resource = String::NewFromTwoByte(isolate, (uint16_t const *)resource_name, v8::NewStringType::kNormal).ToLocalChecked(); - ScriptOrigin *origin = new ScriptOrigin(resource); + ScriptOrigin *origin = new ScriptOrigin(isolate, resource); script = Script::Compile(JavascriptContext::GetCurrentIsolate()->GetCurrentContext(), source, origin); } diff --git a/Source/Noesis.Javascript/packages.config b/Source/Noesis.Javascript/packages.config index eea5068..0be2bcb 100644 --- a/Source/Noesis.Javascript/packages.config +++ b/Source/Noesis.Javascript/packages.config @@ -1,7 +1,7 @@  - - - - + + + + \ No newline at end of file From 616850c71bb8075057360c35e579fe0439888bf6 Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Wed, 25 Oct 2023 11:54:50 +0200 Subject: [PATCH 2/4] Update V8 to 11.9.169.4 - adapts library names of third party libs (certain libs like zlib are now prefixed by third_party_) - removes static ctor of JavascriptContext - after unmanaged init engine flags cannot be set - move unmanaged init to normal ctor so users can call JavascriptContext.SetFlags - throw exception in SetFlags method if unmanaged init has already happened - alter flag test - since we can only set flags once remove the --strict flag test as it would require a lot of test changes - set --stack-size in a global test init method instead of --strict which also improves test reliability when run in a command line setting (e.g. build server) - add test that verifies an exception is thrown when flags are set after initialization - adds new property to get a process global boolean if the unmanaged initialization of V8 has already been done Certain operations like setting engine flags are only allowed before the V8 platform is initialized. Since managed C# code does not have support for real process global state (static globals are always local to an app domain), you can't really determine and persist the initialization state in calling code. The new property passes through the unmanaged real process global initialization state of V8 instead to mitigate that. --- Fiddling/Fiddling.csproj | 2 +- .../Noesis.Javascript/JavaScript.Net.vcxproj | 16 +++++++------- .../Noesis.Javascript/JavascriptContext.cpp | 17 +++++++++----- Source/Noesis.Javascript/JavascriptContext.h | 8 +++++-- Source/Noesis.Javascript/packages.config | 8 +++---- Tests/Noesis.Javascript.Tests/FlagsTest.cs | 22 ++++++++++++------- .../Noesis.Javascript.Tests.csproj | 2 +- 7 files changed, 46 insertions(+), 29 deletions(-) diff --git a/Fiddling/Fiddling.csproj b/Fiddling/Fiddling.csproj index 10a5ccc..45fd980 100644 --- a/Fiddling/Fiddling.csproj +++ b/Fiddling/Fiddling.csproj @@ -85,7 +85,7 @@ copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\v8.dll $(ProjectDir)$(OutDir) copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\v8_libbase.dll $(ProjectDir)$(OutDir) copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\v8_libplatform.dll $(ProjectDir)$(OutDir) -copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\zlib.dll $(ProjectDir)$(OutDir) +copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\third_party_*.dll $(ProjectDir)$(OutDir) copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\icu*.* $(ProjectDir)$(OutDir) diff --git a/Source/Noesis.Javascript/JavaScript.Net.vcxproj b/Source/Noesis.Javascript/JavaScript.Net.vcxproj index 527d153..67edff0 100644 --- a/Source/Noesis.Javascript/JavaScript.Net.vcxproj +++ b/Source/Noesis.Javascript/JavaScript.Net.vcxproj @@ -1,9 +1,9 @@ - - - - + + + + Debug @@ -183,9 +183,9 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - + + + + \ No newline at end of file diff --git a/Source/Noesis.Javascript/JavascriptContext.cpp b/Source/Noesis.Javascript/JavascriptContext.cpp index 126bd18..e3befcb 100644 --- a/Source/Noesis.Javascript/JavascriptContext.cpp +++ b/Source/Noesis.Javascript/JavascriptContext.cpp @@ -118,11 +118,6 @@ v8::Local ToV8String(Isolate* isolate, System::String^ value) { return String::NewFromTwoByte(isolate, (uint16_t*)name, v8::NewStringType::kNormal).ToLocalChecked(); } -static JavascriptContext::JavascriptContext() -{ - UnmanagedInitialisation(); -} - //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -151,6 +146,11 @@ void JavascriptContext::FatalErrorCallbackMember(const char* location, const cha JavascriptContext::JavascriptContext() { + // Certain static operations like setting flags cannot be performed after V8 has been initialized. Since we allow setting flags by + // a static method we can't do the unmanaged initialization in the static constructor, because that would always run before any other + // static method. Instead we call it here. The internal checks in UnmanagedInitialisation make this thread safe. + UnmanagedInitialisation(); + // Unfortunately the fatal error handler is not installed early enough to catch // out-of-memory errors while creating new isolates // (see my post Catching V8::FatalProcessOutOfMemory while creating an isolate (SetFatalErrorHandler does not work)). @@ -213,6 +213,8 @@ void JavascriptContext::SetFatalErrorHandler(FatalErrorHandler^ handler) void JavascriptContext::SetFlags(System::String^ flags) { + if (initialized) + throw gcnew System::InvalidOperationException("Flags can only be set once before the first context and therefore V8 is initialized."); std::string convertedFlags = msclr::interop::marshal_as(flags); v8::V8::SetFlagsFromString(convertedFlags.c_str(), (int)convertedFlags.length()); } @@ -538,6 +540,11 @@ System::String^ JavascriptContext::V8Version::get() return gcnew System::String(v8::V8::GetVersion()); } +bool JavascriptContext::IsV8Initialized::get() +{ + return initialized; +} + //////////////////////////////////////////////////////////////////////////////////////////////////// Local