From a415f594585cb16cd1b4067cab905ddab61c6e5b Mon Sep 17 00:00:00 2001 From: littledan Date: Wed, 8 Jul 2015 14:49:44 -0700 Subject: [PATCH] Guard @@isConcatSpreadable behind a flag The breakage to Chrome seems to be based on @@isConcatSpreadable and turning that part off with this patch fixes the Maps Tips & Tricks test case. BUG=chromium:507553 LOG=Y R=adamk Review URL: https://codereview.chromium.org/1226063002 Cr-Commit-Position: refs/heads/master@{#29545} --- BUILD.gn | 1 + src/bootstrapper.cc | 4 ++++ src/flag-definitions.h | 5 +++-- src/harmony-array.js | 5 ----- src/harmony-concat-spreadable.js | 16 ++++++++++++++++ src/runtime/runtime-array.cc | 16 +++++++++------- test/mjsunit/harmony/array-concat.js | 2 +- tools/gyp/v8.gyp | 1 + 8 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 src/harmony-concat-spreadable.js diff --git a/BUILD.gn b/BUILD.gn index e75ffb7656c..059ee070862 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -273,6 +273,7 @@ action("js2c_experimental") { "src/generator.js", "src/harmony-atomics.js", "src/harmony-array-includes.js", + "src/harmony-concat-spreadable.js", "src/harmony-tostring.js", "src/harmony-regexp.js", "src/harmony-reflect.js", diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 983da4787fe..43fc0eb8355 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -1819,6 +1819,7 @@ EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_spread_arrays) EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_sharedarraybuffer) EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_atomics) EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_new_target) +EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_concat_spreadable) void Genesis::InstallNativeFunctions_harmony_proxies() { @@ -1850,6 +1851,7 @@ EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spread_arrays) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_atomics) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_new_target) +EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_concat_spreadable) void Genesis::InitializeGlobal_harmony_regexps() { Handle builtins(native_context()->builtins()); @@ -2500,6 +2502,8 @@ bool Genesis::InstallExperimentalNatives() { static const char* harmony_atomics_natives[] = {"native harmony-atomics.js", nullptr}; static const char* harmony_new_target_natives[] = {nullptr}; + static const char* harmony_concat_spreadable_natives[] = { + "native harmony-concat-spreadable.js", nullptr}; for (int i = ExperimentalNatives::GetDebuggerCount(); i < ExperimentalNatives::GetBuiltinsCount(); i++) { diff --git a/src/flag-definitions.h b/src/flag-definitions.h index 033d0b3e8fa..2771671c315 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -199,8 +199,9 @@ DEFINE_BOOL(legacy_const, true, "legacy semantics for const in sloppy mode") V(harmony_new_target, "harmony new.target") // Features that are complete (but still behind --harmony/es-staging flag). -#define HARMONY_STAGED(V) \ - V(harmony_tostring, "harmony toString") \ +#define HARMONY_STAGED(V) \ + V(harmony_tostring, "harmony toString") \ + V(harmony_concat_spreadable, "harmony isConcatSpreadable") \ V(harmony_rest_parameters, "harmony rest parameters") // Features that are shipping (turned on by default, but internal flag remains). diff --git a/src/harmony-array.js b/src/harmony-array.js index 637dd6ed857..e94134b81aa 100644 --- a/src/harmony-array.js +++ b/src/harmony-array.js @@ -287,11 +287,6 @@ function ArrayOf() { // ------------------------------------------------------------------- -utils.InstallConstants(GlobalSymbol, [ - // TODO(dslomov, caitp): Move to symbol.js when shipping - "isConcatSpreadable", symbolIsConcatSpreadable -]); - %FunctionSetLength(ArrayCopyWithin, 2); %FunctionSetLength(ArrayFrom, 1); %FunctionSetLength(ArrayFill, 1); diff --git a/src/harmony-concat-spreadable.js b/src/harmony-concat-spreadable.js new file mode 100644 index 00000000000..362701c1230 --- /dev/null +++ b/src/harmony-concat-spreadable.js @@ -0,0 +1,16 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +(function(global, utils) { + +'use strict'; + +%CheckIsBootstrapping(); + +utils.InstallConstants(global.Symbol, [ + // TODO(littledan): Move to symbol.js when shipping + "isConcatSpreadable", symbolIsConcatSpreadable +]); + +}) diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc index b2865dcbdf3..d00df71576b 100644 --- a/src/runtime/runtime-array.cc +++ b/src/runtime/runtime-array.cc @@ -729,13 +729,15 @@ static bool IterateElements(Isolate* isolate, Handle receiver, static bool IsConcatSpreadable(Isolate* isolate, Handle obj) { HandleScope handle_scope(isolate); if (!obj->IsSpecObject()) return false; - Handle key(isolate->factory()->is_concat_spreadable_symbol()); - Handle value; - MaybeHandle maybeValue = - i::Runtime::GetObjectProperty(isolate, obj, key); - if (maybeValue.ToHandle(&value)) { - if (!value->IsUndefined()) { - return value->BooleanValue(); + if (FLAG_harmony_concat_spreadable) { + Handle key(isolate->factory()->is_concat_spreadable_symbol()); + Handle value; + MaybeHandle maybeValue = + i::Runtime::GetObjectProperty(isolate, obj, key); + if (maybeValue.ToHandle(&value)) { + if (!value->IsUndefined()) { + return value->BooleanValue(); + } } } return obj->IsJSArray(); diff --git a/test/mjsunit/harmony/array-concat.js b/test/mjsunit/harmony/array-concat.js index 89a884143dd..71b6790bc7b 100644 --- a/test/mjsunit/harmony/array-concat.js +++ b/test/mjsunit/harmony/array-concat.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-arrays +// Flags: --harmony-concat-spreadable (function testArrayConcatArity() { "use strict"; diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index 6ef9b3818e3..a77acfa1091 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -1786,6 +1786,7 @@ '../../src/generator.js', '../../src/harmony-atomics.js', '../../src/harmony-array-includes.js', + '../../src/harmony-concat-spreadable.js', '../../src/harmony-tostring.js', '../../src/harmony-regexp.js', '../../src/harmony-reflect.js',