Skip to content

Commit

Permalink
fix: global and timers this arg in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Mesteery committed Aug 27, 2021
1 parent 2189194 commit 1e93ab1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/internal/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function makeNodeError(Base) {
};
}

class AssertionError extends global.Error {
class AssertionError extends globalThis.Error {
generatedMessage: any;
name: any;
code: any;
Expand Down Expand Up @@ -74,9 +74,9 @@ function E(sym, val) {
messages[sym] = typeof val === 'function' ? val : String(val);
}

export const Error = makeNodeError(global.Error);
export const TypeError = makeNodeError(global.TypeError);
export const RangeError = makeNodeError(global.RangeError);
export const Error = makeNodeError(globalThis.Error);
export const TypeError = makeNodeError(globalThis.TypeError);
export const RangeError = makeNodeError(globalThis.RangeError);

export {
message,
Expand Down
4 changes: 2 additions & 2 deletions src/setImmediate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type TSetImmediate = (callback: (...args) => void, args?) => void;
let _setImmediate: TSetImmediate;

if (typeof setImmediate === 'function') _setImmediate = setImmediate.bind(global);
else _setImmediate = setTimeout.bind(global);
if (typeof setImmediate === 'function') _setImmediate = setImmediate.bind(globalThis);
else _setImmediate = setTimeout.bind(globalThis);

export default _setImmediate as TSetImmediate;
2 changes: 1 addition & 1 deletion src/setTimeoutUnref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type TSetTimeout = (callback: (...args) => void, time?: number, args?: an
* only in Node's environment it will "unref" its macro task.
*/
function setTimeoutUnref(callback, time?, args?): object {
const ref = setTimeout.apply(null, arguments);
const ref = setTimeout.apply(globalThis, arguments);
if (ref && typeof ref === 'object' && typeof ref.unref === 'function') ref.unref();
return ref;
}
Expand Down
2 changes: 1 addition & 1 deletion src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,7 @@ export class StatWatcher extends EventEmitter {

start(path: string, persistent: boolean = true, interval: number = 5007) {
this.filename = pathToFilename(path);
this.setTimeout = persistent ? setTimeout : setTimeoutUnref;
this.setTimeout = persistent ? setTimeout.bind(globalThis) : setTimeoutUnref;
this.interval = interval;
this.prev = this.vol.statSync(this.filename);
this.loop();
Expand Down

0 comments on commit 1e93ab1

Please sign in to comment.