mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 22:40:57 +00:00

V8 should invoke native functions in their creation context, preventing dynamic context by the caller. However, the lazy getter has no JavaScript function representation and has no creation context. It is not invoked in the original creation context. Fix the null realm by retrieving the creation context via `this` argument. PR-URL: https://github.com/nodejs/node/pull/57168 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
27 lines
736 B
JavaScript
27 lines
736 B
JavaScript
'use strict';
|
|
require('../common');
|
|
|
|
const vm = require('node:vm');
|
|
const util = require('node:util');
|
|
const assert = require('node:assert');
|
|
|
|
// This verifies that invoking property getters defined with
|
|
// `require('internal/util').defineLazyProperties` does not crash
|
|
// the process.
|
|
|
|
const ctx = vm.createContext();
|
|
const getter = vm.runInContext(`
|
|
function getter(object, property) {
|
|
return object[property];
|
|
}
|
|
getter;
|
|
`, ctx);
|
|
|
|
// `util.parseArgs` is a lazy property.
|
|
const parseArgs = getter(util, 'parseArgs');
|
|
assert.strictEqual(parseArgs, util.parseArgs);
|
|
|
|
// `globalThis.TextEncoder` is a lazy property.
|
|
const TextEncoder = getter(globalThis, 'TextEncoder');
|
|
assert.strictEqual(TextEncoder, globalThis.TextEncoder);
|