Skip to content

Commit

Permalink
implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 30, 2016
1 parent ca43a36 commit 80b5a40
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
5 changes: 5 additions & 0 deletions browserShim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var systemGlobal = require('./');

module.exports = systemGlobal.shim();
14 changes: 14 additions & 0 deletions implementation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* globals self, window, global */
/* eslint no-negated-condition: 0, no-new-func: 0 */

'use strict';

if (typeof self !== 'undefined') {
module.exports = self;
} else if (typeof window !== 'undefined') {
module.exports = window;
} else if (typeof global !== 'undefined') {
module.exports = global;
} else {
module.exports = Function('return this')();
}
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

var defineProperties = require('define-properties');

var implementation = require('./implementation');
var getPolyfill = require('./polyfill');
var shim = require('./shim');

var polyfill = getPolyfill();

var getGlobal = function () { return polyfill; };

defineProperties(getGlobal, {
getPolyfill: getPolyfill,
implementation: implementation,
shim: shim
});

module.exports = getGlobal;
10 changes: 10 additions & 0 deletions polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

var implementation = require('./implementation');

module.exports = function getPolyfill() {
if (typeof System !== 'object' || !System.global || System.global.Math !== Math || System.global.Array !== Array) {
return implementation;
}
return System.global;
};
26 changes: 26 additions & 0 deletions shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

var define = require('define-properties');
var getPolyfill = require('./polyfill');

module.exports = function shimSystemAndGlobal() {
var polyfill = getPolyfill();
define(
polyfill,
{ System: {} },
{ System: function () { return typeof System !== 'object'; } }
);
if (System.global !== polyfill) {
if (define.supportsDescriptors) {
Object.defineProperty(System, 'global', {
configurable: true,
enumerable: false,
value: polyfill,
writable: false
});
} else {
System.global = polyfill;
}
}
return polyfill;
};

0 comments on commit 80b5a40

Please sign in to comment.