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

Side by Side Diff: Source/devtools/front_end/Runtime.js

Issue 475073002: DevTools: normalize sourceURL paths in importScript function (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/devtools/front_end/common/ParsedURL.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 29 matching lines...) Expand all
40 xhr.open("GET", url, false); 40 xhr.open("GET", url, false);
41 try { 41 try {
42 xhr.send(null); 42 xhr.send(null);
43 } catch (e) { 43 } catch (e) {
44 console.error(url + " -> " + new Error().stack); 44 console.error(url + " -> " + new Error().stack);
45 throw e; 45 throw e;
46 } 46 }
47 return xhr.responseText; 47 return xhr.responseText;
48 } 48 }
49 49
50
51 /**
52 * http://tools.ietf.org/html/rfc3986#section-5.2.4
53 * @param {string} path
54 * @return {string}
55 */
56 function normalizePath(path)
57 {
58 if (path.indexOf("..") === -1 && path.indexOf('.') === -1)
59 return path;
60
61 var normalizedSegments = [];
62 var segments = path.split("/");
63 for (var i = 0; i < segments.length; i++) {
64 var segment = segments[i];
65 if (segment === ".")
66 continue;
67 else if (segment === "..")
68 normalizedSegments.pop();
69 else if (segment)
70 normalizedSegments.push(segment);
71 }
72 var normalizedPath = normalizedSegments.join("/");
73 if (normalizedPath[normalizedPath.length - 1] === "/")
74 return normalizedPath;
75 if (path[0] === "/" && normalizedPath)
76 normalizedPath = "/" + normalizedPath;
77 if ((path[path.length - 1] === "/") || (segments[segments.length - 1] === ". ") || (segments[segments.length - 1] === ".."))
78 normalizedPath = normalizedPath + "/";
79
80 return normalizedPath;
81 }
82
50 /** 83 /**
51 * This function behavior depends on the "debug_devtools" flag value. 84 * This function behavior depends on the "debug_devtools" flag value.
52 * - In debug mode it loads scripts synchronously via xhr request. 85 * - In debug mode it loads scripts synchronously via xhr request.
53 * - In release mode every occurrence of "importScript" in the js files 86 * - In release mode every occurrence of "importScript" in the js files
54 * that have been whitelisted in the build system gets replaced with 87 * that have been whitelisted in the build system gets replaced with
55 * the script source code on the compilation phase. 88 * the script source code on the compilation phase.
56 * The build system will throw an exception if it finds an importScript() call 89 * The build system will throw an exception if it finds an importScript() call
57 * in other files. 90 * in other files.
58 * 91 *
59 * To load scripts lazily in release mode call "loadScript" function. 92 * To load scripts lazily in release mode call "loadScript" function.
60 * @param {string} scriptName 93 * @param {string} scriptName
61 */ 94 */
62 function importScript(scriptName) 95 function importScript(scriptName)
63 { 96 {
64 var sourceURL = self._importScriptPathPrefix + scriptName; 97 var sourceURL = self._importScriptPathPrefix + scriptName;
98 var schemaIndex = sourceURL.indexOf("://") + 3;
99 sourceURL = sourceURL.substring(0, schemaIndex) + normalizePath(sourceURL.su bstring(schemaIndex));
65 if (_importedScripts[sourceURL]) 100 if (_importedScripts[sourceURL])
66 return; 101 return;
67 _importedScripts[sourceURL] = true; 102 _importedScripts[sourceURL] = true;
68 var scriptSource = loadResource(sourceURL); 103 var scriptSource = loadResource(sourceURL);
69 if (!scriptSource) 104 if (!scriptSource)
70 throw "empty response arrived for script '" + sourceURL + "'"; 105 throw "empty response arrived for script '" + sourceURL + "'";
71 var oldPrefix = self._importScriptPathPrefix; 106 var oldPrefix = self._importScriptPathPrefix;
72 self._importScriptPathPrefix += scriptName.substring(0, scriptName.lastIndex Of("/") + 1); 107 self._importScriptPathPrefix += scriptName.substring(0, scriptName.lastIndex Of("/") + 1);
73 try { 108 try {
74 self.eval(scriptSource + "\n//# sourceURL=" + sourceURL); 109 self.eval(scriptSource + "\n//# sourceURL=" + sourceURL);
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 this._instance = new constructorFunction(); 558 this._instance = new constructorFunction();
524 } 559 }
525 return this._instance; 560 return this._instance;
526 } 561 }
527 } 562 }
528 563
529 /** 564 /**
530 * @type {!Runtime} 565 * @type {!Runtime}
531 */ 566 */
532 var runtime; 567 var runtime;
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/common/ParsedURL.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698