OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 7199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7210 {"(function() { 'use strict'; {", "} })()"}, | 7210 {"(function() { 'use strict'; {", "} })()"}, |
7211 { NULL, NULL } | 7211 { NULL, NULL } |
7212 }; | 7212 }; |
7213 const char* sloppy_context[][2] = { | 7213 const char* sloppy_context[][2] = { |
7214 { "", "" }, | 7214 { "", "" }, |
7215 { "{", "}" }, | 7215 { "{", "}" }, |
7216 {"(function() {", "})()"}, | 7216 {"(function() {", "})()"}, |
7217 {"(function() { {", "} })()"}, | 7217 {"(function() { {", "} })()"}, |
7218 { NULL, NULL } | 7218 { NULL, NULL } |
7219 }; | 7219 }; |
| 7220 // Invalid in all contexts |
7220 const char* error_data[] = { | 7221 const char* error_data[] = { |
7221 "try function foo() {} catch (e) {}", | 7222 "try function foo() {} catch (e) {}", |
7222 NULL | 7223 NULL |
7223 }; | 7224 }; |
| 7225 // Valid in sloppy mode only, and only when the |
| 7226 // --harmony-restrictive-declarations flag is off |
7224 const char* unrestricted_data[] = { | 7227 const char* unrestricted_data[] = { |
7225 "do function foo() {} while (0);", | 7228 "do function foo() {} while (0);", |
7226 "for (;false;) function foo() {}", | 7229 "for (;false;) function foo() {}", |
7227 "for (var i = 0; i < 1; i++) function f() { };", | 7230 "for (var i = 0; i < 1; i++) function f() { };", |
7228 "for (var x in {a: 1}) function f() { };", | 7231 "for (var x in {a: 1}) function f() { };", |
7229 "for (var x in {}) function f() { };", | 7232 "for (var x in {}) function f() { };", |
7230 "for (var x in {}) function foo() {}", | 7233 "for (var x in {}) function foo() {}", |
7231 "for (x in {a: 1}) function f() { };", | 7234 "for (x in {a: 1}) function f() { };", |
7232 "for (x in {}) function f() { };", | 7235 "for (x in {}) function f() { };", |
7233 "var x; for (x in {}) function foo() {}", | 7236 "var x; for (x in {}) function foo() {}", |
7234 "with ({}) function f() { };", | 7237 "with ({}) function f() { };", |
| 7238 "do label: function foo() {} while (0);", |
| 7239 "for (;false;) label: function foo() {}", |
| 7240 "for (var i = 0; i < 1; i++) label: function f() { };", |
| 7241 "for (var x in {a: 1}) label: function f() { };", |
| 7242 "for (var x in {}) label: function f() { };", |
| 7243 "for (var x in {}) label: function foo() {}", |
| 7244 "for (x in {a: 1}) label: function f() { };", |
| 7245 "for (x in {}) label: function f() { };", |
| 7246 "var x; for (x in {}) label: function foo() {}", |
| 7247 "with ({}) label: function f() { };", |
| 7248 "if (true) label: function f() {}", |
| 7249 "if (true) {} else label: function f() {}", |
7235 NULL | 7250 NULL |
7236 }; | 7251 }; |
| 7252 // Valid only in sloppy mode, with or without |
| 7253 // --harmony-restrictive-declarations |
7237 const char* sloppy_data[] = { | 7254 const char* sloppy_data[] = { |
7238 "if (true) function foo() {}", | 7255 "if (true) function foo() {}", |
7239 "if (false) {} else function f() { };", | 7256 "if (false) {} else function f() { };", |
7240 "label: function f() { }", | 7257 "label: function f() { }", |
7241 "label: if (true) function f() { }", | 7258 "label: if (true) function f() { }", |
7242 "label: if (true) {} else function f() { }", | 7259 "label: if (true) {} else function f() { }", |
7243 "if (true) label: function f() {}", | |
7244 "if (true) {} else label: function f() {}", | |
7245 NULL | 7260 NULL |
7246 }; | 7261 }; |
7247 // clang-format on | 7262 // clang-format on |
7248 | 7263 |
7249 static const ParserFlag restrictive_flags[] = { | 7264 static const ParserFlag restrictive_flags[] = { |
7250 kAllowHarmonyRestrictiveDeclarations}; | 7265 kAllowHarmonyRestrictiveDeclarations}; |
7251 | 7266 |
| 7267 // Nothing parses in strict mode without a SyntaxError |
7252 RunParserSyncTest(strict_context, error_data, kError); | 7268 RunParserSyncTest(strict_context, error_data, kError); |
7253 RunParserSyncTest(strict_context, error_data, kError, NULL, 0, | 7269 RunParserSyncTest(strict_context, error_data, kError, NULL, 0, |
7254 restrictive_flags, arraysize(restrictive_flags)); | 7270 restrictive_flags, arraysize(restrictive_flags)); |
7255 RunParserSyncTest(strict_context, unrestricted_data, kError); | 7271 RunParserSyncTest(strict_context, unrestricted_data, kError); |
7256 RunParserSyncTest(strict_context, unrestricted_data, kError, NULL, 0, | 7272 RunParserSyncTest(strict_context, unrestricted_data, kError, NULL, 0, |
7257 restrictive_flags, arraysize(restrictive_flags)); | 7273 restrictive_flags, arraysize(restrictive_flags)); |
7258 RunParserSyncTest(strict_context, sloppy_data, kError); | 7274 RunParserSyncTest(strict_context, sloppy_data, kError); |
7259 RunParserSyncTest(strict_context, sloppy_data, kError, NULL, 0, | 7275 RunParserSyncTest(strict_context, sloppy_data, kError, NULL, 0, |
7260 restrictive_flags, arraysize(restrictive_flags)); | 7276 restrictive_flags, arraysize(restrictive_flags)); |
7261 | 7277 |
| 7278 // In sloppy mode, some things are successful, depending on the flag |
7262 RunParserSyncTest(sloppy_context, error_data, kError); | 7279 RunParserSyncTest(sloppy_context, error_data, kError); |
7263 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0, | 7280 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0, |
7264 restrictive_flags, arraysize(restrictive_flags)); | 7281 restrictive_flags, arraysize(restrictive_flags)); |
7265 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess); | 7282 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess); |
7266 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0, | 7283 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0, |
7267 restrictive_flags, arraysize(restrictive_flags)); | 7284 restrictive_flags, arraysize(restrictive_flags)); |
7268 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess); | 7285 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess); |
7269 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags, | 7286 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags, |
7270 arraysize(restrictive_flags)); | 7287 arraysize(restrictive_flags)); |
7271 } | 7288 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7354 // "Array() **= 10", | 7371 // "Array() **= 10", |
7355 NULL | 7372 NULL |
7356 }; | 7373 }; |
7357 // clang-format on | 7374 // clang-format on |
7358 | 7375 |
7359 static const ParserFlag always_flags[] = { | 7376 static const ParserFlag always_flags[] = { |
7360 kAllowHarmonyExponentiationOperator}; | 7377 kAllowHarmonyExponentiationOperator}; |
7361 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, | 7378 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, |
7362 arraysize(always_flags)); | 7379 arraysize(always_flags)); |
7363 } | 7380 } |
OLD | NEW |