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

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

Issue 2781303002: [ES6 modules] Introduce ScriptModuleHash (Closed)
Patch Set: add_tests 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ScriptModule_h 5 #ifndef ScriptModule_h
6 #define ScriptModule_h 6 #define ScriptModule_h
7 7
8 #include "bindings/core/v8/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "bindings/core/v8/SharedPersistent.h" 9 #include "bindings/core/v8/SharedPersistent.h"
10 #include "core/CoreExport.h" 10 #include "core/CoreExport.h"
11 #include "v8/include/v8.h" 11 #include "v8/include/v8.h"
12 #include "wtf/Allocator.h" 12 #include "wtf/Allocator.h"
13 #include "wtf/text/WTFString.h" 13 #include "wtf/text/WTFString.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 class CORE_EXPORT ScriptModule final { 17 class CORE_EXPORT ScriptModule final {
18 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 18 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
19 19
20 public: 20 public:
21 static ScriptModule compile(v8::Isolate*, 21 static ScriptModule compile(v8::Isolate*,
22 const String& source, 22 const String& source,
23 const String& fileName); 23 const String& fileName);
24 24
25 // TODO(kouhei): Remove copy ctor
25 ScriptModule() {} 26 ScriptModule() {}
26 ScriptModule(const ScriptModule& module) : m_module(module.m_module) {} 27 ScriptModule(WTF::HashTableDeletedValueType)
28 : m_module(WTF::HashTableDeletedValue) {}
27 ~ScriptModule(); 29 ~ScriptModule();
28 30
29 bool instantiate(ScriptState*); 31 bool instantiate(ScriptState*);
30 void evaluate(ScriptState*); 32 void evaluate(ScriptState*);
31 33
34 bool isHashTableDeletedValue() const {
35 return m_module.isHashTableDeletedValue();
36 }
37
38 bool operator==(const blink::ScriptModule& other) const {
39 if (isHashTableDeletedValue() && other.isHashTableDeletedValue())
40 return true;
41
42 if (isHashTableDeletedValue() || other.isHashTableDeletedValue())
43 return false;
44
45 blink::SharedPersistent<v8::Module>* left = m_module.get();
46 blink::SharedPersistent<v8::Module>* right = other.m_module.get();
47 if (left == right)
48 return true;
49 if (!left || !right)
50 return false;
51 return *left == *right;
52 }
53
54 bool operator!=(const blink::ScriptModule& other) const {
55 return !(*this == other);
56 }
57
32 bool isNull() const { return m_module->isEmpty(); } 58 bool isNull() const { return m_module->isEmpty(); }
33 59
34 private: 60 private:
35 ScriptModule(v8::Isolate*, v8::Local<v8::Module>); 61 ScriptModule(v8::Isolate*, v8::Local<v8::Module>);
36 62
37 RefPtr<SharedPersistent<v8::Module>> m_module; 63 RefPtr<SharedPersistent<v8::Module>> m_module;
64 unsigned m_identityHash = 0;
65
66 friend struct ScriptModuleHash;
67 };
68
69 struct ScriptModuleHash {
70 STATIC_ONLY(ScriptModuleHash);
71
72 public:
73 static unsigned hash(const blink::ScriptModule& key) {
74 return key.m_identityHash;
haraken 2017/04/04 05:26:06 Why can't we simply use key.m_module.get() for the
kouhei (in TOK) 2017/04/04 05:54:32 Discussed offline. No, because ScriptModule::resol
75 }
76
77 static bool equal(const blink::ScriptModule& a,
78 const blink::ScriptModule& b) {
79 return a == b;
80 }
81
82 static constexpr bool safeToCompareToEmptyOrDeleted = true;
38 }; 83 };
39 84
40 } // namespace blink 85 } // namespace blink
41 86
87 namespace WTF {
88
89 template <>
90 struct DefaultHash<blink::ScriptModule> {
91 using Hash = blink::ScriptModuleHash;
92 };
93
94 template <>
95 struct HashTraits<blink::ScriptModule>
96 : public SimpleClassHashTraits<blink::ScriptModule> {};
97
98 } // namespace WTF
99
42 #endif // ScriptModule_h 100 #endif // ScriptModule_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698