69 lines
2.1 KiB
JavaScript
69 lines
2.1 KiB
JavaScript
|
"use strict";
|
||
|
var root_1 = require('./root');
|
||
|
function polyfillSymbol(root) {
|
||
|
var Symbol = ensureSymbol(root);
|
||
|
ensureIterator(Symbol, root);
|
||
|
ensureObservable(Symbol);
|
||
|
ensureFor(Symbol);
|
||
|
return Symbol;
|
||
|
}
|
||
|
exports.polyfillSymbol = polyfillSymbol;
|
||
|
function ensureFor(Symbol) {
|
||
|
if (!Symbol.for) {
|
||
|
Symbol.for = symbolForPolyfill;
|
||
|
}
|
||
|
}
|
||
|
exports.ensureFor = ensureFor;
|
||
|
var id = 0;
|
||
|
function ensureSymbol(root) {
|
||
|
if (!root.Symbol) {
|
||
|
root.Symbol = function symbolFuncPolyfill(description) {
|
||
|
return "@@Symbol(" + description + "):" + id++;
|
||
|
};
|
||
|
}
|
||
|
return root.Symbol;
|
||
|
}
|
||
|
exports.ensureSymbol = ensureSymbol;
|
||
|
function symbolForPolyfill(key) {
|
||
|
return '@@' + key;
|
||
|
}
|
||
|
exports.symbolForPolyfill = symbolForPolyfill;
|
||
|
function ensureIterator(Symbol, root) {
|
||
|
if (!Symbol.iterator) {
|
||
|
if (typeof Symbol.for === 'function') {
|
||
|
Symbol.iterator = Symbol.for('iterator');
|
||
|
}
|
||
|
else if (root.Set && typeof new root.Set()['@@iterator'] === 'function') {
|
||
|
// Bug for mozilla version
|
||
|
Symbol.iterator = '@@iterator';
|
||
|
}
|
||
|
else if (root.Map) {
|
||
|
// es6-shim specific logic
|
||
|
var keys = Object.getOwnPropertyNames(root.Map.prototype);
|
||
|
for (var i = 0; i < keys.length; ++i) {
|
||
|
var key = keys[i];
|
||
|
if (key !== 'entries' && key !== 'size' && root.Map.prototype[key] === root.Map.prototype['entries']) {
|
||
|
Symbol.iterator = key;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
Symbol.iterator = '@@iterator';
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
exports.ensureIterator = ensureIterator;
|
||
|
function ensureObservable(Symbol) {
|
||
|
if (!Symbol.observable) {
|
||
|
if (typeof Symbol.for === 'function') {
|
||
|
Symbol.observable = Symbol.for('observable');
|
||
|
}
|
||
|
else {
|
||
|
Symbol.observable = '@@observable';
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
exports.ensureObservable = ensureObservable;
|
||
|
exports.SymbolShim = polyfillSymbol(root_1.root);
|
||
|
//# sourceMappingURL=SymbolShim.js.map
|