src: handle thrown errors in CopyProperties()
This commit prevents thrown JavaScript exceptions from crashing the process in node_contextify's CopyProperties() function. Fixes: https://github.com/nodejs/node/issues/8537 PR-URL: https://github.com/nodejs/node/pull/8649 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
d469321946
commit
d7994db70c
@ -125,7 +125,14 @@ class ContextifyContext {
|
||||
int length = names->Length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
Local<String> key = names->Get(i)->ToString(env()->isolate());
|
||||
bool has = sandbox_obj->HasOwnProperty(context, key).FromJust();
|
||||
auto maybe_has = sandbox_obj->HasOwnProperty(context, key);
|
||||
|
||||
// Check for pending exceptions
|
||||
if (!maybe_has.IsJust())
|
||||
break;
|
||||
|
||||
bool has = maybe_has.FromJust();
|
||||
|
||||
if (!has) {
|
||||
// Could also do this like so:
|
||||
//
|
||||
|
@ -16,3 +16,16 @@ sandbox = { Proxy: Proxy };
|
||||
vm.runInNewContext('this.Proxy = Proxy', sandbox);
|
||||
assert.strictEqual(typeof sandbox.Proxy, 'function');
|
||||
assert.strictEqual(sandbox.Proxy, Proxy);
|
||||
|
||||
// Handle a sandbox that throws while copying properties
|
||||
assert.throws(() => {
|
||||
const handler = {
|
||||
getOwnPropertyDescriptor: (target, prop) => {
|
||||
throw new Error('whoops');
|
||||
}
|
||||
};
|
||||
const sandbox = new Proxy({foo: 'bar'}, handler);
|
||||
const context = vm.createContext(sandbox);
|
||||
|
||||
vm.runInContext('', context);
|
||||
}, /whoops/);
|
||||
|
Loading…
x
Reference in New Issue
Block a user