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 #if !defined(_WIN32) && !defined(_WIN64) | 5 #if !defined(_WIN32) && !defined(_WIN64) |
6 #include <unistd.h> // NOLINT | 6 #include <unistd.h> // NOLINT |
7 #endif // !defined(_WIN32) && !defined(_WIN64) | 7 #endif // !defined(_WIN32) && !defined(_WIN64) |
8 | 8 |
9 #include <locale.h> | 9 #include <locale.h> |
10 | 10 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 183 } |
184 | 184 |
185 static void Load(const v8::FunctionCallbackInfo<v8::Value>& args) { | 185 static void Load(const v8::FunctionCallbackInfo<v8::Value>& args) { |
186 if (args.Length() != 1 || !args[0]->IsString()) { | 186 if (args.Length() != 1 || !args[0]->IsString()) { |
187 fprintf(stderr, "Internal error: load gets one string argument."); | 187 fprintf(stderr, "Internal error: load gets one string argument."); |
188 Exit(); | 188 Exit(); |
189 } | 189 } |
190 v8::internal::Vector<const char> chars; | 190 v8::internal::Vector<const char> chars; |
191 v8::Isolate* isolate = args.GetIsolate(); | 191 v8::Isolate* isolate = args.GetIsolate(); |
192 if (ReadFile(isolate, args[0], &chars)) { | 192 if (ReadFile(isolate, args[0], &chars)) { |
193 ExecuteStringTask task(chars); | 193 ExecuteStringTask(chars).RunOnTaskRunner( |
194 v8::Global<v8::Context> context(isolate, isolate->GetCurrentContext()); | 194 TaskRunner::FromContext(isolate->GetCurrentContext())); |
195 task.Run(isolate, context); | |
196 } | 195 } |
197 } | 196 } |
198 | 197 |
199 static void CompileAndRunWithOrigin( | 198 static void CompileAndRunWithOrigin( |
200 const v8::FunctionCallbackInfo<v8::Value>& args) { | 199 const v8::FunctionCallbackInfo<v8::Value>& args) { |
201 if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsString() || | 200 if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsString() || |
202 !args[2]->IsInt32() || !args[3]->IsInt32() || !args[4]->IsBoolean()) { | 201 !args[2]->IsInt32() || !args[3]->IsInt32() || !args[4]->IsBoolean()) { |
203 fprintf(stderr, | 202 fprintf(stderr, |
204 "Internal error: compileAndRunWithOrigin(source, name, line, " | 203 "Internal error: compileAndRunWithOrigin(source, name, line, " |
205 "column, is_module)."); | 204 "column, is_module)."); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 294 |
296 class SetTimeoutTask : public AsyncTask { | 295 class SetTimeoutTask : public AsyncTask { |
297 public: | 296 public: |
298 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function, | 297 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function, |
299 const char* task_name, v8_inspector::V8Inspector* inspector) | 298 const char* task_name, v8_inspector::V8Inspector* inspector) |
300 : AsyncTask(task_name, inspector), function_(isolate, function) {} | 299 : AsyncTask(task_name, inspector), function_(isolate, function) {} |
301 virtual ~SetTimeoutTask() {} | 300 virtual ~SetTimeoutTask() {} |
302 | 301 |
303 bool is_inspector_task() final { return false; } | 302 bool is_inspector_task() final { return false; } |
304 | 303 |
305 void AsyncRun(v8::Isolate* isolate, | 304 private: |
306 const v8::Global<v8::Context>& global_context) override { | 305 void AsyncRun() override { |
307 v8::MicrotasksScope microtasks_scope(isolate, | 306 v8::MicrotasksScope microtasks_scope(isolate(), |
308 v8::MicrotasksScope::kRunMicrotasks); | 307 v8::MicrotasksScope::kRunMicrotasks); |
309 v8::HandleScope handle_scope(isolate); | 308 v8::HandleScope handle_scope(isolate()); |
310 v8::Local<v8::Context> context = global_context.Get(isolate); | 309 v8::Local<v8::Context> context = default_context(); |
311 v8::Context::Scope context_scope(context); | 310 v8::Context::Scope context_scope(context); |
312 | 311 |
313 v8::Local<v8::Function> function = function_.Get(isolate); | 312 v8::Local<v8::Function> function = function_.Get(isolate()); |
314 v8::MaybeLocal<v8::Value> result; | 313 v8::MaybeLocal<v8::Value> result; |
315 result = function->Call(context, context->Global(), 0, nullptr); | 314 result = function->Call(context, context->Global(), 0, nullptr); |
316 } | 315 } |
317 | 316 |
318 private: | |
319 v8::Global<v8::Function> function_; | 317 v8::Global<v8::Function> function_; |
320 }; | 318 }; |
321 | 319 |
322 class SetTimeoutExtension : public TaskRunner::SetupGlobalTask { | 320 class SetTimeoutExtension : public TaskRunner::SetupGlobalTask { |
323 public: | 321 public: |
324 void Run(v8::Isolate* isolate, | 322 void Run(v8::Isolate* isolate, |
325 v8::Local<v8::ObjectTemplate> global) override { | 323 v8::Local<v8::ObjectTemplate> global) override { |
326 global->Set( | 324 global->Set( |
327 ToV8String(isolate, "setTimeout"), | 325 ToV8String(isolate, "setTimeout"), |
328 v8::FunctionTemplate::New(isolate, &SetTimeoutExtension::SetTimeout)); | 326 v8::FunctionTemplate::New(isolate, &SetTimeoutExtension::SetTimeout)); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 } | 649 } |
652 frontend_runner.Append(new ExecuteStringTask(chars)); | 650 frontend_runner.Append(new ExecuteStringTask(chars)); |
653 } | 651 } |
654 | 652 |
655 frontend_runner.Join(); | 653 frontend_runner.Join(); |
656 backend_runner.Join(); | 654 backend_runner.Join(); |
657 | 655 |
658 delete startup_data.data; | 656 delete startup_data.data; |
659 return 0; | 657 return 0; |
660 } | 658 } |
OLD | NEW |