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 3415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3426 i::Isolate* isolate = CcTest::i_isolate(); | 3426 i::Isolate* isolate = CcTest::i_isolate(); |
3427 i::HandleScope scope(isolate); | 3427 i::HandleScope scope(isolate); |
3428 LocalContext env; | 3428 LocalContext env; |
3429 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; | 3429 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
3430 global_use_counts = use_counts; | 3430 global_use_counts = use_counts; |
3431 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); | 3431 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); |
3432 CompileRun("\"use asm\";\n" | 3432 CompileRun("\"use asm\";\n" |
3433 "var foo = 1;\n" | 3433 "var foo = 1;\n" |
3434 "\"use asm\";\n" // Only the first one counts. | 3434 "\"use asm\";\n" // Only the first one counts. |
3435 "function bar() { \"use asm\"; var baz = 1; }"); | 3435 "function bar() { \"use asm\"; var baz = 1; }"); |
3436 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); | 3436 // Optimizing will double-count because the source is parsed twice. |
| 3437 CHECK_EQ(i::FLAG_always_opt ? 4 : 2, use_counts[v8::Isolate::kUseAsm]); |
3437 } | 3438 } |
3438 | 3439 |
3439 | 3440 |
3440 TEST(UseConstLegacyCount) { | 3441 TEST(UseConstLegacyCount) { |
3441 i::Isolate* isolate = CcTest::i_isolate(); | 3442 i::Isolate* isolate = CcTest::i_isolate(); |
3442 i::HandleScope scope(isolate); | 3443 i::HandleScope scope(isolate); |
3443 LocalContext env; | 3444 LocalContext env; |
3444 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; | 3445 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
3445 global_use_counts = use_counts; | 3446 global_use_counts = use_counts; |
3446 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); | 3447 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); |
3447 CompileRun( | 3448 CompileRun( |
3448 "const x = 1;\n" | 3449 "const x = 1;\n" |
3449 "var foo = 1;\n" | 3450 "var foo = 1;\n" |
3450 "const y = 1;\n" | 3451 "const y = 1;\n" |
3451 "function bar() {\n" | 3452 "function bar() {\n" |
3452 " const z = 1; var baz = 1;\n" | 3453 " const z = 1; var baz = 1;\n" |
3453 " function q() { const k = 42; }\n" | 3454 " function q() { const k = 42; }\n" |
3454 "}"); | 3455 "}"); |
3455 CHECK_EQ(4, use_counts[v8::Isolate::kLegacyConst]); | 3456 // Optimizing will double-count because the source is parsed twice. |
| 3457 CHECK_EQ(i::FLAG_always_opt ? 8 : 4, use_counts[v8::Isolate::kLegacyConst]); |
3456 } | 3458 } |
3457 | 3459 |
3458 | 3460 |
3459 TEST(ErrorsArrowFunctions) { | 3461 TEST(ErrorsArrowFunctions) { |
3460 // Tests that parser and preparser generate the same kind of errors | 3462 // Tests that parser and preparser generate the same kind of errors |
3461 // on invalid arrow function syntax. | 3463 // on invalid arrow function syntax. |
3462 const char* context_data[][2] = { | 3464 const char* context_data[][2] = { |
3463 {"", ";"}, | 3465 {"", ";"}, |
3464 {"v = ", ";"}, | 3466 {"v = ", ";"}, |
3465 {"bar ? (", ") : baz;"}, | 3467 {"bar ? (", ") : baz;"}, |
(...skipping 2329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5795 v8::Script::Compile(v8_str(script3)); | 5797 v8::Script::Compile(v8_str(script3)); |
5796 CHECK(try_catch2.HasCaught()); | 5798 CHECK(try_catch2.HasCaught()); |
5797 v8::String::Utf8Value exception(try_catch2.Exception()); | 5799 v8::String::Utf8Value exception(try_catch2.Exception()); |
5798 CHECK_EQ(0, | 5800 CHECK_EQ(0, |
5799 strcmp( | 5801 strcmp( |
5800 "ReferenceError: In strong mode, using an undeclared global " | 5802 "ReferenceError: In strong mode, using an undeclared global " |
5801 "variable 'not_there3' is not allowed", | 5803 "variable 'not_there3' is not allowed", |
5802 *exception)); | 5804 *exception)); |
5803 } | 5805 } |
5804 } | 5806 } |
OLD | NEW |