Skip to content

Commit

Permalink
Merge pull request #5 from rdkcentral/fix/polyfill-global-this
Browse files Browse the repository at this point in the history
Added a 'horrifying' polyfill for globalThis (https://mathiasbynens.b…
  • Loading branch information
wouterlucas authored Apr 15, 2020
2 parents d0e3d04 + f2209ca commit 69ec65f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/thunderJS.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions module/thunderJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ const unregister = function(plugin, event) {
}
};

(function (Object) {
typeof globalThis !== 'object' && (
this ?
get() :
(Object.defineProperty(Object.prototype, '_T_', {
configurable: true,
get: get
}), _T_)
);
function get() {
this.globalThis = this;
delete Object.prototype._T_;
}
}(Object));

let api;
var thunderJS = options => {
if (globalThis.thunder && typeof globalThis.thunder.token === 'function') {
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Metrological, Wouter <[email protected]>"
],
"name": "ThunderJS",
"version": "1.2.0",
"version": "1.2.1",
"license": "apache",
"browser": "dist/thunderJS.js",
"main": "src/thunderJS.js",
Expand Down Expand Up @@ -60,6 +60,7 @@
"tape": "^4.13.2"
},
"dependencies": {
"@ungap/global-this": "^0.3.1",
"ws": "^7.2.3"
}
}
1 change: 1 addition & 0 deletions src/thunderJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import API from './api'
import plugins from './plugins/index'
import listener from './listener'
import '@ungap/global-this'

let api

Expand Down

0 comments on commit 69ec65f

Please sign in to comment.