Skip to content

Commit

Permalink
feat(ses): redefine SharedSymbol to bypass Hermes prototype bug on ob…
Browse files Browse the repository at this point in the history
…j literal short-hand methods (#2206)

Fix SES compat with Hermes when calling
`addIntrinsics(tameSymbolConstructor());`
- #1891

Follow-up to
- #2108
  • Loading branch information
leotm committed May 7, 2024
1 parent 79c43e7 commit 59bb9ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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

0 comments on commit 59bb9ba

Please sign in to comment.