diff options
author | Fedor Indutny <fedor@indutny.com> | 2016-01-20 19:34:19 -0500 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2016-01-24 16:34:55 -0500 |
commit | 96934cbb302275400f15675717e81729690446a7 (patch) | |
tree | 28383884b71e780759911fa209a84781d6a0fa1f /test/parallel/test-vm-cached-data.js | |
parent | 83e43fbb04dbc2f81d576abbe693e49f1c046715 (diff) | |
download | android-node-v8-96934cbb302275400f15675717e81729690446a7.tar.gz android-node-v8-96934cbb302275400f15675717e81729690446a7.tar.bz2 android-node-v8-96934cbb302275400f15675717e81729690446a7.zip |
vm: introduce `cachedData`/`produceCachedData`
Introduce `cachedData`/`produceCachedData` options for `v8.Script`.
Could be used to consume/produce V8's code cache for speeding up
compilation of known code.
PR-URL: https://github.com/nodejs/node/pull/4777
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test/parallel/test-vm-cached-data.js')
-rw-r--r-- | test/parallel/test-vm-cached-data.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/parallel/test-vm-cached-data.js b/test/parallel/test-vm-cached-data.js new file mode 100644 index 0000000000..47ea592b53 --- /dev/null +++ b/test/parallel/test-vm-cached-data.js @@ -0,0 +1,37 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const vm = require('vm'); +const Buffer = require('buffer').Buffer; + +const originalSource = '(function bcd() { return \'original\'; })'; + +// It should produce code cache +const original = new vm.Script(originalSource, { + produceCachedData: true +}); +assert(original.cachedData instanceof Buffer); + +assert.equal(original.runInThisContext()(), 'original'); + +// It should consume code cache +const success = new vm.Script(originalSource, { + cachedData: original.cachedData +}); +assert(!success.cachedDataRejected); + +assert.equal(success.runInThisContext()(), 'original'); + +// It should reject invalid code cache +const reject = new vm.Script('(function abc() { return \'invalid\'; })', { + cachedData: original.cachedData +}); +assert(reject.cachedDataRejected); +assert.equal(reject.runInThisContext()(), 'invalid'); + +// It should throw on non-Buffer cachedData +assert.throws(() => { + new vm.Script('function abc() {}', { + cachedData: 'ohai' + }); +}); |