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/Vector.h" |
13 #include "wtf/text/WTFString.h" | 14 #include "wtf/text/WTFString.h" |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 // ScriptModule wraps a handle to a v8::Module for use in core. | 18 // ScriptModule wraps a handle to a v8::Module for use in core. |
18 // | 19 // |
19 // Using ScriptModules needs a ScriptState and its scope to operate in. You | 20 // Using ScriptModules needs a ScriptState and its scope to operate in. You |
20 // should always provide the same ScriptState and not try to reuse ScriptModules | 21 // should always provide the same ScriptState and not try to reuse ScriptModules |
21 // across different contexts. | 22 // across different contexts. |
22 // Currently all ScriptModule users can easily access its context Modulator, so | 23 // Currently all ScriptModule users can easily access its context Modulator, so |
23 // we use it to fill ScriptState in. | 24 // we use it to fill ScriptState in. |
24 class CORE_EXPORT ScriptModule final { | 25 class CORE_EXPORT ScriptModule final { |
25 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 26 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
26 | 27 |
27 public: | 28 public: |
28 static ScriptModule compile(v8::Isolate*, | 29 static ScriptModule compile(v8::Isolate*, |
29 const String& source, | 30 const String& source, |
30 const String& fileName); | 31 const String& fileName); |
31 | 32 |
32 ScriptModule() {} | 33 ScriptModule() {} |
33 ScriptModule(const ScriptModule& module) : m_module(module.m_module) {} | 34 ScriptModule(const ScriptModule& module) : m_module(module.m_module) {} |
34 ~ScriptModule(); | 35 ~ScriptModule(); |
35 | 36 |
36 // Returns exception, if any. | 37 // Returns exception, if any. |
37 ScriptValue instantiate(ScriptState*); | 38 ScriptValue instantiate(ScriptState*); |
38 void evaluate(ScriptState*); | 39 void evaluate(ScriptState*); |
39 | 40 |
| 41 Vector<String> moduleRequests(ScriptState*); |
| 42 |
40 bool isNull() const { return !m_module || m_module->isEmpty(); } | 43 bool isNull() const { return !m_module || m_module->isEmpty(); } |
41 | 44 |
42 private: | 45 private: |
43 ScriptModule(v8::Isolate*, v8::Local<v8::Module>); | 46 ScriptModule(v8::Isolate*, v8::Local<v8::Module>); |
44 | 47 |
45 static v8::MaybeLocal<v8::Module> resolveModuleCallback( | 48 static v8::MaybeLocal<v8::Module> resolveModuleCallback( |
46 v8::Local<v8::Context>, | 49 v8::Local<v8::Context>, |
47 v8::Local<v8::String> specifier, | 50 v8::Local<v8::String> specifier, |
48 v8::Local<v8::Module> referrer); | 51 v8::Local<v8::Module> referrer); |
49 | 52 |
50 RefPtr<SharedPersistent<v8::Module>> m_module; | 53 RefPtr<SharedPersistent<v8::Module>> m_module; |
51 }; | 54 }; |
52 | 55 |
53 } // namespace blink | 56 } // namespace blink |
54 | 57 |
55 #endif // ScriptModule_h | 58 #endif // ScriptModule_h |
OLD | NEW |