Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed self to window since we're in a browser environment and want to support jsdom/jsdomify #239

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions fetch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';

if (self.fetch) {
if (typeof window !== 'object' || window.fetch) {
return
}

Expand Down Expand Up @@ -108,16 +108,16 @@
}

var support = {
blob: 'FileReader' in self && 'Blob' in self && (function() {
blob: 'FileReader' in window && 'Blob' in window && (function() {
try {
new Blob();
return true
} catch(e) {
return false
}
})(),
formData: 'FormData' in self,
arrayBuffer: 'ArrayBuffer' in self
formData: 'FormData' in window,
arrayBuffer: 'ArrayBuffer' in window
}

function Body() {
Expand Down Expand Up @@ -312,11 +312,11 @@
return new Response(null, {status: status, headers: {location: url}})
}

self.Headers = Headers;
self.Request = Request;
self.Response = Response;
window.Headers = Headers;
window.Request = Request;
window.Response = Response;

self.fetch = function(input, init) {
window.fetch = function(input, init) {
return new Promise(function(resolve, reject) {
var request
if (Request.prototype.isPrototypeOf(input) && !init) {
Expand Down Expand Up @@ -377,5 +377,5 @@
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit)
})
}
self.fetch.polyfill = true
window.fetch.polyfill = true
})();
2 changes: 1 addition & 1 deletion test/test-worker.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
})
break
case 'end':
if (self.mochaPhantomJS) {
if (window.mochaPhantomJS) {
mochaPhantomJS.run()
} else {
mocha.run()
Expand Down
4 changes: 2 additions & 2 deletions test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script src="../node_modules/mocha/mocha.js"></script>
<script>
mocha.setup('tdd')
self.assert = chai.assert
window.assert = chai.assert
</script>

<script src="../bower_components/es6-promise/promise.js"></script>
Expand All @@ -20,7 +20,7 @@
<script src="test.js"></script>

<script>
if (self.mochaPhantomJS) {
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
} else {
var runner = mocha.run();
Expand Down
12 changes: 6 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function readBlobAsText(blob) {
if ('FileReader' in self) {
if ('FileReader' in window) {
return new Promise(function(resolve, reject) {
var reader = new FileReader()
reader.onload = function() {
Expand All @@ -10,15 +10,15 @@ function readBlobAsText(blob) {
}
reader.readAsText(blob)
})
} else if ('FileReaderSync' in self) {
} else if ('FileReaderSync' in window) {
return new FileReaderSync().readAsText(blob)
} else {
throw new ReferenceError('FileReader is not defined')
}
}

function readBlobAsBytes(blob) {
if ('FileReader' in self) {
if ('FileReader' in window) {
return new Promise(function(resolve, reject) {
var reader = new FileReader()
reader.onload = function() {
Expand All @@ -30,7 +30,7 @@ function readBlobAsBytes(blob) {
}
reader.readAsArrayBuffer(blob)
})
} else if ('FileReaderSync' in self) {
} else if ('FileReaderSync' in window) {
return new FileReaderSync().readAsArrayBuffer(blob)
} else {
throw new ReferenceError('FileReader is not defined')
Expand Down Expand Up @@ -205,7 +205,7 @@ suite('Request', function() {
})
})

;(ArrayBuffer in self ? test : test.skip)('sends ArrayBuffer body', function() {
;(ArrayBuffer in window ? test : test.skip)('sends ArrayBuffer body', function() {
var text = 'name=Hubot'

var buf = new ArrayBuffer(text.length)
Expand Down Expand Up @@ -834,7 +834,7 @@ suite('Atomic HTTP redirect handling', function() {

// https://fetch.spec.whatwg.org/#concept-request-credentials-mode
suite('credentials mode', function() {
var omitSupported = !self.fetch.polyfill
var omitSupported = !window.fetch.polyfill

setup(function() {
return fetch('/cookie?name=foo&value=reset', {credentials: 'same-origin'});
Expand Down
10 changes: 5 additions & 5 deletions test/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ importScripts('../node_modules/chai/chai.js')
importScripts('../node_modules/mocha/mocha.js')

mocha.setup('tdd')
self.assert = chai.assert
window.assert = chai.assert

importScripts('../bower_components/es6-promise/promise.js')
importScripts('../fetch.js')
Expand All @@ -15,15 +15,15 @@ function title(test) {

function reporter(runner) {
runner.on('pending', function(test){
self.postMessage({name: 'pending', title: title(test)});
window.postMessage({name: 'pending', title: title(test)});
});

runner.on('pass', function(test){
self.postMessage({name: 'pass', title: title(test)});
window.postMessage({name: 'pass', title: title(test)});
});

runner.on('fail', function(test, err){
self.postMessage({
window.postMessage({
name: 'fail',
title: title(test),
message: err.message,
Expand All @@ -32,7 +32,7 @@ function reporter(runner) {
});

runner.on('end', function(){
self.postMessage({name: 'end'});
window.postMessage({name: 'end'});
});
}

Expand Down