| 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 2669 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  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  Loading... | 
|  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  Loading... | 
|  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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  4661  |  4652  | 
|  4662   static const ParserFlag always_flags[] = { |  4653   static const ParserFlag always_flags[] = { | 
|  4663     kAllowHarmonyClasses, |  4654     kAllowHarmonyClasses, | 
|  4664     kAllowHarmonyComputedPropertyNames, |  4655     kAllowHarmonyComputedPropertyNames, | 
|  4665     kAllowHarmonyObjectLiterals, |  4656     kAllowHarmonyObjectLiterals, | 
|  4666     kAllowHarmonySloppy, |  4657     kAllowHarmonySloppy, | 
|  4667   }; |  4658   }; | 
|  4668   RunParserSyncTest(context_data, error_data, kError, NULL, 0, |  4659   RunParserSyncTest(context_data, error_data, kError, NULL, 0, | 
|  4669                     always_flags, arraysize(always_flags)); |  4660                     always_flags, arraysize(always_flags)); | 
|  4670 } |  4661 } | 
 |  4662  | 
 |  4663  | 
 |  4664 TEST(DuplicateProtoError) { | 
 |  4665   const char* context_data[][2] = { | 
 |  4666     {"({", "});"}, | 
 |  4667     {"'use strict'; ({", "});"}, | 
 |  4668     {NULL, NULL} | 
 |  4669   }; | 
 |  4670   const char* error_data[] = { | 
 |  4671     "__proto__: {}, __proto__: {}", | 
 |  4672     "__proto__: {}, \"__proto__\": {}", | 
 |  4673     "__proto__: {}, \"__\x70roto__\": {}", | 
 |  4674     "__proto__: {}, a: 1, __proto__: {}", | 
 |  4675     NULL | 
 |  4676   }; | 
 |  4677  | 
 |  4678   RunParserSyncTest(context_data, error_data, kError); | 
 |  4679 } | 
 |  4680  | 
 |  4681  | 
 |  4682 TEST(DuplicateProtoNoError) { | 
 |  4683   const char* context_data[][2] = { | 
 |  4684     {"({", "});"}, | 
 |  4685     {"'use strict'; ({", "});"}, | 
 |  4686     {NULL, NULL} | 
 |  4687   }; | 
 |  4688   const char* error_data[] = { | 
 |  4689     "__proto__: {}, ['__proto__']: {}", | 
 |  4690     "__proto__: {}, __proto__() {}", | 
 |  4691     "__proto__: {}, get __proto__() {}", | 
 |  4692     "__proto__: {}, set __proto__(v) {}", | 
 |  4693     "__proto__: {}, __proto__", | 
 |  4694     NULL | 
 |  4695   }; | 
 |  4696  | 
 |  4697   static const ParserFlag always_flags[] = { | 
 |  4698     kAllowHarmonyComputedPropertyNames, | 
 |  4699     kAllowHarmonyObjectLiterals, | 
 |  4700   }; | 
 |  4701   RunParserSyncTest(context_data, error_data, kSuccess, NULL, 0, | 
 |  4702                     always_flags, arraysize(always_flags)); | 
 |  4703 } | 
| OLD | NEW |