Browse Source

lib: add setFlagsFromString() to tracing module

Expose v8::V8::SetFlagsFromString() on tracing.v8 in lib/tracing.js.

PR-URL: https://github.com/node-forward/node/pull/62
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
archived-io.js-v0.12
Ben Noordhuis 10 years ago
parent
commit
f8076c4067
  1. 15
      doc/api/tracing.markdown
  2. 1
      lib/tracing.js
  3. 9
      src/node_v8.cc
  4. 26
      test/simple/test-v8-flags.js

15
doc/api/tracing.markdown

@ -58,6 +58,21 @@ Returns an object with the following properties
}
```
### setFlagsFromString()
Set additional V8 command line flags. Use with care; changing settings
after the VM has started may result in unpredictable behavior, including
crashes and data loss. Or it may simply do nothing.
Usage:
```
// Print GC events to stdout for one minute.
var v8 = require('tracing').v8;
v8.setFlagsFromString('--trace_gc');
setTimeout(function() { v8.setFlagsFromString('--notrace_gc'); }, 60e3);
```
# Async Listeners

1
lib/tracing.js

@ -31,6 +31,7 @@ exports._nodeInitialization = function nodeInitialization(pobj) {
// Finish setting up the v8 Object.
v8.getHeapStatistics = v8binding.getHeapStatistics;
v8.setFlagsFromString = v8binding.setFlagsFromString;
// Part of the AsyncListener setup to share objects/callbacks with the
// native layer.

9
src/node_v8.cc

@ -41,7 +41,9 @@ using v8::Local;
using v8::Null;
using v8::Number;
using v8::Object;
using v8::String;
using v8::Uint32;
using v8::V8;
using v8::Value;
using v8::kGCTypeAll;
using v8::kGCTypeMarkSweepCompact;
@ -204,6 +206,12 @@ void StopGarbageCollectionTracking(const FunctionCallbackInfo<Value>& args) {
}
void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) {
String::Utf8Value flags(args[0]);
V8::SetFlagsFromString(*flags, flags.length());
}
void InitializeV8Bindings(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context) {
@ -215,6 +223,7 @@ void InitializeV8Bindings(Handle<Object> target,
"stopGarbageCollectionTracking",
StopGarbageCollectionTracking);
env->SetMethod(target, "getHeapStatistics", GetHeapStatistics);
env->SetMethod(target, "setFlagsFromString", SetFlagsFromString);
}
} // namespace node

26
test/simple/test-v8-flags.js

@ -0,0 +1,26 @@
// Copyright (c) 2014, StrongLoop Inc.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
var common = require('../common');
var assert = require('assert');
var v8 = require('tracing').v8;
var vm = require('vm');
v8.setFlagsFromString('--allow_natives_syntax');
assert(eval('%_IsSmi(42)'));
assert(vm.runInThisContext('%_IsSmi(42)'));
v8.setFlagsFromString('--noallow_natives_syntax');
assert.throws(function() { eval('%_IsSmi(42)') }, SyntaxError);
assert.throws(function() { vm.runInThisContext('%_IsSmi(42)') }, SyntaxError);
Loading…
Cancel
Save