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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 12 matching lines...) Expand all
23 // Currently all ScriptModule users can easily access its context Modulator, so 23 // Currently all ScriptModule users can easily access its context Modulator, so
24 // we use it to fill ScriptState in. 24 // we use it to fill ScriptState in.
25 class CORE_EXPORT ScriptModule final { 25 class CORE_EXPORT ScriptModule final {
26 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 26 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
27 27
28 public: 28 public:
29 static ScriptModule compile(v8::Isolate*, 29 static ScriptModule compile(v8::Isolate*,
30 const String& source, 30 const String& source,
31 const String& fileName); 31 const String& fileName);
32 32
33 // TODO(kouhei): Remove copy ctor
33 ScriptModule() {} 34 ScriptModule() {}
34 ScriptModule(const ScriptModule& module) : m_module(module.m_module) {} 35 ScriptModule(WTF::HashTableDeletedValueType)
36 : m_module(WTF::HashTableDeletedValue) {}
35 ~ScriptModule(); 37 ~ScriptModule();
36 38
37 // Returns exception, if any. 39 // Returns exception, if any.
38 ScriptValue instantiate(ScriptState*); 40 ScriptValue instantiate(ScriptState*);
39 void evaluate(ScriptState*); 41 void evaluate(ScriptState*);
40 42
41 Vector<String> moduleRequests(ScriptState*); 43 Vector<String> moduleRequests(ScriptState*);
42 44
45 bool isHashTableDeletedValue() const {
46 return m_module.isHashTableDeletedValue();
47 }
48
49 bool operator==(const blink::ScriptModule& other) const {
50 if (isHashTableDeletedValue() && other.isHashTableDeletedValue())
51 return true;
52
53 if (isHashTableDeletedValue() || other.isHashTableDeletedValue())
54 return false;
55
56 blink::SharedPersistent<v8::Module>* left = m_module.get();
57 blink::SharedPersistent<v8::Module>* right = other.m_module.get();
58 if (left == right)
59 return true;
60 if (!left || !right)
61 return false;
62 return *left == *right;
63 }
64
65 bool operator!=(const blink::ScriptModule& other) const {
66 return !(*this == other);
67 }
68
43 bool isNull() const { return !m_module || m_module->isEmpty(); } 69 bool isNull() const { return !m_module || m_module->isEmpty(); }
44 70
45 private: 71 private:
46 ScriptModule(v8::Isolate*, v8::Local<v8::Module>); 72 ScriptModule(v8::Isolate*, v8::Local<v8::Module>);
47 73
48 static v8::MaybeLocal<v8::Module> resolveModuleCallback( 74 static v8::MaybeLocal<v8::Module> resolveModuleCallback(
49 v8::Local<v8::Context>, 75 v8::Local<v8::Context>,
50 v8::Local<v8::String> specifier, 76 v8::Local<v8::String> specifier,
51 v8::Local<v8::Module> referrer); 77 v8::Local<v8::Module> referrer);
52 78
53 RefPtr<SharedPersistent<v8::Module>> m_module; 79 RefPtr<SharedPersistent<v8::Module>> m_module;
80 unsigned m_identityHash = 0;
81
82 friend struct ScriptModuleHash;
83 };
84
85 struct ScriptModuleHash {
86 STATIC_ONLY(ScriptModuleHash);
87
88 public:
89 static unsigned hash(const blink::ScriptModule& key) {
90 return key.m_identityHash;
91 }
92
93 static bool equal(const blink::ScriptModule& a,
94 const blink::ScriptModule& b) {
95 return a == b;
96 }
97
98 static constexpr bool safeToCompareToEmptyOrDeleted = true;
54 }; 99 };
55 100
56 } // namespace blink 101 } // namespace blink
57 102
103 namespace WTF {
104
105 template <>
106 struct DefaultHash<blink::ScriptModule> {
107 using Hash = blink::ScriptModuleHash;
108 };
109
110 template <>
111 struct HashTraits<blink::ScriptModule>
112 : public SimpleClassHashTraits<blink::ScriptModule> {};
113
114 } // namespace WTF
115
58 #endif // ScriptModule_h 116 #endif // ScriptModule_h
OLDNEW
« 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