Index: third_party/WebKit/Source/bindings/core/v8/ScriptModule.h |
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptModule.h b/third_party/WebKit/Source/bindings/core/v8/ScriptModule.h |
index fc51232d7f5d635423021db752bd6d01bb9ff217..5cee51c11974d2448c311809515669d1db8adf1d 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptModule.h |
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptModule.h |
@@ -5,38 +5,118 @@ |
#ifndef ScriptModule_h |
#define ScriptModule_h |
+#include <v8.h> |
#include "bindings/core/v8/ScriptState.h" |
#include "bindings/core/v8/SharedPersistent.h" |
#include "core/CoreExport.h" |
#include "v8/include/v8.h" |
#include "wtf/Allocator.h" |
+#include "wtf/HashTableDeletedValueType.h" |
+#include "wtf/HashTraits.h" |
+#include "wtf/Vector.h" |
#include "wtf/text/WTFString.h" |
namespace blink { |
+class ScriptState; |
+ |
+// ScriptModule wraps a handle to a v8::Module for use in core. |
+// |
+// Using ScriptModules needs a ScriptState and its scope to operate in. You |
+// should always provide the same ScriptState and not try to reuse ScriptModules |
+// across different contexts. |
+// Currently all ScriptModule users can easily access its context Modulator, so |
+// we use it to fill ScriptState in. |
class CORE_EXPORT ScriptModule final { |
DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
public: |
+ class Hash; |
+ |
static ScriptModule compile(v8::Isolate*, |
const String& source, |
const String& fileName); |
+ // TODO(kouhei): Remove copy ctor |
ScriptModule() {} |
- ScriptModule(const ScriptModule& module) : m_module(module.m_module) {} |
+ ScriptModule(WTF::HashTableDeletedValueType) |
+ : m_module(WTF::HashTableDeletedValue) {} |
+ |
+ ScriptModule(const ScriptModule&) = default; |
+ ScriptModule(ScriptModule&&) = default; |
+ ScriptModule& operator=(ScriptModule&&) = default; |
+ ScriptModule& operator=(const ScriptModule&) = default; |
~ScriptModule(); |
- bool instantiate(ScriptState*); |
+ ScriptValue instantiate(ScriptState*); |
void evaluate(ScriptState*); |
+ Vector<String> moduleRequests(ScriptState*); |
+ |
+ bool isHashTableDeletedValue() const { |
+ return m_module.isHashTableDeletedValue(); |
+ } |
+ |
+ bool operator==(const blink::ScriptModule& rhs) const { |
+ if (m_module.isHashTableDeletedValue() && |
+ rhs.m_module.isHashTableDeletedValue()) |
+ return true; |
+ |
+ blink::SharedPersistent<v8::Module>* lhsp = m_module.get(); |
+ blink::SharedPersistent<v8::Module>* rhsp = rhs.m_module.get(); |
+ if (lhsp == rhsp) |
+ return true; |
+ if (!lhsp || !rhsp) |
+ return false; |
+ return *lhsp == *rhsp; |
+ } |
+ |
bool isNull() const { return m_module->isEmpty(); } |
private: |
ScriptModule(v8::Isolate*, v8::Local<v8::Module>); |
+ static v8::MaybeLocal<v8::Module> resolveModuleCallback( |
+ v8::Local<v8::Context>, |
+ v8::Local<v8::String> specifier, |
+ v8::Local<v8::Module> referrer); |
+ |
+ // TODO(kouhei): Make ScriptModule move-only and make this ScopedPersistent. |
RefPtr<SharedPersistent<v8::Module>> m_module; |
+ unsigned m_identityHash = 0; |
+ |
+ friend struct ScriptModuleHash; |
+}; |
+ |
+struct ScriptModuleHash { |
+ STATIC_ONLY(ScriptModuleHash); |
+ |
+ public: |
+ static unsigned hash(const blink::ScriptModule& key) { |
+ return static_cast<unsigned>(key.m_identityHash); |
+ } |
+ |
+ static bool equal(const blink::ScriptModule& a, |
+ const blink::ScriptModule& b) { |
+ return a == b; |
+ } |
+ |
+ static constexpr bool safeToCompareToEmptyOrDeleted = true; |
}; |
} // namespace blink |
+namespace WTF { |
+ |
+template <> |
+struct DefaultHash<blink::ScriptModule> { |
+ using Hash = blink::ScriptModuleHash; |
+}; |
+ |
+template <> |
+struct HashTraits<blink::ScriptModule> |
+ : public SimpleClassHashTraits<blink::ScriptModule> {}; |
+ |
+} // namespace WTF |
+ |
#endif // ScriptModule_h |