From 91fbaa99bd755484a4642d51b26b22c5cc992650 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Wed, 10 Apr 2024 17:37:51 +0100 Subject: [PATCH 1/6] feat(ses): tolerate non-configurable Symbol props --- packages/ses/src/tame-symbol-constructor.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/ses/src/tame-symbol-constructor.js b/packages/ses/src/tame-symbol-constructor.js index 808c1af833..4e35cf4414 100644 --- a/packages/ses/src/tame-symbol-constructor.js +++ b/packages/ses/src/tame-symbol-constructor.js @@ -50,14 +50,20 @@ export const tameSymbolConstructor = () => { }, }); + const sharedSymbolDescs = getOwnPropertyDescriptors(SharedSymbol); const originalDescsEntries = entries( getOwnPropertyDescriptors(OriginalSymbol), ); const descs = fromEntries( - arrayMap(originalDescsEntries, ([name, desc]) => [ - name, - { ...desc, configurable: true }, - ]), + arrayMap(originalDescsEntries, ([name, desc]) => { + if ( + sharedSymbolDescs[name] && + sharedSymbolDescs[name].configurable === false + ) { + return [name, desc]; + } + return [name, { ...desc, configurable: true }]; + }), ); defineProperties(SharedSymbol, descs); From 8f260a686a36e0d4cc7a2e5265a98a017d54404c Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:32:06 +0100 Subject: [PATCH 2/6] Revert "feat(ses): tolerate non-configurable Symbol props" This reverts commit 22b2c179134e61348da456076f101334f0d06ff7. --- packages/ses/src/tame-symbol-constructor.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/ses/src/tame-symbol-constructor.js b/packages/ses/src/tame-symbol-constructor.js index 4e35cf4414..808c1af833 100644 --- a/packages/ses/src/tame-symbol-constructor.js +++ b/packages/ses/src/tame-symbol-constructor.js @@ -50,20 +50,14 @@ export const tameSymbolConstructor = () => { }, }); - const sharedSymbolDescs = getOwnPropertyDescriptors(SharedSymbol); const originalDescsEntries = entries( getOwnPropertyDescriptors(OriginalSymbol), ); const descs = fromEntries( - arrayMap(originalDescsEntries, ([name, desc]) => { - if ( - sharedSymbolDescs[name] && - sharedSymbolDescs[name].configurable === false - ) { - return [name, desc]; - } - return [name, { ...desc, configurable: true }]; - }), + arrayMap(originalDescsEntries, ([name, desc]) => [ + name, + { ...desc, configurable: true }, + ]), ); defineProperties(SharedSymbol, descs); From 5d4e052c5eab8ceb552c5ae66699382330d553f8 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:32:29 +0100 Subject: [PATCH 3/6] fixup! feat(ses): add functionBind definition in commons.js --- packages/ses/src/commons.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/ses/src/commons.js b/packages/ses/src/commons.js index 57d3683753..d8c89e8ce5 100644 --- a/packages/ses/src/commons.js +++ b/packages/ses/src/commons.js @@ -217,6 +217,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]); From 6c4827a4b543db6b5968d84f6dd23adf3c7c05db Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:32:59 +0100 Subject: [PATCH 4/6] fixup! feat(ses): redefine SharedSymbol using functionBind --- packages/ses/src/tame-symbol-constructor.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/ses/src/tame-symbol-constructor.js b/packages/ses/src/tame-symbol-constructor.js index 808c1af833..aa01f9b254 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,7 @@ export const tameSymbolConstructor = () => { const OriginalSymbol = Symbol; const SymbolPrototype = OriginalSymbol.prototype; - const SharedSymbol = { - Symbol(description) { - return OriginalSymbol(description); - }, - }.Symbol; + const SharedSymbol = functionBind(Symbol, undefined); defineProperties(SymbolPrototype, { constructor: { From 1079bdc8f23922a182ea735bd283a690aa3e26d4 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:33:24 +0100 Subject: [PATCH 5/6] fixup! feat(ses): add comment --- packages/ses/src/tame-symbol-constructor.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/ses/src/tame-symbol-constructor.js b/packages/ses/src/tame-symbol-constructor.js index aa01f9b254..324e3c5acf 100644 --- a/packages/ses/src/tame-symbol-constructor.js +++ b/packages/ses/src/tame-symbol-constructor.js @@ -38,6 +38,8 @@ export const tameSymbolConstructor = () => { const OriginalSymbol = Symbol; const SymbolPrototype = OriginalSymbol.prototype; + // Bypass Hermes bug, fixed in: https://github.com/facebook/hermes/commit/00f18c89c720e1c34592bb85a1a8d311e6e99599 + // Increase JS spec fidelity by no longer defining SharedSymbol as an object literal short-hand method const SharedSymbol = functionBind(Symbol, undefined); defineProperties(SymbolPrototype, { From f74eee94f50c32409f3e7510e4bb298fca346d7e Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:51:04 +0100 Subject: [PATCH 6/6] fixup! feat(ses): update comment Co-authored-by: Mathieu Hofman <86499+mhofman@users.noreply.github.com> --- packages/ses/src/tame-symbol-constructor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ses/src/tame-symbol-constructor.js b/packages/ses/src/tame-symbol-constructor.js index 324e3c5acf..50fe532f3c 100644 --- a/packages/ses/src/tame-symbol-constructor.js +++ b/packages/ses/src/tame-symbol-constructor.js @@ -39,7 +39,7 @@ export const tameSymbolConstructor = () => { const SymbolPrototype = OriginalSymbol.prototype; // Bypass Hermes bug, fixed in: https://github.com/facebook/hermes/commit/00f18c89c720e1c34592bb85a1a8d311e6e99599 - // Increase JS spec fidelity by no longer defining SharedSymbol as an object literal short-hand method + // 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, {