OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Test specific cases of the lazy/eager-parse decision. |
| 6 // |
| 7 // Note that presently most unit tests for parsing are found in |
| 8 // cctest/test-parsing.cc. |
| 9 |
| 10 #include <unordered_map> |
| 11 |
| 12 #include "include/v8.h" |
| 13 #include "src/api.h" |
| 14 #include "src/handles-inl.h" |
| 15 #include "src/isolate.h" |
| 16 #include "src/utils.h" |
| 17 |
| 18 #include "test/cctest/cctest.h" |
| 19 |
| 20 using namespace v8::internal; |
| 21 |
| 22 TEST(EagerlyCompileImmediateUseFunctions) { |
| 23 if (!FLAG_lazy) return; |
| 24 FLAG_min_preparse_length = 0; |
| 25 |
| 26 // Test parenthesized, exclaimed, and regular functions. Make sure these |
| 27 // occur both intermixed and after each other, to make sure the 'reset' |
| 28 // mechanism works. |
| 29 const char src[] = |
| 30 "function normal() { var a; }\n" // Normal: Should lazy parse. |
| 31 "(function parenthesized() { var b; })()\n" // Parenthesized: Pre-parse. |
| 32 "!function exclaimed() { var c; }() \n" // Exclaimed: Pre-parse. |
| 33 "function normal2() { var d; }\n" |
| 34 "(function parenthesized2() { var e; })()\n" |
| 35 "function normal3() { var f; }\n" |
| 36 "!function exclaimed2() { var g; }() \n" |
| 37 "function normal4() { var h; }\n"; |
| 38 |
| 39 Isolate* isolate = CcTest::i_isolate(); |
| 40 HandleScope scope(isolate); |
| 41 LocalContext env; |
| 42 |
| 43 // Compile src & record the 'compiled' state of all top level functions in |
| 44 // is_compiled. |
| 45 std::unordered_map<std::string, bool> is_compiled; |
| 46 { |
| 47 v8::Local<v8::Script> api_script = v8_compile(src); |
| 48 Handle<JSFunction> toplevel_fn = v8::Utils::OpenHandle(*api_script); |
| 49 Handle<Script> script = |
| 50 handle(Script::cast(toplevel_fn->shared()->script())); |
| 51 |
| 52 WeakFixedArray::Iterator iter(script->shared_function_infos()); |
| 53 while (SharedFunctionInfo* shared = iter.Next<SharedFunctionInfo>()) { |
| 54 std::unique_ptr<char[]> name = String::cast(shared->name())->ToCString(); |
| 55 is_compiled[name.get()] = shared->is_compiled(); |
| 56 } |
| 57 } |
| 58 |
| 59 DCHECK(is_compiled.find("normal") != is_compiled.end()); |
| 60 |
| 61 DCHECK(is_compiled["parenthesized"]); |
| 62 DCHECK(is_compiled["parenthesized2"]); |
| 63 DCHECK(is_compiled["exclaimed"]); |
| 64 DCHECK(is_compiled["exclaimed2"]); |
| 65 DCHECK(!is_compiled["normal"]); |
| 66 DCHECK(!is_compiled["normal2"]); |
| 67 DCHECK(!is_compiled["normal3"]); |
| 68 DCHECK(!is_compiled["normal4"]); |
| 69 } |
OLD | NEW |