From 01189f96f387ba6a9e1e927b277e867c8c5d9100 Mon Sep 17 00:00:00 2001 From: Alex Doe Date: Thu, 26 May 2022 21:59:45 -0500 Subject: [PATCH 1/3] [Experimental] Fixes promises evaluation --- src/Context.cpp | 24 ++++++++++++++++++++++-- src/Platform.h | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index 89bf0606..b54c6c36 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -199,7 +199,17 @@ py::object CContext::Evaluate(const std::string& src, CScriptPtr script = engine.Compile(src, name, line, col); - return script->Run(); + boost::python::api::object result = script->Run(); + + while (v8::platform::PumpMessageLoop( + CPlatform::platform.get(), + v8::Isolate::GetCurrent(), + v8::platform::MessageLoopBehavior::kDoNotWait + )) { + v8::Isolate::GetCurrent()->PerformMicrotaskCheckpoint(); + } + + return result; } py::object CContext::EvaluateW(const std::wstring& src, @@ -210,5 +220,15 @@ py::object CContext::EvaluateW(const std::wstring& src, CScriptPtr script = engine.CompileW(src, name, line, col); - return script->Run(); + boost::python::api::object result = script->Run(); + + while (v8::platform::PumpMessageLoop( + CPlatform::platform.get(), + v8::Isolate::GetCurrent(), + v8::platform::MessageLoopBehavior::kDoNotWait + )) { + v8::Isolate::GetCurrent()->PerformMicrotaskCheckpoint(); + } + + return result; } diff --git a/src/Platform.h b/src/Platform.h index ecdc1a38..60818505 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -10,7 +10,6 @@ class CPlatform { private: static bool inited; - static std::unique_ptr platform; constexpr static const char *icu_data = ICU_DATA; const char *GetICUDataFile() @@ -29,4 +28,5 @@ class CPlatform CPlatform(std::string argv0) : argv(argv0) {}; ~CPlatform() {}; void Init(); + static std::unique_ptr platform; }; From 956731dd899d5a44a3fe7df77c813584c7d03fc9 Mon Sep 17 00:00:00 2001 From: Alex Doe Date: Thu, 26 May 2022 22:08:57 -0500 Subject: [PATCH 2/3] Fixes indents --- setup.py | 1 + src/Context.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index b256a769..49ad7cb8 100644 --- a/setup.py +++ b/setup.py @@ -205,6 +205,7 @@ def run(self): "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", ], cmdclass = dict( build = stpyv8_build, diff --git a/src/Context.cpp b/src/Context.cpp index b54c6c36..b9ee0135 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -223,9 +223,9 @@ py::object CContext::EvaluateW(const std::wstring& src, boost::python::api::object result = script->Run(); while (v8::platform::PumpMessageLoop( - CPlatform::platform.get(), - v8::Isolate::GetCurrent(), - v8::platform::MessageLoopBehavior::kDoNotWait + CPlatform::platform.get(), + v8::Isolate::GetCurrent(), + v8::platform::MessageLoopBehavior::kDoNotWait )) { v8::Isolate::GetCurrent()->PerformMicrotaskCheckpoint(); } From caa3025b7b7b2f2b9aa866ac057f8c257be12a36 Mon Sep 17 00:00:00 2001 From: Alex Doe Date: Thu, 26 May 2022 22:19:34 -0500 Subject: [PATCH 3/3] Makes the platform handle private --- setup.py | 1 - src/Context.cpp | 4 ++-- src/Platform.cpp | 5 +++++ src/Platform.h | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 49ad7cb8..b256a769 100644 --- a/setup.py +++ b/setup.py @@ -205,7 +205,6 @@ def run(self): "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", ], cmdclass = dict( build = stpyv8_build, diff --git a/src/Context.cpp b/src/Context.cpp index b9ee0135..4686e663 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -202,7 +202,7 @@ py::object CContext::Evaluate(const std::string& src, boost::python::api::object result = script->Run(); while (v8::platform::PumpMessageLoop( - CPlatform::platform.get(), + CPlatform::GetPlatform(), v8::Isolate::GetCurrent(), v8::platform::MessageLoopBehavior::kDoNotWait )) { @@ -223,7 +223,7 @@ py::object CContext::EvaluateW(const std::wstring& src, boost::python::api::object result = script->Run(); while (v8::platform::PumpMessageLoop( - CPlatform::platform.get(), + CPlatform::GetPlatform(), v8::Isolate::GetCurrent(), v8::platform::MessageLoopBehavior::kDoNotWait )) { diff --git a/src/Platform.cpp b/src/Platform.cpp index 844cc605..34c121c5 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -20,3 +20,8 @@ void CPlatform::Init() inited = true; } + +v8::Platform *CPlatform::GetPlatform(void) +{ + return CPlatform::platform.get(); +} diff --git a/src/Platform.h b/src/Platform.h index 60818505..d5cea0c6 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -10,6 +10,7 @@ class CPlatform { private: static bool inited; + static std::unique_ptr platform; constexpr static const char *icu_data = ICU_DATA; const char *GetICUDataFile() @@ -28,5 +29,5 @@ class CPlatform CPlatform(std::string argv0) : argv(argv0) {}; ~CPlatform() {}; void Init(); - static std::unique_ptr platform; + static v8::Platform *GetPlatform(void); };