Remove always-true --harmony-restrictive-declarations flag

The flag has been on since at least Chrome 53.

R=littledan@chromium.org

Review-Url: https://codereview.chromium.org/2478883002
Cr-Commit-Position: refs/heads/master@{#40780}
This commit is contained in:
adamk 2016-11-04 11:50:22 -07:00 committed by Commit bot
parent 3d0b227493
commit 010770085b
15 changed files with 11 additions and 468 deletions

View File

@ -3229,7 +3229,6 @@ EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_named_captures)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_property)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_function_sent)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tailcalls)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_restrictive_declarations)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_string_padding)
#ifdef V8_I18N_SUPPORT
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(datetime_format_to_parts)
@ -3789,7 +3788,6 @@ bool Genesis::InstallExperimentalNatives() {
nullptr};
static const char* harmony_do_expressions_natives[] = {nullptr};
static const char* harmony_regexp_lookbehind_natives[] = {nullptr};
static const char* harmony_restrictive_declarations_natives[] = {nullptr};
static const char* harmony_regexp_named_captures_natives[] = {nullptr};
static const char* harmony_regexp_property_natives[] = {nullptr};
static const char* harmony_function_sent_natives[] = {nullptr};

View File

@ -223,10 +223,7 @@ DEFINE_IMPLICATION(es_staging, move_object_start)
#endif
// Features that are shipping (turned on by default, but internal flag remains).
#define HARMONY_SHIPPING(V) \
V(harmony_async_await, "harmony async-await") \
V(harmony_restrictive_declarations, \
"harmony limitations on sloppy mode function declarations")
#define HARMONY_SHIPPING(V) V(harmony_async_await, "harmony async-await")
// Once a shipping feature has proved stable in the wild, it will be dropped
// from HARMONY_SHIPPING, all occurrences of the FLAG_ variable are removed,

View File

