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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 v8::internal::Vector<uint16_t>::New(str->Length()); | 44 v8::internal::Vector<uint16_t>::New(str->Length()); |
45 str->Write(buffer.start(), 0, str->Length()); | 45 str->Write(buffer.start(), 0, str->Length()); |
46 return buffer; | 46 return buffer; |
47 } | 47 } |
48 | 48 |
49 v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const char* str) { | 49 v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const char* str) { |
50 return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kNormal) | 50 return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kNormal) |
51 .ToLocalChecked(); | 51 .ToLocalChecked(); |
52 } | 52 } |
53 | 53 |
54 class UtilsExtension : public TaskRunner::SetupGlobalTask { | 54 class UtilsExtension : public IsolateData::SetupGlobalTask { |
55 public: | 55 public: |
56 ~UtilsExtension() override = default; | 56 ~UtilsExtension() override = default; |
57 void Run(v8::Isolate* isolate, | 57 void Run(v8::Isolate* isolate, |
58 v8::Local<v8::ObjectTemplate> global) override { | 58 v8::Local<v8::ObjectTemplate> global) override { |
59 v8::Local<v8::ObjectTemplate> utils = v8::ObjectTemplate::New(isolate); | 59 v8::Local<v8::ObjectTemplate> utils = v8::ObjectTemplate::New(isolate); |
60 utils->Set(ToV8String(isolate, "print"), | 60 utils->Set(ToV8String(isolate, "print"), |
61 v8::FunctionTemplate::New(isolate, &UtilsExtension::Print)); | 61 v8::FunctionTemplate::New(isolate, &UtilsExtension::Print)); |
62 utils->Set(ToV8String(isolate, "quit"), | 62 utils->Set(ToV8String(isolate, "quit"), |
63 v8::FunctionTemplate::New(isolate, &UtilsExtension::Quit)); | 63 v8::FunctionTemplate::New(isolate, &UtilsExtension::Quit)); |
64 utils->Set(ToV8String(isolate, "setlocale"), | 64 utils->Set(ToV8String(isolate, "setlocale"), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(chars).RunOnTaskRunner( | 193 ExecuteStringTask(chars).RunOnTaskRunner( |
194 TaskRunner::FromContext(isolate->GetCurrentContext())); | 194 IsolateData::FromContext(isolate->GetCurrentContext()) |
| 195 ->task_runner()); |
195 } | 196 } |
196 } | 197 } |
197 | 198 |
198 static void CompileAndRunWithOrigin( | 199 static void CompileAndRunWithOrigin( |
199 const v8::FunctionCallbackInfo<v8::Value>& args) { | 200 const v8::FunctionCallbackInfo<v8::Value>& args) { |
200 if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsString() || | 201 if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsString() || |
201 !args[2]->IsInt32() || !args[3]->IsInt32() || !args[4]->IsBoolean()) { | 202 !args[2]->IsInt32() || !args[3]->IsInt32() || !args[4]->IsBoolean()) { |
202 fprintf(stderr, | 203 fprintf(stderr, |
203 "Internal error: compileAndRunWithOrigin(source, name, line, " | 204 "Internal error: compileAndRunWithOrigin(source, name, line, " |
204 "column, is_module)."); | 205 "column, is_module)."); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 v8::Context::Scope context_scope(context); | 311 v8::Context::Scope context_scope(context); |
311 | 312 |
312 v8::Local<v8::Function> function = function_.Get(isolate()); | 313 v8::Local<v8::Function> function = function_.Get(isolate()); |
313 v8::MaybeLocal<v8::Value> result; | 314 v8::MaybeLocal<v8::Value> result; |
314 result = function->Call(context, context->Global(), 0, nullptr); | 315 result = function->Call(context, context->Global(), 0, nullptr); |
315 } | 316 } |
316 | 317 |
317 v8::Global<v8::Function> function_; | 318 v8::Global<v8::Function> function_; |
318 }; | 319 }; |
319 | 320 |
320 class SetTimeoutExtension : public TaskRunner::SetupGlobalTask { | 321 class SetTimeoutExtension : public IsolateData::SetupGlobalTask { |
321 public: | 322 public: |
322 void Run(v8::Isolate* isolate, | 323 void Run(v8::Isolate* isolate, |
323 v8::Local<v8::ObjectTemplate> global) override { | 324 v8::Local<v8::ObjectTemplate> global) override { |
324 global->Set( | 325 global->Set( |
325 ToV8String(isolate, "setTimeout"), | 326 ToV8String(isolate, "setTimeout"), |
326 v8::FunctionTemplate::New(isolate, &SetTimeoutExtension::SetTimeout)); | 327 v8::FunctionTemplate::New(isolate, &SetTimeoutExtension::SetTimeout)); |
327 } | 328 } |
328 | 329 |
329 private: | 330 private: |
330 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) { | 331 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) { |
(...skipping 12 matching lines...) Expand all Loading... |
343 if (args[0]->IsFunction()) { | 344 if (args[0]->IsFunction()) { |
344 task.reset(new SetTimeoutTask(isolate, | 345 task.reset(new SetTimeoutTask(isolate, |
345 v8::Local<v8::Function>::Cast(args[0]), | 346 v8::Local<v8::Function>::Cast(args[0]), |
346 "setTimeout", inspector)); | 347 "setTimeout", inspector)); |
347 } else { | 348 } else { |
348 task.reset(new ExecuteStringTask( | 349 task.reset(new ExecuteStringTask( |
349 ToVector(args[0].As<v8::String>()), v8::String::Empty(isolate), | 350 ToVector(args[0].As<v8::String>()), v8::String::Empty(isolate), |
350 v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0), | 351 v8::Integer::New(isolate, 0), v8::Integer::New(isolate, 0), |
351 v8::Boolean::New(isolate, false), "setTimeout", inspector)); | 352 v8::Boolean::New(isolate, false), "setTimeout", inspector)); |
352 } | 353 } |
353 TaskRunner::FromContext(context)->Append(task.release()); | 354 IsolateData::FromContext(context)->task_runner()->Append(task.release()); |
354 } | 355 } |
355 }; | 356 }; |
356 | 357 |
357 bool StrictAccessCheck(v8::Local<v8::Context> accessing_context, | 358 bool StrictAccessCheck(v8::Local<v8::Context> accessing_context, |
358 v8::Local<v8::Object> accessed_object, | 359 v8::Local<v8::Object> accessed_object, |
359 v8::Local<v8::Value> data) { | 360 v8::Local<v8::Value> data) { |
360 CHECK(accessing_context.IsEmpty()); | 361 CHECK(accessing_context.IsEmpty()); |
361 return accessing_context.IsEmpty(); | 362 return accessing_context.IsEmpty(); |
362 } | 363 } |
363 | 364 |
364 class InspectorExtension : public TaskRunner::SetupGlobalTask { | 365 class InspectorExtension : public IsolateData::SetupGlobalTask { |
365 public: | 366 public: |
366 ~InspectorExtension() override = default; | 367 ~InspectorExtension() override = default; |
367 void Run(v8::Isolate* isolate, | 368 void Run(v8::Isolate* isolate, |
368 v8::Local<v8::ObjectTemplate> global) override { | 369 v8::Local<v8::ObjectTemplate> global) override { |
369 v8::Local<v8::ObjectTemplate> inspector = v8::ObjectTemplate::New(isolate); | 370 v8::Local<v8::ObjectTemplate> inspector = v8::ObjectTemplate::New(isolate); |
370 inspector->Set( | 371 inspector->Set( |
371 ToV8String(isolate, "attachInspector"), | 372 ToV8String(isolate, "attachInspector"), |
372 v8::FunctionTemplate::New(isolate, &InspectorExtension::Attach)); | 373 v8::FunctionTemplate::New(isolate, &InspectorExtension::Attach)); |
373 inspector->Set( | 374 inspector->Set( |
374 ToV8String(isolate, "detachInspector"), | 375 ToV8String(isolate, "detachInspector"), |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 }; | 525 }; |
525 | 526 |
526 void UtilsExtension::CreateContextGroup( | 527 void UtilsExtension::CreateContextGroup( |
527 const v8::FunctionCallbackInfo<v8::Value>& args) { | 528 const v8::FunctionCallbackInfo<v8::Value>& args) { |
528 if (args.Length() != 0) { | 529 if (args.Length() != 0) { |
529 fprintf(stderr, "Internal error: createContextGroup()."); | 530 fprintf(stderr, "Internal error: createContextGroup()."); |
530 Exit(); | 531 Exit(); |
531 } | 532 } |
532 v8::base::Semaphore ready_semaphore(0); | 533 v8::base::Semaphore ready_semaphore(0); |
533 int context_group_id = 0; | 534 int context_group_id = 0; |
534 TaskRunner::SetupGlobalTasks setup_global; | 535 IsolateData::SetupGlobalTasks setup_global; |
535 setup_global.emplace_back(new SetTimeoutExtension()); | 536 setup_global.emplace_back(new SetTimeoutExtension()); |
536 setup_global.emplace_back(new InspectorExtension()); | 537 setup_global.emplace_back(new InspectorExtension()); |
537 inspector_client_->scheduleCreateContextGroup( | 538 inspector_client_->scheduleCreateContextGroup( |
538 std::move(setup_global), &ready_semaphore, &context_group_id); | 539 std::move(setup_global), &ready_semaphore, &context_group_id); |
539 ready_semaphore.Wait(); | 540 ready_semaphore.Wait(); |
540 args.GetReturnValue().Set( | 541 args.GetReturnValue().Set( |
541 v8::Int32::New(args.GetIsolate(), context_group_id)); | 542 v8::Int32::New(args.GetIsolate(), context_group_id)); |
542 } | 543 } |
543 | 544 |
544 v8::Local<v8::String> ToString(v8::Isolate* isolate, | 545 v8::Local<v8::String> ToString(v8::Isolate* isolate, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 v8::StartupData startup_data = {nullptr, 0}; | 603 v8::StartupData startup_data = {nullptr, 0}; |
603 for (int i = 1; i < argc; ++i) { | 604 for (int i = 1; i < argc; ++i) { |
604 if (strcmp(argv[i], "--embed") == 0) { | 605 if (strcmp(argv[i], "--embed") == 0) { |
605 argv[i++] = nullptr; | 606 argv[i++] = nullptr; |
606 printf("Embedding script '%s'\n", argv[i]); | 607 printf("Embedding script '%s'\n", argv[i]); |
607 startup_data = v8::V8::CreateSnapshotDataBlob(argv[i]); | 608 startup_data = v8::V8::CreateSnapshotDataBlob(argv[i]); |
608 argv[i] = nullptr; | 609 argv[i] = nullptr; |
609 } | 610 } |
610 } | 611 } |
611 | 612 |
612 TaskRunner::SetupGlobalTasks backend_extensions; | 613 IsolateData::SetupGlobalTasks backend_extensions; |
613 backend_extensions.emplace_back(new SetTimeoutExtension()); | 614 backend_extensions.emplace_back(new SetTimeoutExtension()); |
614 backend_extensions.emplace_back(new InspectorExtension()); | 615 backend_extensions.emplace_back(new InspectorExtension()); |
615 TaskRunner backend_runner(std::move(backend_extensions), false, | 616 TaskRunner backend_runner(std::move(backend_extensions), false, |
616 &ready_semaphore, | 617 &ready_semaphore, |
617 startup_data.data ? &startup_data : nullptr); | 618 startup_data.data ? &startup_data : nullptr); |
618 ready_semaphore.Wait(); | 619 ready_semaphore.Wait(); |
619 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner); | 620 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner); |
620 UtilsExtension::set_backend_task_runner(&backend_runner); | 621 UtilsExtension::set_backend_task_runner(&backend_runner); |
621 | 622 |
622 TaskRunner::SetupGlobalTasks frontend_extensions; | 623 IsolateData::SetupGlobalTasks frontend_extensions; |
623 frontend_extensions.emplace_back(new UtilsExtension()); | 624 frontend_extensions.emplace_back(new UtilsExtension()); |
624 frontend_extensions.emplace_back(new SendMessageToBackendExtension()); | 625 frontend_extensions.emplace_back(new SendMessageToBackendExtension()); |
625 TaskRunner frontend_runner(std::move(frontend_extensions), true, | 626 TaskRunner frontend_runner(std::move(frontend_extensions), true, |
626 &ready_semaphore, nullptr); | 627 &ready_semaphore, nullptr); |
627 ready_semaphore.Wait(); | 628 ready_semaphore.Wait(); |
628 | 629 |
629 FrontendChannelImpl frontend_channel(&frontend_runner); | 630 FrontendChannelImpl frontend_channel(&frontend_runner); |
630 InspectorClientImpl inspector_client(&backend_runner, &frontend_channel, | 631 InspectorClientImpl inspector_client(&backend_runner, &frontend_channel, |
631 &ready_semaphore); | 632 &ready_semaphore); |
632 ready_semaphore.Wait(); | 633 ready_semaphore.Wait(); |
(...skipping 16 matching lines...) Expand all Loading... |
649 } | 650 } |
650 frontend_runner.Append(new ExecuteStringTask(chars)); | 651 frontend_runner.Append(new ExecuteStringTask(chars)); |
651 } | 652 } |
652 | 653 |
653 frontend_runner.Join(); | 654 frontend_runner.Join(); |
654 backend_runner.Join(); | 655 backend_runner.Join(); |
655 | 656 |
656 delete startup_data.data; | 657 delete startup_data.data; |
657 return 0; | 658 return 0; |
658 } | 659 } |
OLD | NEW |