happy-dom
Advanced tools
Comparing version 0.2.9 to 0.2.10
@@ -10,3 +10,3 @@ /// <reference types="node" /> | ||
private asyncTaskCount; | ||
private asyncError; | ||
private hasAsyncError; | ||
private asyncTimeout; | ||
@@ -43,3 +43,3 @@ private asyncPromises; | ||
/** | ||
* Provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network. | ||
* Provides a GLOBAL fetch() method that provides an easy, logical way to fetch resources asynchronously across the network. | ||
* | ||
@@ -46,0 +46,0 @@ * @param {string} url URL to resource. |
@@ -58,2 +58,3 @@ "use strict"; | ||
var FETCH_RESPONSE_TYPE_METHODS = ['blob', 'json', 'formData', 'text']; | ||
var GLOBAL = global || window; | ||
/** | ||
@@ -69,3 +70,3 @@ * Handles the Window. | ||
_this.asyncTaskCount = 0; | ||
_this.asyncError = null; | ||
_this.hasAsyncError = false; | ||
_this.asyncTimeout = null; | ||
@@ -85,5 +86,5 @@ _this.asyncPromises = []; | ||
this.startAsyncTask(); | ||
return setTimeout(function () { | ||
return GLOBAL.setTimeout(function () { | ||
callback(); | ||
_this.endAsyncTask(); | ||
callback(); | ||
}, delay); | ||
@@ -97,3 +98,3 @@ }; | ||
AsyncWindow.prototype.clearTimeout = function (id) { | ||
clearTimeout(id); | ||
GLOBAL.clearTimeout(id); | ||
this.endAsyncTask(); | ||
@@ -110,3 +111,3 @@ }; | ||
this.startAsyncTask(); | ||
return setInterval(callback, delay); | ||
return GLOBAL.setInterval(callback, delay); | ||
}; | ||
@@ -119,7 +120,7 @@ /** | ||
AsyncWindow.prototype.clearInterval = function (id) { | ||
clearInterval(id); | ||
GLOBAL.clearInterval(id); | ||
this.endAsyncTask(); | ||
}; | ||
/** | ||
* Provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network. | ||
* Provides a GLOBAL fetch() method that provides an easy, logical way to fetch resources asynchronously across the network. | ||
* | ||
@@ -145,8 +146,8 @@ * @param {string} url URL to resource. | ||
.then(function (response) { | ||
resolve(response); | ||
_this.endAsyncTask(); | ||
resolve(response); | ||
}) | ||
.catch(function (error) { | ||
reject(error); | ||
_this.endAsyncTask(error); | ||
reject(error); | ||
}); | ||
@@ -160,8 +161,8 @@ }); | ||
} | ||
resolve(response); | ||
_this.endAsyncTask(); | ||
resolve(response); | ||
}) | ||
.catch(function (error) { | ||
reject(error); | ||
_this.endAsyncTask(error); | ||
reject(error); | ||
}); | ||
@@ -185,3 +186,4 @@ })]; | ||
_this.asyncPromises.push({ resolve: resolve, reject: reject }); | ||
_this.endAsyncTask(); | ||
GLOBAL.clearTimeout(_this.asyncTimeout); | ||
_this.asyncTimeout = GLOBAL.setTimeout(function () { return _this.endAsyncTask(); }, 0); | ||
})]; | ||
@@ -197,6 +199,6 @@ }); | ||
this.isDisposed = true; | ||
this.asyncError = null; | ||
this.hasAsyncError = false; | ||
this.asyncTaskCount = 0; | ||
this.asyncPromises = []; | ||
clearTimeout(this.asyncTimeout); | ||
GLOBAL.clearTimeout(this.asyncTimeout); | ||
}; | ||
@@ -215,28 +217,20 @@ /** | ||
AsyncWindow.prototype.endAsyncTask = function (error) { | ||
var _this = this; | ||
if (!this.isDisposed) { | ||
this.asyncTaskCount--; | ||
if (error && !this.asyncError) { | ||
this.asyncError = error; | ||
var promises = this.asyncPromises; | ||
if (error) { | ||
this.hasAsyncError = true; | ||
this.asyncPromises = []; | ||
for (var _i = 0, promises_1 = promises; _i < promises_1.length; _i++) { | ||
var promise = promises_1[_i]; | ||
promise.reject(error); | ||
} | ||
} | ||
clearTimeout(this.asyncTimeout); | ||
this.asyncTimeout = setTimeout(function () { | ||
if (!_this.isDisposed) { | ||
var promises = _this.asyncPromises; | ||
if (_this.asyncError) { | ||
_this.asyncPromises = []; | ||
for (var _i = 0, promises_1 = promises; _i < promises_1.length; _i++) { | ||
var promise = promises_1[_i]; | ||
promise.reject(_this.asyncError); | ||
} | ||
} | ||
else if (_this.asyncTaskCount === 0) { | ||
_this.asyncPromises = []; | ||
for (var _a = 0, promises_2 = promises; _a < promises_2.length; _a++) { | ||
var promise = promises_2[_a]; | ||
promise.resolve(); | ||
} | ||
} | ||
else if (this.asyncTaskCount === 0 && !this.hasAsyncError) { | ||
this.asyncPromises = []; | ||
for (var _a = 0, promises_2 = promises; _a < promises_2.length; _a++) { | ||
var promise = promises_2[_a]; | ||
promise.resolve(); | ||
} | ||
}, 0); | ||
} | ||
} | ||
@@ -243,0 +237,0 @@ }; |
@@ -39,2 +39,3 @@ "use strict"; | ||
var ShadowRootRenderOptions_1 = __importDefault(require("./shadow-root/ShadowRootRenderOptions")); | ||
var GLOBAL = window || global; | ||
/** | ||
@@ -69,22 +70,12 @@ * Handles the Window. | ||
_this.Window = Window; | ||
// @ts-ignore | ||
_this.Array = typeof global !== undefined ? global.Array : null; | ||
// @ts-ignore | ||
_this.Object = typeof global !== undefined ? global.Object : null; | ||
// @ts-ignore | ||
_this.Number = typeof global !== undefined ? global.Number : null; | ||
// @ts-ignore | ||
_this.Symbol = typeof global !== undefined ? global.Symbol : null; | ||
// @ts-ignore | ||
_this.Function = typeof global !== undefined ? global.Function : null; | ||
// @ts-ignore | ||
_this.RegExp = typeof global !== undefined ? global.RegExp : null; | ||
// @ts-ignore | ||
_this.Date = typeof global !== undefined ? global.Date : null; | ||
// @ts-ignore | ||
_this.JSON = typeof global !== undefined ? global.JSON : null; | ||
// @ts-ignore | ||
_this.Promise = typeof global !== undefined ? global.Promise : null; | ||
// @ts-ignore | ||
_this.Error = typeof global !== undefined ? global.Error : null; | ||
_this.Array = typeof GLOBAL !== undefined ? GLOBAL.Array : null; | ||
_this.Object = typeof GLOBAL !== undefined ? GLOBAL.Object : null; | ||
_this.Number = typeof GLOBAL !== undefined ? GLOBAL.Number : null; | ||
_this.Symbol = typeof GLOBAL !== undefined ? GLOBAL.Symbol : null; | ||
_this.Function = typeof GLOBAL !== undefined ? GLOBAL.Function : null; | ||
_this.RegExp = typeof GLOBAL !== undefined ? GLOBAL.RegExp : null; | ||
_this.Date = typeof GLOBAL !== undefined ? GLOBAL.Date : null; | ||
_this.JSON = typeof GLOBAL !== undefined ? GLOBAL.JSON : null; | ||
_this.Promise = typeof GLOBAL !== undefined ? GLOBAL.Promise : null; | ||
_this.Error = typeof GLOBAL !== undefined ? GLOBAL.Error : null; | ||
_this.customElements = new CustomElementRegistry_1.default(); | ||
@@ -94,4 +85,3 @@ _this.location = new Location_1.default(); | ||
_this.self = _this; | ||
// @ts-ignore | ||
_this.console = typeof global !== undefined ? global.console : null; | ||
_this.console = typeof GLOBAL !== undefined ? GLOBAL.console : null; | ||
// Custom Properties (not part of HTML standard) | ||
@@ -98,0 +88,0 @@ _this.shadowRootRenderOptions = new ShadowRootRenderOptions_1.default(); |
{ | ||
"name": "happy-dom", | ||
"version": "0.2.9", | ||
"version": "0.2.10", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/capricorn86/happy-dom#readme", |
@@ -5,2 +5,3 @@ import NodeFetch from 'node-fetch'; | ||
const FETCH_RESPONSE_TYPE_METHODS = ['blob', 'json', 'formData', 'text']; | ||
const GLOBAL = global || window; | ||
@@ -14,3 +15,3 @@ /** | ||
private asyncTaskCount: number = 0; | ||
private asyncError: Error = null; | ||
private hasAsyncError: boolean = false; | ||
private asyncTimeout: NodeJS.Timeout = null; | ||
@@ -28,5 +29,5 @@ private asyncPromises: { resolve: () => void; reject: (error: Error) => void }[] = []; | ||
this.startAsyncTask(); | ||
return setTimeout(() => { | ||
return GLOBAL.setTimeout(() => { | ||
callback(); | ||
this.endAsyncTask(); | ||
callback(); | ||
}, delay); | ||
@@ -41,3 +42,3 @@ } | ||
public clearTimeout(id: NodeJS.Timeout): void { | ||
clearTimeout(id); | ||
GLOBAL.clearTimeout(id); | ||
this.endAsyncTask(); | ||
@@ -55,3 +56,3 @@ } | ||
this.startAsyncTask(); | ||
return setInterval(callback, delay); | ||
return GLOBAL.setInterval(callback, delay); | ||
} | ||
@@ -65,3 +66,3 @@ | ||
public clearInterval(id: NodeJS.Timeout): void { | ||
clearInterval(id); | ||
GLOBAL.clearInterval(id); | ||
this.endAsyncTask(); | ||
@@ -71,3 +72,3 @@ } | ||
/** | ||
* Provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network. | ||
* Provides a GLOBAL fetch() method that provides an easy, logical way to fetch resources asynchronously across the network. | ||
* | ||
@@ -92,8 +93,8 @@ * @param {string} url URL to resource. | ||
.then(response => { | ||
resolve(response); | ||
this.endAsyncTask(); | ||
resolve(response); | ||
}) | ||
.catch(error => { | ||
reject(error); | ||
this.endAsyncTask(error); | ||
reject(error); | ||
}); | ||
@@ -104,8 +105,8 @@ }); | ||
resolve(response); | ||
this.endAsyncTask(); | ||
resolve(response); | ||
}) | ||
.catch(error => { | ||
reject(error); | ||
this.endAsyncTask(error); | ||
reject(error); | ||
}); | ||
@@ -125,3 +126,4 @@ }); | ||
this.asyncPromises.push({ resolve, reject }); | ||
this.endAsyncTask(); | ||
GLOBAL.clearTimeout(this.asyncTimeout); | ||
this.asyncTimeout = GLOBAL.setTimeout(() => this.endAsyncTask(), 0); | ||
}); | ||
@@ -136,6 +138,6 @@ } | ||
this.isDisposed = true; | ||
this.asyncError = null; | ||
this.hasAsyncError = false; | ||
this.asyncTaskCount = 0; | ||
this.asyncPromises = []; | ||
clearTimeout(this.asyncTimeout); | ||
GLOBAL.clearTimeout(this.asyncTimeout); | ||
} | ||
@@ -159,26 +161,18 @@ | ||
if (error && !this.asyncError) { | ||
this.asyncError = error; | ||
} | ||
const promises = this.asyncPromises; | ||
clearTimeout(this.asyncTimeout); | ||
this.asyncTimeout = setTimeout(() => { | ||
if (!this.isDisposed) { | ||
const promises = this.asyncPromises; | ||
if (this.asyncError) { | ||
this.asyncPromises = []; | ||
for (const promise of promises) { | ||
promise.reject(this.asyncError); | ||
} | ||
} else if (this.asyncTaskCount === 0) { | ||
this.asyncPromises = []; | ||
for (const promise of promises) { | ||
promise.resolve(); | ||
} | ||
} | ||
if (error) { | ||
this.hasAsyncError = true; | ||
this.asyncPromises = []; | ||
for (const promise of promises) { | ||
promise.reject(error); | ||
} | ||
}, 0); | ||
} else if (this.asyncTaskCount === 0 && !this.hasAsyncError) { | ||
this.asyncPromises = []; | ||
for (const promise of promises) { | ||
promise.resolve(); | ||
} | ||
} | ||
} | ||
} | ||
} |
@@ -22,2 +22,4 @@ import CustomElementRegistry from './html-element/CustomElementRegistry'; | ||
const GLOBAL = window || global; | ||
/** | ||
@@ -47,22 +49,12 @@ * Handles the Window. | ||
// @ts-ignore | ||
public Array = typeof global !== undefined ? global.Array : null; | ||
// @ts-ignore | ||
public Object = typeof global !== undefined ? global.Object : null; | ||
// @ts-ignore | ||
public Number = typeof global !== undefined ? global.Number : null; | ||
// @ts-ignore | ||
public Symbol = typeof global !== undefined ? global.Symbol : null; | ||
// @ts-ignore | ||
public Function = typeof global !== undefined ? global.Function : null; | ||
// @ts-ignore | ||
public RegExp = typeof global !== undefined ? global.RegExp : null; | ||
// @ts-ignore | ||
public Date = typeof global !== undefined ? global.Date : null; | ||
// @ts-ignore | ||
public JSON = typeof global !== undefined ? global.JSON : null; | ||
// @ts-ignore | ||
public Promise = typeof global !== undefined ? global.Promise : null; | ||
// @ts-ignore | ||
public Error = typeof global !== undefined ? global.Error : null; | ||
public Array = typeof GLOBAL !== undefined ? GLOBAL.Array : null; | ||
public Object = typeof GLOBAL !== undefined ? GLOBAL.Object : null; | ||
public Number = typeof GLOBAL !== undefined ? GLOBAL.Number : null; | ||
public Symbol = typeof GLOBAL !== undefined ? GLOBAL.Symbol : null; | ||
public Function = typeof GLOBAL !== undefined ? GLOBAL.Function : null; | ||
public RegExp = typeof GLOBAL !== undefined ? GLOBAL.RegExp : null; | ||
public Date = typeof GLOBAL !== undefined ? GLOBAL.Date : null; | ||
public JSON = typeof GLOBAL !== undefined ? GLOBAL.JSON : null; | ||
public Promise = typeof GLOBAL !== undefined ? GLOBAL.Promise : null; | ||
public Error = typeof GLOBAL !== undefined ? GLOBAL.Error : null; | ||
@@ -75,6 +67,4 @@ // Public Properties | ||
public self = this; | ||
public console = typeof GLOBAL !== undefined ? GLOBAL.console : null; | ||
// @ts-ignore | ||
public console = typeof global !== undefined ? global.console : null; | ||
// Custom Properties (not part of HTML standard) | ||
@@ -81,0 +71,0 @@ public shadowRootRenderOptions = new ShadowRootRenderOptions(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
530759
13480
1
125