Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2537)

Side by Side Diff: test/cctest/parsing/test-parse-decision.cc

Issue 2509143003: Treat a '!' preceding a function literal as eager-compile hint. (Closed)
Patch Set: remove empty line. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/parsing/parser.cc ('K') | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 const char src[] =
27 "function normal() { var a; }\n" // Normal: Should lazy parse.
28 "(function parenthesized() { var b; })()\n" // Parenthesized: Pre-parse.
29 "!function exclaimed() { var c; }() \n" // Exclaimed: Pre-parse.
30 "function normal2() { var d; }\n"; // Normal function again.
31
32 Isolate* isolate = CcTest::i_isolate();
33 HandleScope scope(isolate);
34 LocalContext env;
35
36 // Compile src & record the 'compiled' state of all top level functions in
37 // is_compiled.
38 std::unordered_map<std::string, bool> is_compiled;
39 {
40 v8::Local<v8::Script> api_script = v8_compile(src);
41 Handle<JSFunction> toplevel_fn = v8::Utils::OpenHandle(*api_script);
42 Handle<Script> script =
43 handle(Script::cast(toplevel_fn->shared()->script()));
44
45 WeakFixedArray::Iterator iter(script->shared_function_infos());
46 while (SharedFunctionInfo* shared = iter.Next<SharedFunctionInfo>()) {
47 std::unique_ptr<char[]> name = String::cast(shared->name())->ToCString();
48 is_compiled[name.get()] = shared->is_compiled();
49 }
50 }
51
52 DCHECK(is_compiled.find("normal") != is_compiled.end());
53
54 DCHECK(is_compiled["parenthesized"]);
55 DCHECK(is_compiled["exclaimed"]);
56 DCHECK(!is_compiled["normal"]);
57 DCHECK(!is_compiled["normal2"]);
58 }
OLDNEW
« src/parsing/parser.cc ('K') | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698