Skip to content

Commit 879c932

Browse files
devsnekcodebytere
authored andcommitted
vm: allow proxy callbacks to throw
Fixes: #33806 PR-URL: #33808 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent fdaf0ca commit 879c932

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/node_contextify.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void ContextifyContext::PropertySetterCallback(
422422
args.GetReturnValue().Set(false);
423423
}
424424

425-
ctx->sandbox()->Set(ctx->context(), property, value).Check();
425+
USE(ctx->sandbox()->Set(ctx->context(), property, value));
426426
}
427427

428428
// static
@@ -440,9 +440,10 @@ void ContextifyContext::PropertyDescriptorCallback(
440440
Local<Object> sandbox = ctx->sandbox();
441441

442442
if (sandbox->HasOwnProperty(context, property).FromMaybe(false)) {
443-
args.GetReturnValue().Set(
444-
sandbox->GetOwnPropertyDescriptor(context, property)
445-
.ToLocalChecked());
443+
Local<Value> desc;
444+
if (sandbox->GetOwnPropertyDescriptor(context, property).ToLocal(&desc)) {
445+
args.GetReturnValue().Set(desc);
446+
}
446447
}
447448
}
448449

@@ -485,8 +486,7 @@ void ContextifyContext::PropertyDefinerCallback(
485486
desc_for_sandbox->set_configurable(desc.configurable());
486487
}
487488
// Set the property on the sandbox.
488-
sandbox->DefineProperty(context, property, *desc_for_sandbox)
489-
.Check();
489+
USE(sandbox->DefineProperty(context, property, *desc_for_sandbox));
490490
};
491491

492492
if (desc.has_get() || desc.has_set()) {

test/parallel/test-vm-context-property-forwarding.js

+20
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,23 @@ assert.deepStrictEqual(pd_actual, pd_expected);
4343
assert.strictEqual(ctx2[1], 5);
4444
delete ctx2[1];
4545
assert.strictEqual(ctx2[1], undefined);
46+
47+
// https://github.com/nodejs/node/issues/33806
48+
{
49+
const ctx = vm.createContext();
50+
51+
Object.defineProperty(ctx, 'prop', {
52+
get() {
53+
return undefined;
54+
},
55+
set(val) {
56+
throw new Error('test error');
57+
},
58+
});
59+
60+
assert.throws(() => {
61+
vm.runInContext('prop = 42', ctx);
62+
}, {
63+
message: 'test error',
64+
});
65+
}

0 commit comments

Comments
 (0)