Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v14.x backport] deps: V8: cherry-pick 81814ed44574 #39743

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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.81',
'v8_embedder_string': '-node.82',

##### V8 defaults for Node.js #####

Expand Down
158 changes: 94 additions & 64 deletions deps/v8/src/d8/d8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,11 @@ Local<String> Shell::Stringify(Isolate* isolate, Local<Value> value) {

Local<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
Local<ObjectTemplate> 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));
Expand All @@ -1895,8 +1900,77 @@ Local<ObjectTemplate> 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<ObjectTemplate> Shell::CreateOSTemplate(Isolate* isolate) {
Local<ObjectTemplate> os_template = ObjectTemplate::New(isolate);
AddOSMethods(isolate, os_template);
return os_template;
}

Local<FunctionTemplate> Shell::CreateWorkerTemplate(Isolate* isolate) {
Local<FunctionTemplate> worker_fun_template =
FunctionTemplate::New(isolate, WorkerNew);
Local<Signature> 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<Value>(),
worker_signature));
worker_fun_template->PrototypeTemplate()->Set(
isolate, "postMessage",
FunctionTemplate::New(isolate, WorkerPostMessage, Local<Value>(),
worker_signature));
worker_fun_template->PrototypeTemplate()->Set(
isolate, "getMessage",
FunctionTemplate::New(isolate, WorkerGetMessage, Local<Value>(),
worker_signature));
worker_fun_template->InstanceTemplate()->SetInternalFieldCount(1);
return worker_fun_template;
}

Local<ObjectTemplate> Shell::CreateAsyncHookTemplate(Isolate* isolate) {
Local<ObjectTemplate> 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<ObjectTemplate> Shell::CreatePromiseHookTemplate(Isolate* isolate) {
Local<ObjectTemplate> promise_hooks_templ = ObjectTemplate::New(isolate);
promise_hooks_templ->Set(
isolate, "setHooks",
FunctionTemplate::New(isolate, SetPromiseHooks, Local<Value>(),
Local<Signature>(), 4));
return promise_hooks_templ;
}

Local<ObjectTemplate> Shell::CreateTestRunnerTemplate(Isolate* isolate) {
Local<ObjectTemplate> 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",
Expand All @@ -1905,13 +1979,20 @@ Local<ObjectTemplate> 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<ObjectTemplate> Shell::CreatePerformanceTemplate(Isolate* isolate) {
Local<ObjectTemplate> 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<ObjectTemplate> Shell::CreateRealmTemplate(Isolate* isolate) {
Local<ObjectTemplate> realm_template = ObjectTemplate::New(isolate);
realm_template->Set(isolate, "current",
FunctionTemplate::New(isolate, RealmCurrent));
Expand All @@ -1936,64 +2017,13 @@ Local<ObjectTemplate> 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<ObjectTemplate> 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<FunctionTemplate> worker_fun_template =
FunctionTemplate::New(isolate, WorkerNew);
Local<Signature> 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<Value>(),
worker_signature));
worker_fun_template->PrototypeTemplate()->Set(
isolate, "postMessage",
FunctionTemplate::New(isolate, WorkerPostMessage, Local<Value>(),
worker_signature));
worker_fun_template->PrototypeTemplate()->Set(
isolate, "getMessage",
FunctionTemplate::New(isolate, WorkerGetMessage, Local<Value>(),
worker_signature));
worker_fun_template->InstanceTemplate()->SetInternalFieldCount(1);
global_template->Set(isolate, "Worker", worker_fun_template);

Local<ObjectTemplate> os_templ = ObjectTemplate::New(isolate);
AddOSMethods(isolate, os_templ);
global_template->Set(isolate, "os", os_templ);

if (i::FLAG_expose_async_hooks) {
Local<ObjectTemplate> 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<ObjectTemplate> promise_template = ObjectTemplate::New(isolate);
promise_template->Set(
isolate, "setHooks",
FunctionTemplate::New(isolate, SetPromiseHooks, Local<Value>(),
Local<Signature>(), 4));
global_template->Set(isolate, "promise", promise_template);
}
return global_template;
return realm_template;
}
Local<ObjectTemplate> Shell::CreateD8Template(Isolate* isolate) {
Local<ObjectTemplate> d8_template = ObjectTemplate::New(isolate);
d8_template->Set(isolate, "promise",
Shell::CreatePromiseHookTemplate(isolate));
return d8_template;
}

static void PrintMessageCallback(Local<Message> message, Local<Value> error) {
Expand Down
10 changes: 10 additions & 0 deletions deps/v8/src/d8/d8.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,17 @@ class Shell : public i::AllStatic {
static Local<String> Stringify(Isolate* isolate, Local<Value> value);
static void RunShell(Isolate* isolate);
static bool SetOptions(int argc, char* argv[]);

static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
static Local<ObjectTemplate> CreateOSTemplate(Isolate* isolate);
static Local<FunctionTemplate> CreateWorkerTemplate(Isolate* isolate);
static Local<ObjectTemplate> CreateAsyncHookTemplate(Isolate* isolate);
static Local<ObjectTemplate> CreatePromiseHookTemplate(Isolate* isolate);
static Local<ObjectTemplate> CreateTestRunnerTemplate(Isolate* isolate);
static Local<ObjectTemplate> CreatePerformanceTemplate(Isolate* isolate);
static Local<ObjectTemplate> CreateRealmTemplate(Isolate* isolate);
static Local<ObjectTemplate> CreateD8Template(Isolate* isolate);

static MaybeLocal<Context> CreateRealm(
const v8::FunctionCallbackInfo<v8::Value>& args, int index,
v8::MaybeLocal<Value> global_object);
Expand Down
10 changes: 9 additions & 1 deletion deps/v8/src/objects/contexts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,15 @@ void NativeContext::RunPromiseHook(PromiseHookType type,

Handle<Object> receiver = isolate->global_proxy();

if (Execution::Call(isolate, hook, receiver, argc, argv).is_null()) {
StackLimitCheck check(isolate);
bool failed = false;
if (check.HasOverflowed()) {
isolate->StackOverflow();
failed = true;
} else {
failed = Execution::Call(isolate, hook, receiver, argc, argv).is_null();
}
if (failed) {
DCHECK(isolate->has_pending_exception());
Handle<Object> exception(isolate->pending_exception(), isolate);

Expand Down
8 changes: 8 additions & 0 deletions deps/v8/test/mjsunit/promise-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,11 @@ exceptions();

d8.promise.setHooks();
})();

(function overflow(){
d8.promise.setHooks(() => { new Promise(()=>{}) });
// Trigger overflow from JS code:
Promise.all([Promise.resolve(1)]);
%PerformMicrotaskCheckpoint();
d8.promise.setHooks();
});