| 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 17 matching lines...) Expand all Loading... |
| 28 #include <memory> | 28 #include <memory> |
| 29 | 29 |
| 30 #include "bindings/core/v8/BindingSecurity.h" | 30 #include "bindings/core/v8/BindingSecurity.h" |
| 31 #include "bindings/core/v8/RejectedPromises.h" | 31 #include "bindings/core/v8/RejectedPromises.h" |
| 32 #include "bindings/core/v8/RetainedDOMInfo.h" | 32 #include "bindings/core/v8/RetainedDOMInfo.h" |
| 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/V8ContextSnapshot.h" |
| 38 #include "bindings/core/v8/V8DOMException.h" | 39 #include "bindings/core/v8/V8DOMException.h" |
| 39 #include "bindings/core/v8/V8ErrorEvent.h" | 40 #include "bindings/core/v8/V8ErrorEvent.h" |
| 40 #include "bindings/core/v8/V8ErrorHandler.h" | 41 #include "bindings/core/v8/V8ErrorHandler.h" |
| 41 #include "bindings/core/v8/V8GCController.h" | 42 #include "bindings/core/v8/V8GCController.h" |
| 42 #include "bindings/core/v8/V8IdleTaskRunner.h" | 43 #include "bindings/core/v8/V8IdleTaskRunner.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" |
| (...skipping 333 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 V8ContextSnapshot::EnsureInterfaceTemplates(isolate); |
| 391 } | 394 } |
| 392 | 395 |
| 393 namespace { | 396 namespace { |
| 394 | 397 |
| 395 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 398 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| 396 // Allocate() methods return null to signal allocation failure to V8, which | 399 // Allocate() methods return null to signal allocation failure to V8, which |
| 397 // should respond by throwing a RangeError, per | 400 // should respond by throwing a RangeError, per |
| 398 // http://www.ecma-international.org/ecma-262/6.0/#sec-createbytedatablock. | 401 // http://www.ecma-international.org/ecma-262/6.0/#sec-createbytedatablock. |
| 399 void* Allocate(size_t size) override { | 402 void* Allocate(size_t size) override { |
| 400 return WTF::ArrayBufferContents::AllocateMemoryOrNull( | 403 return WTF::ArrayBufferContents::AllocateMemoryOrNull( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 457 |
| 455 process_total += diff; | 458 process_total += diff; |
| 456 DCHECK_GE(process_total, 0) | 459 DCHECK_GE(process_total, 0) |
| 457 << "total amount = " << process_total << ", diff = " << diff; | 460 << "total amount = " << process_total << ", diff = " << diff; |
| 458 } | 461 } |
| 459 #endif | 462 #endif |
| 460 | 463 |
| 461 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(diff); | 464 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(diff); |
| 462 } | 465 } |
| 463 | 466 |
| 464 void V8Initializer::InitializeMainThread() { | 467 void V8Initializer::InitializeMainThread(intptr_t* reference_table) { |
| 465 DCHECK(IsMainThread()); | 468 DCHECK(IsMainThread()); |
| 466 | 469 |
| 467 WTF::ArrayBufferContents::Initialize(AdjustAmountOfExternalAllocatedMemory); | 470 WTF::ArrayBufferContents::Initialize(AdjustAmountOfExternalAllocatedMemory); |
| 468 | 471 |
| 469 DEFINE_STATIC_LOCAL(ArrayBufferAllocator, array_buffer_allocator, ()); | 472 DEFINE_STATIC_LOCAL(ArrayBufferAllocator, array_buffer_allocator, ()); |
| 470 auto v8_extras_mode = RuntimeEnabledFeatures::ExperimentalV8ExtrasEnabled() | 473 auto v8_extras_mode = RuntimeEnabledFeatures::ExperimentalV8ExtrasEnabled() |
| 471 ? gin::IsolateHolder::kStableAndExperimentalV8Extras | 474 ? gin::IsolateHolder::kStableAndExperimentalV8Extras |
| 472 : gin::IsolateHolder::kStableV8Extras; | 475 : gin::IsolateHolder::kStableV8Extras; |
| 473 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, | 476 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, |
| 474 v8_extras_mode, &array_buffer_allocator); | 477 v8_extras_mode, &array_buffer_allocator); |
| 475 | 478 |
| 476 // NOTE: Some threads (namely utility threads) don't have a scheduler. | 479 // NOTE: Some threads (namely utility threads) don't have a scheduler. |
| 477 WebScheduler* scheduler = Platform::Current()->CurrentThread()->Scheduler(); | 480 WebScheduler* scheduler = Platform::Current()->CurrentThread()->Scheduler(); |
| 481 |
| 482 V8PerIsolateData::V8ContextSnapshotMode v8_context_snapshot_mode = |
| 483 Platform::Current()->IsTakingV8ContextSnapshot() |
| 484 ? V8PerIsolateData::V8ContextSnapshotMode::kTakeSnapshot |
| 485 : V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot; |
| 486 if (v8_context_snapshot_mode == |
| 487 V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot && |
| 488 !RuntimeEnabledFeatures::V8ContextSnapshotEnabled()) { |
| 489 v8_context_snapshot_mode = |
| 490 V8PerIsolateData::V8ContextSnapshotMode::kDontUseSnapshot; |
| 491 reference_table = nullptr; |
| 492 } |
| 493 V8ContextSnapshot::SetReferenceTable(reference_table); |
| 494 |
| 478 // When timer task runner is used for PerIsolateData, GC tasks are getting | 495 // When timer task runner is used for PerIsolateData, GC tasks are getting |
| 479 // throttled and memory usage goes up. For now we're using loading task queue | 496 // throttled and memory usage goes up. For now we're using loading task queue |
| 480 // to prevent this. | 497 // to prevent this. |
| 481 // TODO(altimin): Consider switching to timerTaskRunner here. | 498 // TODO(altimin): Consider switching to timerTaskRunner here. |
| 482 v8::Isolate* isolate = V8PerIsolateData::Initialize( | 499 v8::Isolate* isolate = V8PerIsolateData::Initialize( |
| 483 scheduler ? scheduler->LoadingTaskRunner() | 500 scheduler ? scheduler->LoadingTaskRunner() |
| 484 : Platform::Current()->CurrentThread()->GetWebTaskRunner()); | 501 : Platform::Current()->CurrentThread()->GetWebTaskRunner(), |
| 502 reference_table, v8_context_snapshot_mode); |
| 485 | 503 |
| 486 InitializeV8Common(isolate); | 504 InitializeV8Common(isolate); |
| 487 | 505 |
| 488 isolate->SetOOMErrorHandler(ReportOOMErrorInMainThread); | 506 isolate->SetOOMErrorHandler(ReportOOMErrorInMainThread); |
| 489 isolate->SetFatalErrorHandler(ReportFatalErrorInMainThread); | 507 isolate->SetFatalErrorHandler(ReportFatalErrorInMainThread); |
| 490 isolate->AddMessageListenerWithErrorLevel( | 508 isolate->AddMessageListenerWithErrorLevel( |
| 491 MessageHandlerInMainThread, | 509 MessageHandlerInMainThread, |
| 492 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | | 510 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | |
| 493 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | | 511 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | |
| 494 v8::Isolate::kMessageLog); | 512 v8::Isolate::kMessageLog); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 v8::Isolate::kMessageLog); | 616 v8::Isolate::kMessageLog); |
| 599 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); | 617 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); |
| 600 | 618 |
| 601 uint32_t here; | 619 uint32_t here; |
| 602 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - | 620 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - |
| 603 kWorkerMaxStackSize); | 621 kWorkerMaxStackSize); |
| 604 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); | 622 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); |
| 605 } | 623 } |
| 606 | 624 |
| 607 } // namespace blink | 625 } // namespace blink |
| OLD | NEW |