Skip to content

Commit

Permalink
fix(ses): expect fn instance prototype on Hermes in permit
Browse files Browse the repository at this point in the history
  • Loading branch information
leotm committed Oct 28, 2024
1 parent d6c6c69 commit 1d4bd35
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/ses/src/permits.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ export const FunctionInstance = {
// Do not specify "prototype" here, since only Function instances that can
// be used as a constructor have a prototype property. For constructors,
// since prototype properties are instance-specific, we define it there.
// Older versions of Hermes contain a non-standard prototype, noted below in 'hermesFn'.
// This is fixed fully in Static Hermes: https://github.com/facebook/hermes/tree/static_h
// See: https://speakerdeck.com/tmikov2023/optimizing-with-static-hermes-chain-react-2024
};

// AsyncFunction Instances
Expand All @@ -281,6 +284,14 @@ export const AsyncFunctionInstance = {

// Aliases
const fn = FunctionInstance;
// Bypass Hermes bugs, fixed in:
// - https://github.com/facebook/hermes/commit/c42491de94aff479e5e83c073eff96a6261da080 (hermes: v0.13.0)
// - https://github.com/facebook/hermes/commit/00f18c89c720e1c34592bb85a1a8d311e6e99599 (sh_stable, static_h)
// Expect Additional Properties of the Global Object (Annex B) proposed by SES,
// that are function instances defined as arrow functions ('lockdown' and 'harden')
// and concise methods ('%InitialGetStackString%'), to have their non-standard
// prototype properties set to `undefined` in intrinsics.js when completing prototypes.
const hermesFn = { ...FunctionInstance, prototype: 'undefined' };
const asyncFn = AsyncFunctionInstance;

const getter = {
Expand Down Expand Up @@ -1643,8 +1654,8 @@ export const permitted = {
'@@toStringTag': 'string',
},

lockdown: fn,
harden: { ...fn, isFake: 'boolean' },
lockdown: hermesFn,
harden: { ...hermesFn, isFake: 'boolean' },

'%InitialGetStackString%': fn,
'%InitialGetStackString%': hermesFn,
};

0 comments on commit 1d4bd35

Please sign in to comment.