forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: fix crash when lazy getter is invoked in a vm context
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: nodejs#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>
- Loading branch information
1 parent
ba66c3f
commit 1930ad1
Showing
3 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'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); |