From 327838dd9670d9f3a19eb0d804dfb8929d6985b4 Mon Sep 17 00:00:00 2001 From: Stephen Belanger Date: Thu, 26 Aug 2021 11:45:03 +0200 Subject: [PATCH] deps: V8: backport c9224589cf53 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [PATCH] Reland "[d8] Add d8 global variable" This is a reland of 6798619a69dfe3e244f85b83c4a327d94d426b32 Original change's description: > [d8] Add d8 global variable > > - Add a a "d8" global variable where d8 can provide helpers. > This in in preparation of adding d8.log for testing our log parsers > written in JavaScript. > > - Separate d8 helper creation into individual functions. > > Bug: v8:10668 > Change-Id: I84e434452463afb93ae403f890d8841b20b00703 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2400990 > Reviewed-by: Toon Verwaest > Commit-Queue: Camillo Bruni > Cr-Commit-Position: refs/heads/master@{#69801} Tbr: verwaest@chromium.org Bug: v8:10668 Change-Id: If3256ec4e11f01ef1dc5c2e61fa33ed6d7a6aee3 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2409274 Reviewed-by: Camillo Bruni Commit-Queue: Camillo Bruni Cr-Commit-Position: refs/heads/master@{#69867} Refs: https://github.com/v8/v8/commit/c9224589cf538d722ee1adccf378bbacef80eccc PR-URL: https://github.com/nodejs/node/pull/39743 Reviewed-By: Tobias Nießen Reviewed-By: Anna Henningsen Reviewed-By: Franziska Hinkelmann Reviewed-By: Gerhard Stöbich Reviewed-By: Michaël Zasso --- common.gypi | 2 +- deps/v8/src/d8/d8.cc | 158 +++++++++++++++++++++++++------------------ deps/v8/src/d8/d8.h | 10 +++ 3 files changed, 105 insertions(+), 65 deletions(-) diff --git a/common.gypi b/common.gypi index c00b283306c291..24bcd90a248498 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.82', + 'v8_embedder_string': '-node.83', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/d8/d8.cc b/deps/v8/src/d8/d8.cc index 523b30666353f0..a6c55be0523f8a 100644 --- a/deps/v8/src/d8/d8.cc +++ b/deps/v8/src/d8/d8.cc @@ -1877,6 +1877,11 @@ Local Shell::Stringify(Isolate* isolate, Local value) { Local Shell::CreateGlobalTemplate(Isolate* isolate) { Local global_template = ObjectTemplate::New(isolate); + global_template->Set(Symbol::GetToStringTag(isolate), + String::NewFromUtf8Literal(isolate, "global")); + global_template->Set(isolate, "version", + FunctionTemplate::New(isolate, Version)); + global_template->Set(isolate, "print", FunctionTemplate::New(isolate, Print)); global_template->Set(isolate, "printErr", FunctionTemplate::New(isolate, PrintErr)); @@ -1895,8 +1900,77 @@ Local Shell::CreateGlobalTemplate(Isolate* isolate) { if (!options.omit_quit) { global_template->Set(isolate, "quit", FunctionTemplate::New(isolate, Quit)); } + global_template->Set(isolate, "testRunner", + Shell::CreateTestRunnerTemplate(isolate)); + global_template->Set(isolate, "Realm", Shell::CreateRealmTemplate(isolate)); + global_template->Set(isolate, "performance", + Shell::CreatePerformanceTemplate(isolate)); + global_template->Set(isolate, "Worker", Shell::CreateWorkerTemplate(isolate)); + global_template->Set(isolate, "os", Shell::CreateOSTemplate(isolate)); + global_template->Set(isolate, "d8", Shell::CreateD8Template(isolate)); + + if (i::FLAG_expose_async_hooks) { + global_template->Set(isolate, "async_hooks", + Shell::CreateAsyncHookTemplate(isolate)); + } + + return global_template; +} + +Local Shell::CreateOSTemplate(Isolate* isolate) { + Local os_template = ObjectTemplate::New(isolate); + AddOSMethods(isolate, os_template); + return os_template; +} + +Local Shell::CreateWorkerTemplate(Isolate* isolate) { + Local worker_fun_template = + FunctionTemplate::New(isolate, WorkerNew); + Local worker_signature = + Signature::New(isolate, worker_fun_template); + worker_fun_template->SetClassName( + String::NewFromUtf8Literal(isolate, "Worker")); + worker_fun_template->ReadOnlyPrototype(); + worker_fun_template->PrototypeTemplate()->Set( + isolate, "terminate", + FunctionTemplate::New(isolate, WorkerTerminate, Local(), + worker_signature)); + worker_fun_template->PrototypeTemplate()->Set( + isolate, "postMessage", + FunctionTemplate::New(isolate, WorkerPostMessage, Local(), + worker_signature)); + worker_fun_template->PrototypeTemplate()->Set( + isolate, "getMessage", + FunctionTemplate::New(isolate, WorkerGetMessage, Local(), + worker_signature)); + worker_fun_template->InstanceTemplate()->SetInternalFieldCount(1); + return worker_fun_template; +} + +Local Shell::CreateAsyncHookTemplate(Isolate* isolate) { + Local async_hooks_templ = ObjectTemplate::New(isolate); + async_hooks_templ->Set(isolate, "createHook", + FunctionTemplate::New(isolate, AsyncHooksCreateHook)); + async_hooks_templ->Set( + isolate, "executionAsyncId", + FunctionTemplate::New(isolate, AsyncHooksExecutionAsyncId)); + async_hooks_templ->Set( + isolate, "triggerAsyncId", + FunctionTemplate::New(isolate, AsyncHooksTriggerAsyncId)); + return async_hooks_templ; +} + +Local Shell::CreatePromiseHookTemplate(Isolate* isolate) { + Local promise_hooks_templ = ObjectTemplate::New(isolate); + promise_hooks_templ->Set( + isolate, "setHooks", + FunctionTemplate::New(isolate, SetPromiseHooks, Local(), + Local(), 4)); + return promise_hooks_templ; +} + +Local Shell::CreateTestRunnerTemplate(Isolate* isolate) { Local test_template = ObjectTemplate::New(isolate); - global_template->Set(isolate, "testRunner", test_template); test_template->Set(isolate, "notifyDone", FunctionTemplate::New(isolate, NotifyDone)); test_template->Set(isolate, "waitUntilDone", @@ -1905,13 +1979,20 @@ Local Shell::CreateGlobalTemplate(Isolate* isolate) { // installed on the global object can be hidden with the --omit-quit flag // (e.g. on asan bots). test_template->Set(isolate, "quit", FunctionTemplate::New(isolate, Quit)); + return test_template; +} - global_template->Set(isolate, "version", - FunctionTemplate::New(isolate, Version)); - global_template->Set(Symbol::GetToStringTag(isolate), - String::NewFromUtf8Literal(isolate, "global")); +Local Shell::CreatePerformanceTemplate(Isolate* isolate) { + Local performance_template = ObjectTemplate::New(isolate); + performance_template->Set(isolate, "now", + FunctionTemplate::New(isolate, PerformanceNow)); + performance_template->Set( + isolate, "measureMemory", + FunctionTemplate::New(isolate, PerformanceMeasureMemory)); + return performance_template; +} - // Bind the Realm object. +Local Shell::CreateRealmTemplate(Isolate* isolate) { Local realm_template = ObjectTemplate::New(isolate); realm_template->Set(isolate, "current", FunctionTemplate::New(isolate, RealmCurrent)); @@ -1936,64 +2017,13 @@ Local Shell::CreateGlobalTemplate(Isolate* isolate) { FunctionTemplate::New(isolate, RealmEval)); realm_template->SetAccessor(String::NewFromUtf8Literal(isolate, "shared"), RealmSharedGet, RealmSharedSet); - global_template->Set(isolate, "Realm", realm_template); - - Local performance_template = ObjectTemplate::New(isolate); - performance_template->Set(isolate, "now", - FunctionTemplate::New(isolate, PerformanceNow)); - performance_template->Set( - isolate, "measureMemory", - FunctionTemplate::New(isolate, PerformanceMeasureMemory)); - global_template->Set(isolate, "performance", performance_template); - - Local worker_fun_template = - FunctionTemplate::New(isolate, WorkerNew); - Local worker_signature = - Signature::New(isolate, worker_fun_template); - worker_fun_template->SetClassName( - String::NewFromUtf8Literal(isolate, "Worker")); - worker_fun_template->ReadOnlyPrototype(); - worker_fun_template->PrototypeTemplate()->Set( - isolate, "terminate", - FunctionTemplate::New(isolate, WorkerTerminate, Local(), - worker_signature)); - worker_fun_template->PrototypeTemplate()->Set( - isolate, "postMessage", - FunctionTemplate::New(isolate, WorkerPostMessage, Local(), - worker_signature)); - worker_fun_template->PrototypeTemplate()->Set( - isolate, "getMessage", - FunctionTemplate::New(isolate, WorkerGetMessage, Local(), - worker_signature)); - worker_fun_template->InstanceTemplate()->SetInternalFieldCount(1); - global_template->Set(isolate, "Worker", worker_fun_template); - - Local os_templ = ObjectTemplate::New(isolate); - AddOSMethods(isolate, os_templ); - global_template->Set(isolate, "os", os_templ); - - if (i::FLAG_expose_async_hooks) { - Local async_hooks_templ = ObjectTemplate::New(isolate); - async_hooks_templ->Set( - isolate, "createHook", - FunctionTemplate::New(isolate, AsyncHooksCreateHook)); - async_hooks_templ->Set( - isolate, "executionAsyncId", - FunctionTemplate::New(isolate, AsyncHooksExecutionAsyncId)); - async_hooks_templ->Set( - isolate, "triggerAsyncId", - FunctionTemplate::New(isolate, AsyncHooksTriggerAsyncId)); - global_template->Set(isolate, "async_hooks", async_hooks_templ); - } - { - Local promise_template = ObjectTemplate::New(isolate); - promise_template->Set( - isolate, "setHooks", - FunctionTemplate::New(isolate, SetPromiseHooks, Local(), - Local(), 4)); - global_template->Set(isolate, "promise", promise_template); - } - return global_template; + return realm_template; +} +Local Shell::CreateD8Template(Isolate* isolate) { + Local d8_template = ObjectTemplate::New(isolate); + d8_template->Set(isolate, "promise", + Shell::CreatePromiseHookTemplate(isolate)); + return d8_template; } static void PrintMessageCallback(Local message, Local error) { diff --git a/deps/v8/src/d8/d8.h b/deps/v8/src/d8/d8.h index b4fbde5a9d6449..069115525d4815 100644 --- a/deps/v8/src/d8/d8.h +++ b/deps/v8/src/d8/d8.h @@ -492,7 +492,17 @@ class Shell : public i::AllStatic { static Local Stringify(Isolate* isolate, Local value); static void RunShell(Isolate* isolate); static bool SetOptions(int argc, char* argv[]); + static Local CreateGlobalTemplate(Isolate* isolate); + static Local CreateOSTemplate(Isolate* isolate); + static Local CreateWorkerTemplate(Isolate* isolate); + static Local CreateAsyncHookTemplate(Isolate* isolate); + static Local CreatePromiseHookTemplate(Isolate* isolate); + static Local CreateTestRunnerTemplate(Isolate* isolate); + static Local CreatePerformanceTemplate(Isolate* isolate); + static Local CreateRealmTemplate(Isolate* isolate); + static Local CreateD8Template(Isolate* isolate); + static MaybeLocal CreateRealm( const v8::FunctionCallbackInfo& args, int index, v8::MaybeLocal global_object);