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); | |
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 WTF::ArrayBufferContents::Initialize(AdjustAmountOfExternalAllocatedMemory); | 439 WTF::ArrayBufferContents::Initialize(AdjustAmountOfExternalAllocatedMemory); |
436 | 440 |
437 DEFINE_STATIC_LOCAL(ArrayBufferAllocator, array_buffer_allocator, ()); | 441 DEFINE_STATIC_LOCAL(ArrayBufferAllocator, array_buffer_allocator, ()); |
438 auto v8_extras_mode = RuntimeEnabledFeatures::ExperimentalV8ExtrasEnabled() | 442 auto v8_extras_mode = RuntimeEnabledFeatures::ExperimentalV8ExtrasEnabled() |
439 ? gin::IsolateHolder::kStableAndExperimentalV8Extras | 443 ? gin::IsolateHolder::kStableAndExperimentalV8Extras |
440 : gin::IsolateHolder::kStableV8Extras; | 444 : gin::IsolateHolder::kStableV8Extras; |
441 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, | 445 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, |
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 Platform* platform = Platform::Current(); |
450 WebThread* thread = platform->CurrentThread(); | |
Yuki
2017/06/23 15:20:44
As I took a look at the codebase, it seems better
peria
2017/06/27 09:52:37
Done.
| |
451 WebScheduler* scheduler = thread ? thread->Scheduler() : nullptr; | |
452 | |
446 // When timer task runner is used for PerIsolateData, GC tasks are getting | 453 // 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 | 454 // throttled and memory usage goes up. For now we're using loading task queue |
448 // to prevent this. | 455 // to prevent this. |
449 // TODO(altimin): Consider switching to timerTaskRunner here. | 456 // TODO(altimin): Consider switching to timerTaskRunner here. |
450 v8::Isolate* isolate = V8PerIsolateData::Initialize( | 457 v8::Isolate* isolate = V8PerIsolateData::Initialize( |
451 scheduler ? scheduler->LoadingTaskRunner() | 458 scheduler ? scheduler->LoadingTaskRunner() |
452 : Platform::Current()->CurrentThread()->GetWebTaskRunner()); | 459 : thread ? thread->GetWebTaskRunner() : nullptr, |
Yuki
2017/06/23 15:20:44
Ditto.
peria
2017/06/27 09:52:37
Done.
| |
460 V8SnapshotUtil::GetReferenceTable(), | |
461 platform->IsToTakeV8Snapshot() | |
462 ? V8PerIsolateData::V8ContextMode::kTakeSnapshot | |
463 : V8PerIsolateData::V8ContextMode::kUseSnapshot); | |
453 | 464 |
454 InitializeV8Common(isolate); | 465 InitializeV8Common(isolate); |
455 | 466 |
456 isolate->SetOOMErrorHandler(ReportOOMErrorInMainThread); | 467 isolate->SetOOMErrorHandler(ReportOOMErrorInMainThread); |
457 isolate->SetFatalErrorHandler(ReportFatalErrorInMainThread); | 468 isolate->SetFatalErrorHandler(ReportFatalErrorInMainThread); |
458 isolate->AddMessageListenerWithErrorLevel( | 469 isolate->AddMessageListenerWithErrorLevel( |
459 MessageHandlerInMainThread, | 470 MessageHandlerInMainThread, |
460 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | | 471 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | |
461 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | | 472 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | |
462 v8::Isolate::kMessageLog); | 473 v8::Isolate::kMessageLog); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 v8::Isolate::kMessageLog); | 577 v8::Isolate::kMessageLog); |
567 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); | 578 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); |
568 | 579 |
569 uint32_t here; | 580 uint32_t here; |
570 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - | 581 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - |
571 kWorkerMaxStackSize); | 582 kWorkerMaxStackSize); |
572 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); | 583 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); |
573 } | 584 } |
574 | 585 |
575 } // namespace blink | 586 } // namespace blink |
OLD | NEW |