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

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: ModuleScriptLoaderTest 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..76980b3854780f22ab3f1f215c5749d8d8bcf930
--- /dev/null
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptModule.h
@@ -0,0 +1,142 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ScriptModule_h
+#define ScriptModule_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;
+
+// A ScriptModule wraps a handle to v8::Module for its carry outside V8
+// bindings.
+//
+// Use ModuleController to actually operate or extract information from
+// ScriptModule.
+class CORE_EXPORT ScriptModule final {
+ DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
+
+ public:
+ static ScriptModule compile(v8::Isolate*,
+ const String& source,
+ const String& fileName);
+
+ ScriptModule() {}
+ ScriptModule(const ScriptModule& module)
+ : m_module(module.m_module), m_identityHash(module.m_identityHash) {}
+ ~ScriptModule();
+
+ bool instantiate(ScriptState*);
+ void evaluate(ScriptState*);
+
+ 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;
haraken 2017/01/06 05:47:58 Will ScopedPersistent work? (SharedPersistent shou
kouhei (in TOK) 2017/01/11 01:41:57 Probably. Added a TODO comment to fix this.
+ 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;
+ }
+
+ private:
+ friend class ScriptModule;
+ friend struct ScriptModuleIdentifierHash;
+
+ explicit ScriptModuleIdentifier(
+ const RefPtr<SharedPersistent<v8::Module>>& module,
+ unsigned identityHash)
+ : m_module(module), m_identityHash(identityHash) {}
+
+ 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 const bool safeToCompareToEmptyOrDeleted = false;
+};
+
+} // 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

Powered by Google App Engine
This is Rietveld 408576698