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

Commit 8ff4941

Browse files
committed
use API functions based on availability (from #228)
1 parent aa5f686 commit 8ff4941

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/system.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
}
6060

6161
var fetchTextFromURL;
62-
if (isBrowser || isWorker) {
62+
if (typeof XMLHttpRequest != 'undefined') {
6363
fetchTextFromURL = function(url, fulfill, reject) {
6464
var xhr = new XMLHttpRequest();
6565
var sameDomain = true;
@@ -72,7 +72,7 @@
7272
sameDomain &= domainCheck[1] === window.location.protocol;
7373
}
7474
}
75-
if (!sameDomain) {
75+
if (!sameDomain && typeof XDomainRequest != 'undefined') {
7676
xhr = new XDomainRequest();
7777
xhr.onload = load;
7878
xhr.onerror = error;
@@ -102,7 +102,7 @@
102102
xhr.send(null);
103103
}
104104
}
105-
else {
105+
else if (typeof require != 'undefined') {
106106
var fs;
107107
fetchTextFromURL = function(url, fulfill, reject) {
108108
fs = fs || require('fs');
@@ -114,20 +114,26 @@
114114
});
115115
}
116116
}
117+
else {
118+
throw new TypeError('No environment fetch API available.');
119+
}
117120

118121
class SystemLoader extends __global.LoaderPolyfill {
119122

120123
constructor(options) {
121124
super(options || {});
122125

123126
// Set default baseURL and paths
124-
if (isBrowser || isWorker) {
127+
if (typeof location != 'undefined' && location.href) {
125128
var href = __global.location.href.split('#')[0].split('?')[0];
126129
this.baseURL = href.substring(0, href.lastIndexOf('/') + 1);
127130
}
128-
else {
131+
else if (typeof process != 'undefined' && process.cwd) {
129132
this.baseURL = process.cwd() + '/';
130133
}
134+
else {
135+
throw new TypeError('No environment baseURL');
136+
}
131137
this.paths = { '*': '*.js' };
132138
}
133139

@@ -255,7 +261,7 @@
255261

256262
// <script type="module"> support
257263
// allow a data-init function callback once loaded
258-
if (isBrowser) {
264+
if (isBrowser && typeof document.getElementsByTagName != 'undefined') {
259265
var curScript = document.getElementsByTagName('script');
260266
curScript = curScript[curScript.length - 1];
261267

0 commit comments

Comments
 (0)