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

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

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: address haraken/yhirano comments Created 3 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef ScriptModule_h
6 #define ScriptModule_h
7
8 #include "bindings/core/v8/ScriptState.h"
9 #include "bindings/core/v8/SharedPersistent.h"
10 #include "core/CoreExport.h"
11 #include "wtf/Allocator.h"
12 #include "wtf/HashTableDeletedValueType.h"
13 #include "wtf/HashTraits.h"
14 #include "wtf/Vector.h"
15 #include "wtf/text/WTFString.h"
16 #include <v8.h>
17
18 namespace blink {
19
20 class ScriptModuleIdentifier;
21 class ScriptState;
22
23 // A ScriptModule wraps a handle to v8::Module for its carry outside V8
dominicc (has gone to gerrit) 2017/01/11 03:23:47 Grammar: "for its carry" doesn't make sense. Maybe
kouhei (in TOK) 2017/01/17 05:26:13 Done.
24 // bindings.
25 //
26 // Note: Use ModulatorImpl to provide scriptState context to actually
dominicc (has gone to gerrit) 2017/01/11 03:23:47 Hmm, why do these abstractions need to depend on o
kouhei (in TOK) 2017/01/17 05:26:12 adamk, dominicc: PTAL
27 // operate or extract information from ScriptModule.
28 class CORE_EXPORT ScriptModule final {
29 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
30
31 public:
32 static ScriptModule compile(v8::Isolate*,
33 const String& source,
34 const String& fileName);
35
36 ScriptModule() {}
37 ScriptModule(const ScriptModule& module)
dominicc (has gone to gerrit) 2017/01/11 03:23:47 Just curious but is it possible to use = default f
kouhei (in TOK) 2017/01/17 05:26:13 Done.
38 : m_module(module.m_module), m_identityHash(module.m_identityHash) {}
39 ~ScriptModule();
40
41 bool instantiate(ScriptState*);
42 void evaluate(ScriptState*);
43
44 Vector<String> moduleRequests(ScriptState*);
45
46 bool isNull() const { return !m_module || m_module->isEmpty(); }
47 ScriptModuleIdentifier identifier();
48
49 private:
50 friend class ScriptModuleIdentifier;
51 ScriptModule(v8::Isolate*, v8::Local<v8::Module>);
52
53 static v8::MaybeLocal<v8::Module> resolveModuleCallback(
54 v8::Local<v8::Context>,
55 v8::Local<v8::String> specifier,
56 v8::Local<v8::Module> referrer);
57
58 RefPtr<SharedPersistent<v8::Module>> m_module;
59 unsigned m_identityHash = 0;
60 };
61
62 // TODO(kouhei): Split header/cpp
63 // TODO(kouhei): PeekType which can be construct w/ only v8::Local
64 class ScriptModuleIdentifier {
dominicc (has gone to gerrit) 2017/01/11 03:23:47 Is this class pulling its weight? If you don't add
kouhei (in TOK) 2017/01/17 05:26:12 Reason 1: One ScriptModule instance per v8::Module
65 public:
66 class Hash;
67
68 ScriptModuleIdentifier() = default;
69 ScriptModuleIdentifier(const ScriptModuleIdentifier& id)
70 : m_module(id.m_module), m_identityHash(id.m_identityHash) {}
71 ScriptModuleIdentifier(WTF::HashTableDeletedValueType)
72 : m_module(WTF::HashTableDeletedValue) {}
73 /*
74 FIXME(kouhei): need move op=
75 ScriptModuleIdentifier(ScriptModuleIdentifier&& id)
76 : m_module(std::move(id.m_module)), m_identityHash(id.m_identityHash) {}
77 */
78 ~ScriptModuleIdentifier() = default;
79
80 bool isHashTableDeletedValue() const {
81 return m_module.isHashTableDeletedValue();
82 }
83
84 bool operator==(const blink::ScriptModuleIdentifier& rhs) const {
85 if (m_module.isHashTableDeletedValue() &&
dominicc (has gone to gerrit) 2017/01/11 03:23:47 Hmm, why not just implement so isSafeToCompareEmpt
kouhei (in TOK) 2017/01/17 05:26:13 Done.
86 rhs.m_module.isHashTableDeletedValue())
87 return true;
88
89 blink::SharedPersistent<v8::Module>* lhsp = m_module.get();
90 blink::SharedPersistent<v8::Module>* rhsp = rhs.m_module.get();
91 if (lhsp == rhsp)
92 return true;
93 if (!lhsp || !rhsp)
94 return false;
95 return *lhsp == *rhsp;
96 }
97
98 private:
99 friend class ScriptModule;
100 friend struct ScriptModuleIdentifierHash;
101
102 explicit ScriptModuleIdentifier(
103 const RefPtr<SharedPersistent<v8::Module>>& module,
104 unsigned identityHash)
105 : m_module(module), m_identityHash(identityHash) {}
106
107 // TODO(kouhei): Make ScriptModule move-only and make this ScopedPersistent.
108 RefPtr<SharedPersistent<v8::Module>> m_module;
109 unsigned m_identityHash = 0;
110 };
111
112 struct ScriptModuleIdentifierHash {
113 STATIC_ONLY(ScriptModuleIdentifierHash);
114
115 public:
116 static unsigned hash(const blink::ScriptModuleIdentifier& key) {
117 return static_cast<unsigned>(key.m_identityHash);
118 }
119
120 static bool equal(const blink::ScriptModuleIdentifier& a,
121 const blink::ScriptModuleIdentifier& b) {
122 return a == b;
123 }
124
125 static const bool safeToCompareToEmptyOrDeleted = false;
126 };
127
128 } // namespace blink
129
130 namespace WTF {
131
132 template <>
133 struct DefaultHash<blink::ScriptModuleIdentifier> {
134 using Hash = blink::ScriptModuleIdentifierHash;
135 };
136
137 template <>
138 struct HashTraits<blink::ScriptModuleIdentifier>
139 : public SimpleClassHashTraits<blink::ScriptModuleIdentifier> {};
140
141 } // namespace WTF
142
143 #endif // ScriptModule_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698