Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ses): redefine SharedSymbol to bypass Hermes prototype bug on obj literal short-hand methods #2206

Merged
merged 7 commits into from
May 7, 2024
1 change: 1 addition & 0 deletions packages/ses/src/commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
9 changes: 4 additions & 5 deletions packages/ses/src/tame-symbol-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getOwnPropertyDescriptors,
defineProperties,
arrayMap,
functionBind,
} from './commons.js';

/**
Expand Down Expand Up @@ -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: {
Expand Down
Loading