| 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 3145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3156 } | 3156 } |
| 3157 } | 3157 } |
| 3158 } | 3158 } |
| 3159 } | 3159 } |
| 3160 } | 3160 } |
| 3161 | 3161 |
| 3162 namespace { | 3162 namespace { |
| 3163 | 3163 |
| 3164 int* global_use_counts = NULL; | 3164 int* global_use_counts = NULL; |
| 3165 | 3165 |
| 3166 void MockUseCounterCallback(v8::Isolate* isolate, | 3166 void UseCounterCallback(v8::Isolate* isolate, |
| 3167 v8::Isolate::UseCounterFeature feature) { | 3167 v8::Isolate::UseCounterFeature feature) { |
| 3168 ++global_use_counts[feature]; | 3168 ++global_use_counts[feature]; |
| 3169 } | 3169 } |
| 3170 | 3170 |
| 3171 } | 3171 } |
| 3172 | 3172 |
| 3173 | 3173 |
| 3174 TEST(UseAsmUseCount) { | 3174 TEST(UseAsmUseCount) { |
| 3175 i::Isolate* isolate = CcTest::i_isolate(); | 3175 i::Isolate* isolate = CcTest::i_isolate(); |
| 3176 i::HandleScope scope(isolate); | 3176 i::HandleScope scope(isolate); |
| 3177 LocalContext env; | 3177 LocalContext env; |
| 3178 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; | 3178 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
| 3179 global_use_counts = use_counts; | 3179 global_use_counts = use_counts; |
| 3180 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); | 3180 CcTest::isolate()->SetUseCounterCallback(UseCounterCallback); |
| 3181 CompileRun("\"use asm\";\n" | 3181 CompileRun("\"use asm\";\n" |
| 3182 "var foo = 1;\n" | 3182 "var foo = 1;\n" |
| 3183 "\"use asm\";\n" // Only the first one counts. | 3183 "\"use asm\";\n" // Only the first one counts. |
| 3184 "function bar() { \"use asm\"; var baz = 1; }"); | 3184 "function bar() { \"use asm\"; var baz = 1; }"); |
| 3185 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); | 3185 // Optimizing will double-count because the source is parsed twice. |
| 3186 CHECK_EQ(i::FLAG_always_opt ? 4 : 2, use_counts[v8::Isolate::kUseAsm]); |
| 3186 } | 3187 } |
| 3187 | 3188 |
| 3188 | 3189 |
| 3189 TEST(ErrorsArrowFunctions) { | 3190 TEST(ErrorsArrowFunctions) { |
| 3190 // Tests that parser and preparser generate the same kind of errors | 3191 // Tests that parser and preparser generate the same kind of errors |
| 3191 // on invalid arrow function syntax. | 3192 // on invalid arrow function syntax. |
| 3192 const char* context_data[][2] = { | 3193 const char* context_data[][2] = { |
| 3193 {"", ";"}, | 3194 {"", ";"}, |
| 3194 {"v = ", ";"}, | 3195 {"v = ", ";"}, |
| 3195 {"bar ? (", ") : baz;"}, | 3196 {"bar ? (", ") : baz;"}, |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3340 | 3341 |
| 3341 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) | 3342 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) |
| 3342 "foo ? bar : baz => {}", | 3343 "foo ? bar : baz => {}", |
| 3343 NULL | 3344 NULL |
| 3344 }; | 3345 }; |
| 3345 | 3346 |
| 3346 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; | 3347 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; |
| 3347 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3348 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 3348 always_flags, ARRAY_SIZE(always_flags)); | 3349 always_flags, ARRAY_SIZE(always_flags)); |
| 3349 } | 3350 } |
| OLD | NEW |