OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8ContextSnapshot_h |
| 6 #define V8ContextSnapshot_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "platform/wtf/Allocator.h" |
| 10 #include "v8/include/v8.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class Document; |
| 15 class DOMWrapperWorld; |
| 16 |
| 17 // This class contains helper functions to take and use a V8 context snapshot. |
| 18 // |
| 19 // The V8 context snapshot is taken by tools/v8_context_snapshot/ when Chromium |
| 20 // is built, and is used when Blink creates a new V8 context. When to build or |
| 21 // to use the V8 context snapshot, you have a table of references of C++ |
| 22 // callbacks exposed to V8. |
| 23 // |
| 24 // A V8 context snapshot contains: |
| 25 // - Interface templates of Window, EventTarget, Node, Document, and |
| 26 // HTMLDocument. |
| 27 // - Two types of V8 contexts; one is for the main world, and the other is for |
| 28 // other worlds. |
| 29 // - HTMLDocument's wrapper (window.document) in the context for the main |
| 30 // world. |
| 31 // |
| 32 // Currently, the V8 context snapshot supports only the main thread. If it is |
| 33 // the main world, we need a special logic to serialize / deserialize |
| 34 // window.document (so only HTMLDocument is supported on the main world). |
| 35 // Worker threads are not yet supported. |
| 36 class CORE_EXPORT V8ContextSnapshot { |
| 37 STATIC_ONLY(V8ContextSnapshot); |
| 38 |
| 39 public: |
| 40 static v8::Local<v8::Context> CreateContextFromSnapshot( |
| 41 v8::Isolate*, |
| 42 const DOMWrapperWorld&, |
| 43 v8::ExtensionConfiguration*, |
| 44 v8::Local<v8::Object> global_proxy, |
| 45 Document*); |
| 46 // Install runtime enabled features on some v8::Object's in a context |
| 47 // created from a snapshot. |
| 48 static void InstallRuntimeEnabledFeatures(v8::Local<v8::Context>, Document*); |
| 49 |
| 50 static void EnsureInterfaceTemplates(v8::Isolate*); |
| 51 |
| 52 static void SetReferenceTable(intptr_t* table); |
| 53 static intptr_t* GetReferenceTable(); |
| 54 |
| 55 // Do not call this in production. |
| 56 static v8::StartupData TakeSnapshot(); |
| 57 |
| 58 private: |
| 59 static v8::StartupData SerializeInternalField(v8::Local<v8::Object> holder, |
| 60 int index, |
| 61 void* data); |
| 62 static void DeserializeInternalField(v8::Local<v8::Object> holder, |
| 63 int index, |
| 64 v8::StartupData payload, |
| 65 void* data); |
| 66 static bool CanCreateContextFromSnapshot(v8::Isolate*, |
| 67 const DOMWrapperWorld&, |
| 68 Document*); |
| 69 |
| 70 static void EnsureInterfaceTemplatesForWorld(v8::Isolate*, |
| 71 const DOMWrapperWorld&); |
| 72 |
| 73 static void TakeSnapshotForWorld(v8::SnapshotCreator*, |
| 74 const DOMWrapperWorld&); |
| 75 }; |
| 76 |
| 77 } // namespace blink |
| 78 |
| 79 #endif // V8ContextSnapshot_h |
OLD | NEW |