| 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 "platform/loader/fetch/AccessControlStatus.h" | 11 #include "platform/loader/fetch/AccessControlStatus.h" |
| 12 #include "platform/wtf/Allocator.h" | 12 #include "platform/wtf/Allocator.h" |
| 13 #include "platform/wtf/Vector.h" | 13 #include "platform/wtf/Vector.h" |
| 14 #include "platform/wtf/text/WTFString.h" | 14 #include "platform/wtf/text/WTFString.h" |
| 15 #include "v8/include/v8.h" | 15 #include "v8/include/v8.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 class ModuleScript; |
| 20 |
| 19 // ScriptModule wraps a handle to a v8::Module for use in core. | 21 // ScriptModule wraps a handle to a v8::Module for use in core. |
| 20 // | 22 // |
| 21 // Using ScriptModules needs a ScriptState and its scope to operate in. You | 23 // Using ScriptModules needs a ScriptState and its scope to operate in. You |
| 22 // should always provide the same ScriptState and not try to reuse ScriptModules | 24 // should always provide the same ScriptState and not try to reuse ScriptModules |
| 23 // across different contexts. | 25 // across different contexts. |
| 24 // Currently all ScriptModule users can easily access its context Modulator, so | 26 // Currently all ScriptModule users can easily access its context Modulator, so |
| 25 // we use it to fill ScriptState in. | 27 // we use it to fill ScriptState in. |
| 26 class CORE_EXPORT ScriptModule final { | 28 class CORE_EXPORT ScriptModule final { |
| 27 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 29 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 28 | 30 |
| 29 public: | 31 public: |
| 30 static ScriptModule Compile(v8::Isolate*, | 32 static ScriptModule Compile(v8::Isolate*, |
| 31 const String& source, | 33 const String& source, |
| 32 const String& file_name, | 34 const String& file_name, |
| 33 AccessControlStatus); | 35 AccessControlStatus); |
| 34 | 36 |
| 35 // TODO(kouhei): Remove copy ctor | 37 // TODO(kouhei): Remove copy ctor |
| 36 ScriptModule() {} | 38 ScriptModule() {} |
| 37 ScriptModule(WTF::HashTableDeletedValueType) | 39 ScriptModule(WTF::HashTableDeletedValueType) |
| 38 : module_(WTF::kHashTableDeletedValue) {} | 40 : module_(WTF::kHashTableDeletedValue) {} |
| 39 ~ScriptModule(); | 41 ~ScriptModule(); |
| 40 | 42 |
| 41 // Returns exception, if any. | 43 // Returns exception, if any. |
| 42 ScriptValue Instantiate(ScriptState*); | 44 ScriptValue Instantiate(ScriptState*); |
| 43 void Evaluate(ScriptState*); | 45 static void Evaluate(ScriptState*, const ModuleScript*); |
| 44 | 46 |
| 45 Vector<String> ModuleRequests(ScriptState*); | 47 Vector<String> ModuleRequests(ScriptState*); |
| 46 | 48 |
| 47 bool IsHashTableDeletedValue() const { | 49 bool IsHashTableDeletedValue() const { |
| 48 return module_.IsHashTableDeletedValue(); | 50 return module_.IsHashTableDeletedValue(); |
| 49 } | 51 } |
| 50 | 52 |
| 51 bool operator==(const blink::ScriptModule& other) const { | 53 bool operator==(const blink::ScriptModule& other) const { |
| 52 if (IsHashTableDeletedValue() && other.IsHashTableDeletedValue()) | 54 if (IsHashTableDeletedValue() && other.IsHashTableDeletedValue()) |
| 53 return true; | 55 return true; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 using Hash = blink::ScriptModuleHash; | 111 using Hash = blink::ScriptModuleHash; |
| 110 }; | 112 }; |
| 111 | 113 |
| 112 template <> | 114 template <> |
| 113 struct HashTraits<blink::ScriptModule> | 115 struct HashTraits<blink::ScriptModule> |
| 114 : public SimpleClassHashTraits<blink::ScriptModule> {}; | 116 : public SimpleClassHashTraits<blink::ScriptModule> {}; |
| 115 | 117 |
| 116 } // namespace WTF | 118 } // namespace WTF |
| 117 | 119 |
| 118 #endif // ScriptModule_h | 120 #endif // ScriptModule_h |
| OLD | NEW |