From 1f5715738ffa472bf3463b6cc6f03db2f31dde65 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 8 Dec 2015 14:54:55 -0800 Subject: [PATCH] fix(SymbolShim): Symbol polyfill is a function Symbol is supposed to be a function that takes a description and returns a unique symbol such that `Symbol('foo') !== Symbol('foo')`. The polyfill therefor returns a string that has a unique identifier concatenated to it: `@@Symbol(description):1` `@@Symbol(description):2` etc fixes #988 --- spec/util/SymbolShim-spec.js | 14 +++++++++++++- src/util/SymbolShim.ts | 6 +++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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; }