Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/ScriptModule.h

Issue 2781303002: [ES6 modules] Introduce ScriptModuleHash (Closed)
Patch Set: rebased Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 bc5a9c36e3342aa77189877d0a36ff6b7656fd82..9ae36b7b7d98df6d46c7c8d1355aadb0ef62c8eb 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptModule.h
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptModule.h
@@ -30,8 +30,10 @@ class CORE_EXPORT ScriptModule final {
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();
// Returns exception, if any.
@@ -40,6 +42,30 @@ class CORE_EXPORT ScriptModule final {
Vector<String> moduleRequests(ScriptState*);
+ bool isHashTableDeletedValue() const {
+ return m_module.isHashTableDeletedValue();
+ }
+
+ bool operator==(const blink::ScriptModule& other) const {
+ if (isHashTableDeletedValue() && other.isHashTableDeletedValue())
+ return true;
+
+ if (isHashTableDeletedValue() || other.isHashTableDeletedValue())
+ return false;
+
+ blink::SharedPersistent<v8::Module>* left = m_module.get();
+ blink::SharedPersistent<v8::Module>* right = other.m_module.get();
+ if (left == right)
+ return true;
+ if (!left || !right)
+ return false;
+ return *left == *right;
+ }
+
+ bool operator!=(const blink::ScriptModule& other) const {
+ return !(*this == other);
+ }
+
bool isNull() const { return !m_module || m_module->isEmpty(); }
private:
@@ -51,8 +77,40 @@ class CORE_EXPORT ScriptModule final {
v8::Local<v8::Module> referrer);
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 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698