Skip to content

Commit d5caa00

Browse files
committed
test: v8-flags is sensitive to script caching
V8 may cache compiled scripts, and it is not safe to assume that the V8 flags can be changed after an isolate has been created. In this particular case, since we are using the same script multiple times, the test would fail if V8 cached the result of the compilation. Ref: #6280 Fixes: #6258
1 parent 697790c commit d5caa00

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/parallel/test-v8-flags.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ var assert = require('assert');
44
var v8 = require('v8');
55
var vm = require('vm');
66

7+
// Note: changing V8 flags after an isolate started is not guaranteed to work.
8+
// Specifically here, V8 may cache compiled scripts between the flip of the
9+
// flag. We use a different script each time to work around this problem.
710
v8.setFlagsFromString('--allow_natives_syntax');
811
assert(eval('%_IsSmi(42)'));
9-
assert(vm.runInThisContext('%_IsSmi(42)'));
12+
assert(vm.runInThisContext('%_IsSmi(43)'));
1013

1114
v8.setFlagsFromString('--noallow_natives_syntax');
12-
assert.throws(function() { eval('%_IsSmi(42)'); }, SyntaxError);
13-
assert.throws(function() { vm.runInThisContext('%_IsSmi(42)'); }, SyntaxError);
15+
assert.throws(function() { eval('%_IsSmi(44)'); }, SyntaxError);
16+
assert.throws(function() { vm.runInThisContext('%_IsSmi(45)'); }, SyntaxError);

0 commit comments

Comments
 (0)