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"],
strong_var: ["Please don't use 'var' in strong mode, use 'let' or 'const' 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."],
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.
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 }
};
};
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,
--- /dev/null
+// 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);
+})();
(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"));
})();
--- /dev/null
+// 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);
+})();