From a2751e3e1e70ecc9147f6dd6a58dbe9dc0d6b3be Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 9 Jan 2015 02:39:46 +0100 Subject: [PATCH] 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 https://github.com/iojs/io.js/issues/251 for background and discussion. PR-URL: https://github.com/iojs/io.js/pull/272 Reviewed-By: Colin Ihrig Reviewed-By: Domenic Denicola --- src/node.cc | 6 ++++++ test/parallel/test-v8-features.js | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 test/parallel/test-v8-features.js diff --git a/src/node.cc b/src/node.cc index 9ffaab895a16bd..0ff8aa21b157b4 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3355,6 +3355,12 @@ void Init(int* argc, DispatchDebugMessagesAsyncCallback); uv_unref(reinterpret_cast(&dispatch_debug_messages_async)); + // TODO(bnoordhuis) V8 3.32 is unshipping Harmony classes for the moment. + // We're currently at 3.31, disable classes for feature parity. Remove + // again when we upgrade. + V8::SetFlagsFromString("--noharmony_classes", + sizeof("--noharmony_classes") - 1); + #if defined(NODE_V8_OPTIONS) // Should come before the call to V8::SetFlagsFromCommandLine() // so the user can disable a flag --foo at run-time by passing diff --git a/test/parallel/test-v8-features.js b/test/parallel/test-v8-features.js new file mode 100644 index 00000000000000..50757264ae39cc --- /dev/null +++ b/test/parallel/test-v8-features.js @@ -0,0 +1,21 @@ +var common = require('../common'); +var assert = require('assert'); +var spawnSync = require('child_process').spawnSync; +var v8 = require('v8'); + +// --harmony_classes implies --harmony_scoping; ensure that scoping still works +// when classes are disabled. +assert.throws(function() { eval('"use strict"; class C {}'); }, SyntaxError); +eval('"use strict"; let x = 42'); // Should not throw. +eval('"use strict"; const y = 42'); // Should not throw. + +v8.setFlagsFromString('--harmony_classes'); +eval('"use strict"; class C {}'); // Should not throw. +eval('"use strict"; let x = 42'); // Should not throw. +eval('"use strict"; const y = 42'); // Should not throw. + +// Verify that the --harmony_classes flag unlocks classes again. +var args = ['--harmony_classes', '--use_strict', '-p', 'class C {}']; +var cp = spawnSync(process.execPath, args); +assert.equal(cp.status, 0); +assert.equal(cp.stdout.toString('utf8').trim(), '[Function: C]');