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

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

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: snapshot Created 3 years, 10 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/Modulator.h" 5 #include "core/dom/Modulator.h"
6 6
7 #include "bindings/core/v8/ScriptState.h" 7 #include "bindings/core/v8/ScriptState.h"
8 #include "bindings/core/v8/V8PerContextData.h"
9 #include "core/dom/Document.h"
10 #include "core/dom/ModulatorImpl.h"
11 #include "core/frame/LocalFrame.h"
8 12
9 namespace blink { 13 namespace blink {
10 14
11 Modulator* Modulator::from(LocalFrame* frame) { 15 Modulator* Modulator::from(LocalFrame* frame) {
12 ScriptState* scriptState = ScriptState::forMainWorld(frame); 16 ScriptState* scriptState = ScriptState::forMainWorld(frame);
13 if (!scriptState) 17 if (!scriptState)
14 return nullptr; 18 return nullptr;
15 // TODO(kouhei): setModulator in V8PerContextData when we land ModulatorImpl. 19 Modulator* modulator = scriptState->perContextData()->modulator();
16 return scriptState->perContextData()->modulator(); 20 if (!modulator) {
21 if (Document* document = frame->document()) {
22 ScriptState* scriptState = ScriptState::forMainWorld(frame);
23 modulator = ModulatorImpl::create(scriptState, *document);
24 scriptState->perContextData()->setModulator(modulator);
25 }
26 }
27 return modulator;
17 } 28 }
18 29
19 KURL Modulator::resolveModuleSpecifier(const String& moduleRequest, 30 KURL Modulator::resolveModuleSpecifier(const String& moduleRequest0,
20 const KURL& baseURL) { 31 const KURL& baseURL) {
32 String moduleRequest = moduleRequest0.isolatedCopy();
33 if (!moduleRequest.endsWith(".js") && !moduleRequest.endsWith(".glsl")) {
34 moduleRequest.append('.');
35 moduleRequest.append('j');
36 moduleRequest.append('s');
37 }
38 if (moduleRequest.endsWith(".glsl")) {
39 moduleRequest =
40 KURL(KURL(), "data:text/javascript, export default 'glslsrc';");
41 }
21 // Step 1. Apply the URL parser to specifier. If the result is not failure, 42 // Step 1. Apply the URL parser to specifier. If the result is not failure,
22 // return the result. 43 // return the result.
23 KURL url(KURL(), moduleRequest); 44 KURL url(KURL(), moduleRequest);
24 if (url.isValid()) 45 if (url.isValid())
25 return url; 46 return url;
26 47
27 // Step 2. If specifier does not start with the character U+002F SOLIDUS (/), 48 // Step 2. If specifier does not start with the character U+002F SOLIDUS (/),
28 // the two-character sequence U+002E FULL STOP, U+002F SOLIDUS (./), or the 49 // the two-character sequence U+002E FULL STOP, U+002F SOLIDUS (./), or the
29 // three-character sequence U+002E FULL STOP, U+002E FULL STOP, U+002F SOLIDUS 50 // three-character sequence U+002E FULL STOP, U+002E FULL STOP, U+002F SOLIDUS
30 // (../), return failure and abort these steps. 51 // (../), return failure and abort these steps.
31 if (!moduleRequest.startsWith("/") && !moduleRequest.startsWith("./") && 52 if (!moduleRequest.startsWith("/") && !moduleRequest.startsWith("./") &&
32 !moduleRequest.startsWith("../")) 53 !moduleRequest.startsWith("../"))
33 return KURL(); 54 return KURL();
34 55
35 // Step 3. Return the result of applying the URL parser to specifier with 56 // Step 3. Return the result of applying the URL parser to specifier with
36 // script's base URL as the base URL. 57 // script's base URL as the base URL.
37 DCHECK(baseURL.isValid()); 58 DCHECK(baseURL.isValid());
38 KURL absoluteURL(baseURL, moduleRequest); 59 KURL absoluteURL(baseURL, moduleRequest);
39 if (absoluteURL.isValid()) 60 if (absoluteURL.isValid())
40 return absoluteURL; 61 return absoluteURL;
41 62
42 return KURL(); 63 return KURL();
43 } 64 }
44 65
45 } // namespace blink 66 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Modulator.h ('k') | third_party/WebKit/Source/core/dom/ModulatorImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698