OLD | NEW |
1 description("Tests to ensure that we can use ES reserved words as property names
."); | 1 description("Tests to ensure that we can use ES reserved words as property names
."); |
2 | 2 |
3 var reservedWords = ["true", "false", "null", "break", "case", "catch", "continu
e", "debugger", "default", "delete", "do", "else", "finally", "for", | 3 var reservedWords = ["true", "false", "null", "break", "case", "catch", "continu
e", "debugger", "default", "delete", "do", "else", "finally", "for", |
4 "function", "if", "in", "instanceof", "new", "return", "swi
tch", "this", "throw", "try", "typeof", "var", "void", "while", "with", | 4 "function", "if", "in", "instanceof", "new", "return", "swi
tch", "this", "throw", "try", "typeof", "var", "void", "while", "with", |
5 "class", "const", "enum", "export", "extends", "import", "s
uper"]; | 5 "class", "const", "enum", "export", "extends", "import", "s
uper"]; |
6 | 6 |
7 var strictReservedWords = [ | 7 var strictReservedWords = [ |
8 "implements", | 8 "implements", |
9 "let", | 9 "let", |
10 "private", | 10 "private", |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 function testWord(word, strictPrefix, expectedResult) { | 49 function testWord(word, strictPrefix, expectedResult) { |
50 testWordEvalAndFunction(strictPrefix + "var " + word + "; true", expectedRes
ult); | 50 testWordEvalAndFunction(strictPrefix + "var " + word + "; true", expectedRes
ult); |
51 testWordEvalAndFunction(strictPrefix + "var " + word + " = 42; " + word + "
=== 42", expectedResult); | 51 testWordEvalAndFunction(strictPrefix + "var " + word + " = 42; " + word + "
=== 42", expectedResult); |
52 testWordEvalAndFunction(strictPrefix + "function g(" + word + "){ " + strict
Prefix + " }; true", expectedResult); | 52 testWordEvalAndFunction(strictPrefix + "function g(" + word + "){ " + strict
Prefix + " }; true", expectedResult); |
53 testWordEvalAndFunction(strictPrefix + "/" + word + "/.test(function g(" + w
ord + "){ " + strictPrefix + " })", expectedResult); | 53 testWordEvalAndFunction(strictPrefix + "/" + word + "/.test(function g(" + w
ord + "){ " + strictPrefix + " })", expectedResult); |
54 testWordEvalAndFunction(strictPrefix + "try{}catch(" + word + "){}; true", e
xpectedResult); | 54 testWordEvalAndFunction(strictPrefix + "try{}catch(" + word + "){}; true", e
xpectedResult); |
55 testWordEvalAndFunction(strictPrefix + "function " + word + "(){ " + strictP
refix + " }; true", expectedResult); | 55 testWordEvalAndFunction(strictPrefix + "function " + word + "(){ " + strictP
refix + " }; true", expectedResult); |
56 // These should be allowed for all words, even reserved ones. | 56 // These should be allowed for all words, even reserved ones. |
57 testWordEvalAndFunction(strictPrefix + "({ \"" + word + "\": 42 }." + word +
" === 42)", false); | 57 testWordEvalAndFunction(strictPrefix + "({ \"" + word + "\": 42 }." + word +
" === 42)", false); |
58 testWordEvalAndFunction(strictPrefix + "({ " + word + ": 42 }." + word + " =
== 42)", false); | 58 testWordEvalAndFunction(strictPrefix + "({ " + word + ": 42 }." + word + " =
== 42)", false); |
59 testWordEvalAndFunction(strictPrefix + "({ get " + word + "(){}, set " + wor
d + "(){}, parsedOkay: 42 }.parsedOkay === 42)", false); | 59 testWordEvalAndFunction(strictPrefix + "({ get " + word + "(){}, set " + wor
d + "(_){}, parsedOkay: 42 }.parsedOkay === 42)", false); |
60 } | 60 } |
61 | 61 |
62 function testWordStrictAndNonStrict(word, condition) { | 62 function testWordStrictAndNonStrict(word, condition) { |
63 testWord(word, '', condition == "keyword"); | 63 testWord(word, '', condition == "keyword"); |
64 testWord(word, '"use strict";', condition != "identifier"); | 64 testWord(word, '"use strict";', condition != "identifier"); |
65 } | 65 } |
66 | 66 |
67 for (var i = 0; i < reservedWords.length; i++) | 67 for (var i = 0; i < reservedWords.length; i++) |
68 testWordStrictAndNonStrict(reservedWords[i], "keyword"); | 68 testWordStrictAndNonStrict(reservedWords[i], "keyword"); |
69 for (var i = 0; i < strictReservedWords.length; i++) | 69 for (var i = 0; i < strictReservedWords.length; i++) |
70 testWordStrictAndNonStrict(strictReservedWords[i], "strict"); | 70 testWordStrictAndNonStrict(strictReservedWords[i], "strict"); |
71 for (var i = 0; i < unreservedWords.length; i++) | 71 for (var i = 0; i < unreservedWords.length; i++) |
72 testWordStrictAndNonStrict(unreservedWords[i], "identifier"); | 72 testWordStrictAndNonStrict(unreservedWords[i], "identifier"); |
73 | 73 |
74 // test access via window. | 74 // test access via window. |
75 var yield = 42; | 75 var yield = 42; |
76 shouldBeTrue("window.yield === 42"); | 76 shouldBeTrue("window.yield === 42"); |
OLD | NEW |