diff --git a/packages/ses/src/commons.js b/packages/ses/src/commons.js index bd5f42bd5c..5028a7f572 100644 --- a/packages/ses/src/commons.js +++ b/packages/ses/src/commons.js @@ -224,6 +224,7 @@ export const weaksetAdd = uncurryThis(weaksetPrototype.add); export const weaksetHas = uncurryThis(weaksetPrototype.has); // export const functionToString = uncurryThis(functionPrototype.toString); +export const functionBind = uncurryThis(bind); // const { all } = Promise; export const promiseAll = promises => apply(all, Promise, [promises]); diff --git a/packages/ses/src/tame-symbol-constructor.js b/packages/ses/src/tame-symbol-constructor.js index 808c1af833..50fe532f3c 100644 --- a/packages/ses/src/tame-symbol-constructor.js +++ b/packages/ses/src/tame-symbol-constructor.js @@ -5,6 +5,7 @@ import { getOwnPropertyDescriptors, defineProperties, arrayMap, + functionBind, } from './commons.js'; /** @@ -37,11 +38,9 @@ export const tameSymbolConstructor = () => { const OriginalSymbol = Symbol; const SymbolPrototype = OriginalSymbol.prototype; - const SharedSymbol = { - Symbol(description) { - return OriginalSymbol(description); - }, - }.Symbol; + // Bypass Hermes bug, fixed in: https://github.com/facebook/hermes/commit/00f18c89c720e1c34592bb85a1a8d311e6e99599 + // Make a "copy" of the primordial [Symbol "constructor"](https://tc39.es/ecma262/#sec-symbol-description) which maintains all observable behavior. The primordial explicitly throws on `[[Construct]]` and has a `[[Call]]` which ignores the receiver. Binding also maintains the `toString` source as a native function. The `name` is restored below when copying own properties. + const SharedSymbol = functionBind(Symbol, undefined); defineProperties(SymbolPrototype, { constructor: {