Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 491053002: Add back the duplicate property checker (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/preparser.h ('k') | test/mjsunit/strict-mode.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2468 matching lines...) Expand 10 before | Expand all | Expand 10 after
2479 {"\"use strict\"; var myobject = {", "};"}, 2479 {"\"use strict\"; var myobject = {", "};"},
2480 {"\"use strict\"; var myobject = {", ",};"}, 2480 {"\"use strict\"; var myobject = {", ",};"},
2481 { NULL, NULL } 2481 { NULL, NULL }
2482 }; 2482 };
2483 const char* non_strict_context_data[][2] = { 2483 const char* non_strict_context_data[][2] = {
2484 {"var myobject = {", "};"}, 2484 {"var myobject = {", "};"},
2485 {"var myobject = {", ",};"}, 2485 {"var myobject = {", ",};"},
2486 { NULL, NULL } 2486 { NULL, NULL }
2487 }; 2487 };
2488 2488
2489 // ES6 allows duplicate properties even in strict mode. 2489 // These are only errors in strict mode.
2490 const char* statement_data[] = { 2490 const char* statement_data[] = {
2491 "foo: 1, foo: 2", 2491 "foo: 1, foo: 2",
2492 "\"foo\": 1, \"foo\": 2", 2492 "\"foo\": 1, \"foo\": 2",
2493 "foo: 1, \"foo\": 2", 2493 "foo: 1, \"foo\": 2",
2494 "1: 1, 1: 2", 2494 "1: 1, 1: 2",
2495 "1: 1, \"1\": 2", 2495 "1: 1, \"1\": 2",
2496 "get: 1, get: 2", // Not a getter for real, just a property called get. 2496 "get: 1, get: 2", // Not a getter for real, just a property called get.
2497 "set: 1, set: 2", // Not a setter for real, just a property called set. 2497 "set: 1, set: 2", // Not a setter for real, just a property called set.
2498 NULL 2498 NULL
2499 }; 2499 };
2500 2500
2501 RunParserSyncTest(non_strict_context_data, statement_data, kSuccess); 2501 RunParserSyncTest(non_strict_context_data, statement_data, kSuccess);
2502 RunParserSyncTest(strict_context_data, statement_data, kSuccess); 2502 RunParserSyncTest(strict_context_data, statement_data, kError);
2503 } 2503 }
2504 2504
2505 2505
2506 TEST(ErrorsObjectLiteralChecking) { 2506 TEST(ErrorsObjectLiteralChecking) {
2507 const char* context_data[][2] = { 2507 const char* context_data[][2] = {
2508 {"\"use strict\"; var myobject = {", "};"}, 2508 {"\"use strict\"; var myobject = {", "};"},
2509 {"var myobject = {", "};"}, 2509 {"var myobject = {", "};"},
2510 { NULL, NULL } 2510 { NULL, NULL }
2511 }; 2511 };
2512 2512
2513 const char* statement_data[] = { 2513 const char* statement_data[] = {
2514 ",", 2514 ",", "foo: 1, get foo() {}", "foo: 1, set foo(v) {}",
2515 // Wrong number of parameters 2515 "\"foo\": 1, get \"foo\"() {}", "\"foo\": 1, set \"foo\"(v) {}",
2516 "get bar(x) {}", 2516 "1: 1, get 1() {}", "1: 1, set 1() {}",
2517 "get bar(x, y) {}", 2517 // It's counter-intuitive, but these collide too (even in classic
2518 "set bar() {}", 2518 // mode). Note that we can have "foo" and foo as properties in classic
2519 "set bar(x, y) {}", 2519 // mode,
2520 // Parsing FunctionLiteral for getter or setter fails 2520 // but we cannot have "foo" and get foo, or foo and get "foo".
2521 "get foo( +", 2521 "foo: 1, get \"foo\"() {}", "foo: 1, set \"foo\"(v) {}",
2522 "get foo() \"error\"", 2522 "\"foo\": 1, get foo() {}", "\"foo\": 1, set foo(v) {}",
2523 NULL 2523 "1: 1, get \"1\"() {}", "1: 1, set \"1\"() {}",
2524 }; 2524 "\"1\": 1, get 1() {}"
2525 "\"1\": 1, set 1(v) {}"
2526 // Wrong number of parameters
2527 "get bar(x) {}",
2528 "get bar(x, y) {}", "set bar() {}", "set bar(x, y) {}",
2529 // Parsing FunctionLiteral for getter or setter fails
2530 "get foo( +", "get foo() \"error\"", NULL};
2525 2531
2526 RunParserSyncTest(context_data, statement_data, kError); 2532 RunParserSyncTest(context_data, statement_data, kError);
2527 } 2533 }
2528 2534
2529 2535
2530 TEST(NoErrorsObjectLiteralChecking) { 2536 TEST(NoErrorsObjectLiteralChecking) {
2531 const char* context_data[][2] = { 2537 const char* context_data[][2] = {
2532 {"var myobject = {", "};"}, 2538 {"var myobject = {", "};"},
2533 {"var myobject = {", ",};"}, 2539 {"var myobject = {", ",};"},
2534 {"\"use strict\"; var myobject = {", "};"}, 2540 {"\"use strict\"; var myobject = {", "};"},
(...skipping 23 matching lines...) Expand all
2558 "\"foo\": 1, set \"bar\"(v) {}", 2564 "\"foo\": 1, set \"bar\"(v) {}",
2559 "1: 1, get 2() {}", 2565 "1: 1, get 2() {}",
2560 "1: 1, set 2(v) {}", 2566 "1: 1, set 2(v) {}",
2561 // Keywords, future reserved and strict future reserved are also allowed as 2567 // Keywords, future reserved and strict future reserved are also allowed as
2562 // property names. 2568 // property names.
2563 "if: 4", 2569 "if: 4",
2564 "interface: 5", 2570 "interface: 5",
2565 "super: 6", 2571 "super: 6",
2566 "eval: 7", 2572 "eval: 7",
2567 "arguments: 8", 2573 "arguments: 8",
2568 // Duplicate property names are allowed in ES6.
2569 "foo: 1, get foo() {}",
2570 "foo: 1, set foo(v) {}",
2571 "\"foo\": 1, get \"foo\"() {}",
2572 "\"foo\": 1, set \"foo\"(v) {}",
2573 "1: 1, get 1() {}",
2574 "1: 1, set 1(v) {}",
2575 // It's counter-intuitive, but these collide too (even in classic
2576 // mode). Note that we can have "foo" and foo as properties in classic mode,
2577 // but we cannot have "foo" and get foo, or foo and get "foo".
2578 "foo: 1, get \"foo\"() {}",
2579 "foo: 1, set \"foo\"(v) {}",
2580 "\"foo\": 1, get foo() {}",
2581 "\"foo\": 1, set foo(v) {}",
2582 "1: 1, get \"1\"() {}",
2583 "1: 1, set \"1\"(v) {}",
2584 "\"1\": 1, get 1() {}",
2585 "\"1\": 1, set 1(v) {}",
2586 NULL 2574 NULL
2587 }; 2575 };
2588 2576
2589 RunParserSyncTest(context_data, statement_data, kSuccess); 2577 RunParserSyncTest(context_data, statement_data, kSuccess);
2590 } 2578 }
2591 2579
2592 2580
2593 TEST(TooManyArguments) { 2581 TEST(TooManyArguments) {
2594 const char* context_data[][2] = { 2582 const char* context_data[][2] = {
2595 {"foo(", "0)"}, 2583 {"foo(", "0)"},
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
3385 const char* statement_data[] = { 3373 const char* statement_data[] = {
3386 "super = x", 3374 "super = x",
3387 "y = super", 3375 "y = super",
3388 "f(super)", 3376 "f(super)",
3389 NULL}; 3377 NULL};
3390 3378
3391 static const ParserFlag always_flags[] = {kAllowClasses}; 3379 static const ParserFlag always_flags[] = {kAllowClasses};
3392 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, 3380 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
3393 always_flags, ARRAY_SIZE(always_flags)); 3381 always_flags, ARRAY_SIZE(always_flags));
3394 } 3382 }
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | test/mjsunit/strict-mode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698