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

all: Guard against window not existing. #332

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/bundle/core+encrypt+promise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Core } from '../core';
import { Encrypt } from '../encrypt';
import Promise from '../promise';
import PolyfillPromise from '../promise';

/**
* @param {object} [cfg]
Expand All @@ -11,6 +11,6 @@ function Ravelin(cfg) {
this.encrypt = new Encrypt(this.core, cfg);
}

Ravelin.Promise = window.Promise || Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise || PolyfillPromise;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier to do a null check? Same goes for the other ones?

Suggested change
Ravelin.Promise = typeof Promise !== 'undefined' && Promise || PolyfillPromise;
Ravelin.Promise = Promise != null && Promise || PolyfillPromise;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In older browsers before Promise because a thing, you'd get an equivalent of a ReferenceError because it's not a defined global.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UGH I hate older browsers


export default Ravelin;
2 changes: 1 addition & 1 deletion lib/bundle/core+encrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ function Ravelin(cfg) {
this.encrypt = new Encrypt(this.core, cfg);
}

Ravelin.Promise = window.Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise;

export default Ravelin;
4 changes: 2 additions & 2 deletions lib/bundle/core+promise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Core } from '../core';
import Promise from '../promise';
import PolyfillPromise from '../promise';

/**
* @param {object} [cfg]
Expand All @@ -9,6 +9,6 @@ function Ravelin(cfg) {
this.core = new Core(cfg);
}

Ravelin.Promise = window.Promise || Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise || PolyfillPromise;

export default Ravelin;
4 changes: 2 additions & 2 deletions lib/bundle/core+track+encrypt+promise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Core } from '../core';
import { Track } from '../track';
import { Encrypt } from '../encrypt';
import Promise from '../promise';
import PolyfillPromise from '../promise';

/**
* @typedef {object} Config
Expand All @@ -26,6 +26,6 @@ function Ravelin(cfg) {
this.encrypt = new Encrypt(this.core, cfg);
}

Ravelin.Promise = window.Promise || Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise || PolyfillPromise;

export default Ravelin;
2 changes: 1 addition & 1 deletion lib/bundle/core+track+encrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ function Ravelin(cfg) {
this.encrypt = new Encrypt(this.core, cfg);
}

Ravelin.Promise = window.Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise;

export default Ravelin;
4 changes: 2 additions & 2 deletions lib/bundle/core+track+promise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Core } from '../core';
import { Track } from '../track';
import Promise from '../promise';
import PolyfillPromise from '../promise';

/**
* @param {object} [cfg]
Expand All @@ -11,6 +11,6 @@ function Ravelin(cfg) {
this.track = new Track(this.core, cfg);
}

Ravelin.Promise = window.Promise || Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise || PolyfillPromise;

export default Ravelin;
2 changes: 1 addition & 1 deletion lib/bundle/core+track.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ function Ravelin(cfg) {
this.track = new Track(this.core, cfg);
}

Ravelin.Promise = window.Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise;

export default Ravelin;
2 changes: 1 addition & 1 deletion lib/bundle/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ function Ravelin(cfg) {
this.core = new Core(cfg);
}

Ravelin.Promise = window.Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise;

export default Ravelin;
2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function apiFromKey(key) {
return 'https://' + encodeURIComponent(env) + '.ravelin.click';
}

var _XDomainRequest = window.XDomainRequest;
var _XDomainRequest = typeof XDomainRequest !== 'undefined' && XDomainRequest;

/**
* @typedef {Object} CoreResponse
Expand Down