@ -211,7 +211,6 @@ class ParserBase {
allow_lazy_(false),
allow_natives_(false),
allow_tailcalls_(false),
allow_harmony_restrictive_declarations_(false),
allow_harmony_do_expressions_(false),
allow_harmony_function_sent_(false),
allow_harmony_async_await_(false),
@ -226,7 +225,6 @@ class ParserBase {
ALLOW_ACCESSORS(lazy);
ALLOW_ACCESSORS(natives);
ALLOW_ACCESSORS(tailcalls);
ALLOW_ACCESSORS(harmony_restrictive_declarations);
ALLOW_ACCESSORS(harmony_do_expressions);
ALLOW_ACCESSORS(harmony_function_sent);
ALLOW_ACCESSORS(harmony_async_await);
@ -1463,7 +1461,6 @@ class ParserBase {
bool allow_lazy_;
bool allow_natives_;
bool allow_tailcalls_;
bool allow_harmony_restrictive_declarations_;
bool allow_harmony_do_expressions_;
bool allow_harmony_function_sent_;
bool allow_harmony_async_await_;
@ -3683,13 +3680,10 @@ ParserBase<Impl>::ParseFunctionDeclaration(bool* ok) {
int pos = position();
ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
if (Check(Token::MUL)) {
flags |= ParseFunctionFlags::kIsGenerator;
if (allow_harmony_restrictive_declarations()) {
impl()->ReportMessageAt(scanner()->location(),
MessageTemplate::kGeneratorInLegacyContext);
*ok = false;
return impl()->NullStatement();
}
impl()->ReportMessageAt(scanner()->location(),
MessageTemplate::kGeneratorInLegacyContext);
*ok = false;
return impl()->NullStatement();
}
return ParseHoistableDeclaration(pos, flags, nullptr, false, ok);
}
@ -4645,8 +4639,7 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock(
template <typename Impl>
typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseScopedStatement(
ZoneList<const AstRawString*>* labels, bool legacy, bool* ok) {
if (is_strict(language_mode()) || peek() != Token::FUNCTION ||
(legacy && allow_harmony_restrictive_declarations())) {
if (is_strict(language_mode()) || peek() != Token::FUNCTION || legacy) {
return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok);
} else {
if (legacy) {

View File

@ -625,8 +625,6 @@ Parser::Parser(ParseInfo* info)
info->isolate()->is_tail_call_elimination_enabled());
set_allow_harmony_do_expressions(FLAG_harmony_do_expressions);
set_allow_harmony_function_sent(FLAG_harmony_function_sent);
set_allow_harmony_restrictive_declarations(
FLAG_harmony_restrictive_declarations);
set_allow_harmony_async_await(FLAG_harmony_async_await);
set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators);
set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas);
@ -3301,7 +3299,6 @@ PreParser::PreParseResult Parser::ParseFunctionWithPreParser(
SET_ALLOW(natives);
SET_ALLOW(harmony_do_expressions);
SET_ALLOW(harmony_function_sent);
SET_ALLOW(harmony_restrictive_declarations);
SET_ALLOW(harmony_async_await);
SET_ALLOW(harmony_trailing_commas);
SET_ALLOW(harmony_class_fields);

View File

@ -1306,7 +1306,6 @@ enum ParserFlag {
kAllowLazy,
kAllowNatives,
kAllowHarmonyFunctionSent,
kAllowHarmonyRestrictiveDeclarations,
kAllowHarmonyAsyncAwait,
kAllowHarmonyRestrictiveGenerators,
kAllowHarmonyTrailingCommas,
@ -1326,8 +1325,6 @@ void SetParserFlags(i::ParserBase<Traits>* parser,
parser->set_allow_natives(flags.Contains(kAllowNatives));
parser->set_allow_harmony_function_sent(
flags.Contains(kAllowHarmonyFunctionSent));
parser->set_allow_harmony_restrictive_declarations(
flags.Contains(kAllowHarmonyRestrictiveDeclarations));
parser->set_allow_harmony_async_await(
flags.Contains(kAllowHarmonyAsyncAwait));
parser->set_allow_harmony_restrictive_generators(
@ -7660,11 +7657,6 @@ TEST(FunctionDeclarationError) {
// Invalid in all contexts
const char* error_data[] = {
"try function foo() {} catch (e) {}",
NULL
};
// Valid in sloppy mode only, and only when the
// --harmony-restrictive-declarations flag is off
const char* unrestricted_data[] = {
"do function foo() {} while (0);",
"for (;false;) function foo() {}",
"for (var i = 0; i < 1; i++) function f() { };",
@ -7696,8 +7688,7 @@ TEST(FunctionDeclarationError) {
// "{ function* f() {} function f() {} }",
NULL
};
// Valid only in sloppy mode, with or without
// --harmony-restrictive-declarations
// Valid only in sloppy mode.
const char* sloppy_data[] = {
"if (true) function foo() {}",
"if (false) {} else function f() { };",
@ -7708,30 +7699,13 @@ TEST(FunctionDeclarationError) {
};
// clang-format on
static const ParserFlag restrictive_flags[] = {
kAllowHarmonyRestrictiveDeclarations};
// Nothing parses in strict mode without a SyntaxError
RunParserSyncTest(strict_context, error_data, kError);
RunParserSyncTest(strict_context, error_data, kError, NULL, 0,
restrictive_flags, arraysize(restrictive_flags));
RunParserSyncTest(strict_context, unrestricted_data, kError);
RunParserSyncTest(strict_context, unrestricted_data, kError, NULL, 0,
restrictive_flags, arraysize(restrictive_flags));
RunParserSyncTest(strict_context, sloppy_data, kError);
RunParserSyncTest(strict_context, sloppy_data, kError, NULL, 0,
restrictive_flags, arraysize(restrictive_flags));
// In sloppy mode, some things are successful, depending on the flag
// In sloppy mode, sloppy_data is successful
RunParserSyncTest(sloppy_context, error_data, kError);
RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0,
restrictive_flags, arraysize(restrictive_flags));
RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess);
RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0,
restrictive_flags, arraysize(restrictive_flags));
RunParserSyncTest(sloppy_context, sloppy_data, kSuccess);
RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags,
arraysize(restrictive_flags));
}
TEST(ExponentiationOperator) {

View File

@ -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-restrictive-declarations
// ES#sec-functiondeclarations-in-ifstatement-statement-clauses
// Annex B 3.4 FunctionDeclarations in IfStatement Statement Clauses
// In sloppy mode, function declarations in if statements act like

View File

@ -1,97 +0,0 @@
// Copyright 2016 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.
// Flags: --no-harmony-restrictive-declarations
// ES#sec-functiondeclarations-in-ifstatement-statement-clauses
// Annex B 3.4 FunctionDeclarations in IfStatement Statement Clauses
// In sloppy mode, function declarations in if statements act like
// they have a block around them. Prohibited in strict mode.
(function() {
assertEquals(undefined, f);
if (false) function f() { };
assertEquals(undefined, f);
})();
(function() {
assertEquals(undefined, f);
if (true) function f() { };
assertEquals('function', typeof f);
})();
(function() {
assertEquals(undefined, f);
if (true) {} else function f() { };
assertEquals(undefined, f);
})();
(function() {
assertEquals(undefined, f);
if (false) {} else function f() { };
assertEquals('function', typeof f);
})();
// For legacy reasons, we also support these types of semantics as
// the body of a for or with statement.
(function() {
for (;false;) function f() { };
assertEquals(undefined, f);
})();
(function() {
for (var x in {}) function f() { };
assertEquals(undefined, f);
})();
(function() {
var x;
for (x in {}) function f() { };
assertEquals(undefined, f);
})();
(function() {
for (var i = 0; i < 1; i++) function f() { };
assertEquals('function', typeof f);
})();
(function() {
for (var x in {a: 1}) function f() { };
assertEquals('function', typeof f);
})();
(function() {
var x;
for (x in {a: 1}) function f() { };
assertEquals('function', typeof f);
})();
(function() {
with ({}) function f() { };
assertEquals('function', typeof f);
})();
(function() {
do function f() {} while (0);
assertEquals('function', typeof f);
})();
// Labeled function declarations undergo the same hoisting/FiB semantics as if
// they were unalbeled.
(function() {
function bar() {
return f;
x: function f() {}
}
assertEquals('function', typeof bar());
})();
(function() {
function bar() {
return f;
{
x: function f() {}
}
}
assertEquals(undefined, bar());
})();

View File

@ -1,33 +0,0 @@
// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (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: --no-harmony-restrictive-declarations
function foo(f) { eval(f); }
// Ensure that compiling a declaration of a function does not crash.
foo("(function (x) { with ({x: []}) function x(){} })");

View File

@ -1,11 +0,0 @@
// 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.
// Flags: --no-harmony-restrictive-declarations
// At some point, this code led to DCHECK errors in debug mode
for (; false;) function foo() {};
for (x in []) function foo() {};

View File

@ -1,18 +0,0 @@
// 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.
// Flags: --no-harmony-restrictive-declarations
// Previously, this caused a CHECK fail in debug mode
// https://code.google.com/p/chromium/issues/detail?id=542099
var foo = {};
var bar = foo;
for (foo.x in {a: 1}) function foo() { return foo; }
assertEquals("object", typeof bar);
assertEquals("a", bar.x);
assertEquals("function", typeof foo);
assertEquals("function", typeof foo());
assertSame(foo, foo());
assertEquals(undefined, foo.x);

View File

@ -1,25 +0,0 @@
// 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.
// Flags: --no-harmony-restrictive-declarations
(function() {
var x = {a: 1}
assertEquals("undefined", typeof f);
with (x)
function f() { return a; }
assertEquals("function", typeof f);
assertEquals(1, f());
x.a = 2;
assertEquals(2, f());
})();
var y = {b: 1}
assertEquals("undefined", typeof g);
with (y)
function g() { return b; }
assertEquals("function", typeof g);
assertEquals(1, g());
y.b = 2;
assertEquals(2, g());

View File

@ -308,8 +308,8 @@ PASS Invalid: "while if (a) ;"
PASS Invalid: "function f() { while if (a) ; }"
PASS Valid: "if (a) function f() {} else function g() {}"
PASS Valid: "function f() { if (a) function f() {} else function g() {} }"
PASS Valid: "if (a()) while(0) function f() {} else function g() {}"
PASS Valid: "function f() { if (a()) while(0) function f() {} else function g() {} }"
PASS Invalid: "if (a()) while(0) function f() {} else function g() {}"
PASS Invalid: "function f() { if (a()) while(0) function f() {} else function g() {} }"
PASS Invalid: "if (a()) function f() { else function g() }"
PASS Invalid: "function f() { if (a()) function f() { else function g() } }"
PASS Invalid: "if (a) if (b) ; else function f {}"

View File

@ -21,8 +21,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: --no-harmony-restrictive-declarations
description(
"This test checks that the following expressions or statements are valid ECMASCRIPT code or should throw parse error"
);
@ -231,7 +229,7 @@ valid ("do if (a) with (b) continue; else debugger; while (false)");
invalid("do if (a) while (false) else debugger");
invalid("while if (a) ;");
valid ("if (a) function f() {} else function g() {}");
valid ("if (a()) while(0) function f() {} else function g() {}");
invalid("if (a()) while(0) function f() {} else function g() {}");
invalid("if (a()) function f() { else function g() }");
invalid("if (a) if (b) ; else function f {}");
invalid("if (a) if (b) ; else function (){}");

View File

@ -1,43 +0,0 @@
# Copyright 2013 the V8 project authors. All rights reserved.
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This test checks that function declarations are treated as statements.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS ifTest() is true
PASS ifElseTest() is true
PASS doWhileTest() is true
PASS whileTest() is true
PASS forTest() is true
PASS forVarTest() is true
PASS forInTest() is true
PASS forInVarTest() is true
PASS forInVarInitTest() is true
PASS withTest() is true
PASS labelTest() is true
PASS successfullyParsed is true
TEST COMPLETE

View File

@ -1,185 +0,0 @@
// Copyright 2013 the V8 project authors. All rights reserved.
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (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: --no-harmony-restrictive-declarations
description(
"This test checks that function declarations are treated as statements."
);
function f()
{
return false;
}
function ifTest()
{
if (true)
function f()
{
return true;
}
return f();
}
shouldBeTrue("ifTest()");
function ifElseTest()
{
if (false)
return false;
else
function f()
{
return true;
}
return f();
}
shouldBeTrue("ifElseTest()");
function doWhileTest()
{
var i = 0;
do
function f()
{
return true;
}
while (i++ < 10)
return f();
}
shouldBeTrue("doWhileTest()");
function whileTest()
{
var i = 0;
while (i++ < 10)
function f()
{
return true;
}
return f();
}
shouldBeTrue("whileTest()");
function forTest()
{
var i;
for (i = 0; i < 10; ++i)
function f()
{
return true;
}
return f();
}
shouldBeTrue("forTest()");
function forVarTest()
{
for (var i = 0; i < 10; ++i)
function f()
{
return true;
}
return f();
}
shouldBeTrue("forVarTest()");
function forInTest()
{
var a;
for (a in { field: false })
function f()
{
return true;
}
return f();
}
shouldBeTrue("forInTest()");
function forInVarTest()
{
var a;
for (var a in { field: false })
function f()
{
return true;
}
return f();
}
shouldBeTrue("forInVarTest()");
function forInVarInitTest()
{
var a;
for (var a in { field: false })
function f()
{
return true;
}
return f();
}
shouldBeTrue("forInVarInitTest()");
function withTest()
{
with ({ })
function f()
{
return true;
}
return f();
}
shouldBeTrue("withTest()");
function labelTest()
{
label:
function f()
{
return true;
}
return f();
}
shouldBeTrue("labelTest()");