Reviewers: marja,
Description:
[strong] Deprecate delete
[email protected]
BUG=
Please review this at https://codereview.chromium.org/932833002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+61, -11 lines):
M src/messages.js
M src/preparser.h
M test/cctest/test-parsing.cc
A test/mjsunit/strong/delete.js
M test/mjsunit/strong/equality.js
A test/mjsunit/strong/use-strong.js
Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index
e60ab92586e0a5f4aa2002397492d1d171769e2a..da330eee7f5b545584619b28f511cf167fb283e0
100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -162,6 +162,7 @@ var kMessages = {
strict_poison_pill: ["'caller', 'callee', and 'arguments'
properties may not be accessed on strict mode functions or the arguments
objects for calls to them"],
strict_caller: ["Illegal access to a strict mode caller
function."],
strong_equal: ["Please don't use '==' or '!=' in strong
mode, use '===' or '!==' instead"],
+ strong_delete: ["Please don't use 'delete' in strong
mode, use maps or sets instead"],
malformed_arrow_function_parameter_list: ["Malformed arrow function
parameter list"],
generator_poison_pill: ["'caller' and 'arguments' properties may
not be accessed on generator functions."],
cant_prevent_ext_external_array_elements: ["Cannot prevent extension of
an object with external array elements"],
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index
9f8fc13653a893d8c2adc7fcc2884773f2fd8f34..e82753c08e7599be5252eb2ad625e0d89d4f4c7a
100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -2497,12 +2497,17 @@ ParserBase<Traits>::ParseUnaryExpression(bool* ok) {
int pos = position();
ExpressionT expression = ParseUnaryExpression(CHECK_OK);
- // "delete identifier" is a syntax error in strict mode.
- if (op == Token::DELETE && is_strict(language_mode()) &&
- this->IsIdentifier(expression)) {
- ReportMessage("strict_delete");
- *ok = false;
- return this->EmptyExpression();
+ if (op == Token::DELETE && is_strict(language_mode())) {
+ if (is_strong(language_mode())) {
+ ReportMessage("strong_delete");
+ *ok = false;
+ return this->EmptyExpression();
+ } else if (this->IsIdentifier(expression)) {
+ // "delete identifier" is a syntax error in strict mode.
+ ReportMessage("strict_delete");
+ *ok = false;
+ return this->EmptyExpression();
+ }
}
// Allow Traits do rewrite the expression.
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index
7a624cb0bf38f99a55ade2350f72af62986ed960..866edaf20a3725a8fba9f43000d7631b0da1261b
100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -2891,9 +2891,13 @@ TEST(TooManyArguments) {
TEST(StrictDelete) {
// "delete <Identifier>" is not allowed in strict mode.
+ const char* strong_context_data[][2] = {
+ {"\"use strong\"; ", ""},
+ { NULL, NULL }
+ };
+
const char* strict_context_data[][2] = {
{"\"use strict\"; ", ""},
- {"\"use strong\"; ", ""},
{ NULL, NULL }
};
@@ -2934,16 +2938,22 @@ TEST(StrictDelete) {
};
static const ParserFlag always_flags[] = {kAllowStrongMode};
+ RunParserSyncTest(strong_context_data, sloppy_statement_data, kError,
NULL, 0,
+ always_flags, arraysize(always_flags));
RunParserSyncTest(strict_context_data, sloppy_statement_data, kError,
NULL, 0,
always_flags, arraysize(always_flags));
RunParserSyncTest(sloppy_context_data, sloppy_statement_data, kSuccess,
NULL,
0, always_flags, arraysize(always_flags));
+ RunParserSyncTest(strong_context_data, good_statement_data, kError,
NULL, 0,
+ always_flags, arraysize(always_flags));
RunParserSyncTest(strict_context_data, good_statement_data, kSuccess,
NULL, 0,
always_flags, arraysize(always_flags));
RunParserSyncTest(sloppy_context_data, good_statement_data, kSuccess,
NULL, 0,
always_flags, arraysize(always_flags));
+ RunParserSyncTest(strong_context_data, bad_statement_data, kError, NULL,
0,
+ always_flags, arraysize(always_flags));
RunParserSyncTest(strict_context_data, bad_statement_data, kError, NULL,
0,
always_flags, arraysize(always_flags));
RunParserSyncTest(sloppy_context_data, bad_statement_data, kError, NULL,
0,
Index: test/mjsunit/strong/delete.js
diff --git a/test/mjsunit/strong/delete.js b/test/mjsunit/strong/delete.js
new file mode 100644
index
0000000000000000000000000000000000000000..90e229d54665962c7fea9cfd5ef7eb3cc4441896
--- /dev/null
+++ b/test/mjsunit/strong/delete.js
@@ -0,0 +1,11 @@
+// Copyright 2014 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: --strong-mode
+
+(function NoDelete() {
+ const o = {a: 0};
+ assertThrows("'use strong'; delete o.a", SyntaxError);
+ assertThrows("'use strong'; delete o", SyntaxError);
+})();
Index: test/mjsunit/strong/equality.js
diff --git a/test/mjsunit/strong/equality.js
b/test/mjsunit/strong/equality.js
index
d5fe3fdb4738995c2f1aa0b5f7466cf380ddcd95..dd32644112a0f86f0777725cf12a0cb8932a5a18
100644
--- a/test/mjsunit/strong/equality.js
+++ b/test/mjsunit/strong/equality.js
@@ -7,8 +7,4 @@
(function NoSloppyEquality() {
assertThrows("'use strong'; 0 == 0", SyntaxError);
assertThrows("'use strong'; 0 != 0", SyntaxError);
- assertThrows("function f() { 'use strong'; 0 == 0 }", SyntaxError);
- assertThrows("function f() { 'use strong'; 0 != 0 }", SyntaxError);
- assertTrue(eval("function f() { 'use strong' } 0 == 0"));
- assertTrue(eval("function f() { 'use strong' } 0 != 1"));
})();
Index: test/mjsunit/strong/use-strong.js
diff --git a/test/mjsunit/strong/use-strong.js
b/test/mjsunit/strong/use-strong.js
new file mode 100644
index
0000000000000000000000000000000000000000..7702e9ab4ef8e642118035663dfa4632a18c352f
--- /dev/null
+++ b/test/mjsunit/strong/use-strong.js
@@ -0,0 +1,27 @@
+// Copyright 2014 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: --strong-mode
+
+(function UseStrongScoping() {
+ assertThrows("'use strong'; 0 == 0", SyntaxError);
+ assertThrows("'use strong'; try {} catch(e) { { 0 == 0 } }",
SyntaxError);
+ assertThrows("function f() { 'use strong'; 0 == 0 }", SyntaxError);
+ assertThrows("'use strong'; function f() { 0 == 0 }", SyntaxError);
+ assertThrows("'use strong'; function f() { function g() { 0 == 0 } }",
SyntaxError);
+ assertThrows("'use strong'; eval('function f() { 0 == 0 }')",
SyntaxError);
+ assertTrue(eval("function f() { 'use strong' } 0 == 0"));
+ assertTrue(eval("eval('\'use strong\''); 0 == 0"));
+})();
+
+(function UseStrongMixed() {
+ assertThrows("'use strict'; 'use strong'; 0 == 0", SyntaxError);
+ assertThrows("'use strong'; 'use strict'; 0 == 0", SyntaxError);
+ assertThrows("'use strong'; 'use strong'; 0 == 0", SyntaxError);
+ assertThrows("'use strict'; function f() { 'use strong'; 0 == 0 }",
SyntaxError);
+ assertThrows("'use strong'; function f() { 'use strict'; 0 == 0 }",
SyntaxError);
+ assertTrue(eval("'use strict'; function f() { 'use strong' } 0 == 0"));
+ assertTrue(eval("var x; function f() { 'use strong' } delete x"));
+ assertThrows("'use strict'; var x; function f() { 'use strong' } delete
x", SyntaxError);
+})();
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.