OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Test specific cases of the lazy/eager-parse decision. | 5 // Test specific cases of the lazy/eager-parse decision. |
6 // | 6 // |
7 // Note that presently most unit tests for parsing are found in | 7 // Note that presently most unit tests for parsing are found in |
8 // cctest/test-parsing.cc. | 8 // cctest/test-parsing.cc. |
9 | 9 |
10 #include <unordered_map> | 10 #include <unordered_map> |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // Record the 'compiled' state of all top level functions. | 24 // Record the 'compiled' state of all top level functions. |
25 void GetTopLevelFunctionInfo( | 25 void GetTopLevelFunctionInfo( |
26 v8::Local<v8::Script> script, | 26 v8::Local<v8::Script> script, |
27 std::unordered_map<std::string, bool>* is_compiled) { | 27 std::unordered_map<std::string, bool>* is_compiled) { |
28 // Get the v8::internal::Script object from the API v8::Script. | 28 // Get the v8::internal::Script object from the API v8::Script. |
29 // The API object 'wraps' the compiled top-level function, not the i::Script. | 29 // The API object 'wraps' the compiled top-level function, not the i::Script. |
30 Handle<JSFunction> toplevel_fn = v8::Utils::OpenHandle(*script); | 30 Handle<JSFunction> toplevel_fn = v8::Utils::OpenHandle(*script); |
31 Handle<Script> i_script = | 31 Handle<Script> i_script = |
32 handle(Script::cast(toplevel_fn->shared()->script())); | 32 handle(Script::cast(toplevel_fn->shared()->script())); |
| 33 SharedFunctionInfo::ScriptIterator iterator(i_script); |
33 | 34 |
34 WeakFixedArray::Iterator iter(i_script->shared_function_infos()); | 35 while (SharedFunctionInfo* shared = iterator.Next()) { |
35 while (SharedFunctionInfo* shared = iter.Next<SharedFunctionInfo>()) { | |
36 std::unique_ptr<char[]> name = String::cast(shared->name())->ToCString(); | 36 std::unique_ptr<char[]> name = String::cast(shared->name())->ToCString(); |
37 is_compiled->insert(std::make_pair(name.get(), shared->is_compiled())); | 37 is_compiled->insert(std::make_pair(name.get(), shared->is_compiled())); |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 } // anonymous namespace | 41 } // anonymous namespace |
42 | 42 |
43 TEST(GetTopLevelFunctionInfo) { | 43 TEST(GetTopLevelFunctionInfo) { |
44 if (!FLAG_lazy) return; | 44 if (!FLAG_lazy) return; |
45 | 45 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 LocalContext env; | 97 LocalContext env; |
98 | 98 |
99 const char src[] = "!function a(){}(),function b(){}(),function c(){}();"; | 99 const char src[] = "!function a(){}(),function b(){}(),function c(){}();"; |
100 std::unordered_map<std::string, bool> is_compiled; | 100 std::unordered_map<std::string, bool> is_compiled; |
101 GetTopLevelFunctionInfo(v8_compile(src), &is_compiled); | 101 GetTopLevelFunctionInfo(v8_compile(src), &is_compiled); |
102 | 102 |
103 DCHECK(is_compiled["a"]); | 103 DCHECK(is_compiled["a"]); |
104 DCHECK(is_compiled["b"]); | 104 DCHECK(is_compiled["b"]); |
105 DCHECK(is_compiled["c"]); | 105 DCHECK(is_compiled["c"]); |
106 } | 106 } |
OLD | NEW |