Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit bca9fcc

Browse files
committed
ios7 webworker changes port, url polyfill not a global
1 parent dd28e61 commit bca9fcc

File tree

3 files changed

+68
-72
lines changed

3 files changed

+68
-72
lines changed

src/system.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ function SystemLoader(options) {
1717

1818
var baseURL;
1919
// Set default baseURL and paths
20-
if (isWorker) {
21-
baseURL = __global.location.href;
22-
}
23-
else if (typeof document != 'undefined') {
20+
if (typeof document != 'undefined' && document.getElementsByTagName) {
2421
baseURL = document.baseURI;
2522

2623
if (!baseURL) {
@@ -37,6 +34,9 @@ function SystemLoader(options) {
3734
if (isWindows)
3835
baseURL = baseURL.replace(/\\/g, '/');
3936
}
37+
else if (typeof location != 'undefined') {
38+
baseURL = __global.location.href;
39+
}
4040
else {
4141
throw new TypeError('No environment baseURL');
4242
}

src/url-polyfill.js

+62-66
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,67 @@
11
// from https://gist.github.com/Yaffle/1088850
2-
if (typeof URL === 'undefined')
3-
URL = (function() {
4-
function URL(url, baseURL) {
5-
if (typeof url != 'string')
6-
throw new TypeError('URL must be a string');
7-
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
8-
if (!m) {
9-
throw new RangeError();
2+
function URL(url, baseURL) {
3+
if (typeof url != 'string')
4+
throw new TypeError('URL must be a string');
5+
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
6+
if (!m) {
7+
throw new RangeError();
8+
}
9+
var protocol = m[1] || "";
10+
var username = m[2] || "";
11+
var password = m[3] || "";
12+
var host = m[4] || "";
13+
var hostname = m[5] || "";
14+
var port = m[6] || "";
15+
var pathname = m[7] || "";
16+
var search = m[8] || "";
17+
var hash = m[9] || "";
18+
if (baseURL !== undefined) {
19+
var base = baseURL instanceof URL ? baseURL : new URL(baseURL);
20+
var flag = protocol === "" && host === "" && username === "";
21+
if (flag && pathname === "" && search === "") {
22+
search = base.search;
23+
}
24+
if (flag && pathname.charAt(0) !== "/") {
25+
pathname = (pathname !== "" ? (((base.host !== "" || base.username !== "") && base.pathname === "" ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname);
26+
}
27+
// dot segments removal
28+
var output = [];
29+
pathname.replace(/^(\.\.?(\/|$))+/, "")
30+
.replace(/\/(\.(\/|$))+/g, "/")
31+
.replace(/\/\.\.$/, "/../")
32+
.replace(/\/?[^\/]*/g, function (p) {
33+
if (p === "/..") {
34+
output.pop();
35+
} else {
36+
output.push(p);
37+
}
38+
});
39+
pathname = output.join("").replace(/^\//, pathname.charAt(0) === "/" ? "/" : "");
40+
if (flag) {
41+
port = base.port;
42+
hostname = base.hostname;
43+
host = base.host;
44+
password = base.password;
45+
username = base.username;
1046
}
11-
var protocol = m[1] || "";
12-
var username = m[2] || "";
13-
var password = m[3] || "";
14-
var host = m[4] || "";
15-
var hostname = m[5] || "";
16-
var port = m[6] || "";
17-
var pathname = m[7] || "";
18-
var search = m[8] || "";
19-
var hash = m[9] || "";
20-
if (baseURL !== undefined) {
21-
var base = baseURL instanceof URL ? baseURL : new URL(baseURL);
22-
var flag = protocol === "" && host === "" && username === "";
23-
if (flag && pathname === "" && search === "") {
24-
search = base.search;
25-
}
26-
if (flag && pathname.charAt(0) !== "/") {
27-
pathname = (pathname !== "" ? (((base.host !== "" || base.username !== "") && base.pathname === "" ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname);
28-
}
29-
// dot segments removal
30-
var output = [];
31-
pathname.replace(/^(\.\.?(\/|$))+/, "")
32-
.replace(/\/(\.(\/|$))+/g, "/")
33-
.replace(/\/\.\.$/, "/../")
34-
.replace(/\/?[^\/]*/g, function (p) {
35-
if (p === "/..") {
36-
output.pop();
37-
} else {
38-
output.push(p);
39-
}
40-
});
41-
pathname = output.join("").replace(/^\//, pathname.charAt(0) === "/" ? "/" : "");
42-
if (flag) {
43-
port = base.port;
44-
hostname = base.hostname;
45-
host = base.host;
46-
password = base.password;
47-
username = base.username;
48-
}
49-
if (protocol === "") {
50-
protocol = base.protocol;
51-
}
47+
if (protocol === "") {
48+
protocol = base.protocol;
5249
}
50+
}
5351

54-
// convert windows file URLs to use /
55-
if (protocol == 'file:')
56-
pathname = pathname.replace(/\\/g, '/');
52+
// convert windows file URLs to use /
53+
if (protocol == 'file:')
54+
pathname = pathname.replace(/\\/g, '/');
5755

58-
this.origin = protocol + (protocol !== "" || host !== "" ? "//" : "") + host;
59-
this.href = protocol + (protocol !== "" || host !== "" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash;
60-
this.protocol = protocol;
61-
this.username = username;
62-
this.password = password;
63-
this.host = host;
64-
this.hostname = hostname;
65-
this.port = port;
66-
this.pathname = pathname;
67-
this.search = search;
68-
this.hash = hash;
69-
}
70-
return URL;
71-
})();
56+
this.origin = protocol + (protocol !== "" || host !== "" ? "//" : "") + host;
57+
this.href = protocol + (protocol !== "" || host !== "" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash;
58+
this.protocol = protocol;
59+
this.username = username;
60+
this.password = password;
61+
this.host = host;
62+
this.hostname = hostname;
63+
this.port = port;
64+
this.pathname = pathname;
65+
this.search = search;
66+
this.hash = hash;
67+
}

src/wrapper-start.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function(__global) {
22

3-
var isWorker = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
4-
var isBrowser = typeof window != 'undefined' && !isWorker;
3+
var isWorker = typeof window == 'undefined' && typeof self != 'undefined' && typeof importScripts != 'undefined';
4+
var isBrowser = typeof window != 'undefined' && typeof document != 'undefined';
55
var isWindows = typeof process != 'undefined' && !!process.platform.match(/^win/);
66

77
if (__global.console)

0 commit comments

Comments
 (0)