Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
vm: add Script.createCodeCache()
PR-URL: #20300 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Yang Guo <yangguo@chromium.org>
- Loading branch information
Showing
with
87 additions
and 2 deletions.
- +9 −0 doc/api/deprecations.md
- +32 −0 doc/api/vm.md
- +24 −2 src/node_contextify.cc
- +22 −0 test/parallel/test-vm-createcacheddata.js
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const { Script } = require('vm'); | ||
const assert = require('assert'); | ||
|
||
const source = 'function x() {} const y = x();'; | ||
|
||
const script = new Script(source); | ||
let cachedData = script.createCachedData(); | ||
assert(cachedData instanceof Buffer); | ||
|
||
assert(!new Script(source, { cachedData }).cachedDataRejected); | ||
|
||
script.runInNewContext(); | ||
|
||
for (let i = 0; i < 10; i += 1) { | ||
cachedData = script.createCachedData(); | ||
|
||
assert(!new Script(source, { cachedData }).cachedDataRejected); | ||
} |