1'use strict'; 2require('../common'); 3const assert = require('assert'); 4const vm = require('vm'); 5 6// This, admittedly contrived, example tests an edge cases of the vm module. 7// 8// The GetterCallback explicitly checks the global_proxy() if a property is 9// not found on the sandbox. In the following test, the explicit check 10// inside the callback yields different results than deferring the 11// check until after the callback. The check is deferred if the 12// callback does not intercept, i.e., if args.GetReturnValue().Set() is 13// not called. 14 15// Check that the GetterCallback explicitly calls GetRealNamedProperty() 16// on the global proxy if the property is not found on the sandbox. 17// 18// foo is not defined on the sandbox until we call CopyProperties(). 19// In the GetterCallback, we do not find the property on the sandbox and 20// get the property from the global proxy. Since the return value is 21// the sandbox, we replace it by 22// the global_proxy to keep the correct identities. 23// 24// This test case is partially inspired by 25// https://github.com/nodejs/node/issues/855 26const sandbox = { console }; 27sandbox.document = { defaultView: sandbox }; 28vm.createContext(sandbox); 29const code = `Object.defineProperty( 30 this, 31 'foo', 32 { get: function() {return document.defaultView} } 33 ); 34 var result = foo === this;`; 35 36vm.runInContext(code, sandbox); 37assert.strictEqual(sandbox.result, true); 38