Chromium Code Reviews| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsString() || | 170 if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsString() || |
| 171 !args[2]->IsInt32() || !args[3]->IsInt32()) { | 171 !args[2]->IsInt32() || !args[3]->IsInt32()) { |
| 172 fprintf(stderr, | 172 fprintf(stderr, |
| 173 "Internal error: compileAndRunWithOrigin(source, name, line, " | 173 "Internal error: compileAndRunWithOrigin(source, name, line, " |
| 174 "column)."); | 174 "column)."); |
| 175 Exit(); | 175 Exit(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 backend_runner_->Append(new ExecuteStringTask( | 178 backend_runner_->Append(new ExecuteStringTask( |
| 179 ToVector(args[0].As<v8::String>()), args[1].As<v8::String>(), | 179 ToVector(args[0].As<v8::String>()), args[1].As<v8::String>(), |
| 180 args[2].As<v8::Int32>(), args[3].As<v8::Int32>())); | 180 args[2].As<v8::Int32>(), args[3].As<v8::Int32>(), false)); |
| 181 } | 181 } |
| 182 }; | 182 }; |
| 183 | 183 |
| 184 TaskRunner* UtilsExtension::backend_runner_ = nullptr; | 184 TaskRunner* UtilsExtension::backend_runner_ = nullptr; |
| 185 | 185 |
| 186 class SetTimeoutTask : public TaskRunner::Task { | 186 class SetTimeoutTask : public TaskRunner::Task { |
| 187 public: | 187 public: |
| 188 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function) | 188 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function) |
| 189 : function_(isolate, function) {} | 189 : function_(isolate, function) {} |
| 190 virtual ~SetTimeoutTask() {} | 190 virtual ~SetTimeoutTask() {} |
| 191 | 191 |
| 192 bool is_inspector_task() final { return false; } | 192 bool is_inspector_task() final { return false; } |
| 193 | 193 |
| 194 void Run(v8::Isolate* isolate, | 194 void Run(v8::Isolate* isolate, |
| 195 const v8::Global<v8::Context>& global_context) override { | 195 const v8::Global<v8::Context>& global_context) override { |
| 196 v8::MicrotasksScope microtasks_scope(isolate, | 196 v8::MicrotasksScope microtasks_scope(isolate, |
| 197 v8::MicrotasksScope::kRunMicrotasks); | 197 v8::MicrotasksScope::kRunMicrotasks); |
| 198 v8::HandleScope handle_scope(isolate); | 198 v8::HandleScope handle_scope(isolate); |
| 199 v8::Local<v8::Context> context = global_context.Get(isolate); | 199 v8::Local<v8::Context> context = global_context.Get(isolate); |
| 200 v8::Context::Scope context_scope(context); | 200 v8::Context::Scope context_scope(context); |
| 201 | 201 |
| 202 v8::Local<v8::Function> function = function_.Get(isolate); | 202 v8::Local<v8::Function> function = function_.Get(isolate); |
| 203 v8::MaybeLocal<v8::Value> result; | 203 v8::MaybeLocal<v8::Value> result; |
| 204 v8_inspector::V8Inspector* inspector = | 204 v8_inspector::V8Inspector* inspector = |
| 205 InspectorClientImpl::InspectorFromContext(context); | 205 InspectorClientImpl::InspectorFromContext(context); |
| 206 if (inspector) inspector->willExecuteScript(context, function->ScriptId()); | 206 if (inspector) { |
| 207 inspector->willExecuteScript(context, function->ScriptId()); | |
| 208 inspector->asyncTaskStarted(this); | |
| 209 } | |
| 207 result = function->Call(context, context->Global(), 0, nullptr); | 210 result = function->Call(context, context->Global(), 0, nullptr); |
| 208 if (inspector) inspector->didExecuteScript(context); | 211 if (inspector) { |
| 212 inspector->asyncTaskFinished(this); | |
| 213 inspector->didExecuteScript(context); | |
| 214 } | |
| 209 } | 215 } |
| 210 | 216 |
| 211 private: | 217 private: |
| 212 v8::Global<v8::Function> function_; | 218 v8::Global<v8::Function> function_; |
| 213 }; | 219 }; |
| 214 | 220 |
| 215 class SetTimeoutExtension : public v8::Extension { | 221 class SetTimeoutExtension : public v8::Extension { |
| 216 public: | 222 public: |
| 217 SetTimeoutExtension() | 223 SetTimeoutExtension() |
| 218 : v8::Extension("v8_inspector/setTimeout", | 224 : v8::Extension("v8_inspector/setTimeout", |
| 219 "native function setTimeout();") {} | 225 "native function setTimeout();") {} |
| 220 | 226 |
| 221 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( | 227 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
| 222 v8::Isolate* isolate, v8::Local<v8::String> name) { | 228 v8::Isolate* isolate, v8::Local<v8::String> name) { |
| 223 return v8::FunctionTemplate::New(isolate, SetTimeoutExtension::SetTimeout); | 229 return v8::FunctionTemplate::New(isolate, SetTimeoutExtension::SetTimeout); |
| 224 } | 230 } |
| 225 | 231 |
| 226 private: | 232 private: |
| 227 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) { | 233 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 228 if (args.Length() != 2 || !args[1]->IsNumber() || | 234 if (args.Length() != 2 || !args[1]->IsNumber() || |
| 229 (!args[0]->IsFunction() && !args[0]->IsString()) || | 235 (!args[0]->IsFunction() && !args[0]->IsString()) || |
| 230 args[1].As<v8::Number>()->Value() != 0.0) { | 236 args[1].As<v8::Number>()->Value() != 0.0) { |
| 231 fprintf(stderr, | 237 fprintf(stderr, |
| 232 "Internal error: only setTimeout(function, 0) is supported."); | 238 "Internal error: only setTimeout(function, 0) is supported."); |
| 233 Exit(); | 239 Exit(); |
| 234 } | 240 } |
| 235 v8::Isolate* isolate = args.GetIsolate(); | 241 v8::Isolate* isolate = args.GetIsolate(); |
| 236 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 242 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 243 std::unique_ptr<TaskRunner::Task> task; | |
| 237 if (args[0]->IsFunction()) { | 244 if (args[0]->IsFunction()) { |
| 238 TaskRunner::FromContext(context)->Append( | 245 task.reset( |
| 239 new SetTimeoutTask(isolate, v8::Local<v8::Function>::Cast(args[0]))); | 246 new SetTimeoutTask(isolate, v8::Local<v8::Function>::Cast(args[0]))); |
| 240 } else { | 247 } else { |
| 241 TaskRunner::FromContext(context)->Append(new ExecuteStringTask( | 248 task.reset(new ExecuteStringTask( |
| 242 ToVector(args[0].As<v8::String>()), v8::String::Empty(isolate), | 249 ToVector(args[0].As<v8::String>()), v8::String::Empty(isolate), |
| 243 v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0))); | 250 v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0), true)); |
| 244 } | 251 } |
| 252 const char* set_timeout = "setTimeout"; | |
| 253 v8_inspector::V8Inspector* inspector = | |
| 254 InspectorClientImpl::InspectorFromContext(context); | |
| 255 if (inspector) { | |
| 256 inspector->asyncTaskScheduled( | |
|
dgozman
2016/12/13 17:31:54
Why doesn't ExecuteStringTask do this in construct
kozy
2016/12/13 18:24:26
Done.
| |
| 257 v8_inspector::StringView( | |
| 258 reinterpret_cast<const uint8_t*>(set_timeout), | |
| 259 strlen(set_timeout)), | |
| 260 task.get(), false); | |
| 261 } | |
| 262 TaskRunner::FromContext(context)->Append(task.release()); | |
| 245 } | 263 } |
| 246 }; | 264 }; |
| 247 | 265 |
| 248 class InspectorExtension : public v8::Extension { | 266 class InspectorExtension : public v8::Extension { |
| 249 public: | 267 public: |
| 250 InspectorExtension() | 268 InspectorExtension() |
| 251 : v8::Extension("v8_inspector/inspector", | 269 : v8::Extension("v8_inspector/inspector", |
| 252 "native function attachInspector();" | 270 "native function attachInspector();" |
| 253 "native function detachInspector();") {} | 271 "native function detachInspector();") {} |
| 254 | 272 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 v8::Local<v8::String> message_string = ToString(isolate, message); | 347 v8::Local<v8::String> message_string = ToString(isolate, message); |
| 330 v8::Local<v8::String> suffix = | 348 v8::Local<v8::String> suffix = |
| 331 v8::String::NewFromUtf8(isolate, ")", v8::NewStringType::kInternalized) | 349 v8::String::NewFromUtf8(isolate, ")", v8::NewStringType::kInternalized) |
| 332 .ToLocalChecked(); | 350 .ToLocalChecked(); |
| 333 | 351 |
| 334 v8::Local<v8::String> result = v8::String::Concat(prefix, message_string); | 352 v8::Local<v8::String> result = v8::String::Concat(prefix, message_string); |
| 335 result = v8::String::Concat(result, suffix); | 353 result = v8::String::Concat(result, suffix); |
| 336 | 354 |
| 337 frontend_task_runner_->Append(new ExecuteStringTask( | 355 frontend_task_runner_->Append(new ExecuteStringTask( |
| 338 ToVector(result), v8::String::Empty(isolate), | 356 ToVector(result), v8::String::Empty(isolate), |
| 339 v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0))); | 357 v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0), false)); |
| 340 } | 358 } |
| 341 | 359 |
| 342 private: | 360 private: |
| 343 TaskRunner* frontend_task_runner_; | 361 TaskRunner* frontend_task_runner_; |
| 344 }; | 362 }; |
| 345 | 363 |
| 346 } // namespace | 364 } // namespace |
| 347 | 365 |
| 348 int main(int argc, char* argv[]) { | 366 int main(int argc, char* argv[]) { |
| 349 v8::V8::InitializeICUDefaultLocation(argv[0]); | 367 v8::V8::InitializeICUDefaultLocation(argv[0]); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 argv[i]); | 417 argv[i]); |
| 400 Exit(); | 418 Exit(); |
| 401 } | 419 } |
| 402 frontend_runner.Append(new ExecuteStringTask(chars)); | 420 frontend_runner.Append(new ExecuteStringTask(chars)); |
| 403 } | 421 } |
| 404 | 422 |
| 405 frontend_runner.Join(); | 423 frontend_runner.Join(); |
| 406 backend_runner.Join(); | 424 backend_runner.Join(); |
| 407 return 0; | 425 return 0; |
| 408 } | 426 } |
| OLD | NEW |