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

Unified 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: snapshot Created 3 years, 10 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 | « synerr.js ('k') | 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 8fdb3a452a48cba2293d2cd6692be92ccad2c6ee..305a78e04fc6f06b8377cee7f352566f5a47f8d9 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptModule.h
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptModule.h
@@ -5,15 +5,28 @@
#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 "wtf/Allocator.h"
+#include "wtf/HashTableDeletedValueType.h"
+#include "wtf/HashTraits.h"
+#include "wtf/Vector.h"
#include "wtf/text/WTFString.h"
-#include <v8.h>
namespace blink {
+class ScriptModuleIdentifier;
+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();
@@ -22,21 +35,115 @@ 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(const ScriptModule&) = default;
+ ScriptModule(ScriptModule&&) = default;
+ ScriptModule& operator=(ScriptModule&&) = default;
~ScriptModule();
- bool instantiate(ScriptState*);
+ ScriptValue instantiate(ScriptState*);
void evaluate(ScriptState*);
- bool isNull() const { return m_module->isEmpty(); }
+ Vector<String> moduleRequests(ScriptState*);
+
+ bool isNull() const { return !m_module || m_module->isEmpty(); }
+ ScriptModuleIdentifier identifier();
private:
+ friend class ScriptModuleIdentifier;
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);
+
RefPtr<SharedPersistent<v8::Module>> m_module;
+ unsigned m_identityHash = 0;
+};
+
+// TODO(kouhei): Split header/cpp
+// TODO(kouhei): PeekType which can be construct w/ only v8::Local
+class ScriptModuleIdentifier {
+ public:
+ class Hash;
+
+ ScriptModuleIdentifier() = default;
+ ScriptModuleIdentifier(const ScriptModuleIdentifier& id)
+ : m_module(id.m_module), m_identityHash(id.m_identityHash) {}
+ ScriptModuleIdentifier(WTF::HashTableDeletedValueType)
+ : m_module(WTF::HashTableDeletedValue) {}
+ /*
+ FIXME(kouhei): need move op=
+ ScriptModuleIdentifier(ScriptModuleIdentifier&& id)
+ : m_module(std::move(id.m_module)), m_identityHash(id.m_identityHash) {}
+ */
+ ~ScriptModuleIdentifier() = default;
+
+ bool isHashTableDeletedValue() const {
+ return m_module.isHashTableDeletedValue();
+ }
+
+ bool operator==(const blink::ScriptModuleIdentifier& 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:
+ friend class ScriptModule;
+ friend struct ScriptModuleIdentifierHash;
+
+ explicit ScriptModuleIdentifier(
+ const RefPtr<SharedPersistent<v8::Module>>& module,
+ unsigned identityHash)
+ : m_module(module), m_identityHash(identityHash) {}
+
+ // TODO(kouhei): Make ScriptModule move-only and make this ScopedPersistent.
+ RefPtr<SharedPersistent<v8::Module>> m_module;
+ unsigned m_identityHash = 0;
+};
+
+struct ScriptModuleIdentifierHash {
+ STATIC_ONLY(ScriptModuleIdentifierHash);
+
+ public:
+ static unsigned hash(const blink::ScriptModuleIdentifier& key) {
+ return static_cast<unsigned>(key.m_identityHash);
+ }
+
+ static bool equal(const blink::ScriptModuleIdentifier& a,
+ const blink::ScriptModuleIdentifier& b) {
+ return a == b;
+ }
+
+ static constexpr bool safeToCompareToEmptyOrDeleted = true;
};
} // namespace blink
+namespace WTF {
+
+template <>
+struct DefaultHash<blink::ScriptModuleIdentifier> {
+ using Hash = blink::ScriptModuleIdentifierHash;
+};
+
+template <>
+struct HashTraits<blink::ScriptModuleIdentifier>
+ : public SimpleClassHashTraits<blink::ScriptModuleIdentifier> {};
+
+} // namespace WTF
+
#endif // ScriptModule_h
« no previous file with comments | « synerr.js ('k') | third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698