OLD | NEW |
(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 #include "test/inspector-protocol/task.h" |
| 6 |
| 7 #include "src/base/platform/platform.h" |
| 8 #include "src/inspector/string-util.h" |
| 9 #include "test/inspector-protocol/task-queue.h" |
| 10 #include "test/inspector-protocol/task-runner.h" |
| 11 |
| 12 namespace v8_inspector { |
| 13 |
| 14 TaskScope::TaskScope(v8::Isolate* isolate, |
| 15 const v8::Global<v8::Context>& context) |
| 16 : isolate_(isolate), |
| 17 isolate_scope_(isolate), |
| 18 handle_scope_(isolate), |
| 19 context_(context.Get(isolate)), |
| 20 context_scope_(context_), |
| 21 microtasks_scope_(isolate_, v8::MicrotasksScope::kRunMicrotasks), |
| 22 try_catch_(isolate_) {} |
| 23 |
| 24 TaskScope::~TaskScope() { |
| 25 if (try_catch_.HasCaught()) { |
| 26 v8_inspector::String16 message = |
| 27 v8_inspector::toProtocolString(try_catch_.Message()->Get()); |
| 28 fprintf(stderr, "Unhandle exception: %s\n", message.utf8().data()); |
| 29 fflush(stdout); |
| 30 fflush(stderr); |
| 31 _exit(0); |
| 32 } |
| 33 } |
| 34 |
| 35 ExecuteStringTask::ExecuteStringTask(const StringView& expression) |
| 36 : expression_(toString16(expression)) {} |
| 37 |
| 38 void ExecuteStringTask::Run(v8::Isolate* isolate, |
| 39 const v8::Global<v8::Context>& global_context) { |
| 40 TaskScope task_scope(isolate, global_context); |
| 41 v8::Local<v8::Context> context = task_scope.context(); |
| 42 v8::ScriptOrigin origin(v8::String::Empty(isolate)); |
| 43 v8::ScriptCompiler::Source scriptSource(toV8String(isolate, expression_), |
| 44 origin); |
| 45 v8::Local<v8::Script> script; |
| 46 if (!v8::ScriptCompiler::Compile(context, &scriptSource).ToLocal(&script)) |
| 47 return; |
| 48 v8::MaybeLocal<v8::Value> result; |
| 49 result = script->Run(context); |
| 50 } |
| 51 |
| 52 InitTask::InitTask(v8::ExtensionConfiguration* extensions, |
| 53 v8_inspector::TaskRunner* task_runner, |
| 54 v8::base::Semaphore* ready) |
| 55 : extensions_(extensions), task_runner_(task_runner), ready_(ready) {} |
| 56 |
| 57 void InitTask::Run() { |
| 58 v8::Isolate::CreateParams params; |
| 59 params.array_buffer_allocator = |
| 60 v8::ArrayBuffer::Allocator::NewDefaultAllocator(); |
| 61 v8::Isolate* isolate = v8::Isolate::New(params); |
| 62 isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped); |
| 63 v8::Isolate::Scope isolate_scope(isolate); |
| 64 v8::HandleScope handle_scope(isolate); |
| 65 |
| 66 v8::Local<v8::ObjectTemplate> global_template = |
| 67 v8::ObjectTemplate::New(isolate); |
| 68 v8::Local<v8::Context> context = |
| 69 v8::Context::New(isolate, extensions_, global_template); |
| 70 task_runner_->Queue()->SetContext(context); |
| 71 task_runner_->SetContext(context); |
| 72 |
| 73 if (ready_) ready_->Signal(); |
| 74 } |
| 75 |
| 76 } // v8_inspector |
OLD | NEW |