Skip to content

Commit 78d5c35

Browse files
committed
src: run the method getter in the saved frame
Signed-off-by: Nigro Simone <nigro.simone@gmail.com>
1 parent 1212c0d commit 78d5c35

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

‎src/api/async_resource.cc‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ MaybeLocal<Value> AsyncResource::MakeCallback(Local<String> symbol,
6868
// Check can_call_into_js() first because calling Get() might do so.
6969
if (!env_->can_call_into_js()) return {};
7070
Local<Value> callback;
71-
if (!get_resource()
72-
->Get(isolate->GetCurrentContext(), symbol)
73-
.ToLocal(&callback)) {
74-
return {};
71+
{
72+
// A getter runs in the saved frame too, so what it enters stays there.
73+
async_context_frame::Scope async_context_frame_scope(
74+
isolate, context_frame_.Get(isolate));
75+
if (!get_resource()
76+
->Get(isolate->GetCurrentContext(), symbol)
77+
.ToLocal(&callback)) {
78+
return {};
79+
}
7580
}
7681
if (!callback->IsFunction()) return Undefined(isolate);
7782
return MakeCallback(callback.As<Function>(), argc, argv);

‎test/addons/async-resource/test-async-local-storage.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,25 @@ binding.callViaFunction(resource);
2020
binding.callViaString(resource);
2121
binding.callViaUtf8Name(resource);
2222
binding.destroyAsyncResource(resource);
23+
24+
// A getter of the method runs in that frame too, and what it enters stays
25+
// there.
26+
{
27+
let getterStore;
28+
const object = Object.defineProperty({}, 'methöd', {
29+
get: common.mustCall(() => {
30+
getterStore = als.getStore();
31+
als.enterWith('getter');
32+
return common.mustCall();
33+
}),
34+
});
35+
const resource =
36+
als.run('resource', () => binding.createAsyncResource(object));
37+
let callerStore;
38+
als.run('caller', () => {
39+
binding.callViaString(resource);
40+
callerStore = als.getStore();
41+
});
42+
binding.destroyAsyncResource(resource);
43+
assert.deepStrictEqual([getterStore, callerStore], ['resource', 'caller']);
44+
}

0 commit comments

Comments
 (0)