From 0de5f2db879d36b05f44b08b534b31d550c5c6de Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Fri, 19 Dec 2025 06:12:36 +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 7185756..225292e 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 0089f72..8b28c1f 100644 --- a/Source/Noesis.Javascript/JavascriptContext.cpp +++ b/Source/Noesis.Javascript/JavascriptContext.cpp @@ -577,7 +577,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 48557b99c685a24314e492c235978e32d541f3c7 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 a3304ec..b801171 100644 --- a/Fiddling/Fiddling.csproj +++ b/Fiddling/Fiddling.csproj @@ -27,6 +27,6 @@ - + \ No newline at end of file diff --git a/Source/Noesis.Javascript/JavaScript.Net.vcxproj b/Source/Noesis.Javascript/JavaScript.Net.vcxproj index 225292e..220d23a 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 8b28c1f..9a23ac0 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)). @@ -232,6 +232,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()); } @@ -557,6 +559,11 @@ System::String^ JavascriptContext::V8Version::get() return gcnew System::String(v8::V8::GetVersion()); } +bool JavascriptContext::IsV8Initialized::get() +{ + return initialized; +} + //////////////////////////////////////////////////////////////////////////////////////////////////// Local