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 #include "core/dom/ModuleScript.h" | 5 #include "core/dom/ModuleScript.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
8 #include "bindings/core/v8/ScriptValue.h" | 8 #include "bindings/core/v8/ScriptValue.h" |
9 #include "v8/include/v8.h" | 9 #include "v8/include/v8.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 ModuleScript* ModuleScript::Create( | 13 ModuleScript* ModuleScript::Create( |
14 const String& source_text, | 14 const String& source_text, |
15 Modulator* modulator, | 15 Modulator* modulator, |
16 const KURL& base_url, | 16 const KURL& base_url, |
17 const String& nonce, | 17 const String& nonce, |
18 ParserDisposition parser_state, | 18 ParserDisposition parser_state, |
19 WebURLRequest::FetchCredentialsMode credentials_mode, | 19 WebURLRequest::FetchCredentialsMode credentials_mode, |
20 AccessControlStatus access_control_status) { | 20 AccessControlStatus access_control_status) { |
| 21 // https://html.spec.whatwg.org/#creating-a-module-script |
21 // Step 1. Let script be a new module script that this algorithm will | 22 // Step 1. Let script be a new module script that this algorithm will |
22 // subsequently initialize. | 23 // subsequently initialize. |
23 // Step 2. Set script's settings object to the environment settings object | 24 // Step 2. Set script's settings object to the environment settings object |
24 // provided. | 25 // provided. |
25 // Note: "script's settings object" will be "modulator". | 26 // Note: "script's settings object" will be "modulator". |
26 | 27 |
27 // Delegate to Modulator::compileModule to process Steps 3-6. | 28 // Delegate to Modulator::compileModule to process Steps 3-6. |
28 ScriptModule result = modulator->CompileModule( | 29 ScriptModule result = modulator->CompileModule( |
29 source_text, base_url.GetString(), access_control_status); | 30 source_text, base_url.GetString(), access_control_status); |
30 // Step 6: "...return null, and abort these steps." | 31 // Step 6: "...return null, and abort these steps." |
31 if (result.IsNull()) | 32 if (result.IsNull()) |
32 return nullptr; | 33 return nullptr; |
| 34 |
| 35 return CreateInternal(modulator, result, base_url, nonce, parser_state, |
| 36 credentials_mode); |
| 37 } |
| 38 |
| 39 ModuleScript* ModuleScript::CreateInternal( |
| 40 Modulator* modulator, |
| 41 ScriptModule result, |
| 42 const KURL& base_url, |
| 43 const String& nonce, |
| 44 ParserDisposition parser_state, |
| 45 WebURLRequest::FetchCredentialsMode credentials_mode) { |
| 46 // https://html.spec.whatwg.org/#creating-a-module-script |
33 // Step 7. Set script's module record to result. | 47 // Step 7. Set script's module record to result. |
34 // Step 8. Set script's base URL to the script base URL provided. | 48 // Step 8. Set script's base URL to the script base URL provided. |
35 // Step 9. Set script's cryptographic nonce to the cryptographic nonce | 49 // Step 9. Set script's cryptographic nonce to the cryptographic nonce |
36 // provided. | 50 // provided. |
37 // Step 10. Set script's parser state to the parser state. | 51 // Step 10. Set script's parser state to the parser state. |
38 // Step 11. Set script's credentials mode to the credentials mode provided. | 52 // Step 11. Set script's credentials mode to the credentials mode provided. |
39 // Step 12. Return script. | 53 // Step 12. Return script. |
40 return new ModuleScript(modulator, result, base_url, nonce, parser_state, | 54 return new ModuleScript(modulator, result, base_url, nonce, parser_state, |
41 credentials_mode); | 55 credentials_mode); |
42 } | 56 } |
43 | 57 |
| 58 ModuleScript* ModuleScript::CreateForTest( |
| 59 Modulator* modulator, |
| 60 ScriptModule record, |
| 61 const KURL& base_url, |
| 62 const String& nonce, |
| 63 ParserDisposition parser_state, |
| 64 WebURLRequest::FetchCredentialsMode credentials_mode) { |
| 65 return CreateInternal(modulator, record, base_url, nonce, parser_state, |
| 66 credentials_mode); |
| 67 } |
| 68 |
44 void ModuleScript::SetInstantiationErrorAndClearRecord(ScriptValue error) { | 69 void ModuleScript::SetInstantiationErrorAndClearRecord(ScriptValue error) { |
45 // Implements Step 7.1 of: | 70 // Implements Step 7.1 of: |
46 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri
pt-graph-fetching-procedure | 71 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri
pt-graph-fetching-procedure |
47 | 72 |
48 // "set script's instantiation state to "errored", ..." | 73 // "set script's instantiation state to "errored", ..." |
49 DCHECK_EQ(instantiation_state_, ModuleInstantiationState::kUninstantiated); | 74 DCHECK_EQ(instantiation_state_, ModuleInstantiationState::kUninstantiated); |
50 instantiation_state_ = ModuleInstantiationState::kErrored; | 75 instantiation_state_ = ModuleInstantiationState::kErrored; |
51 | 76 |
52 // "its instantiation error to instantiationStatus.[[Value]], and ..." | 77 // "its instantiation error to instantiationStatus.[[Value]], and ..." |
53 DCHECK(!error.IsEmpty()); | 78 DCHECK(!error.IsEmpty()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 118 } |
94 | 119 |
95 String ModuleScript::InlineSourceTextForCSP() const { | 120 String ModuleScript::InlineSourceTextForCSP() const { |
96 // Currently we don't support inline module scripts. | 121 // Currently we don't support inline module scripts. |
97 // TODO(hiroshige): Implement this. | 122 // TODO(hiroshige): Implement this. |
98 NOTREACHED(); | 123 NOTREACHED(); |
99 return String(); | 124 return String(); |
100 } | 125 } |
101 | 126 |
102 } // namespace blink | 127 } // namespace blink |
OLD | NEW |