| 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 "test/inspector/task-runner.h" | 5 #include "test/inspector/task-runner.h" |
| 6 | 6 |
| 7 #if !defined(_WIN32) && !defined(_WIN64) | 7 #if !defined(_WIN32) && !defined(_WIN64) |
| 8 #include <unistd.h> // NOLINT | 8 #include <unistd.h> // NOLINT |
| 9 #endif // !defined(_WIN32) && !defined(_WIN64) | 9 #endif // !defined(_WIN32) && !defined(_WIN64) |
| 10 | 10 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 process_queue_semaphore_.Wait(); | 116 process_queue_semaphore_.Wait(); |
| 117 } | 117 } |
| 118 return nullptr; | 118 return nullptr; |
| 119 } | 119 } |
| 120 | 120 |
| 121 TaskRunner* TaskRunner::FromContext(v8::Local<v8::Context> context) { | 121 TaskRunner* TaskRunner::FromContext(v8::Local<v8::Context> context) { |
| 122 return static_cast<TaskRunner*>( | 122 return static_cast<TaskRunner*>( |
| 123 context->GetAlignedPointerFromEmbedderData(kTaskRunnerIndex)); | 123 context->GetAlignedPointerFromEmbedderData(kTaskRunnerIndex)); |
| 124 } | 124 } |
| 125 | 125 |
| 126 namespace { |
| 127 |
| 128 v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) { |
| 129 v8::internal::Vector<uint16_t> buffer = |
| 130 v8::internal::Vector<uint16_t>::New(str->Length()); |
| 131 str->Write(buffer.start(), 0, str->Length()); |
| 132 return buffer; |
| 133 } |
| 134 |
| 135 } // namespace |
| 136 |
| 126 ExecuteStringTask::ExecuteStringTask( | 137 ExecuteStringTask::ExecuteStringTask( |
| 127 const v8::internal::Vector<uint16_t>& expression) | 138 const v8::internal::Vector<uint16_t>& expression, |
| 128 : expression_(expression) {} | 139 v8::Local<v8::String> name, v8::Local<v8::Integer> line_offset, |
| 140 v8::Local<v8::Integer> column_offset) |
| 141 : expression_(expression), |
| 142 name_(ToVector(name)), |
| 143 line_offset_(line_offset.As<v8::Int32>()->Value()), |
| 144 column_offset_(column_offset.As<v8::Int32>()->Value()) {} |
| 129 | 145 |
| 130 ExecuteStringTask::ExecuteStringTask( | 146 ExecuteStringTask::ExecuteStringTask( |
| 131 const v8::internal::Vector<const char>& expression) | 147 const v8::internal::Vector<const char>& expression) |
| 132 : expression_utf8_(expression) {} | 148 : expression_utf8_(expression), line_offset_(0), column_offset_(0) {} |
| 133 | 149 |
| 134 void ExecuteStringTask::Run(v8::Isolate* isolate, | 150 void ExecuteStringTask::Run(v8::Isolate* isolate, |
| 135 const v8::Global<v8::Context>& context) { | 151 const v8::Global<v8::Context>& context) { |
| 136 v8::MicrotasksScope microtasks_scope(isolate, | 152 v8::MicrotasksScope microtasks_scope(isolate, |
| 137 v8::MicrotasksScope::kRunMicrotasks); | 153 v8::MicrotasksScope::kRunMicrotasks); |
| 138 v8::HandleScope handle_scope(isolate); | 154 v8::HandleScope handle_scope(isolate); |
| 139 v8::Local<v8::Context> local_context = context.Get(isolate); | 155 v8::Local<v8::Context> local_context = context.Get(isolate); |
| 140 v8::Context::Scope context_scope(local_context); | 156 v8::Context::Scope context_scope(local_context); |
| 141 | 157 |
| 142 v8::ScriptOrigin origin(v8::String::Empty(isolate)); | 158 v8::Local<v8::String> name = |
| 159 v8::String::NewFromTwoByte(isolate, name_.start(), |
| 160 v8::NewStringType::kNormal, name_.length()) |
| 161 .ToLocalChecked(); |
| 162 v8::Local<v8::Integer> line_offset = v8::Integer::New(isolate, line_offset_); |
| 163 v8::Local<v8::Integer> column_offset = |
| 164 v8::Integer::New(isolate, column_offset_); |
| 165 |
| 166 v8::ScriptOrigin origin(name, line_offset, column_offset); |
| 143 v8::Local<v8::String> source; | 167 v8::Local<v8::String> source; |
| 144 if (expression_.length()) { | 168 if (expression_.length()) { |
| 145 source = v8::String::NewFromTwoByte(isolate, expression_.start(), | 169 source = v8::String::NewFromTwoByte(isolate, expression_.start(), |
| 146 v8::NewStringType::kNormal, | 170 v8::NewStringType::kNormal, |
| 147 expression_.length()) | 171 expression_.length()) |
| 148 .ToLocalChecked(); | 172 .ToLocalChecked(); |
| 149 } else { | 173 } else { |
| 150 source = v8::String::NewFromUtf8(isolate, expression_utf8_.start(), | 174 source = v8::String::NewFromUtf8(isolate, expression_utf8_.start(), |
| 151 v8::NewStringType::kNormal, | 175 v8::NewStringType::kNormal, |
| 152 expression_utf8_.length()) | 176 expression_utf8_.length()) |
| 153 .ToLocalChecked(); | 177 .ToLocalChecked(); |
| 154 } | 178 } |
| 155 | 179 |
| 156 v8::ScriptCompiler::Source scriptSource(source, origin); | 180 v8::ScriptCompiler::Source scriptSource(source, origin); |
| 157 v8::Local<v8::Script> script; | 181 v8::Local<v8::Script> script; |
| 158 if (!v8::ScriptCompiler::Compile(local_context, &scriptSource) | 182 if (!v8::ScriptCompiler::Compile(local_context, &scriptSource) |
| 159 .ToLocal(&script)) | 183 .ToLocal(&script)) |
| 160 return; | 184 return; |
| 161 v8::MaybeLocal<v8::Value> result; | 185 v8::MaybeLocal<v8::Value> result; |
| 162 result = script->Run(local_context); | 186 result = script->Run(local_context); |
| 163 } | 187 } |
| OLD | NEW |