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

Side by Side Diff: test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc

Issue 2193813002: Add parser finalization step (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 4 months 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
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher-job.cc ('k') | test/unittests/test-utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <memory> 5 #include <memory>
6 6
7 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" 7 #include "src/compiler-dispatcher/compiler-dispatcher-job.h"
8 #include "src/flags.h" 8 #include "src/flags.h"
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 #include "test/unittests/test-utils.h" 10 #include "test/unittests/test-utils.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 ->NewExternalStringFromOneByte(maybe_resource) 42 ->NewExternalStringFromOneByte(maybe_resource)
43 .ToHandleChecked(); 43 .ToHandleChecked();
44 } else { 44 } else {
45 source = isolate->factory()->NewStringFromStaticChars("source"); 45 source = isolate->factory()->NewStringFromStaticChars("source");
46 } 46 }
47 Handle<Script> script = isolate->factory()->NewScript(source); 47 Handle<Script> script = isolate->factory()->NewScript(source);
48 Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo( 48 Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
49 isolate->factory()->NewStringFromStaticChars("f"), MaybeHandle<Code>(), 49 isolate->factory()->NewStringFromStaticChars("f"), MaybeHandle<Code>(),
50 false); 50 false);
51 SharedFunctionInfo::SetScript(shared, script); 51 SharedFunctionInfo::SetScript(shared, script);
52 shared->set_end_position(source->length() - 1);
52 Handle<JSFunction> function = 53 Handle<JSFunction> function =
53 isolate->factory()->NewFunctionFromSharedFunctionInfo( 54 isolate->factory()->NewFunctionFromSharedFunctionInfo(
54 shared, handle(isolate->context(), isolate)); 55 shared, handle(isolate->context(), isolate));
55 return scope.CloseAndEscape(function); 56 return scope.CloseAndEscape(function);
56 } 57 }
57 58
58 } // namespace 59 } // namespace
59 60
60 TEST_F(CompilerDispatcherJobTest, Construct) { 61 TEST_F(CompilerDispatcherJobTest, Construct) {
61 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate());
62 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( 62 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
63 i_isolate, CreateFunction(i_isolate, nullptr), FLAG_stack_size)); 63 i_isolate(), CreateFunction(i_isolate(), nullptr), FLAG_stack_size));
64 } 64 }
65 65
66 TEST_F(CompilerDispatcherJobTest, CanParseOnBackgroundThread) { 66 TEST_F(CompilerDispatcherJobTest, CanParseOnBackgroundThread) {
67 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate());
68 { 67 {
69 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( 68 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
70 i_isolate, CreateFunction(i_isolate, nullptr), FLAG_stack_size)); 69 i_isolate(), CreateFunction(i_isolate(), nullptr), FLAG_stack_size));
71 ASSERT_FALSE(job->can_parse_on_background_thread()); 70 ASSERT_FALSE(job->can_parse_on_background_thread());
72 } 71 }
73 { 72 {
74 ScriptResource script("script", strlen("script")); 73 ScriptResource script("script", strlen("script"));
75 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( 74 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
76 i_isolate, CreateFunction(i_isolate, &script), FLAG_stack_size)); 75 i_isolate(), CreateFunction(i_isolate(), &script), FLAG_stack_size));
77 ASSERT_TRUE(job->can_parse_on_background_thread()); 76 ASSERT_TRUE(job->can_parse_on_background_thread());
78 } 77 }
79 } 78 }
80 79
81 TEST_F(CompilerDispatcherJobTest, StateTransitions) { 80 TEST_F(CompilerDispatcherJobTest, StateTransitions) {
82 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate());
83 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( 81 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
84 i_isolate, CreateFunction(i_isolate, nullptr), FLAG_stack_size)); 82 i_isolate(), CreateFunction(i_isolate(), nullptr), FLAG_stack_size));
85 83
86 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); 84 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
87 job->PrepareToParseOnMainThread(); 85 job->PrepareToParseOnMainThread();
88 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToParse); 86 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToParse);
89 job->Parse(); 87 job->Parse();
90 ASSERT_TRUE(job->status() == CompileJobStatus::kParsed); 88 ASSERT_TRUE(job->status() == CompileJobStatus::kParsed);
89 job->FinalizeParsingOnMainThread();
90 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile);
91 job->ResetOnMainThread();
92 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
93 }
94
95 TEST_F(CompilerDispatcherJobTest, SyntaxError) {
96 ScriptResource script("^^^", strlen("^^^"));
97 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
98 i_isolate(), CreateFunction(i_isolate(), &script), FLAG_stack_size));
99
100 job->PrepareToParseOnMainThread();
101 job->Parse();
102 job->FinalizeParsingOnMainThread();
103
104 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed);
105 ASSERT_FALSE(i_isolate()->has_pending_exception());
106 job->ReportErrorsOnMainThread();
107 ASSERT_TRUE(job->status() == CompileJobStatus::kDone);
108 ASSERT_TRUE(i_isolate()->has_pending_exception());
91 } 109 }
92 110
93 } // namespace internal 111 } // namespace internal
94 } // namespace v8 112 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher-job.cc ('k') | test/unittests/test-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698