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

Side by Side Diff: third_party/WebKit/Source/core/dom/ModuleScript.cpp

Issue 2842923002: Support Inline module script (Closed)
Patch Set: Rebase Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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 "core/dom/ScriptModuleResolver.h" 9 #include "core/dom/ScriptModuleResolver.h"
10 #include "v8/include/v8.h" 10 #include "v8/include/v8.h"
(...skipping 15 matching lines...) Expand all
26 // provided. 26 // provided.
27 // Note: "script's settings object" will be "modulator". 27 // Note: "script's settings object" will be "modulator".
28 28
29 // Delegate to Modulator::compileModule to process Steps 3-6. 29 // Delegate to Modulator::compileModule to process Steps 3-6.
30 ScriptModule result = modulator->CompileModule( 30 ScriptModule result = modulator->CompileModule(
31 source_text, base_url.GetString(), access_control_status); 31 source_text, base_url.GetString(), access_control_status);
32 // Step 6: "...return null, and abort these steps." 32 // Step 6: "...return null, and abort these steps."
33 if (result.IsNull()) 33 if (result.IsNull())
34 return nullptr; 34 return nullptr;
35 35
36 return CreateInternal(modulator, result, base_url, nonce, parser_state, 36 return CreateInternal(source_text, modulator, result, base_url, nonce,
37 credentials_mode); 37 parser_state, credentials_mode);
38 } 38 }
39 39
40 ModuleScript* ModuleScript::CreateInternal( 40 ModuleScript* ModuleScript::CreateInternal(
41 const String& source_text,
41 Modulator* modulator, 42 Modulator* modulator,
42 ScriptModule result, 43 ScriptModule result,
43 const KURL& base_url, 44 const KURL& base_url,
44 const String& nonce, 45 const String& nonce,
45 ParserDisposition parser_state, 46 ParserDisposition parser_state,
46 WebURLRequest::FetchCredentialsMode credentials_mode) { 47 WebURLRequest::FetchCredentialsMode credentials_mode) {
47 // https://html.spec.whatwg.org/#creating-a-module-script 48 // https://html.spec.whatwg.org/#creating-a-module-script
48 // Step 7. Set script's module record to result. 49 // Step 7. Set script's module record to result.
49 // Step 8. Set script's base URL to the script base URL provided. 50 // Step 8. Set script's base URL to the script base URL provided.
50 // Step 9. Set script's cryptographic nonce to the cryptographic nonce 51 // Step 9. Set script's cryptographic nonce to the cryptographic nonce
51 // provided. 52 // provided.
52 // Step 10. Set script's parser state to the parser state. 53 // Step 10. Set script's parser state to the parser state.
53 // Step 11. Set script's credentials mode to the credentials mode provided. 54 // Step 11. Set script's credentials mode to the credentials mode provided.
54 // Step 12. Return script. 55 // Step 12. Return script.
55 ModuleScript* module_script = new ModuleScript( 56 // [not specced] |source_text| is saved for CSP checks.
56 modulator, result, base_url, nonce, parser_state, credentials_mode); 57 ModuleScript* module_script =
58 new ModuleScript(modulator, result, base_url, nonce, parser_state,
59 credentials_mode, source_text);
57 60
58 // Step 5, a part of ParseModule(): Passing script as the last parameter 61 // Step 5, a part of ParseModule(): Passing script as the last parameter
59 // here ensures result.[[HostDefined]] will be script. 62 // here ensures result.[[HostDefined]] will be script.
60 modulator->GetScriptModuleResolver()->RegisterModuleScript(module_script); 63 modulator->GetScriptModuleResolver()->RegisterModuleScript(module_script);
61 64
62 return module_script; 65 return module_script;
63 } 66 }
64 67
65 ModuleScript* ModuleScript::CreateForTest( 68 ModuleScript* ModuleScript::CreateForTest(
66 Modulator* modulator, 69 Modulator* modulator,
67 ScriptModule record, 70 ScriptModule record,
68 const KURL& base_url, 71 const KURL& base_url,
69 const String& nonce, 72 const String& nonce,
70 ParserDisposition parser_state, 73 ParserDisposition parser_state,
71 WebURLRequest::FetchCredentialsMode credentials_mode) { 74 WebURLRequest::FetchCredentialsMode credentials_mode) {
72 return CreateInternal(modulator, record, base_url, nonce, parser_state, 75 String dummy_source_text = "";
73 credentials_mode); 76 return CreateInternal(dummy_source_text, modulator, record, base_url, nonce,
77 parser_state, credentials_mode);
74 } 78 }
75 79
76 void ModuleScript::SetInstantiationErrorAndClearRecord(ScriptValue error) { 80 void ModuleScript::SetInstantiationErrorAndClearRecord(ScriptValue error) {
77 // Implements Step 7.1 of: 81 // Implements Step 7.1 of:
78 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri pt-graph-fetching-procedure 82 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri pt-graph-fetching-procedure
79 83
80 // "set script's instantiation state to "errored", ..." 84 // "set script's instantiation state to "errored", ..."
81 DCHECK_EQ(instantiation_state_, ModuleInstantiationState::kUninstantiated); 85 DCHECK_EQ(instantiation_state_, ModuleInstantiationState::kUninstantiated);
82 instantiation_state_ = ModuleInstantiationState::kErrored; 86 instantiation_state_ = ModuleInstantiationState::kErrored;
83 87
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // We don't check MIME type here because we check the MIME type in 122 // We don't check MIME type here because we check the MIME type in
119 // ModuleScriptLoader::WasModuleLoadSuccessful(). 123 // ModuleScriptLoader::WasModuleLoadSuccessful().
120 return true; 124 return true;
121 } 125 }
122 126
123 void ModuleScript::RunScript(LocalFrame* frame, const SecurityOrigin*) const { 127 void ModuleScript::RunScript(LocalFrame* frame, const SecurityOrigin*) const {
124 settings_object_->ExecuteModule(this); 128 settings_object_->ExecuteModule(this);
125 } 129 }
126 130
127 String ModuleScript::InlineSourceTextForCSP() const { 131 String ModuleScript::InlineSourceTextForCSP() const {
128 // Currently we don't support inline module scripts. 132 return source_text_;
129 // TODO(hiroshige): Implement this.
130 NOTREACHED();
131 return String();
132 } 133 }
133 134
134 } // namespace blink 135 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ModuleScript.h ('k') | third_party/WebKit/Source/core/dom/ScriptLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698