From 25b10d752085d5d860756cd421d6749d8cf4511b Mon Sep 17 00:00:00 2001 From: Moritz Moeller Date: Fri, 10 Oct 2014 15:34:43 +0200 Subject: [PATCH 1/4] Use XMLHttpRequest if available, even if not in browser --- src/system.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/system.js b/src/system.js index 89c0858..b31f9e7 100644 --- a/src/system.js +++ b/src/system.js @@ -59,7 +59,7 @@ } var fetchTextFromURL; - if (isBrowser || isWorker) { + if (typeof XMLHttpRequest != 'undefined') { fetchTextFromURL = function(url, fulfill, reject) { var xhr = new XMLHttpRequest(); var sameDomain = true; @@ -72,7 +72,7 @@ sameDomain &= domainCheck[1] === window.location.protocol; } } - if (!sameDomain) { + if (!sameDomain && typeof XDomainRequest != 'undefined') { xhr = new XDomainRequest(); xhr.onload = load; xhr.onerror = error; @@ -102,7 +102,7 @@ xhr.send(null); } } - else { + else if (typeof request != 'undefined') { var fs; fetchTextFromURL = function(url, fulfill, reject) { fs = fs || require('fs'); @@ -114,6 +114,9 @@ }); } } + else { + throw new TypeError('No API available to load external resources'); + } class SystemLoader extends __global.LoaderPolyfill { From 798e11cbeec8502acb6cc6e4bf3b0b560f7f17a4 Mon Sep 17 00:00:00 2001 From: Moritz Moeller Date: Fri, 10 Oct 2014 15:36:51 +0200 Subject: [PATCH 2/4] check availability of document.location and getElementsByTagName --- src/system.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/system.js b/src/system.js index b31f9e7..fa9b20f 100644 --- a/src/system.js +++ b/src/system.js @@ -124,13 +124,16 @@ super(options || {}); // Set default baseURL and paths - if (isBrowser || isWorker) { + if (typeof __global.location != 'undefined' && typeof __global.location.href != 'undefined') { var href = __global.location.href.split('#')[0].split('?')[0]; this.baseURL = href.substring(0, href.lastIndexOf('/') + 1); } - else { + else if (typeof process != 'undefined' && typeof process.cwd != 'undefined') { this.baseURL = process.cwd() + '/'; } + else { + this.baseURL = '.'; + } this.paths = { '*': '*.js' }; } @@ -258,7 +261,7 @@ //