Chromium Code Reviews| Index: test/mjsunit/strong/undefined.js |
| diff --git a/test/mjsunit/strong/undefined.js b/test/mjsunit/strong/undefined.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..275e2ab0209411299a249b60d035f0d4fbc8cf2e |
| --- /dev/null |
| +++ b/test/mjsunit/strong/undefined.js |
| @@ -0,0 +1,104 @@ |
| +// 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 |
| + |
| +//repurposing the strict mode 'eval' and 'arguments' tests to test for correct |
|
rossberg
2015/04/08 11:30:11
Style nit: Spaces after // (here and below). Also,
conradw
2015/04/09 12:24:17
Done.
|
| +//behaviour of 'undefined' as an identifier in strong mode |
|
rossberg
2015/04/08 11:30:11
Please add tests for:
- bindings to undefined (va
conradw
2015/04/09 12:24:17
Done.
|
| + |
| +function CheckStrongMode(code, exception) { |
| + assertDoesNotThrow("'use strict';\n" + code); |
| + assertThrows("'use strong';\n" + code, exception); |
| + assertThrows('"use strong";\n' + code, exception); |
| + assertDoesNotThrow("\ |
| + function outer() {\ |
| + 'use strict';\ |
| + function inner() {\n" |
| + + code + |
| + "\n}\ |
| + }"); |
| + assertThrows("\ |
| + function outer() {\ |
| + 'use strong';\ |
| + function inner() {\n" |
| + + code + |
| + "\n}\ |
| + }", exception); |
| +} |
|
rossberg
2015/04/08 11:30:11
We also should have test contexts that are (strict
conradw
2015/04/09 12:24:17
Done.
|
| + |
| +function CheckFunctionConstructorStrongMode() { |
| + var args = []; |
| + for (var i = 0; i < arguments.length; i ++) { |
|
rossberg
2015/04/08 11:30:11
With adding --harmony-rest-parameters to Flags you
conradw
2015/04/09 12:24:17
Acknowledged.
|
| + args[i] = arguments[i]; |
| + } |
| + // Create non-strong function. No exception. |
| + args[arguments.length] = ""; |
| + assertDoesNotThrow(function() { |
| + Function.apply(this, args); |
| + }); |
| + // Create strong mode function. Exception expected. |
| + args[arguments.length] = "'use strong';"; |
| + assertThrows(function() { |
| + Function.apply(this, args); |
| + }, SyntaxError); |
| +} |
| + |
| +//Function named 'undefined'. |
| +CheckStrongMode("function undefined() {}", SyntaxError); |
| + |
| +// Function parameter named 'undefined'. |
| +CheckStrongMode("function foo(a, b, undefined, c, d) {}", SyntaxError); |
| + |
| +// Property accessor parameter named 'undefined'. |
| +CheckStrongMode("let o = { set foo(undefined) {} }", SyntaxError); |
| + |
| +//Function constructor: 'undefined' parameter name. |
| +CheckFunctionConstructorStrongMode("undefined"); |
| + |
| +//catch(undefined) |
| +CheckStrongMode("try{}catch(undefined){};", SyntaxError); |
| + |
| +//Assignment to undefined |
| +CheckStrongMode("function strong() { undefined = undefined; }", SyntaxError); |
| +CheckStrongMode("function strong() { print(undefined = undefined); }", SyntaxError); |
|
rossberg
2015/04/08 11:30:11
Style nit: line length (here and below)
conradw
2015/04/09 12:24:17
Done.
|
| +CheckStrongMode("function strong() { let x = undefined = undefined; }", SyntaxError); |
| + |
| +// Compound assignment to undefined |
| +CheckStrongMode("function strong() { undefined *= undefined; }", SyntaxError); |
| +CheckStrongMode("function strong() { undefined /= undefined; }", SyntaxError); |
| +CheckStrongMode("function strong() { print(undefined %= undefined); }", SyntaxError); |
| +CheckStrongMode("function strong() { let x = undefined += undefined; }", |
| + SyntaxError); |
| +CheckStrongMode("function strong() { let x = undefined -= undefined; }", |
| + SyntaxError); |
| +CheckStrongMode("function strong() { undefined <<= undefined; }", SyntaxError); |
| +CheckStrongMode("function strong() { undefined >>= undefined; }", SyntaxError); |
| +CheckStrongMode("function strong() { print(undefined >>>= undefined); }", |
| + SyntaxError); |
| +CheckStrongMode("function strong() { print(undefined &= undefined); }", |
| + SyntaxError); |
| +CheckStrongMode("function strong() { let x = undefined ^= undefined; }", |
| + SyntaxError); |
| +CheckStrongMode("function strong() { let x = undefined |= undefined; }", |
| + SyntaxError); |
| + |
| +// Postfix increment with undefined |
| +CheckStrongMode("function strong() { undefined++; }", SyntaxError); |
| +CheckStrongMode("function strong() { print(undefined++); }", SyntaxError); |
| +CheckStrongMode("function strong() { let x = undefined++; }", SyntaxError); |
| + |
| +// Postfix decrement with undefined |
| +CheckStrongMode("function strong() { undefined--; }", SyntaxError); |
| +CheckStrongMode("function strong() { print(undefined--); }", SyntaxError); |
| +CheckStrongMode("function strong() { let x = undefined--; }", SyntaxError); |
| + |
| +// Prefix increment with undefined |
| +CheckStrongMode("function strong() { ++undefined; }", SyntaxError); |
| +CheckStrongMode("function strong() { print(++undefined); }", SyntaxError); |
| +CheckStrongMode("function strong() { let x = ++undefined; }", SyntaxError); |
| + |
| +// Prefix decrement with undefined |
| +CheckStrongMode("function strong() { --undefined; }", SyntaxError); |
| +CheckStrongMode("function strong() { print(--undefined); }", SyntaxError); |
| +CheckStrongMode("function strong() { let x = --undefined; }", SyntaxError); |