diff --git a/spec/util/SymbolShim-spec.js b/spec/util/SymbolShim-spec.js index ac251d4e5f..de77c8cab7 100644 --- a/spec/util/SymbolShim-spec.js +++ b/spec/util/SymbolShim-spec.js @@ -5,7 +5,19 @@ var Rx = require('../../dist/cjs/Rx'); var polyfillSymbol = SymbolShim.polyfillSymbol; var ensureIterator = SymbolShim.ensureIterator; -describe('SymbolShim', function () { +describe('SymbolShim.polyfillSymbol', function () { + it('should polyfill Symbol to be a function that returns a primitive that is unique', function () { + var Symbol = polyfillSymbol({ }); + + expect(typeof Symbol).toBe('function'); + var x = Symbol('test'); + var y = Symbol('test'); + expect(x !== y).toBe(true); // should be obvious, but this is the important part. + + expect(x).toBe('@@Symbol(test):0'); + expect(y).toBe('@@Symbol(test):1'); + }); + it('should setup symbol if root does not have it', function () { var root = {}; diff --git a/src/util/SymbolShim.ts b/src/util/SymbolShim.ts index 98e4163403..eebbf45fda 100644 --- a/src/util/SymbolShim.ts +++ b/src/util/SymbolShim.ts @@ -14,9 +14,13 @@ export function ensureFor(Symbol) { } } +let id = 0; + export function ensureSymbol(root) { if (!root.Symbol) { - root.Symbol = {}; + root.Symbol = function symbolFuncPolyfill(description) { + return `@@Symbol(${description}):${id++}`; + }; } return root.Symbol; }