-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
(function() { | ||
var _currentDirectory = (function () { | ||
var _url; | ||
var lines = new Error().stack.split('\n'); | ||
function lookupUrl() { | ||
if (lines.length > 2) { | ||
var match = lines[1].match(/^\s+at (.+):\d+:\d+$/); | ||
// Chrome. | ||
if (match) return match[1]; | ||
// Chrome nested eval case. | ||
match = lines[1].match(/^\s+at eval [(](.+):\d+:\d+[)]$/); | ||
if (match) return match[1]; | ||
// Edge. | ||
match = lines[1].match(/^\s+at.+\((.+):\d+:\d+\)$/); | ||
if (match) return match[1]; | ||
// Firefox. | ||
match = lines[0].match(/[<][@](.+):\d+:\d+$/) | ||
if (match) return match[1]; | ||
} | ||
// Safari. | ||
return lines[0].match(/(.+):\d+:\d+$/)[1]; | ||
} | ||
_url = lookupUrl(); | ||
var lastSlash = _url.lastIndexOf('/'); | ||
if (lastSlash == -1) return _url; | ||
var currentDirectory = _url.substring(0, lastSlash + 1); | ||
return currentDirectory; | ||
})(); | ||
|
||
var baseUrl = (function () { | ||
// Attempt to detect --precompiled mode for tests, and set the base url | ||
// appropriately, otherwise set it to '/'. | ||
var pathParts = location.pathname.split("/"); | ||
if (pathParts[0] == "") { | ||
pathParts.shift(); | ||
} | ||
if (pathParts.length > 1 && pathParts[1] == "test") { | ||
return "/" + pathParts.slice(0, 2).join("/") + "/"; | ||
} | ||
// Attempt to detect base url using <base href> html tag | ||
// base href should start and end with "/" | ||
if (typeof document !== 'undefined') { | ||
var el = document.getElementsByTagName('base'); | ||
if (el && el[0] && el[0].getAttribute("href") && el[0].getAttribute | ||
("href").startsWith("/") && el[0].getAttribute("href").endsWith("/")){ | ||
return el[0].getAttribute("href"); | ||
} | ||
} | ||
// return default value | ||
return "/"; | ||
}()); | ||
|
||
|
||
var mapperUri = baseUrl + "packages/build_web_compilers/src/" + | ||
"dev_compiler_stack_trace/stack_trace_mapper.dart.js"; | ||
var requireUri = baseUrl + | ||
"packages/build_web_compilers/src/dev_compiler/require.js"; | ||
var mainUri = _currentDirectory + "background.dart.bootstrap"; | ||
|
||
if (typeof document != 'undefined') { | ||
var el = document.createElement("script"); | ||
el.defer = true; | ||
el.async = false; | ||
el.src = mapperUri; | ||
document.head.appendChild(el); | ||
|
||
el = document.createElement("script"); | ||
el.defer = true; | ||
el.async = false; | ||
el.src = requireUri; | ||
el.setAttribute("data-main", mainUri); | ||
document.head.appendChild(el); | ||
} else { | ||
importScripts(mapperUri, requireUri); | ||
require.config({ | ||
baseUrl: baseUrl, | ||
}); | ||
// TODO: update bootstrap code to take argument - dart-lang/build#1115 | ||
window = self; | ||
require([mainUri + '.js']); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters