OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 ModuleProxy_h |
| 6 #define ModuleProxy_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "wtf/Allocator.h" |
| 10 #include "wtf/StdLibExtras.h" |
| 11 #include <v8.h> |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 class ExecutionContext; |
| 16 |
| 17 // A proxy class to invoke functions implemented in bindings/modules |
| 18 // from bindings/core. |
| 19 class CORE_EXPORT ModuleProxy { |
| 20 USING_FAST_MALLOC(ModuleProxy); |
| 21 public: |
| 22 static ModuleProxy& moduleProxy() |
| 23 { |
| 24 DEFINE_STATIC_LOCAL(ModuleProxy, moduleProxy, ()); |
| 25 return moduleProxy; |
| 26 } |
| 27 |
| 28 ExecutionContext* toExecutionContextForModules(v8::Local<v8::Context> contex
t) |
| 29 { |
| 30 RELEASE_ASSERT(m_toExecutionContextForModules); |
| 31 return (*m_toExecutionContextForModules)(context); |
| 32 } |
| 33 |
| 34 void registerToExecutionContextForModules(ExecutionContext* (*toExecutionCon
textForModules)(v8::Local<v8::Context>)) |
| 35 { |
| 36 m_toExecutionContextForModules = toExecutionContextForModules; |
| 37 } |
| 38 |
| 39 v8::Local<v8::Context> toV8ContextForModules(ExecutionContext* context) |
| 40 { |
| 41 RELEASE_ASSERT(m_toV8ContextForModules); |
| 42 return (*m_toV8ContextForModules)(context); |
| 43 } |
| 44 |
| 45 void registerToV8ContextForModules(v8::Local<v8::Context> (*toV8ContextForMo
dules)(ExecutionContext*)) |
| 46 { |
| 47 m_toV8ContextForModules = toV8ContextForModules; |
| 48 } |
| 49 |
| 50 private: |
| 51 ModuleProxy() { } |
| 52 |
| 53 ExecutionContext* (*m_toExecutionContextForModules)(v8::Local<v8::Context>)
= nullptr; |
| 54 v8::Local<v8::Context> (*m_toV8ContextForModules)(ExecutionContext*) = nullp
tr; |
| 55 }; |
| 56 |
| 57 } // namespace blink |
| 58 |
| 59 #endif // ModuleProxy_h |
OLD | NEW |