| 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 2967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2978 CHECK(var->is_used() || !expected); | 2978 CHECK(var->is_used() || !expected); |
| 2979 CHECK(var->maybe_assigned() == expected); | 2979 CHECK(var->maybe_assigned() == expected); |
| 2980 } | 2980 } |
| 2981 } | 2981 } |
| 2982 } | 2982 } |
| 2983 | 2983 |
| 2984 namespace { | 2984 namespace { |
| 2985 | 2985 |
| 2986 int* global_use_counts = NULL; | 2986 int* global_use_counts = NULL; |
| 2987 | 2987 |
| 2988 void MockUseCounterCallback(v8::Isolate* isolate, | 2988 void UseCounterCallback(v8::Isolate* isolate, |
| 2989 v8::Isolate::UseCounterFeature feature) { | 2989 v8::Isolate::UseCounterFeature feature) { |
| 2990 ++global_use_counts[feature]; | 2990 ++global_use_counts[feature]; |
| 2991 } | 2991 } |
| 2992 | 2992 |
| 2993 } | 2993 } |
| 2994 | 2994 |
| 2995 | 2995 |
| 2996 TEST(UseAsmUseCount) { | 2996 TEST(UseAsmUseCount) { |
| 2997 i::Isolate* isolate = CcTest::i_isolate(); | 2997 i::Isolate* isolate = CcTest::i_isolate(); |
| 2998 i::HandleScope scope(isolate); | 2998 i::HandleScope scope(isolate); |
| 2999 LocalContext env; | 2999 LocalContext env; |
| 3000 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; | 3000 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
| 3001 global_use_counts = use_counts; | 3001 global_use_counts = use_counts; |
| 3002 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); | 3002 CcTest::isolate()->SetUseCounterCallback(UseCounterCallback); |
| 3003 CompileRun("\"use asm\";\n" | 3003 CompileRun("\"use asm\";\n" |
| 3004 "var foo = 1;\n" | 3004 "var foo = 1;\n" |
| 3005 "\"use asm\";\n" // Only the first one counts. | 3005 "\"use asm\";\n" // Only the first one counts. |
| 3006 "function bar() { \"use asm\"; var baz = 1; }"); | 3006 "function bar() { \"use asm\"; var baz = 1; }"); |
| 3007 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); | 3007 // Optimizing will double-count because the source is parsed twice. |
| 3008 CHECK_EQ(i::FLAG_always_opt ? 4 : 2, use_counts[v8::Isolate::kUseAsm]); |
| 3008 } | 3009 } |
| 3009 | 3010 |
| 3010 | 3011 |
| 3011 TEST(ErrorsArrowFunctions) { | 3012 TEST(ErrorsArrowFunctions) { |
| 3012 // Tests that parser and preparser generate the same kind of errors | 3013 // Tests that parser and preparser generate the same kind of errors |
| 3013 // on invalid arrow function syntax. | 3014 // on invalid arrow function syntax. |
| 3014 const char* context_data[][2] = { | 3015 const char* context_data[][2] = { |
| 3015 {"", ";"}, | 3016 {"", ";"}, |
| 3016 {"v = ", ";"}, | 3017 {"v = ", ";"}, |
| 3017 {"bar ? (", ") : baz;"}, | 3018 {"bar ? (", ") : baz;"}, |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3162 | 3163 |
| 3163 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) | 3164 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) |
| 3164 "foo ? bar : baz => {}", | 3165 "foo ? bar : baz => {}", |
| 3165 NULL | 3166 NULL |
| 3166 }; | 3167 }; |
| 3167 | 3168 |
| 3168 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; | 3169 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; |
| 3169 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3170 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 3170 always_flags, ARRAY_SIZE(always_flags)); | 3171 always_flags, ARRAY_SIZE(always_flags)); |
| 3171 } | 3172 } |
| OLD | NEW |