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.
vm: use default HDO when importModuleDynamically is not set
This makes it possile to hit the in-isolate compilation cache when host-defined options are not necessary. PR-URL: nodejs#49950 Refs: nodejs#35375 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
- Loading branch information
1 parent
fc003be
commit d183187
Showing
6 changed files
with
81 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
// This benchmarks compiling scripts that hit the in-isolate compilation | ||
// cache (by having the same source). | ||
const common = require('../common.js'); | ||
const fs = require('fs'); | ||
const vm = require('vm'); | ||
const fixtures = require('../../test/common/fixtures.js'); | ||
const scriptPath = fixtures.path('snapshot', 'typescript.js'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: ['with-dynamic-import-callback', 'without-dynamic-import-callback'], | ||
n: [100], | ||
}); | ||
|
||
const scriptSource = fs.readFileSync(scriptPath, 'utf8'); | ||
|
||
function main({ n, type }) { | ||
let script; | ||
bench.start(); | ||
const options = {}; | ||
switch (type) { | ||
case 'with-dynamic-import-callback': | ||
// Use a dummy callback for now until we really need to benchmark it. | ||
options.importModuleDynamically = async () => {}; | ||
break; | ||
case 'without-dynamic-import-callback': | ||
break; | ||
} | ||
for (let i = 0; i < n; i++) { | ||
script = new vm.Script(scriptSource, options); | ||
} | ||
bench.end(n); | ||
script.runInThisContext(); | ||
} |
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
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,13 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const { Script } = require('vm'); | ||
const assert = require('assert'); | ||
|
||
assert.rejects(async () => { | ||
const script = new Script('import("fs")'); | ||
const imported = script.runInThisContext(); | ||
await imported; | ||
}, { | ||
code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING' | ||
}); |