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 3530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3541 "const y = 1;\n" | 3541 "const y = 1;\n" |
3542 "function bar() {\n" | 3542 "function bar() {\n" |
3543 " const z = 1; var baz = 1;\n" | 3543 " const z = 1; var baz = 1;\n" |
3544 " function q() { const k = 42; }\n" | 3544 " function q() { const k = 42; }\n" |
3545 "}"); | 3545 "}"); |
3546 // Optimizing will double-count because the source is parsed twice. | 3546 // Optimizing will double-count because the source is parsed twice. |
3547 CHECK_EQ(i::FLAG_always_opt ? 8 : 4, use_counts[v8::Isolate::kLegacyConst]); | 3547 CHECK_EQ(i::FLAG_always_opt ? 8 : 4, use_counts[v8::Isolate::kLegacyConst]); |
3548 } | 3548 } |
3549 | 3549 |
3550 | 3550 |
| 3551 TEST(StrictModeUseCount) { |
| 3552 i::Isolate* isolate = CcTest::i_isolate(); |
| 3553 i::HandleScope scope(isolate); |
| 3554 LocalContext env; |
| 3555 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
| 3556 global_use_counts = use_counts; |
| 3557 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); |
| 3558 CompileRun( |
| 3559 "\"use strict\";\n" |
| 3560 "function bar() { var baz = 1; }"); // strict mode inherits |
| 3561 CHECK_LT(0, use_counts[v8::Isolate::kStrictMode]); |
| 3562 CHECK_EQ(0, use_counts[v8::Isolate::kSloppyMode]); |
| 3563 } |
| 3564 |
| 3565 |
| 3566 TEST(SloppyModeUseCount) { |
| 3567 i::Isolate* isolate = CcTest::i_isolate(); |
| 3568 i::HandleScope scope(isolate); |
| 3569 LocalContext env; |
| 3570 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
| 3571 global_use_counts = use_counts; |
| 3572 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); |
| 3573 CompileRun("function bar() { var baz = 1; }"); |
| 3574 CHECK_LT(0, use_counts[v8::Isolate::kSloppyMode]); |
| 3575 CHECK_EQ(0, use_counts[v8::Isolate::kStrictMode]); |
| 3576 } |
| 3577 |
| 3578 |
| 3579 TEST(BothModesUseCount) { |
| 3580 i::Isolate* isolate = CcTest::i_isolate(); |
| 3581 i::HandleScope scope(isolate); |
| 3582 LocalContext env; |
| 3583 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
| 3584 global_use_counts = use_counts; |
| 3585 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); |
| 3586 CompileRun("function bar() { 'use strict'; var baz = 1; }"); |
| 3587 CHECK_LT(0, use_counts[v8::Isolate::kSloppyMode]); |
| 3588 CHECK_LT(0, use_counts[v8::Isolate::kStrictMode]); |
| 3589 } |
| 3590 |
| 3591 |
3551 TEST(ErrorsArrowFormalParameters) { | 3592 TEST(ErrorsArrowFormalParameters) { |
3552 const char* context_data[][2] = { | 3593 const char* context_data[][2] = { |
3553 { "()", "=>{}" }, | 3594 { "()", "=>{}" }, |
3554 { "()", "=>{};" }, | 3595 { "()", "=>{};" }, |
3555 { "var x = ()", "=>{}" }, | 3596 { "var x = ()", "=>{}" }, |
3556 { "var x = ()", "=>{};" }, | 3597 { "var x = ()", "=>{};" }, |
3557 | 3598 |
3558 { "a", "=>{}" }, | 3599 { "a", "=>{}" }, |
3559 { "a", "=>{};" }, | 3600 { "a", "=>{};" }, |
3560 { "var x = a", "=>{}" }, | 3601 { "var x = a", "=>{}" }, |
(...skipping 3667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7228 NULL | 7269 NULL |
7229 }; | 7270 }; |
7230 // clang-format on | 7271 // clang-format on |
7231 | 7272 |
7232 static const ParserFlag fail_flags[] = { | 7273 static const ParserFlag fail_flags[] = { |
7233 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, | 7274 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, |
7234 kAllowHarmonyDestructuring}; | 7275 kAllowHarmonyDestructuring}; |
7235 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, | 7276 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, |
7236 arraysize(fail_flags)); | 7277 arraysize(fail_flags)); |
7237 } | 7278 } |
OLD | NEW |