Skip to content

Commit a2751e3

Browse files
committed
src: disable harmony classes
The V8 development branch has unshipped ES6 classes pending resolution of a number of inheritance edge cases. Disable classes in io.js for the sake of feature parity. See #251 for background and discussion. PR-URL: #272 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Domenic Denicola <[email protected]>
1 parent bc629c0 commit a2751e3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/node.cc

+6
Original file line numberDiff line numberDiff line change
@@ -3355,6 +3355,12 @@ void Init(int* argc,
33553355
DispatchDebugMessagesAsyncCallback);
33563356
uv_unref(reinterpret_cast<uv_handle_t*>(&dispatch_debug_messages_async));
33573357

3358+
// TODO(bnoordhuis) V8 3.32 is unshipping Harmony classes for the moment.
3359+
// We're currently at 3.31, disable classes for feature parity. Remove
3360+
// again when we upgrade.
3361+
V8::SetFlagsFromString("--noharmony_classes",
3362+
sizeof("--noharmony_classes") - 1);
3363+
33583364
#if defined(NODE_V8_OPTIONS)
33593365
// Should come before the call to V8::SetFlagsFromCommandLine()
33603366
// so the user can disable a flag --foo at run-time by passing

test/parallel/test-v8-features.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var common = require('../common');
2+
var assert = require('assert');
3+
var spawnSync = require('child_process').spawnSync;
4+
var v8 = require('v8');
5+
6+
// --harmony_classes implies --harmony_scoping; ensure that scoping still works
7+
// when classes are disabled.
8+
assert.throws(function() { eval('"use strict"; class C {}'); }, SyntaxError);
9+
eval('"use strict"; let x = 42'); // Should not throw.
10+
eval('"use strict"; const y = 42'); // Should not throw.
11+
12+
v8.setFlagsFromString('--harmony_classes');
13+
eval('"use strict"; class C {}'); // Should not throw.
14+
eval('"use strict"; let x = 42'); // Should not throw.
15+
eval('"use strict"; const y = 42'); // Should not throw.
16+
17+
// Verify that the --harmony_classes flag unlocks classes again.
18+
var args = ['--harmony_classes', '--use_strict', '-p', 'class C {}'];
19+
var cp = spawnSync(process.execPath, args);
20+
assert.equal(cp.status, 0);
21+
assert.equal(cp.stdout.toString('utf8').trim(), '[Function: C]');

0 commit comments

Comments
 (0)