2011-01-20 18:51:47 +00:00
|
|
|
// Copyright 2011 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.
|
|
|
|
|
|
|
|
function CheckStrictMode(code, exception) {
|
|
|
|
assertDoesNotThrow(code);
|
|
|
|
assertThrows("'use strict';\n" + code, exception);
|
|
|
|
assertThrows('"use strict";\n' + code, exception);
|
|
|
|
assertDoesNotThrow("\
|
|
|
|
function outer() {\
|
|
|
|
function inner() {\n"
|
|
|
|
+ code +
|
|
|
|
"\n}\
|
|
|
|
}");
|
|
|
|
assertThrows("\
|
|
|
|
function outer() {\
|
|
|
|
'use strict';\
|
|
|
|
function inner() {\n"
|
|
|
|
+ code +
|
|
|
|
"\n}\
|
|
|
|
}", exception);
|
|
|
|
}
|
|
|
|
|
2011-01-26 18:10:26 +00:00
|
|
|
function CheckFunctionConstructorStrictMode() {
|
|
|
|
var args = [];
|
|
|
|
for (var i = 0; i < arguments.length; i ++) {
|
|
|
|
args[i] = arguments[i];
|
|
|
|
}
|
|
|
|
// Create non-strict function. No exception.
|
|
|
|
args[arguments.length] = "";
|
|
|
|
assertDoesNotThrow(function() {
|
|
|
|
Function.apply(this, args);
|
|
|
|
});
|
|
|
|
// Create strict mode function. Exception expected.
|
|
|
|
args[arguments.length] = "'use strict';";
|
|
|
|
assertThrows(function() {
|
|
|
|
Function.apply(this, args);
|
|
|
|
}, SyntaxError);
|
|
|
|
}
|
|
|
|
|
2011-01-20 18:51:47 +00:00
|
|
|
// Incorrect 'use strict' directive.
|
2011-01-31 22:35:27 +00:00
|
|
|
(function UseStrictEscape() {
|
2011-01-20 18:51:47 +00:00
|
|
|
"use\\x20strict";
|
|
|
|
with ({}) {};
|
2011-01-31 22:35:27 +00:00
|
|
|
})();
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// 'use strict' in non-directive position.
|
2011-01-31 22:35:27 +00:00
|
|
|
(function UseStrictNonDirective() {
|
2011-01-20 18:51:47 +00:00
|
|
|
void(0);
|
|
|
|
"use strict";
|
|
|
|
with ({}) {};
|
2011-01-31 22:35:27 +00:00
|
|
|
})();
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// Multiple directives, including "use strict".
|
|
|
|
assertThrows('\
|
|
|
|
"directive 1";\
|
|
|
|
"another directive";\
|
|
|
|
"use strict";\
|
|
|
|
"directive after strict";\
|
|
|
|
"and one more";\
|
|
|
|
with({}) {}', SyntaxError);
|
|
|
|
|
|
|
|
// 'with' disallowed in strict mode.
|
|
|
|
CheckStrictMode("with({}) {}", SyntaxError);
|
|
|
|
|
|
|
|
// Function named 'eval'.
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function eval() {}", SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// Function named 'arguments'.
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function arguments() {}", SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// Function parameter named 'eval'.
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function foo(a, b, eval, c, d) {}", SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// Function parameter named 'arguments'.
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function foo(a, b, arguments, c, d) {}", SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// Property accessor parameter named 'eval'.
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("var o = { set foo(eval) {} }", SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// Property accessor parameter named 'arguments'.
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("var o = { set foo(arguments) {} }", SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// Duplicate function parameter name.
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function foo(a, b, c, d, b) {}", SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
2011-01-26 18:10:26 +00:00
|
|
|
// Function constructor: eval parameter name.
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckFunctionConstructorStrictMode("eval");
|
2011-01-26 18:10:26 +00:00
|
|
|
|
|
|
|
// Function constructor: arguments parameter name.
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckFunctionConstructorStrictMode("arguments");
|
2011-01-26 18:10:26 +00:00
|
|
|
|
|
|
|
// Function constructor: duplicate parameter name.
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckFunctionConstructorStrictMode("a", "b", "c", "b");
|
|
|
|
CheckFunctionConstructorStrictMode("a,b,c,b");
|
2011-01-26 18:10:26 +00:00
|
|
|
|
2011-01-20 18:51:47 +00:00
|
|
|
// catch(eval)
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("try{}catch(eval){};", SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// catch(arguments)
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("try{}catch(arguments){};", SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// var eval
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("var eval;", SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// var arguments
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("var arguments;", SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// Strict mode applies to the function in which the directive is used..
|
2011-01-25 17:21:45 +00:00
|
|
|
assertThrows('\
|
|
|
|
function foo(eval) {\
|
|
|
|
"use strict";\
|
|
|
|
}', SyntaxError);
|
2011-01-20 18:51:47 +00:00
|
|
|
|
|
|
|
// Strict mode doesn't affect the outer stop of strict code.
|
2011-01-31 22:35:27 +00:00
|
|
|
(function NotStrict(eval) {
|
2011-01-20 18:51:47 +00:00
|
|
|
function Strict() {
|
|
|
|
"use strict";
|
|
|
|
}
|
|
|
|
with ({}) {};
|
2011-01-31 22:35:27 +00:00
|
|
|
})();
|
2011-01-24 18:13:18 +00:00
|
|
|
|
|
|
|
// Octal literal
|
|
|
|
CheckStrictMode("var x = 012");
|
|
|
|
CheckStrictMode("012");
|
|
|
|
CheckStrictMode("'Hello octal\\032'");
|
|
|
|
CheckStrictMode("function octal() { return 012; }");
|
|
|
|
CheckStrictMode("function octal() { return '\\032'; }");
|
|
|
|
|
2011-01-31 22:35:27 +00:00
|
|
|
(function ValidEscape() {
|
|
|
|
"use strict";
|
|
|
|
var x = '\0';
|
|
|
|
var y = "\0";
|
|
|
|
})();
|
|
|
|
|
2011-01-24 18:13:18 +00:00
|
|
|
// Octal before "use strict"
|
|
|
|
assertThrows('\
|
|
|
|
function strict() {\
|
|
|
|
"octal\\032directive";\
|
|
|
|
"use strict";\
|
|
|
|
}', SyntaxError);
|
2011-01-25 18:42:35 +00:00
|
|
|
|
|
|
|
// Duplicate data properties.
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("var x = { dupe : 1, nondupe: 3, dupe : 2 };", SyntaxError);
|
|
|
|
CheckStrictMode("var x = { '1234' : 1, '2345' : 2, '1234' : 3 };", SyntaxError);
|
|
|
|
CheckStrictMode("var x = { '1234' : 1, '2345' : 2, 1234 : 3 };", SyntaxError);
|
|
|
|
CheckStrictMode("var x = { 3.14 : 1, 2.71 : 2, 3.14 : 3 };", SyntaxError);
|
|
|
|
CheckStrictMode("var x = { 3.14 : 1, '3.14' : 2 };", SyntaxError);
|
2011-02-14 18:44:26 +00:00
|
|
|
CheckStrictMode("var x = { \
|
|
|
|
123: 1, \
|
|
|
|
123.00000000000000000000000000000000000000000000000000000000000000000001: 2 \
|
|
|
|
}", SyntaxError);
|
2011-01-25 18:42:35 +00:00
|
|
|
|
|
|
|
// Non-conflicting data properties.
|
2011-01-31 22:35:27 +00:00
|
|
|
(function StrictModeNonDuplicate() {
|
2011-01-25 18:42:35 +00:00
|
|
|
"use strict";
|
|
|
|
var x = { 123 : 1, "0123" : 2 };
|
2011-02-14 18:44:26 +00:00
|
|
|
var x = {
|
|
|
|
123: 1,
|
|
|
|
'123.00000000000000000000000000000000000000000000000000000000000000000001':
|
|
|
|
2
|
|
|
|
};
|
2011-01-31 22:35:27 +00:00
|
|
|
})();
|
2011-01-25 18:42:35 +00:00
|
|
|
|
|
|
|
// Two getters (non-strict)
|
2011-01-31 22:35:27 +00:00
|
|
|
assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError);
|
|
|
|
assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError);
|
|
|
|
assertThrows("var x = { get 12(){}, get '12'(){}};", SyntaxError);
|
2011-01-25 18:42:35 +00:00
|
|
|
|
|
|
|
// Two setters (non-strict)
|
2011-01-31 22:35:27 +00:00
|
|
|
assertThrows("var x = { set foo(v) { }, set foo(v) { } };", SyntaxError);
|
|
|
|
assertThrows("var x = { set foo(v) { }, set 'foo'(v) { } };", SyntaxError);
|
|
|
|
assertThrows("var x = { set 13(v) { }, set '13'(v) { } };", SyntaxError);
|
2011-01-25 18:42:35 +00:00
|
|
|
|
|
|
|
// Setter and data (non-strict)
|
2011-01-31 22:35:27 +00:00
|
|
|
assertThrows("var x = { foo: 'data', set foo(v) { } };", SyntaxError);
|
|
|
|
assertThrows("var x = { set foo(v) { }, foo: 'data' };", SyntaxError);
|
|
|
|
assertThrows("var x = { foo: 'data', set 'foo'(v) { } };", SyntaxError);
|
|
|
|
assertThrows("var x = { set foo(v) { }, 'foo': 'data' };", SyntaxError);
|
|
|
|
assertThrows("var x = { 'foo': 'data', set foo(v) { } };", SyntaxError);
|
|
|
|
assertThrows("var x = { set 'foo'(v) { }, foo: 'data' };", SyntaxError);
|
|
|
|
assertThrows("var x = { 'foo': 'data', set 'foo'(v) { } };", SyntaxError);
|
|
|
|
assertThrows("var x = { set 'foo'(v) { }, 'foo': 'data' };", SyntaxError);
|
2011-01-25 18:42:35 +00:00
|
|
|
assertThrows("var x = { 12: 1, set '12'(v){}};", SyntaxError);
|
|
|
|
assertThrows("var x = { 12: 1, set 12(v){}};", SyntaxError);
|
|
|
|
assertThrows("var x = { '12': 1, set '12'(v){}};", SyntaxError);
|
|
|
|
assertThrows("var x = { '12': 1, set 12(v){}};", SyntaxError);
|
|
|
|
|
|
|
|
// Getter and data (non-strict)
|
2011-01-31 22:35:27 +00:00
|
|
|
assertThrows("var x = { foo: 'data', get foo() { } };", SyntaxError);
|
|
|
|
assertThrows("var x = { get foo() { }, foo: 'data' };", SyntaxError);
|
|
|
|
assertThrows("var x = { 'foo': 'data', get foo() { } };", SyntaxError);
|
|
|
|
assertThrows("var x = { get 'foo'() { }, 'foo': 'data' };", SyntaxError);
|
2011-01-25 18:42:35 +00:00
|
|
|
assertThrows("var x = { '12': 1, get '12'(){}};", SyntaxError);
|
|
|
|
assertThrows("var x = { '12': 1, get 12(){}};", SyntaxError);
|
2011-01-26 19:21:46 +00:00
|
|
|
|
|
|
|
// Assignment to eval or arguments
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function strict() { eval = undefined; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { arguments = undefined; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { print(eval = undefined); }", SyntaxError);
|
2011-02-14 18:44:26 +00:00
|
|
|
CheckStrictMode("function strict() { print(arguments = undefined); }",
|
|
|
|
SyntaxError);
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function strict() { var x = eval = undefined; }", SyntaxError);
|
2011-02-14 18:44:26 +00:00
|
|
|
CheckStrictMode("function strict() { var x = arguments = undefined; }",
|
|
|
|
SyntaxError);
|
2011-01-26 19:21:46 +00:00
|
|
|
|
|
|
|
// Compound assignment to eval or arguments
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function strict() { eval *= undefined; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { arguments /= undefined; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { print(eval %= undefined); }", SyntaxError);
|
2011-02-14 18:44:26 +00:00
|
|
|
CheckStrictMode("function strict() { print(arguments %= undefined); }",
|
|
|
|
SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = eval += undefined; }",
|
|
|
|
SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = arguments -= undefined; }",
|
|
|
|
SyntaxError);
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function strict() { eval <<= undefined; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { arguments >>= undefined; }", SyntaxError);
|
2011-02-14 18:44:26 +00:00
|
|
|
CheckStrictMode("function strict() { print(eval >>>= undefined); }",
|
|
|
|
SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { print(arguments &= undefined); }",
|
|
|
|
SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = eval ^= undefined; }",
|
|
|
|
SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = arguments |= undefined; }",
|
|
|
|
SyntaxError);
|
2011-01-26 19:21:46 +00:00
|
|
|
|
|
|
|
// Postfix increment with eval or arguments
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function strict() { eval++; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { arguments++; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { print(eval++); }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { print(arguments++); }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = eval++; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = arguments++; }", SyntaxError);
|
2011-01-26 19:21:46 +00:00
|
|
|
|
|
|
|
// Postfix decrement with eval or arguments
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function strict() { eval--; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { arguments--; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { print(eval--); }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { print(arguments--); }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = eval--; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = arguments--; }", SyntaxError);
|
2011-01-26 19:21:46 +00:00
|
|
|
|
|
|
|
// Prefix increment with eval or arguments
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function strict() { ++eval; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { ++arguments; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { print(++eval); }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { print(++arguments); }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = ++eval; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = ++arguments; }", SyntaxError);
|
2011-01-26 19:21:46 +00:00
|
|
|
|
|
|
|
// Prefix decrement with eval or arguments
|
2011-01-31 22:35:27 +00:00
|
|
|
CheckStrictMode("function strict() { --eval; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { --arguments; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { print(--eval); }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { print(--arguments); }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = --eval; }", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError);
|
2011-01-26 19:21:46 +00:00
|
|
|
|
2011-02-14 18:44:26 +00:00
|
|
|
// Delete of an unqialified identifier
|
|
|
|
CheckStrictMode("delete unqualified;", SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { delete unqualified; }", SyntaxError);
|
|
|
|
CheckStrictMode("function function_name() { delete function_name; }",
|
|
|
|
SyntaxError);
|
|
|
|
CheckStrictMode("function strict(parameter) { delete parameter; }",
|
|
|
|
SyntaxError);
|
|
|
|
CheckStrictMode("function strict() { var variable; delete variable; }",
|
|
|
|
SyntaxError);
|
|
|
|
CheckStrictMode("var variable; delete variable;", SyntaxError);
|
|
|
|
|
2011-01-26 19:21:46 +00:00
|
|
|
// Prefix unary operators other than delete, ++, -- are valid in strict mode
|
2011-01-31 22:35:27 +00:00
|
|
|
(function StrictModeUnaryOperators() {
|
2011-01-26 19:21:46 +00:00
|
|
|
"use strict";
|
|
|
|
var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval];
|
|
|
|
var y = [void arguments, typeof arguments,
|
|
|
|
+arguments, -arguments, ~arguments, !arguments];
|
2011-01-31 22:35:27 +00:00
|
|
|
})();
|
2011-02-04 18:36:37 +00:00
|
|
|
|
|
|
|
// 7.6.1.2 Future Reserved Words
|
|
|
|
var future_reserved_words = [
|
|
|
|
"class",
|
|
|
|
"enum",
|
|
|
|
"export",
|
|
|
|
"extends",
|
|
|
|
"import",
|
|
|
|
"super",
|
|
|
|
"implements",
|
|
|
|
"interface",
|
|
|
|
"let",
|
|
|
|
"package",
|
|
|
|
"private",
|
|
|
|
"protected",
|
|
|
|
"public",
|
|
|
|
"static",
|
|
|
|
"yield" ];
|
|
|
|
|
|
|
|
function testFutureReservedWord(word) {
|
|
|
|
// Simple use of each reserved word
|
|
|
|
CheckStrictMode("var " + word + " = 1;", SyntaxError);
|
|
|
|
|
|
|
|
// object literal properties
|
|
|
|
eval("var x = { " + word + " : 42 };");
|
|
|
|
eval("var x = { get " + word + " () {} };");
|
|
|
|
eval("var x = { set " + word + " (value) {} };");
|
|
|
|
|
|
|
|
// object literal with string literal property names
|
|
|
|
eval("var x = { '" + word + "' : 42 };");
|
|
|
|
eval("var x = { get '" + word + "' () { } };");
|
|
|
|
eval("var x = { set '" + word + "' (value) { } };");
|
|
|
|
eval("var x = { get '" + word + "' () { 'use strict'; } };");
|
|
|
|
eval("var x = { set '" + word + "' (value) { 'use strict'; } };");
|
|
|
|
|
|
|
|
// Function names and arguments, strict and non-strict contexts
|
|
|
|
CheckStrictMode("function " + word + " () {}", SyntaxError);
|
|
|
|
CheckStrictMode("function foo (" + word + ") {}", SyntaxError);
|
|
|
|
CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError);
|
|
|
|
CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError);
|
|
|
|
CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError);
|
|
|
|
CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError);
|
|
|
|
CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError);
|
|
|
|
|
|
|
|
// Function names and arguments when the body is strict
|
|
|
|
assertThrows("function " + word + " () { 'use strict'; }", SyntaxError);
|
|
|
|
assertThrows("function foo (" + word + ") 'use strict'; {}", SyntaxError);
|
2011-02-14 18:44:26 +00:00
|
|
|
assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }",
|
|
|
|
SyntaxError);
|
2011-02-04 18:36:37 +00:00
|
|
|
assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError);
|
|
|
|
assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError);
|
2011-02-14 18:44:26 +00:00
|
|
|
assertThrows("function foo (a, " + word + ", b) { 'use strict'; }",
|
|
|
|
SyntaxError);
|
|
|
|
assertThrows("var foo = function (" + word + ") { 'use strict'; }",
|
|
|
|
SyntaxError);
|
2011-02-04 18:36:37 +00:00
|
|
|
|
|
|
|
// get/set when the body is strict
|
|
|
|
eval("var x = { get " + word + " () { 'use strict'; } };");
|
|
|
|
eval("var x = { set " + word + " (value) { 'use strict'; } };");
|
2011-02-14 18:44:26 +00:00
|
|
|
assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };",
|
|
|
|
SyntaxError);
|
|
|
|
assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };",
|
|
|
|
SyntaxError);
|
2011-02-04 18:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < future_reserved_words.length; i++) {
|
|
|
|
testFutureReservedWord(future_reserved_words[i]);
|
|
|
|
}
|
|
|
|
|
2011-02-13 16:19:53 +00:00
|
|
|
function testAssignToUndefined(should_throw) {
|
|
|
|
"use strict";
|
|
|
|
try {
|
|
|
|
possibly_undefined_variable_for_strict_mode_test = "should throw?";
|
|
|
|
} catch (e) {
|
|
|
|
assertTrue(should_throw, "strict mode");
|
|
|
|
assertInstanceof(e, ReferenceError, "strict mode");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assertFalse(should_throw, "strict mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
testAssignToUndefined(true);
|
|
|
|
testAssignToUndefined(true);
|
|
|
|
testAssignToUndefined(true);
|
|
|
|
|
|
|
|
possibly_undefined_variable_for_strict_mode_test = "value";
|
|
|
|
|
|
|
|
testAssignToUndefined(false);
|
|
|
|
testAssignToUndefined(false);
|
|
|
|
testAssignToUndefined(false);
|
|
|
|
|
|
|
|
delete possibly_undefined_variable_for_strict_mode_test;
|
|
|
|
|
|
|
|
testAssignToUndefined(true);
|
|
|
|
testAssignToUndefined(true);
|
|
|
|
testAssignToUndefined(true);
|
|
|
|
|
|
|
|
function repeat(n, f) {
|
|
|
|
for (var i = 0; i < n; i ++) { f(); }
|
|
|
|
}
|
2011-02-04 18:36:37 +00:00
|
|
|
|
2011-02-13 16:19:53 +00:00
|
|
|
repeat(10, function() { testAssignToUndefined(true); });
|
|
|
|
possibly_undefined_variable_for_strict_mode_test = "value";
|
|
|
|
repeat(10, function() { testAssignToUndefined(false); });
|
|
|
|
delete possibly_undefined_variable_for_strict_mode_test;
|
|
|
|
repeat(10, function() { testAssignToUndefined(true); });
|
|
|
|
possibly_undefined_variable_for_strict_mode_test = undefined;
|
|
|
|
repeat(10, function() { testAssignToUndefined(false); });
|