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

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

Issue 2268983002: Finalizing parsing in a compile job should immediately report errors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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') | 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
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 "include/v8.h" 7 #include "include/v8.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" 10 #include "src/compiler-dispatcher/compiler-dispatcher-job.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 TEST_F(CompilerDispatcherJobTest, StateTransitions) { 86 TEST_F(CompilerDispatcherJobTest, StateTransitions) {
87 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( 87 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
88 i_isolate(), CreateFunction(i_isolate(), nullptr), FLAG_stack_size)); 88 i_isolate(), CreateFunction(i_isolate(), nullptr), FLAG_stack_size));
89 89
90 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); 90 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
91 job->PrepareToParseOnMainThread(); 91 job->PrepareToParseOnMainThread();
92 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToParse); 92 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToParse);
93 job->Parse(); 93 job->Parse();
94 ASSERT_TRUE(job->status() == CompileJobStatus::kParsed); 94 ASSERT_TRUE(job->status() == CompileJobStatus::kParsed);
95 job->FinalizeParsingOnMainThread(); 95 ASSERT_TRUE(job->FinalizeParsingOnMainThread());
96 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile); 96 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile);
97 job->ResetOnMainThread(); 97 job->ResetOnMainThread();
98 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); 98 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
99 } 99 }
100 100
101 TEST_F(CompilerDispatcherJobTest, SyntaxError) { 101 TEST_F(CompilerDispatcherJobTest, SyntaxError) {
102 ScriptResource script("^^^", strlen("^^^")); 102 ScriptResource script("^^^", strlen("^^^"));
103 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( 103 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
104 i_isolate(), CreateFunction(i_isolate(), &script), FLAG_stack_size)); 104 i_isolate(), CreateFunction(i_isolate(), &script), FLAG_stack_size));
105 105
106 job->PrepareToParseOnMainThread(); 106 job->PrepareToParseOnMainThread();
107 job->Parse(); 107 job->Parse();
108 job->FinalizeParsingOnMainThread(); 108 ASSERT_FALSE(job->FinalizeParsingOnMainThread());
109 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed);
110 ASSERT_TRUE(i_isolate()->has_pending_exception());
109 111
110 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed);
111 ASSERT_FALSE(i_isolate()->has_pending_exception());
112 job->ReportErrorsOnMainThread();
113 ASSERT_TRUE(job->status() == CompileJobStatus::kDone);
114 ASSERT_TRUE(i_isolate()->has_pending_exception());
115 i_isolate()->clear_pending_exception(); 112 i_isolate()->clear_pending_exception();
113
114 job->ResetOnMainThread();
115 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
116 } 116 }
117 117
118 TEST_F(CompilerDispatcherJobTest, ScopeChain) { 118 TEST_F(CompilerDispatcherJobTest, ScopeChain) {
119 const char script[] = 119 const char script[] =
120 "function g() { var g = 1; function f(x) { return x * g }; return f; } " 120 "function g() { var g = 1; function f(x) { return x * g }; return f; } "
121 "g();"; 121 "g();";
122 Handle<JSFunction> f = Handle<JSFunction>::cast(Utils::OpenHandle( 122 Handle<JSFunction> f = Handle<JSFunction>::cast(Utils::OpenHandle(
123 *v8::Script::Compile(isolate()->GetCurrentContext(), 123 *v8::Script::Compile(isolate()->GetCurrentContext(),
124 v8::String::NewFromUtf8(isolate(), script, 124 v8::String::NewFromUtf8(isolate(), script,
125 v8::NewStringType::kNormal) 125 v8::NewStringType::kNormal)
126 .ToLocalChecked()) 126 .ToLocalChecked())
127 .ToLocalChecked() 127 .ToLocalChecked()
128 ->Run(isolate()->GetCurrentContext()) 128 ->Run(isolate()->GetCurrentContext())
129 .ToLocalChecked())); 129 .ToLocalChecked()));
130 130
131 std::unique_ptr<CompilerDispatcherJob> job( 131 std::unique_ptr<CompilerDispatcherJob> job(
132 new CompilerDispatcherJob(i_isolate(), f, FLAG_stack_size)); 132 new CompilerDispatcherJob(i_isolate(), f, FLAG_stack_size));
133 133
134 job->PrepareToParseOnMainThread(); 134 job->PrepareToParseOnMainThread();
135 job->Parse(); 135 job->Parse();
136 job->FinalizeParsingOnMainThread(); 136 ASSERT_TRUE(job->FinalizeParsingOnMainThread());
137 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile); 137 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile);
138 138
139 const AstRawString* var_x = 139 const AstRawString* var_x =
140 job->parse_info_->ast_value_factory()->GetOneByteString("x"); 140 job->parse_info_->ast_value_factory()->GetOneByteString("x");
141 Variable* var = job->parse_info_->literal()->scope()->Lookup(var_x); 141 Variable* var = job->parse_info_->literal()->scope()->Lookup(var_x);
142 ASSERT_TRUE(var); 142 ASSERT_TRUE(var);
143 ASSERT_TRUE(var->IsUnallocated()); 143 ASSERT_TRUE(var->IsUnallocated());
144 144
145 const AstRawString* var_g = 145 const AstRawString* var_g =
146 job->parse_info_->ast_value_factory()->GetOneByteString("g"); 146 job->parse_info_->ast_value_factory()->GetOneByteString("g");
147 var = job->parse_info_->literal()->scope()->Lookup(var_g); 147 var = job->parse_info_->literal()->scope()->Lookup(var_g);
148 ASSERT_TRUE(var); 148 ASSERT_TRUE(var);
149 ASSERT_TRUE(var->IsContextSlot()); 149 ASSERT_TRUE(var->IsContextSlot());
150 150
151 job->ResetOnMainThread(); 151 job->ResetOnMainThread();
152 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); 152 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
153 } 153 }
154 154
155 } // namespace internal 155 } // namespace internal
156 } // namespace v8 156 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher-job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698