-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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: #57168 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
- Loading branch information
1 parent
a025d7b
commit ef314dc
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); |