diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 3072dc8a7bb50f..b90b369d1b379c 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -419,7 +419,7 @@ void ContextifyContext::PropertySetterCallback( args.GetReturnValue().Set(false); } - ctx->sandbox()->Set(ctx->context(), property, value).Check(); + USE(ctx->sandbox()->Set(ctx->context(), property, value)); } // static @@ -437,9 +437,10 @@ void ContextifyContext::PropertyDescriptorCallback( Local sandbox = ctx->sandbox(); if (sandbox->HasOwnProperty(context, property).FromMaybe(false)) { - args.GetReturnValue().Set( - sandbox->GetOwnPropertyDescriptor(context, property) - .ToLocalChecked()); + Local desc; + if (sandbox->GetOwnPropertyDescriptor(context, property).ToLocal(&desc)) { + args.GetReturnValue().Set(desc); + } } } @@ -482,8 +483,7 @@ void ContextifyContext::PropertyDefinerCallback( desc_for_sandbox->set_configurable(desc.configurable()); } // Set the property on the sandbox. - sandbox->DefineProperty(context, property, *desc_for_sandbox) - .Check(); + USE(sandbox->DefineProperty(context, property, *desc_for_sandbox)); }; if (desc.has_get() || desc.has_set()) { diff --git a/test/parallel/test-vm-context-property-forwarding.js b/test/parallel/test-vm-context-property-forwarding.js index 800a9fa2438988..53d38c1467a5a2 100644 --- a/test/parallel/test-vm-context-property-forwarding.js +++ b/test/parallel/test-vm-context-property-forwarding.js @@ -43,3 +43,23 @@ assert.deepStrictEqual(pd_actual, pd_expected); assert.strictEqual(ctx2[1], 5); delete ctx2[1]; assert.strictEqual(ctx2[1], undefined); + +// https://github.com/nodejs/node/issues/33806 +{ + const ctx = vm.createContext(); + + Object.defineProperty(ctx, 'prop', { + get() { + return undefined; + }, + set(val) { + throw new Error('test error'); + }, + }); + + assert.throws(() => { + vm.runInContext('prop = 42', ctx); + }, { + message: 'test error', + }); +}