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 2464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2475 {"\"use strict\"; var myobject = {", "};"}, | 2475 {"\"use strict\"; var myobject = {", "};"}, |
2476 {"\"use strict\"; var myobject = {", ",};"}, | 2476 {"\"use strict\"; var myobject = {", ",};"}, |
2477 { NULL, NULL } | 2477 { NULL, NULL } |
2478 }; | 2478 }; |
2479 const char* non_strict_context_data[][2] = { | 2479 const char* non_strict_context_data[][2] = { |
2480 {"var myobject = {", "};"}, | 2480 {"var myobject = {", "};"}, |
2481 {"var myobject = {", ",};"}, | 2481 {"var myobject = {", ",};"}, |
2482 { NULL, NULL } | 2482 { NULL, NULL } |
2483 }; | 2483 }; |
2484 | 2484 |
2485 // These are only errors in strict mode. | 2485 // ES6 allows duplicate properties even in strict mode. |
2486 const char* statement_data[] = { | 2486 const char* statement_data[] = { |
2487 "foo: 1, foo: 2", | 2487 "foo: 1, foo: 2", |
2488 "\"foo\": 1, \"foo\": 2", | 2488 "\"foo\": 1, \"foo\": 2", |
2489 "foo: 1, \"foo\": 2", | 2489 "foo: 1, \"foo\": 2", |
2490 "1: 1, 1: 2", | 2490 "1: 1, 1: 2", |
2491 "1: 1, \"1\": 2", | 2491 "1: 1, \"1\": 2", |
2492 "get: 1, get: 2", // Not a getter for real, just a property called get. | 2492 "get: 1, get: 2", // Not a getter for real, just a property called get. |
2493 "set: 1, set: 2", // Not a setter for real, just a property called set. | 2493 "set: 1, set: 2", // Not a setter for real, just a property called set. |
2494 NULL | 2494 NULL |
2495 }; | 2495 }; |
2496 | 2496 |
2497 RunParserSyncTest(non_strict_context_data, statement_data, kSuccess); | 2497 RunParserSyncTest(non_strict_context_data, statement_data, kSuccess); |
2498 RunParserSyncTest(strict_context_data, statement_data, kError); | 2498 RunParserSyncTest(strict_context_data, statement_data, kSuccess); |
2499 } | 2499 } |
2500 | 2500 |
2501 | 2501 |
2502 TEST(ErrorsObjectLiteralChecking) { | 2502 TEST(ErrorsObjectLiteralChecking) { |
2503 const char* context_data[][2] = { | 2503 const char* context_data[][2] = { |
2504 {"\"use strict\"; var myobject = {", "};"}, | 2504 {"\"use strict\"; var myobject = {", "};"}, |
2505 {"var myobject = {", "};"}, | 2505 {"var myobject = {", "};"}, |
2506 { NULL, NULL } | 2506 { NULL, NULL } |
2507 }; | 2507 }; |
2508 | 2508 |
2509 const char* statement_data[] = { | 2509 const char* statement_data[] = { |
2510 ",", | 2510 ",", |
2511 "foo: 1, get foo() {}", | |
2512 "foo: 1, set foo(v) {}", | |
2513 "\"foo\": 1, get \"foo\"() {}", | |
2514 "\"foo\": 1, set \"foo\"(v) {}", | |
2515 "1: 1, get 1() {}", | |
2516 "1: 1, set 1() {}", | |
2517 // It's counter-intuitive, but these collide too (even in classic | |
2518 // mode). Note that we can have "foo" and foo as properties in classic mode, | |
2519 // but we cannot have "foo" and get foo, or foo and get "foo". | |
2520 "foo: 1, get \"foo\"() {}", | |
2521 "foo: 1, set \"foo\"(v) {}", | |
2522 "\"foo\": 1, get foo() {}", | |
2523 "\"foo\": 1, set foo(v) {}", | |
2524 "1: 1, get \"1\"() {}", | |
2525 "1: 1, set \"1\"() {}", | |
2526 "\"1\": 1, get 1() {}" | |
2527 "\"1\": 1, set 1(v) {}" | |
2528 // Wrong number of parameters | 2511 // Wrong number of parameters |
2529 "get bar(x) {}", | 2512 "get bar(x) {}", |
2530 "get bar(x, y) {}", | 2513 "get bar(x, y) {}", |
2531 "set bar() {}", | 2514 "set bar() {}", |
2532 "set bar(x, y) {}", | 2515 "set bar(x, y) {}", |
2533 // Parsing FunctionLiteral for getter or setter fails | 2516 // Parsing FunctionLiteral for getter or setter fails |
2534 "get foo( +", | 2517 "get foo( +", |
2535 "get foo() \"error\"", | 2518 "get foo() \"error\"", |
2536 NULL | 2519 NULL |
2537 }; | 2520 }; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2571 "\"foo\": 1, set \"bar\"(v) {}", | 2554 "\"foo\": 1, set \"bar\"(v) {}", |
2572 "1: 1, get 2() {}", | 2555 "1: 1, get 2() {}", |
2573 "1: 1, set 2(v) {}", | 2556 "1: 1, set 2(v) {}", |
2574 // Keywords, future reserved and strict future reserved are also allowed as | 2557 // Keywords, future reserved and strict future reserved are also allowed as |
2575 // property names. | 2558 // property names. |
2576 "if: 4", | 2559 "if: 4", |
2577 "interface: 5", | 2560 "interface: 5", |
2578 "super: 6", | 2561 "super: 6", |
2579 "eval: 7", | 2562 "eval: 7", |
2580 "arguments: 8", | 2563 "arguments: 8", |
| 2564 // Duplicate property names are allowed in ES6. |
| 2565 "foo: 1, get foo() {}", |
| 2566 "foo: 1, set foo(v) {}", |
| 2567 "\"foo\": 1, get \"foo\"() {}", |
| 2568 "\"foo\": 1, set \"foo\"(v) {}", |
| 2569 "1: 1, get 1() {}", |
| 2570 "1: 1, set 1(v) {}", |
| 2571 // It's counter-intuitive, but these collide too (even in classic |
| 2572 // mode). Note that we can have "foo" and foo as properties in classic mode, |
| 2573 // but we cannot have "foo" and get foo, or foo and get "foo". |
| 2574 "foo: 1, get \"foo\"() {}", |
| 2575 "foo: 1, set \"foo\"(v) {}", |
| 2576 "\"foo\": 1, get foo() {}", |
| 2577 "\"foo\": 1, set foo(v) {}", |
| 2578 "1: 1, get \"1\"() {}", |
| 2579 "1: 1, set \"1\"(v) {}", |
| 2580 "\"1\": 1, get 1() {}", |
| 2581 "\"1\": 1, set 1(v) {}", |
2581 NULL | 2582 NULL |
2582 }; | 2583 }; |
2583 | 2584 |
2584 RunParserSyncTest(context_data, statement_data, kSuccess); | 2585 RunParserSyncTest(context_data, statement_data, kSuccess); |
2585 } | 2586 } |
2586 | 2587 |
2587 | 2588 |
2588 TEST(TooManyArguments) { | 2589 TEST(TooManyArguments) { |
2589 const char* context_data[][2] = { | 2590 const char* context_data[][2] = { |
2590 {"foo(", "0)"}, | 2591 {"foo(", "0)"}, |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3336 | 3337 |
3337 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) | 3338 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) |
3338 "foo ? bar : baz => {}", | 3339 "foo ? bar : baz => {}", |
3339 NULL | 3340 NULL |
3340 }; | 3341 }; |
3341 | 3342 |
3342 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; | 3343 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; |
3343 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3344 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
3344 always_flags, ARRAY_SIZE(always_flags)); | 3345 always_flags, ARRAY_SIZE(always_flags)); |
3345 } | 3346 } |
OLD | NEW |