Chromium Code Reviews| OLD | NEW |
|---|---|
| 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& rhs) const { | |
| 39 if (m_module.isHashTableDeletedValue() && | |
|
yhirano
2017/03/30 07:35:09
isHashTableDeletedValue() && rhs.isHashTableDelete
kouhei (in TOK)
2017/04/04 05:19:26
Done.
| |
| 40 rhs.m_module.isHashTableDeletedValue()) | |
| 41 return true; | |
| 42 | |
|
yhirano
2017/03/30 07:35:09
if (isHashTableDeltedValue() || rhs.isHashTableDel
kouhei (in TOK)
2017/04/04 05:19:26
Done.
| |
| 43 blink::SharedPersistent<v8::Module>* lhsp = m_module.get(); | |
| 44 blink::SharedPersistent<v8::Module>* rhsp = rhs.m_module.get(); | |
| 45 if (lhsp == rhsp) | |
|
haraken
2017/03/30 13:20:14
Nit: Blink prefers a fully qualified name.
kouhei (in TOK)
2017/04/04 05:19:26
Done.
| |
| 46 return true; | |
| 47 if (!lhsp || !rhsp) | |
| 48 return false; | |
| 49 return *lhsp == *rhsp; | |
| 50 } | |
| 51 | |
| 32 bool isNull() const { return m_module->isEmpty(); } | 52 bool isNull() const { return m_module->isEmpty(); } |
| 33 | 53 |
| 34 private: | 54 private: |
| 35 ScriptModule(v8::Isolate*, v8::Local<v8::Module>); | 55 ScriptModule(v8::Isolate*, v8::Local<v8::Module>); |
| 36 | 56 |
| 37 RefPtr<SharedPersistent<v8::Module>> m_module; | 57 RefPtr<SharedPersistent<v8::Module>> m_module; |
| 58 unsigned m_identityHash = 0; | |
| 59 | |
| 60 friend struct ScriptModuleHash; | |
| 61 }; | |
| 62 | |
| 63 struct ScriptModuleHash { | |
| 64 STATIC_ONLY(ScriptModuleHash); | |
| 65 | |
| 66 public: | |
| 67 static unsigned hash(const blink::ScriptModule& key) { | |
| 68 return static_cast<unsigned>(key.m_identityHash); | |
|
yhirano
2017/03/30 07:35:09
This cast is not needed.
kouhei (in TOK)
2017/04/04 05:19:26
Done.
| |
| 69 } | |
| 70 | |
| 71 static bool equal(const blink::ScriptModule& a, | |
| 72 const blink::ScriptModule& b) { | |
| 73 return a == b; | |
| 74 } | |
| 75 | |
| 76 static constexpr bool safeToCompareToEmptyOrDeleted = true; | |
| 38 }; | 77 }; |
| 39 | 78 |
| 40 } // namespace blink | 79 } // namespace blink |
| 41 | 80 |
| 81 namespace WTF { | |
| 82 | |
| 83 template <> | |
| 84 struct DefaultHash<blink::ScriptModule> { | |
| 85 using Hash = blink::ScriptModuleHash; | |
| 86 }; | |
| 87 | |
| 88 template <> | |
| 89 struct HashTraits<blink::ScriptModule> | |
| 90 : public SimpleClassHashTraits<blink::ScriptModule> {}; | |
| 91 | |
| 92 } // namespace WTF | |
| 93 | |
| 42 #endif // ScriptModule_h | 94 #endif // ScriptModule_h |
| OLD | NEW |