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

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

Issue 873823003: Move object literal checking into checker classes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix assert Created 5 years, 10 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
« no previous file with comments | « src/x87/full-codegen-x87.cc ('k') | test/mjsunit/object-literal-multiple-proto-fields.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 2669 matching lines...) Expand 10 before | Expand all | Expand 10 after
2680 "new ++foo", 2680 "new ++foo",
2681 "new foo ++", 2681 "new foo ++",
2682 NULL 2682 NULL
2683 }; 2683 };
2684 2684
2685 RunParserSyncTest(context_data, statement_data, kError); 2685 RunParserSyncTest(context_data, statement_data, kError);
2686 } 2686 }
2687 2687
2688 2688
2689 TEST(StrictObjectLiteralChecking) { 2689 TEST(StrictObjectLiteralChecking) {
2690 const char* strict_context_data[][2] = { 2690 const char* context_data[][2] = {
2691 {"\"use strict\"; var myobject = {", "};"}, 2691 {"\"use strict\"; var myobject = {", "};"},
2692 {"\"use strict\"; var myobject = {", ",};"}, 2692 {"\"use strict\"; var myobject = {", ",};"},
2693 { NULL, NULL }
2694 };
2695 const char* non_strict_context_data[][2] = {
2696 {"var myobject = {", "};"}, 2693 {"var myobject = {", "};"},
2697 {"var myobject = {", ",};"}, 2694 {"var myobject = {", ",};"},
2698 { NULL, NULL } 2695 { NULL, NULL }
2699 }; 2696 };
2700 2697
2701 // These are only errors in strict mode. 2698 // These are only errors in strict mode.
2702 const char* statement_data[] = { 2699 const char* statement_data[] = {
2703 "foo: 1, foo: 2", 2700 "foo: 1, foo: 2",
2704 "\"foo\": 1, \"foo\": 2", 2701 "\"foo\": 1, \"foo\": 2",
2705 "foo: 1, \"foo\": 2", 2702 "foo: 1, \"foo\": 2",
2706 "1: 1, 1: 2", 2703 "1: 1, 1: 2",
2707 "1: 1, \"1\": 2", 2704 "1: 1, \"1\": 2",
2708 "get: 1, get: 2", // Not a getter for real, just a property called get. 2705 "get: 1, get: 2", // Not a getter for real, just a property called get.
2709 "set: 1, set: 2", // Not a setter for real, just a property called set. 2706 "set: 1, set: 2", // Not a setter for real, just a property called set.
2710 NULL 2707 NULL
2711 }; 2708 };
2712 2709
2713 RunParserSyncTest(non_strict_context_data, statement_data, kSuccess); 2710 RunParserSyncTest(context_data, statement_data, kSuccess);
2714 RunParserSyncTest(strict_context_data, statement_data, kError);
2715 } 2711 }
2716 2712
2717 2713
2718 TEST(ErrorsObjectLiteralChecking) { 2714 TEST(ErrorsObjectLiteralChecking) {
2719 const char* context_data[][2] = { 2715 const char* context_data[][2] = {
2720 {"\"use strict\"; var myobject = {", "};"}, 2716 {"\"use strict\"; var myobject = {", "};"},
2721 {"var myobject = {", "};"}, 2717 {"var myobject = {", "};"},
2722 { NULL, NULL } 2718 { NULL, NULL }
2723 }; 2719 };
2724 2720
2725 const char* statement_data[] = { 2721 const char* statement_data[] = {
2726 ",", 2722 ",",
2727 "foo: 1, get foo() {}", 2723 // Wrong number of parameters
2728 "foo: 1, set foo(v) {}", 2724 "get bar(x) {}",
2729 "\"foo\": 1, get \"foo\"() {}", 2725 "get bar(x, y) {}",
2730 "\"foo\": 1, set \"foo\"(v) {}", 2726 "set bar() {}",
2731 "1: 1, get 1() {}", 2727 "set bar(x, y) {}",
2732 "1: 1, set 1() {}", 2728 // Parsing FunctionLiteral for getter or setter fails
2733 "get foo() {}, get foo() {}", 2729 "get foo( +",
2734 "set foo(_) {}, set foo(_) {}", 2730 "get foo() \"error\"",
2735 // It's counter-intuitive, but these collide too (even in classic 2731 NULL
2736 // mode). Note that we can have "foo" and foo as properties in classic 2732 };
2737 // mode,
2738 // but we cannot have "foo" and get foo, or foo and get "foo".
2739 "foo: 1, get \"foo\"() {}",
2740 "foo: 1, set \"foo\"(v) {}",
2741 "\"foo\": 1, get foo() {}",
2742 "\"foo\": 1, set foo(v) {}",
2743 "1: 1, get \"1\"() {}",
2744 "1: 1, set \"1\"() {}",
2745 "\"1\": 1, get 1() {}"
2746 "\"1\": 1, set 1(v) {}"
2747 // Wrong number of parameters
2748 "get bar(x) {}",
2749 "get bar(x, y) {}",
2750 "set bar() {}",
2751 "set bar(x, y) {}",
2752 // Parsing FunctionLiteral for getter or setter fails
2753 "get foo( +",
2754 "get foo() \"error\"",
2755 NULL};
2756 2733
2757 RunParserSyncTest(context_data, statement_data, kError); 2734 RunParserSyncTest(context_data, statement_data, kError);
2758 } 2735 }
2759 2736
2760 2737
2761 TEST(NoErrorsObjectLiteralChecking) { 2738 TEST(NoErrorsObjectLiteralChecking) {
2762 const char* context_data[][2] = { 2739 const char* context_data[][2] = {
2763 {"var myobject = {", "};"}, 2740 {"var myobject = {", "};"},
2764 {"var myobject = {", ",};"}, 2741 {"var myobject = {", ",};"},
2765 {"\"use strict\"; var myobject = {", "};"}, 2742 {"\"use strict\"; var myobject = {", "};"},
2766 {"\"use strict\"; var myobject = {", ",};"}, 2743 {"\"use strict\"; var myobject = {", ",};"},
2767 { NULL, NULL } 2744 { NULL, NULL }
2768 }; 2745 };
2769 2746
2770 const char* statement_data[] = { 2747 const char* statement_data[] = {
2748 "foo: 1, get foo() {}",
2749 "foo: 1, set foo(v) {}",
2750 "\"foo\": 1, get \"foo\"() {}",
2751 "\"foo\": 1, set \"foo\"(v) {}",
2752 "1: 1, get 1() {}",
2753 "1: 1, set 1(v) {}",
2754 "get foo() {}, get foo() {}",
2755 "set foo(_) {}, set foo(v) {}",
2756 "foo: 1, get \"foo\"() {}",
2757 "foo: 1, set \"foo\"(v) {}",
2758 "\"foo\": 1, get foo() {}",
2759 "\"foo\": 1, set foo(v) {}",
2760 "1: 1, get \"1\"() {}",
2761 "1: 1, set \"1\"(v) {}",
2762 "\"1\": 1, get 1() {}",
2763 "\"1\": 1, set 1(v) {}",
2771 "foo: 1, bar: 2", 2764 "foo: 1, bar: 2",
2772 "\"foo\": 1, \"bar\": 2", 2765 "\"foo\": 1, \"bar\": 2",
2773 "1: 1, 2: 2", 2766 "1: 1, 2: 2",
2774 // Syntax: IdentifierName ':' AssignmentExpression 2767 // Syntax: IdentifierName ':' AssignmentExpression
2775 "foo: bar = 5 + baz", 2768 "foo: bar = 5 + baz",
2776 // Syntax: 'get' PropertyName '(' ')' '{' FunctionBody '}' 2769 // Syntax: 'get' PropertyName '(' ')' '{' FunctionBody '}'
2777 "get foo() {}", 2770 "get foo() {}",
2778 "get \"foo\"() {}", 2771 "get \"foo\"() {}",
2779 "get 1() {}", 2772 "get 1() {}",
2780 // Syntax: 'set' PropertyName '(' PropertySetParameterList ')' 2773 // Syntax: 'set' PropertyName '(' PropertySetParameterList ')'
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
3727 NULL 3720 NULL
3728 }; 3721 };
3729 3722
3730 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals}; 3723 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3731 RunParserSyncTest(context_data, params_data, kError, NULL, 0, 3724 RunParserSyncTest(context_data, params_data, kError, NULL, 0,
3732 always_flags, arraysize(always_flags)); 3725 always_flags, arraysize(always_flags));
3733 } 3726 }
3734 3727
3735 3728
3736 TEST(MethodDefinitionDuplicateProperty) { 3729 TEST(MethodDefinitionDuplicateProperty) {
3737 // Duplicate properties are allowed in ES6 but we haven't removed that check
3738 // yet.
3739 const char* context_data[][2] = {{"'use strict'; ({", "});"}, 3730 const char* context_data[][2] = {{"'use strict'; ({", "});"},
3740 {NULL, NULL}}; 3731 {NULL, NULL}};
3741 3732
3742 const char* params_data[] = { 3733 const char* params_data[] = {
3743 "x: 1, x() {}", 3734 "x: 1, x() {}",
3744 "x() {}, x: 1", 3735 "x() {}, x: 1",
3745 "x() {}, get x() {}", 3736 "x() {}, get x() {}",
3746 "x() {}, set x(_) {}", 3737 "x() {}, set x(_) {}",
3747 "x() {}, x() {}", 3738 "x() {}, x() {}",
3748 "x() {}, y() {}, x() {}", 3739 "x() {}, y() {}, x() {}",
(...skipping 10 matching lines...) Expand all
3759 "*x() {}, y() {}, *x() {}", 3750 "*x() {}, y() {}, *x() {}",
3760 "*x() {}, *\"x\"() {}", 3751 "*x() {}, *\"x\"() {}",
3761 "*x() {}, *'x'() {}", 3752 "*x() {}, *'x'() {}",
3762 "*0() {}, *'0'() {}", 3753 "*0() {}, *'0'() {}",
3763 "*1.0() {}, 1: 1", 3754 "*1.0() {}, 1: 1",
3764 3755
3765 NULL 3756 NULL
3766 }; 3757 };
3767 3758
3768 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals}; 3759 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3769 RunParserSyncTest(context_data, params_data, kError, NULL, 0, 3760 RunParserSyncTest(context_data, params_data, kSuccess, NULL, 0,
3770 always_flags, arraysize(always_flags)); 3761 always_flags, arraysize(always_flags));
3771 } 3762 }
3772 3763
3773 3764
3774 TEST(ClassExpressionNoErrors) { 3765 TEST(ClassExpressionNoErrors) {
3775 const char* context_data[][2] = {{"(", ");"}, 3766 const char* context_data[][2] = {{"(", ");"},
3776 {"var C = ", ";"}, 3767 {"var C = ", ";"},
3777 {"bar, ", ";"}, 3768 {"bar, ", ";"},
3778 {NULL, NULL}}; 3769 {NULL, NULL}};
3779 const char* class_data[] = { 3770 const char* class_data[] = {
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
4715 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 4706 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
4716 isolate->heap()->HashSeed(), 4707 isolate->heap()->HashSeed(),
4717 isolate->unicode_cache()}; 4708 isolate->unicode_cache()};
4718 i::Parser parser(&info, &parse_info); 4709 i::Parser parser(&info, &parse_info);
4719 parser.set_allow_harmony_modules(true); 4710 parser.set_allow_harmony_modules(true);
4720 parser.set_allow_harmony_scoping(true); 4711 parser.set_allow_harmony_scoping(true);
4721 info.MarkAsGlobal(); 4712 info.MarkAsGlobal();
4722 CHECK(!parser.Parse()); 4713 CHECK(!parser.Parse());
4723 } 4714 }
4724 } 4715 }
4716
4717
4718 TEST(DuplicateProtoError) {
4719 const char* context_data[][2] = {
4720 {"({", "});"},
4721 {"'use strict'; ({", "});"},
4722 {NULL, NULL}
4723 };
4724 const char* error_data[] = {
4725 "__proto__: {}, __proto__: {}",
4726 "__proto__: {}, \"__proto__\": {}",
4727 "__proto__: {}, \"__\x70roto__\": {}",
4728 "__proto__: {}, a: 1, __proto__: {}",
4729 NULL
4730 };
4731
4732 RunParserSyncTest(context_data, error_data, kError);
4733 }
4734
4735
4736 TEST(DuplicateProtoNoError) {
4737 const char* context_data[][2] = {
4738 {"({", "});"},
4739 {"'use strict'; ({", "});"},
4740 {NULL, NULL}
4741 };
4742 const char* error_data[] = {
4743 "__proto__: {}, ['__proto__']: {}",
4744 "__proto__: {}, __proto__() {}",
4745 "__proto__: {}, get __proto__() {}",
4746 "__proto__: {}, set __proto__(v) {}",
4747 "__proto__: {}, __proto__",
4748 NULL
4749 };
4750
4751 static const ParserFlag always_flags[] = {
4752 kAllowHarmonyComputedPropertyNames,
4753 kAllowHarmonyObjectLiterals,
4754 };
4755 RunParserSyncTest(context_data, error_data, kSuccess, NULL, 0,
4756 always_flags, arraysize(always_flags));
4757 }
OLDNEW
« no previous file with comments | « src/x87/full-codegen-x87.cc ('k') | test/mjsunit/object-literal-multiple-proto-fields.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698