Permalink
Browse files

v8: add cachedDataVersionTag

Adds `v8.cachedDataVersionTag()`, which returns an integer
representing the version tag for `cachedData` for the current V8
version & flags.

PR-URL: #11515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information...
zertosh authored and addaleax committed Feb 23, 2017
1 parent 94d1c8d commit 70beef97bdf21b52632492c3b54b067a331ea068
Showing with 44 additions and 0 deletions.
  1. +11 −0 doc/api/v8.md
  2. +1 −0 lib/v8.js
  3. +13 −0 src/node_v8.cc
  4. +19 −0 test/parallel/test-v8-version-tag.js
View
@@ -9,6 +9,16 @@ const v8 = require('v8');
*Note*: The APIs and implementation are subject to change at any time.
## v8.cachedDataVersionTag()
<!-- YAML
added: REPLACEME
-->
Returns an integer representing a "version tag" derived from the V8 version,
command line flags and detected CPU features. This is useful for determining
whether a [`vm.Script`][] `cachedData` buffer is compatible with this instance
of V8.
## v8.getHeapSpaceStatistics()
<!-- YAML
added: v6.0.0
@@ -144,5 +154,6 @@ setTimeout(function() { v8.setFlagsFromString('--notrace_gc'); }, 60e3);
```
[V8]: https://developers.google.com/v8/
[`vm.Script`]: vm.html#vm_new_vm_script_code_options
[here]: https://github.com/thlorenz/v8-flags/blob/master/flags-0.11.md
[`GetHeapSpaceStatistics`]: https://v8docs.nodesource.com/node-5.0/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4
View
@@ -59,6 +59,7 @@ exports.getHeapStatistics = function() {
};
};
exports.cachedDataVersionTag = v8binding.cachedDataVersionTag;
exports.setFlagsFromString = v8binding.setFlagsFromString;
exports.getHeapSpaceStatistics = function() {
View
@@ -13,10 +13,12 @@ using v8::Context;
using v8::FunctionCallbackInfo;
using v8::HeapSpaceStatistics;
using v8::HeapStatistics;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::ScriptCompiler;
using v8::String;
using v8::Uint32;
using v8::V8;
@@ -53,6 +55,15 @@ static const size_t kHeapSpaceStatisticsPropertiesCount =
static size_t number_of_heap_spaces = 0;
void CachedDataVersionTag(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Local<Integer> result =
Integer::NewFromUnsigned(env->isolate(),
ScriptCompiler::CachedDataVersionTag());
args.GetReturnValue().Set(result);
}
void UpdateHeapStatisticsArrayBuffer(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
HeapStatistics s;
@@ -99,6 +110,8 @@ void InitializeV8Bindings(Local<Object> target,
Local<Context> context) {
Environment* env = Environment::GetCurrent(context);
env->SetMethod(target, "cachedDataVersionTag", CachedDataVersionTag);
env->SetMethod(target,
"updateHeapStatisticsArrayBuffer",
UpdateHeapStatisticsArrayBuffer);
@@ -0,0 +1,19 @@
'use strict';
require('../common');
const assert = require('assert');
const v8 = require('v8');
const versionTag1 = v8.cachedDataVersionTag();
assert.strictEqual(typeof versionTag1, 'number');
assert.strictEqual(v8.cachedDataVersionTag(), versionTag1);
// The value of cachedDataVersionTag is derived from the command line flags and
// detected CPU features. Test that the value does indeed update when flags
// are toggled.
v8.setFlagsFromString('--allow_natives_syntax');
const versionTag2 = v8.cachedDataVersionTag();
assert.strictEqual(typeof versionTag2, 'number');
assert.strictEqual(v8.cachedDataVersionTag(), versionTag2);
assert.notStrictEqual(versionTag1, versionTag2);

0 comments on commit 70beef9

Please sign in to comment.