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 #include <memory> | 5 #include <memory> |
6 | 6 |
7 #include "include/v8.h" | |
8 #include "src/api.h" | |
9 #include "src/ast/scopes.h" | |
10 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" | 7 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" |
11 #include "src/flags.h" | 8 #include "src/flags.h" |
12 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
13 #include "src/parsing/parser.h" | |
14 #include "test/unittests/test-utils.h" | 10 #include "test/unittests/test-utils.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
16 | 12 |
17 namespace v8 { | 13 namespace v8 { |
18 namespace internal { | 14 namespace internal { |
19 | 15 |
20 typedef TestWithContext CompilerDispatcherJobTest; | 16 typedef TestWithContext CompilerDispatcherJobTest; |
21 | 17 |
22 namespace { | 18 namespace { |
23 | 19 |
24 const char test_script[] = "(x) { x*x; }"; | 20 const char test_script[] = "x*x"; |
25 | 21 |
26 class ScriptResource : public v8::String::ExternalOneByteStringResource { | 22 class ScriptResource : public v8::String::ExternalOneByteStringResource { |
27 public: | 23 public: |
28 ScriptResource(const char* data, size_t length) | 24 ScriptResource(const char* data, size_t length) |
29 : data_(data), length_(length) {} | 25 : data_(data), length_(length) {} |
30 ~ScriptResource() override = default; | 26 ~ScriptResource() override = default; |
31 | 27 |
32 const char* data() const override { return data_; } | 28 const char* data() const override { return data_; } |
33 size_t length() const override { return length_; } | 29 size_t length() const override { return length_; } |
34 | 30 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 101 |
106 job->PrepareToParseOnMainThread(); | 102 job->PrepareToParseOnMainThread(); |
107 job->Parse(); | 103 job->Parse(); |
108 job->FinalizeParsingOnMainThread(); | 104 job->FinalizeParsingOnMainThread(); |
109 | 105 |
110 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed); | 106 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed); |
111 ASSERT_FALSE(i_isolate()->has_pending_exception()); | 107 ASSERT_FALSE(i_isolate()->has_pending_exception()); |
112 job->ReportErrorsOnMainThread(); | 108 job->ReportErrorsOnMainThread(); |
113 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); | 109 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); |
114 ASSERT_TRUE(i_isolate()->has_pending_exception()); | 110 ASSERT_TRUE(i_isolate()->has_pending_exception()); |
115 i_isolate()->clear_pending_exception(); | |
116 } | |
117 | |
118 TEST_F(CompilerDispatcherJobTest, ScopeChain) { | |
119 const char script[] = | |
120 "function g() { var g = 1; function f(x) { return x * g }; return f; } " | |
121 "g();"; | |
122 Handle<JSFunction> f = Handle<JSFunction>::cast(Utils::OpenHandle( | |
123 *v8::Script::Compile(isolate()->GetCurrentContext(), | |
124 v8::String::NewFromUtf8(isolate(), script, | |
125 v8::NewStringType::kNormal) | |
126 .ToLocalChecked()) | |
127 .ToLocalChecked() | |
128 ->Run(isolate()->GetCurrentContext()) | |
129 .ToLocalChecked())); | |
130 | |
131 std::unique_ptr<CompilerDispatcherJob> job( | |
132 new CompilerDispatcherJob(i_isolate(), f, FLAG_stack_size)); | |
133 | |
134 job->PrepareToParseOnMainThread(); | |
135 job->Parse(); | |
136 job->FinalizeParsingOnMainThread(); | |
137 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile); | |
138 | |
139 const AstRawString* var_x = | |
140 job->parse_info_->ast_value_factory()->GetOneByteString("x"); | |
141 Variable* var = job->parse_info_->literal()->scope()->Lookup(var_x); | |
142 ASSERT_TRUE(var); | |
143 ASSERT_TRUE(var->IsUnallocated()); | |
144 | |
145 const AstRawString* var_g = | |
146 job->parse_info_->ast_value_factory()->GetOneByteString("g"); | |
147 var = job->parse_info_->literal()->scope()->Lookup(var_g); | |
148 ASSERT_TRUE(var); | |
149 ASSERT_TRUE(var->IsContextSlot()); | |
150 | |
151 job->ResetOnMainThread(); | |
152 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); | |
153 } | 111 } |
154 | 112 |
155 } // namespace internal | 113 } // namespace internal |
156 } // namespace v8 | 114 } // namespace v8 |
OLD | NEW |