From cebddb662e617d779b5af38a7c1ec829b8e8b4b2 Mon Sep 17 00:00:00 2001 From: "wingo@igalia.com" Date: Thu, 7 Aug 2014 16:42:14 +0000 Subject: [PATCH] Enable ES6 iteration by default This enables for-of, as well as @@iterator implementations for strings and arrays. R=rossberg@chromium.org BUG=v8:2214 LOG=Y Review URL: https://codereview.chromium.org/446023002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22980 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- BUILD.gn | 3 ++- src/bootstrapper.cc | 4 +--- src/flag-definitions.h | 2 -- src/parser.cc | 5 +---- src/preparser.cc | 3 +-- src/preparser.h | 4 ---- src/unscopables.js | 8 ++++---- test/cctest/test-parsing.cc | 14 +++++--------- test/mjsunit/builtins.js | 4 +++- test/mjsunit/debug-script.js | 2 +- test/mjsunit/{harmony => es6}/array-iterator.js | 2 +- test/mjsunit/{harmony => es6}/iteration-semantics.js | 1 - test/mjsunit/{harmony => es6}/iteration-syntax.js | 2 +- .../{harmony => es6}/regress/regress-crbug-248025.js | 2 -- test/mjsunit/{harmony => es6}/string-iterator.js | 2 -- test/mjsunit/{harmony => es6}/typed-array-iterator.js | 2 -- test/mjsunit/harmony/generators-iteration.js | 2 +- test/mjsunit/harmony/proxies.js | 2 +- test/mjsunit/mjsunit.status | 8 ++++---- tools/gyp/v8.gyp | 4 ++-- 20 files changed, 28 insertions(+), 48 deletions(-) rename test/mjsunit/{harmony => es6}/array-iterator.js (99%) rename test/mjsunit/{harmony => es6}/iteration-semantics.js (99%) rename test/mjsunit/{harmony => es6}/iteration-syntax.js (98%) rename test/mjsunit/{harmony => es6}/regress/regress-crbug-248025.js (98%) rename test/mjsunit/{harmony => es6}/string-iterator.js (98%) rename test/mjsunit/{harmony => es6}/typed-array-iterator.js (98%) diff --git a/BUILD.gn b/BUILD.gn index 39c1dc7..c2c1730 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -200,6 +200,8 @@ action("js2c") { "src/promise.js", "src/object-observe.js", "src/macros.py", + "src/array-iterator.js", + "src/string-iterator.js", ] outputs = [ @@ -238,7 +240,6 @@ action("js2c_experimental") { "src/macros.py", "src/proxy.js", "src/generator.js", - "src/array-iterator.js", "src/harmony-string.js", "src/harmony-array.js", "src/unscopables.js", diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 44803f8..a3b3742 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -121,7 +121,7 @@ char* Bootstrapper::AllocateAutoDeletedArray(int bytes) { void Bootstrapper::TearDown() { if (delete_these_non_arrays_on_tear_down_ != NULL) { int len = delete_these_non_arrays_on_tear_down_->length(); - DCHECK(len < 25); // Don't use this mechanism for unbounded allocations. + DCHECK(len < 27); // Don't use this mechanism for unbounded allocations. for (int i = 0; i < len; i++) { delete delete_these_non_arrays_on_tear_down_->at(i); delete_these_non_arrays_on_tear_down_->at(i) = NULL; @@ -2060,8 +2060,6 @@ bool Genesis::InstallExperimentalNatives() { i++) { INSTALL_EXPERIMENTAL_NATIVE(i, proxies, "proxy.js") INSTALL_EXPERIMENTAL_NATIVE(i, generators, "generator.js") - INSTALL_EXPERIMENTAL_NATIVE(i, iteration, "array-iterator.js") - INSTALL_EXPERIMENTAL_NATIVE(i, iteration, "string-iterator.js") INSTALL_EXPERIMENTAL_NATIVE(i, strings, "harmony-string.js") INSTALL_EXPERIMENTAL_NATIVE(i, arrays, "harmony-array.js") INSTALL_EXPERIMENTAL_NATIVE(i, unscopables, "unscopables.js") diff --git a/src/flag-definitions.h b/src/flag-definitions.h index b4e9423..fbe1ed7 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -155,7 +155,6 @@ DEFINE_BOOL(harmony_modules, false, "enable harmony modules (implies block scoping)") DEFINE_BOOL(harmony_proxies, false, "enable harmony proxies") DEFINE_BOOL(harmony_generators, false, "enable harmony generators") -DEFINE_BOOL(harmony_iteration, false, "enable harmony iteration (for-of)") DEFINE_BOOL(harmony_numeric_literals, false, "enable harmony numeric literals (0o77, 0b11)") DEFINE_BOOL(harmony_strings, false, "enable harmony string") @@ -175,7 +174,6 @@ DEFINE_IMPLICATION(harmony, harmony_arrow_functions) DEFINE_IMPLICATION(harmony_modules, harmony_scoping) DEFINE_IMPLICATION(harmony, es_staging) -DEFINE_IMPLICATION(es_staging, harmony_iteration) // Flags for experimental implementation features. DEFINE_BOOL(compiled_keyed_dictionary_loads, true, diff --git a/src/parser.cc b/src/parser.cc index 48e8c4a..6c941da 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -729,7 +729,6 @@ Parser::Parser(CompilationInfo* info) set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); set_allow_lazy(false); // Must be explicitly enabled. set_allow_generators(FLAG_harmony_generators); - set_allow_for_of(FLAG_harmony_iteration); set_allow_arrow_functions(FLAG_harmony_arrow_functions); set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; @@ -2759,8 +2758,7 @@ bool Parser::CheckInOrOf(bool accept_OF, if (Check(Token::IN)) { *visit_mode = ForEachStatement::ENUMERATE; return true; - } else if (allow_for_of() && accept_OF && - CheckContextualKeyword(CStrVector("of"))) { + } else if (accept_OF && CheckContextualKeyword(CStrVector("of"))) { *visit_mode = ForEachStatement::ITERATE; return true; } @@ -3741,7 +3739,6 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); reusable_preparser_->set_allow_lazy(true); reusable_preparser_->set_allow_generators(allow_generators()); - reusable_preparser_->set_allow_for_of(allow_for_of()); reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); reusable_preparser_->set_allow_harmony_numeric_literals( allow_harmony_numeric_literals()); diff --git a/src/preparser.cc b/src/preparser.cc index 1336857..7ce8e3d 100644 --- a/src/preparser.cc +++ b/src/preparser.cc @@ -653,8 +653,7 @@ PreParser::Statement PreParser::ParseWhileStatement(bool* ok) { bool PreParser::CheckInOrOf(bool accept_OF) { if (Check(Token::IN) || - (allow_for_of() && accept_OF && - CheckContextualKeyword(CStrVector("of")))) { + (accept_OF && CheckContextualKeyword(CStrVector("of")))) { return true; } return false; diff --git a/src/preparser.h b/src/preparser.h index b00cbbb..8a93258 100644 --- a/src/preparser.h +++ b/src/preparser.h @@ -81,7 +81,6 @@ class ParserBase : public Traits { allow_lazy_(false), allow_natives_syntax_(false), allow_generators_(false), - allow_for_of_(false), allow_arrow_functions_(false), zone_(zone) {} @@ -90,7 +89,6 @@ class ParserBase : public Traits { bool allow_lazy() const { return allow_lazy_; } bool allow_natives_syntax() const { return allow_natives_syntax_; } bool allow_generators() const { return allow_generators_; } - bool allow_for_of() const { return allow_for_of_; } bool allow_arrow_functions() const { return allow_arrow_functions_; } bool allow_modules() const { return scanner()->HarmonyModules(); } bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } @@ -103,7 +101,6 @@ class ParserBase : public Traits { void set_allow_lazy(bool allow) { allow_lazy_ = allow; } void set_allow_natives_syntax(bool allow) { allow_natives_syntax_ = allow; } void set_allow_generators(bool allow) { allow_generators_ = allow; } - void set_allow_for_of(bool allow) { allow_for_of_ = allow; } void set_allow_arrow_functions(bool allow) { allow_arrow_functions_ = allow; } void set_allow_modules(bool allow) { scanner()->SetHarmonyModules(allow); } void set_allow_harmony_scoping(bool allow) { @@ -570,7 +567,6 @@ class ParserBase : public Traits { bool allow_lazy_; bool allow_natives_syntax_; bool allow_generators_; - bool allow_for_of_; bool allow_arrow_functions_; typename Traits::Type::Zone* zone_; // Only used by Parser. diff --git a/src/unscopables.js b/src/unscopables.js index 0d70ac6..fc030c6 100644 --- a/src/unscopables.js +++ b/src/unscopables.js @@ -8,14 +8,14 @@ // var $Array = global.Array; // var $Symbol = global.Symbol; -function ExtendSymbol() { +function UnscopablesExtendSymbol() { %CheckIsBootstrapping(); InstallConstants($Symbol, $Array( "unscopables", symbolUnscopables )); } -ExtendSymbol(); +UnscopablesExtendSymbol(); var arrayUnscopables = { @@ -30,10 +30,10 @@ var arrayUnscopables = { }; -function ExtendArrayPrototype() { +function UnscopablesExtendArrayPrototype() { %CheckIsBootstrapping(); %AddNamedProperty($Array.prototype, symbolUnscopables, arrayUnscopables, DONT_ENUM | READ_ONLY); } -ExtendArrayPrototype(); +UnscopablesExtendArrayPrototype(); diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc index 74ece30..9cb5d69 100644 --- a/test/cctest/test-parsing.cc +++ b/test/cctest/test-parsing.cc @@ -1208,7 +1208,6 @@ enum ParserFlag { kAllowHarmonyScoping, kAllowModules, kAllowGenerators, - kAllowForOf, kAllowHarmonyNumericLiterals, kAllowArrowFunctions }; @@ -1228,7 +1227,6 @@ void SetParserFlags(i::ParserBase* parser, parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); parser->set_allow_modules(flags.Contains(kAllowModules)); parser->set_allow_generators(flags.Contains(kAllowGenerators)); - parser->set_allow_for_of(flags.Contains(kAllowForOf)); parser->set_allow_harmony_numeric_literals( flags.Contains(kAllowHarmonyNumericLiterals)); parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); @@ -1436,10 +1434,9 @@ TEST(ParserSync) { CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 128 * 1024); - static const ParserFlag flags1[] = { - kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, - kAllowForOf, kAllowArrowFunctions - }; + static const ParserFlag flags1[] = {kAllowLazy, kAllowHarmonyScoping, + kAllowModules, kAllowGenerators, + kAllowArrowFunctions}; for (int i = 0; context_data[i][0] != NULL; ++i) { for (int j = 0; statement_data[j] != NULL; ++j) { for (int k = 0; termination_data[k] != NULL; ++k) { @@ -1514,9 +1511,8 @@ void RunParserSyncTest(const char* context_data[][2], 128 * 1024); static const ParserFlag default_flags[] = { - kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, - kAllowForOf, kAllowNativesSyntax, kAllowArrowFunctions - }; + kAllowLazy, kAllowHarmonyScoping, kAllowModules, + kAllowGenerators, kAllowNativesSyntax, kAllowArrowFunctions}; ParserFlag* generated_flags = NULL; if (flags == NULL) { flags = default_flags; diff --git a/test/mjsunit/builtins.js b/test/mjsunit/builtins.js index 3c92af8..fe7d35d 100644 --- a/test/mjsunit/builtins.js +++ b/test/mjsunit/builtins.js @@ -41,7 +41,9 @@ function isFunction(obj) { function isV8Native(name) { return name == "GeneratorFunctionPrototype" || name == "SetIterator" || - name == "MapIterator"; + name == "MapIterator" || + name == "ArrayIterator" || + name == "StringIterator"; } function checkConstructor(func, name) { diff --git a/test/mjsunit/debug-script.js b/test/mjsunit/debug-script.js index 54e80e0..5b5e759 100644 --- a/test/mjsunit/debug-script.js +++ b/test/mjsunit/debug-script.js @@ -59,7 +59,7 @@ for (i = 0; i < scripts.length; i++) { } // This has to be updated if the number of native scripts change. -assertTrue(named_native_count == 23 || named_native_count == 24); +assertTrue(named_native_count == 25 || named_native_count == 26); // Only the 'gc' extension is loaded. assertEquals(1, extension_count); // This script and mjsunit.js has been loaded. If using d8, d8 loads diff --git a/test/mjsunit/harmony/array-iterator.js b/test/mjsunit/es6/array-iterator.js similarity index 99% rename from test/mjsunit/harmony/array-iterator.js rename to test/mjsunit/es6/array-iterator.js index 2328876..63a7415 100644 --- a/test/mjsunit/harmony/array-iterator.js +++ b/test/mjsunit/es6/array-iterator.js @@ -25,7 +25,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// Flags: --harmony-iteration --allow-natives-syntax +// Flags: --allow-natives-syntax var NONE = 0; diff --git a/test/mjsunit/harmony/iteration-semantics.js b/test/mjsunit/es6/iteration-semantics.js similarity index 99% rename from test/mjsunit/harmony/iteration-semantics.js rename to test/mjsunit/es6/iteration-semantics.js index de4719e..7849b29 100644 --- a/test/mjsunit/harmony/iteration-semantics.js +++ b/test/mjsunit/es6/iteration-semantics.js @@ -25,7 +25,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// Flags: --harmony-iteration // Flags: --harmony-generators --harmony-scoping --harmony-proxies // Test for-of semantics. diff --git a/test/mjsunit/harmony/iteration-syntax.js b/test/mjsunit/es6/iteration-syntax.js similarity index 98% rename from test/mjsunit/harmony/iteration-syntax.js rename to test/mjsunit/es6/iteration-syntax.js index 015523d..356a978 100644 --- a/test/mjsunit/harmony/iteration-syntax.js +++ b/test/mjsunit/es6/iteration-syntax.js @@ -25,7 +25,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// Flags: --harmony-iteration --harmony-scoping --use-strict +// Flags: --harmony-scoping --use-strict // Test for-of syntax. diff --git a/test/mjsunit/harmony/regress/regress-crbug-248025.js b/test/mjsunit/es6/regress/regress-crbug-248025.js similarity index 98% rename from test/mjsunit/harmony/regress/regress-crbug-248025.js rename to test/mjsunit/es6/regress/regress-crbug-248025.js index c598859..b7982cd 100644 --- a/test/mjsunit/harmony/regress/regress-crbug-248025.js +++ b/test/mjsunit/es6/regress/regress-crbug-248025.js @@ -25,8 +25,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// Flags: --harmony-iteration - // Filler long enough to trigger lazy parsing. var filler = "//" + new Array(1024).join('x'); diff --git a/test/mjsunit/harmony/string-iterator.js b/test/mjsunit/es6/string-iterator.js similarity index 98% rename from test/mjsunit/harmony/string-iterator.js rename to test/mjsunit/es6/string-iterator.js index 3e37178..e6bea6d 100644 --- a/test/mjsunit/harmony/string-iterator.js +++ b/test/mjsunit/es6/string-iterator.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-iteration - function TestStringPrototypeIterator() { assertTrue(String.prototype.hasOwnProperty(Symbol.iterator)); diff --git a/test/mjsunit/harmony/typed-array-iterator.js b/test/mjsunit/es6/typed-array-iterator.js similarity index 98% rename from test/mjsunit/harmony/typed-array-iterator.js rename to test/mjsunit/es6/typed-array-iterator.js index 8559dfe..a2e4906 100644 --- a/test/mjsunit/harmony/typed-array-iterator.js +++ b/test/mjsunit/es6/typed-array-iterator.js @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flags: --harmony-iteration - var constructors = [Uint8Array, Int8Array, Uint16Array, Int16Array, diff --git a/test/mjsunit/harmony/generators-iteration.js b/test/mjsunit/harmony/generators-iteration.js index e60e2a9..1a79367 100644 --- a/test/mjsunit/harmony/generators-iteration.js +++ b/test/mjsunit/harmony/generators-iteration.js @@ -25,7 +25,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// Flags: --harmony-generators --expose-gc --harmony-iteration +// Flags: --harmony-generators --expose-gc // Test generator iteration. diff --git a/test/mjsunit/harmony/proxies.js b/test/mjsunit/harmony/proxies.js index 00e605f..b082c06 100644 --- a/test/mjsunit/harmony/proxies.js +++ b/test/mjsunit/harmony/proxies.js @@ -1807,7 +1807,7 @@ TestKeysThrow({ }, }) -TestKeysThrow([], { +TestKeysThrow({ get getOwnPropertyNames() { return function() { return [1, 2] } }, diff --git a/test/mjsunit/mjsunit.status b/test/mjsunit/mjsunit.status index fe22d1b..7728d5e 100644 --- a/test/mjsunit/mjsunit.status +++ b/test/mjsunit/mjsunit.status @@ -155,10 +155,10 @@ 'harmony/regress/regress-3280': [PASS, NO_VARIANTS], # Support for ES6 for-of iteration is missing. - 'harmony/array-iterator': [PASS, NO_VARIANTS], - 'harmony/iteration-semantics': [PASS, NO_VARIANTS], - 'harmony/string-iterator': [PASS, NO_VARIANTS], - 'harmony/typed-array-iterator': [PASS, NO_VARIANTS], + 'es6/array-iterator': [PASS, NO_VARIANTS], + 'es6/iteration-semantics': [PASS, NO_VARIANTS], + 'es6/string-iterator': [PASS, NO_VARIANTS], + 'es6/typed-array-iterator': [PASS, NO_VARIANTS], ############################################################################## # Too slow in debug mode with --stress-opt mode. diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index 7853a43..5da1d88 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -1409,13 +1409,13 @@ '../../src/collection.js', '../../src/collection-iterator.js', '../../src/macros.py', + '../../src/array-iterator.js', + '../../src/string-iterator.js' ], 'experimental_library_files': [ '../../src/macros.py', '../../src/proxy.js', '../../src/generator.js', - '../../src/array-iterator.js', - '../../src/string-iterator.js', '../../src/harmony-string.js', '../../src/harmony-array.js', '../../src/unscopables.js', -- 2.7.4