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

[v12.x backport] deps: V8: cherry-pick eec10a2fd8fa and #34008 #34776

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 @@ -34,7 +34,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.42',
'v8_embedder_string': '-node.43',

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

Expand Down
7 changes: 7 additions & 0 deletions deps/v8/src/builtins/builtins-microtask-queue-gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,17 @@ void MicrotaskQueueBuiltinsAssembler::RunSingleMicrotask(
TNode<Object> const thenable = LoadObjectField(
microtask, PromiseResolveThenableJobTask::kThenableOffset);

RunPromiseHook(Runtime::kPromiseHookBefore, microtask_context,
CAST(promise_to_resolve));

TNode<Object> const result =
CallBuiltin(Builtins::kPromiseResolveThenableJob, native_context,
promise_to_resolve, thenable, then);
GotoIfException(result, &if_exception, &var_exception);

RunPromiseHook(Runtime::kPromiseHookAfter, microtask_context,
CAST(promise_to_resolve));

RewindEnteredContext(saved_entered_context_count);
SetCurrentContext(current_context);
Goto(&done);
Expand Down
13 changes: 12 additions & 1 deletion deps/v8/test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16350,7 +16350,18 @@ TEST(PromiseHook) {
CHECK_EQ(v8::Promise::kPending, GetPromise("p")->State());
CompileRun("resolve(Promise.resolve(value));\n");
CHECK_EQ(v8::Promise::kFulfilled, GetPromise("p")->State());
CHECK_EQ(9, promise_hook_data->promise_hook_count);
CHECK_EQ(11, promise_hook_data->promise_hook_count);

promise_hook_data->Reset();
source =
"var p = Promise.resolve({\n"
" then(r) {\n"
" r();\n"
" }\n"
"});";
CompileRun(source);
CHECK_EQ(GetPromise("p")->State(), v8::Promise::kFulfilled);
CHECK_EQ(promise_hook_data->promise_hook_count, 5);

delete promise_hook_data;
isolate->SetPromiseHook(nullptr);
Expand Down
53 changes: 53 additions & 0 deletions test/async-hooks/test-async-local-storage-thenable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

const common = require('../common');

const assert = require('assert');
const { AsyncLocalStorage } = require('async_hooks');

// This test verifies that async local storage works with thenables

const store = new AsyncLocalStorage();
const data = Symbol('verifier');

const then = common.mustCall((cb) => {
assert.strictEqual(store.getStore(), data);
setImmediate(cb);
}, 4);

function thenable() {
return {
then
};
}

// Await a thenable
store.run(data, async () => {
assert.strictEqual(store.getStore(), data);
await thenable();
assert.strictEqual(store.getStore(), data);
});

// Returning a thenable in an async function
store.run(data, async () => {
try {
assert.strictEqual(store.getStore(), data);
return thenable();
} finally {
assert.strictEqual(store.getStore(), data);
}
});

// Resolving a thenable
store.run(data, () => {
assert.strictEqual(store.getStore(), data);
Promise.resolve(thenable());
assert.strictEqual(store.getStore(), data);
});

// Returning a thenable in a then handler
store.run(data, () => {
assert.strictEqual(store.getStore(), data);
Promise.resolve().then(() => thenable());
assert.strictEqual(store.getStore(), data);
});