-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm: enhance cached data handling for empty functions and add validati…
…on tests
- Loading branch information
Showing
2 changed files
with
42 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const vm = require('vm'); | ||
|
||
// Test that creating cached data for an empty function doesn't crash | ||
{ | ||
const script = new vm.Script(''); | ||
// Get cached data from empty script | ||
const cachedData = script.createCachedData(); | ||
|
||
// Attempt to compile a function using this cached data | ||
// This was previously causing a fatal V8 error | ||
assert.doesNotThrow(() => { | ||
vm.compileFunction('', undefined, { | ||
cachedData, | ||
produceCachedData: true | ||
}); | ||
}, 'Should not crash when compiling empty function with cached data'); | ||
} | ||
|
||
// Test normal case with actual function content still works | ||
{ | ||
const script = new vm.Script('function test() { return 42; }'); | ||
const cachedData = script.createCachedData(); | ||
|
||
const fn = vm.compileFunction('return 42', undefined, { | ||
cachedData, | ||
produceCachedData: true | ||
}); | ||
|
||
assert.strictEqual(fn(), 42, 'Function should compile and run correctly'); | ||
} |