Skip to content

Commit

Permalink
deps: V8: cherry-pick 81814ed44574
Browse files Browse the repository at this point in the history
Original commit message:

    [promise] Avoid stack overflow with context promise hooks in C++

    This was handled in JS but not in C++.

    Bug: chromium:236703, v8:11025
    Change-Id: Ic9adc4ceb4d2af2614427fec459c3e950654572f
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3074460
    Commit-Queue: Camillo Bruni <cbruni@chromium.org>
    Reviewed-by: Victor Gomes <victorgomes@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#76125}

Refs: v8/v8@81814ed

PR-URL: #39719
Backport-PR-URL: #39743
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
Stephen Belanger authored and targos committed Aug 29, 2021
1 parent c41466f commit 66288b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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
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();
});

0 comments on commit 66288b8

Please sign in to comment.