mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
d7994db70c
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>
32 lines
980 B
JavaScript
32 lines
980 B
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
var assert = require('assert');
|
|
var vm = require('vm');
|
|
|
|
// src/node_contextify.cc filters out the Proxy object from the parent
|
|
// context. Make sure that the new context has a Proxy object of its own.
|
|
var sandbox = {};
|
|
vm.runInNewContext('this.Proxy = Proxy', sandbox);
|
|
assert.strictEqual(typeof sandbox.Proxy, 'function');
|
|
assert.notStrictEqual(sandbox.Proxy, Proxy);
|
|
|
|
// Unless we copy the Proxy object explicitly, of course.
|
|
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/);
|