| 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 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 | 1370 |
| 1371 | 1371 |
| 1372 enum ParserFlag { | 1372 enum ParserFlag { |
| 1373 kAllowLazy, | 1373 kAllowLazy, |
| 1374 kAllowNatives, | 1374 kAllowNatives, |
| 1375 kAllowHarmonyModules, | 1375 kAllowHarmonyModules, |
| 1376 kAllowHarmonyArrowFunctions, | 1376 kAllowHarmonyArrowFunctions, |
| 1377 kAllowHarmonyClasses, | 1377 kAllowHarmonyClasses, |
| 1378 kAllowHarmonyObjectLiterals, | 1378 kAllowHarmonyObjectLiterals, |
| 1379 kAllowHarmonyRestParameters, | 1379 kAllowHarmonyRestParameters, |
| 1380 kAllowHarmonyNewTarget, |
| 1380 kAllowHarmonySloppy, | 1381 kAllowHarmonySloppy, |
| 1381 kAllowHarmonyUnicode, | 1382 kAllowHarmonyUnicode, |
| 1382 kAllowHarmonyComputedPropertyNames, | 1383 kAllowHarmonyComputedPropertyNames, |
| 1383 kAllowStrongMode, | 1384 kAllowStrongMode, |
| 1384 kAllowHarmonySpreadCalls | 1385 kAllowHarmonySpreadCalls |
| 1385 }; | 1386 }; |
| 1386 | 1387 |
| 1387 | 1388 |
| 1388 enum ParserSyncTestResult { | 1389 enum ParserSyncTestResult { |
| 1389 kSuccessOrError, | 1390 kSuccessOrError, |
| 1390 kSuccess, | 1391 kSuccess, |
| 1391 kError | 1392 kError |
| 1392 }; | 1393 }; |
| 1393 | 1394 |
| 1394 template <typename Traits> | 1395 template <typename Traits> |
| 1395 void SetParserFlags(i::ParserBase<Traits>* parser, | 1396 void SetParserFlags(i::ParserBase<Traits>* parser, |
| 1396 i::EnumSet<ParserFlag> flags) { | 1397 i::EnumSet<ParserFlag> flags) { |
| 1397 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1398 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
| 1398 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1399 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
| 1399 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); | 1400 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); |
| 1400 parser->set_allow_harmony_object_literals( | 1401 parser->set_allow_harmony_object_literals( |
| 1401 flags.Contains(kAllowHarmonyObjectLiterals)); | 1402 flags.Contains(kAllowHarmonyObjectLiterals)); |
| 1402 parser->set_allow_harmony_arrow_functions( | 1403 parser->set_allow_harmony_arrow_functions( |
| 1403 flags.Contains(kAllowHarmonyArrowFunctions)); | 1404 flags.Contains(kAllowHarmonyArrowFunctions)); |
| 1404 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); | 1405 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); |
| 1405 parser->set_allow_harmony_rest_params( | 1406 parser->set_allow_harmony_rest_params( |
| 1406 flags.Contains(kAllowHarmonyRestParameters)); | 1407 flags.Contains(kAllowHarmonyRestParameters)); |
| 1408 parser->set_allow_harmony_new_target(flags.Contains(kAllowHarmonyNewTarget)); |
| 1407 parser->set_allow_harmony_spreadcalls( | 1409 parser->set_allow_harmony_spreadcalls( |
| 1408 flags.Contains(kAllowHarmonySpreadCalls)); | 1410 flags.Contains(kAllowHarmonySpreadCalls)); |
| 1409 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | 1411 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
| 1410 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); | 1412 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); |
| 1411 parser->set_allow_harmony_computed_property_names( | 1413 parser->set_allow_harmony_computed_property_names( |
| 1412 flags.Contains(kAllowHarmonyComputedPropertyNames)); | 1414 flags.Contains(kAllowHarmonyComputedPropertyNames)); |
| 1413 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); | 1415 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); |
| 1414 } | 1416 } |
| 1415 | 1417 |
| 1416 | 1418 |
| (...skipping 4822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6239 v8::Script::Compile(v8_str(script3)); | 6241 v8::Script::Compile(v8_str(script3)); |
| 6240 CHECK(try_catch2.HasCaught()); | 6242 CHECK(try_catch2.HasCaught()); |
| 6241 v8::String::Utf8Value exception(try_catch2.Exception()); | 6243 v8::String::Utf8Value exception(try_catch2.Exception()); |
| 6242 CHECK_EQ(0, | 6244 CHECK_EQ(0, |
| 6243 strcmp( | 6245 strcmp( |
| 6244 "ReferenceError: In strong mode, using an undeclared global " | 6246 "ReferenceError: In strong mode, using an undeclared global " |
| 6245 "variable 'not_there3' is not allowed", | 6247 "variable 'not_there3' is not allowed", |
| 6246 *exception)); | 6248 *exception)); |
| 6247 } | 6249 } |
| 6248 } | 6250 } |
| 6251 |
| 6252 |
| 6253 TEST(NewTarget) { |
| 6254 const char* bad_context_data[][2] = {{"", ""}, {"'use strict';", ""}, {NULL}}; |
| 6255 const char* good_context_data[][2] = { |
| 6256 {"function f() {", "}"}, |
| 6257 {"'use strict'; function f() {", "}"}, |
| 6258 {"var f = function() {", "}"}, |
| 6259 {"'use strict'; var f = function() {", "}"}, |
| 6260 {"({m: function() {", "}})"}, |
| 6261 {"'use strict'; ({m: function() {", "}})"}, |
| 6262 {"({m() {", "}})"}, |
| 6263 {"'use strict'; ({m() {", "}})"}, |
| 6264 {"({get x() {", "}})"}, |
| 6265 {"'use strict'; ({get x() {", "}})"}, |
| 6266 {"({set x(_) {", "}})"}, |
| 6267 {"'use strict'; ({set x(_) {", "}})"}, |
| 6268 {"class C {m() {", "}}"}, |
| 6269 {"class C {get x() {", "}}"}, |
| 6270 {"class C {set x(_) {", "}}"}, |
| 6271 {NULL}}; |
| 6272 |
| 6273 const char* data[] = {"new.target", "{ new.target }", "() => { new.target }", |
| 6274 "() => new.target", "if (1) { new.target }", |
| 6275 "if (1) {} else { new.target }", |
| 6276 "while (0) { new.target }", |
| 6277 "do { new.target } while (0)", NULL}; |
| 6278 |
| 6279 static const ParserFlag always_flags[] = { |
| 6280 kAllowHarmonyArrowFunctions, kAllowHarmonyClasses, kAllowHarmonyNewTarget, |
| 6281 kAllowHarmonyObjectLiterals, kAllowHarmonySloppy, |
| 6282 }; |
| 6283 |
| 6284 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, |
| 6285 arraysize(always_flags)); |
| 6286 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, |
| 6287 arraysize(always_flags)); |
| 6288 } |
| OLD | NEW |