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

vm: allow proxy callbacks to throw #33808

Merged
merged 1 commit into from
Jun 11, 2020
Merged
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
12 changes: 6 additions & 6 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,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
Expand All @@ -440,9 +440,10 @@ void ContextifyContext::PropertyDescriptorCallback(
Local<Object> sandbox = ctx->sandbox();

if (sandbox->HasOwnProperty(context, property).FromMaybe(false)) {
args.GetReturnValue().Set(
sandbox->GetOwnPropertyDescriptor(context, property)
.ToLocalChecked());
Local<Value> desc;
if (sandbox->GetOwnPropertyDescriptor(context, property).ToLocal(&desc)) {
args.GetReturnValue().Set(desc);
}
}
}

Expand Down Expand Up @@ -485,8 +486,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()) {
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-vm-context-property-forwarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
}