Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 #include "bindings/core/v8/ScriptController.h" | 33 #include "bindings/core/v8/ScriptController.h" |
| 34 #include "bindings/core/v8/ScriptValue.h" | 34 #include "bindings/core/v8/ScriptValue.h" |
| 35 #include "bindings/core/v8/SourceLocation.h" | 35 #include "bindings/core/v8/SourceLocation.h" |
| 36 #include "bindings/core/v8/UseCounterCallback.h" | 36 #include "bindings/core/v8/UseCounterCallback.h" |
| 37 #include "bindings/core/v8/V8BindingForCore.h" | 37 #include "bindings/core/v8/V8BindingForCore.h" |
| 38 #include "bindings/core/v8/V8DOMException.h" | 38 #include "bindings/core/v8/V8DOMException.h" |
| 39 #include "bindings/core/v8/V8ErrorEvent.h" | 39 #include "bindings/core/v8/V8ErrorEvent.h" |
| 40 #include "bindings/core/v8/V8ErrorHandler.h" | 40 #include "bindings/core/v8/V8ErrorHandler.h" |
| 41 #include "bindings/core/v8/V8GCController.h" | 41 #include "bindings/core/v8/V8GCController.h" |
| 42 #include "bindings/core/v8/V8IdleTaskRunner.h" | 42 #include "bindings/core/v8/V8IdleTaskRunner.h" |
| 43 #include "bindings/core/v8/V8SnapshotUtil.h" | |
| 43 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 44 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 44 #include "core/dom/Document.h" | 45 #include "core/dom/Document.h" |
| 45 #include "core/dom/ExecutionContext.h" | 46 #include "core/dom/ExecutionContext.h" |
| 46 #include "core/frame/LocalDOMWindow.h" | 47 #include "core/frame/LocalDOMWindow.h" |
| 47 #include "core/frame/csp/ContentSecurityPolicy.h" | 48 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 48 #include "core/inspector/ConsoleMessage.h" | 49 #include "core/inspector/ConsoleMessage.h" |
| 49 #include "core/inspector/MainThreadDebugger.h" | 50 #include "core/inspector/MainThreadDebugger.h" |
| 50 #include "core/workers/WorkerGlobalScope.h" | 51 #include "core/workers/WorkerGlobalScope.h" |
| 51 #include "platform/EventDispatchForbiddenScope.h" | 52 #include "platform/EventDispatchForbiddenScope.h" |
| 52 #include "platform/RuntimeEnabledFeatures.h" | 53 #include "platform/RuntimeEnabledFeatures.h" |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 V8PerIsolateData::From(isolate)->SetScriptWrappableVisitor( | 382 V8PerIsolateData::From(isolate)->SetScriptWrappableVisitor( |
| 382 std::move(visitor)); | 383 std::move(visitor)); |
| 383 isolate->SetEmbedderHeapTracer( | 384 isolate->SetEmbedderHeapTracer( |
| 384 V8PerIsolateData::From(isolate)->GetScriptWrappableVisitor()); | 385 V8PerIsolateData::From(isolate)->GetScriptWrappableVisitor()); |
| 385 | 386 |
| 386 isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped); | 387 isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped); |
| 387 | 388 |
| 388 isolate->SetUseCounterCallback(&UseCounterCallback); | 389 isolate->SetUseCounterCallback(&UseCounterCallback); |
| 389 isolate->SetWasmModuleCallback(WasmModuleOverride); | 390 isolate->SetWasmModuleCallback(WasmModuleOverride); |
| 390 isolate->SetWasmInstanceCallback(WasmInstanceOverride); | 391 isolate->SetWasmInstanceCallback(WasmInstanceOverride); |
| 392 | |
| 393 v8::HandleScope handle_scope(isolate); | |
|
haraken
2017/07/04 15:04:19
Can we move the HandleScope into EnsureInterfaceTe
peria
2017/07/07 06:21:54
Done.
| |
| 394 V8SnapshotUtil::EnsureInterfaceTemplates(isolate); | |
| 391 } | 395 } |
| 392 | 396 |
| 393 namespace { | 397 namespace { |
| 394 | 398 |
| 395 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 399 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| 396 // Allocate() methods return null to signal allocation failure to V8, which | 400 // Allocate() methods return null to signal allocation failure to V8, which |
| 397 // should respond by throwing a RangeError, per | 401 // should respond by throwing a RangeError, per |
| 398 // http://www.ecma-international.org/ecma-262/6.0/#sec-createbytedatablock. | 402 // http://www.ecma-international.org/ecma-262/6.0/#sec-createbytedatablock. |
| 399 void* Allocate(size_t size) override { | 403 void* Allocate(size_t size) override { |
| 400 return WTF::ArrayBufferContents::AllocateMemoryOrNull( | 404 return WTF::ArrayBufferContents::AllocateMemoryOrNull( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 v8_extras_mode, &array_buffer_allocator); | 446 v8_extras_mode, &array_buffer_allocator); |
| 443 | 447 |
| 444 // NOTE: Some threads (namely utility threads) don't have a scheduler. | 448 // NOTE: Some threads (namely utility threads) don't have a scheduler. |
| 445 WebScheduler* scheduler = Platform::Current()->CurrentThread()->Scheduler(); | 449 WebScheduler* scheduler = Platform::Current()->CurrentThread()->Scheduler(); |
| 446 // When timer task runner is used for PerIsolateData, GC tasks are getting | 450 // When timer task runner is used for PerIsolateData, GC tasks are getting |
| 447 // throttled and memory usage goes up. For now we're using loading task queue | 451 // throttled and memory usage goes up. For now we're using loading task queue |
| 448 // to prevent this. | 452 // to prevent this. |
| 449 // TODO(altimin): Consider switching to timerTaskRunner here. | 453 // TODO(altimin): Consider switching to timerTaskRunner here. |
| 450 v8::Isolate* isolate = V8PerIsolateData::Initialize( | 454 v8::Isolate* isolate = V8PerIsolateData::Initialize( |
| 451 scheduler ? scheduler->LoadingTaskRunner() | 455 scheduler ? scheduler->LoadingTaskRunner() |
| 452 : Platform::Current()->CurrentThread()->GetWebTaskRunner()); | 456 : Platform::Current()->CurrentThread()->GetWebTaskRunner(), |
| 457 V8SnapshotUtil::GetReferenceTable(), | |
| 458 Platform::Current()->IsToTakeV8Snapshot() | |
| 459 ? V8PerIsolateData::V8ContextMode::kTakeSnapshot | |
| 460 : V8PerIsolateData::V8ContextMode::kUseSnapshot); | |
| 453 | 461 |
| 454 InitializeV8Common(isolate); | 462 InitializeV8Common(isolate); |
| 455 | 463 |
| 456 isolate->SetOOMErrorHandler(ReportOOMErrorInMainThread); | 464 isolate->SetOOMErrorHandler(ReportOOMErrorInMainThread); |
| 457 isolate->SetFatalErrorHandler(ReportFatalErrorInMainThread); | 465 isolate->SetFatalErrorHandler(ReportFatalErrorInMainThread); |
| 458 isolate->AddMessageListenerWithErrorLevel( | 466 isolate->AddMessageListenerWithErrorLevel( |
| 459 MessageHandlerInMainThread, | 467 MessageHandlerInMainThread, |
| 460 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | | 468 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | |
| 461 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | | 469 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | |
| 462 v8::Isolate::kMessageLog); | 470 v8::Isolate::kMessageLog); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 v8::Isolate::kMessageLog); | 574 v8::Isolate::kMessageLog); |
| 567 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); | 575 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); |
| 568 | 576 |
| 569 uint32_t here; | 577 uint32_t here; |
| 570 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - | 578 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - |
| 571 kWorkerMaxStackSize); | 579 kWorkerMaxStackSize); |
| 572 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); | 580 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); |
| 573 } | 581 } |
| 574 | 582 |
| 575 } // namespace blink | 583 } // namespace blink |
| OLD | NEW |