From 0421ca7eaf4c69c2343637f495c5e5738230cb8f Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Tue, 28 May 2024 19:40:53 +0100 Subject: [PATCH] feat(ses): strip async generators for Hermes - fix React Native Android release build (Metro bundle) error - fix getAnonymousIntrinsics runtime SES error - strip async generators and iterators - strip related intrinsics (control abstraction objects) - no longer attempt to repair them - remove (and update) related tests - before: 380 passed, 2 known failures, 2 skipped - after: 379 passed, 2 known failures, 2 skipped --- packages/ses/src/get-anonymous-intrinsics.js | 18 ------------ packages/ses/src/permits.js | 28 ------------------- .../ses/src/tame-function-constructors.js | 6 +--- packages/ses/test/harden.test.js | 3 -- packages/ses/test/ses.test.js | 9 +----- packages/ses/test/tame-function-unit.test.js | 16 ----------- 6 files changed, 2 insertions(+), 78 deletions(-) diff --git a/packages/ses/src/get-anonymous-intrinsics.js b/packages/ses/src/get-anonymous-intrinsics.js index cf402c3339..256a121af6 100644 --- a/packages/ses/src/get-anonymous-intrinsics.js +++ b/packages/ses/src/get-anonymous-intrinsics.js @@ -95,20 +95,6 @@ export const getAnonymousIntrinsics = () => { const Generator = GeneratorFunction.prototype; - // 25.3.1 The AsyncGeneratorFunction Constructor - - // eslint-disable-next-line no-empty-function - async function* AsyncGeneratorFunctionInstance() {} - const AsyncGeneratorFunction = getConstructorOf( - AsyncGeneratorFunctionInstance, - ); - - // 25.3.2.2 AsyncGeneratorFunction.prototype - const AsyncGenerator = AsyncGeneratorFunction.prototype; - // 25.5.1 Properties of the AsyncGenerator Prototype Object - const AsyncGeneratorPrototype = AsyncGenerator.prototype; - const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype); - // 25.7.1 The AsyncFunction Constructor // eslint-disable-next-line no-empty-function @@ -119,10 +105,6 @@ export const getAnonymousIntrinsics = () => { '%InertFunction%': InertFunction, '%ArrayIteratorPrototype%': ArrayIteratorPrototype, '%InertAsyncFunction%': AsyncFunction, - '%AsyncGenerator%': AsyncGenerator, - '%InertAsyncGeneratorFunction%': AsyncGeneratorFunction, - '%AsyncGeneratorPrototype%': AsyncGeneratorPrototype, - '%AsyncIteratorPrototype%': AsyncIteratorPrototype, '%Generator%': Generator, '%InertGeneratorFunction%': GeneratorFunction, '%IteratorPrototype%': IteratorPrototype, diff --git a/packages/ses/src/permits.js b/packages/ses/src/permits.js index d364501067..269a4689a0 100644 --- a/packages/ses/src/permits.js +++ b/packages/ses/src/permits.js @@ -1430,24 +1430,6 @@ export const permitted = { '@@toStringTag': 'string', }, - '%InertAsyncGeneratorFunction%': { - // Properties of the AsyncGeneratorFunction Constructor - '[[Proto]]': '%InertFunction%', - prototype: '%AsyncGenerator%', - }, - - '%AsyncGenerator%': { - // Properties of the AsyncGeneratorFunction Prototype Object - '[[Proto]]': '%FunctionPrototype%', - constructor: '%InertAsyncGeneratorFunction%', - prototype: '%AsyncGeneratorPrototype%', - // length prop added here for React Native jsc-android - // https://github.com/endojs/endo/issues/660 - // https://github.com/react-native-community/jsc-android-buildscripts/issues/181 - length: 'number', - '@@toStringTag': 'string', - }, - '%GeneratorPrototype%': { // Properties of the Generator Prototype Object '[[Proto]]': '%IteratorPrototype%', @@ -1458,16 +1440,6 @@ export const permitted = { '@@toStringTag': 'string', }, - '%AsyncGeneratorPrototype%': { - // Properties of the AsyncGenerator Prototype Object - '[[Proto]]': '%AsyncIteratorPrototype%', - constructor: '%AsyncGenerator%', - next: fn, - return: fn, - throw: fn, - '@@toStringTag': 'string', - }, - // TODO: To be replaced with Promise.delegate // // The HandledPromise global variable shimmed by `@agoric/eventual-send/shim` diff --git a/packages/ses/src/tame-function-constructors.js b/packages/ses/src/tame-function-constructors.js index 4380ae4d4e..77dd7f83b5 100644 --- a/packages/ses/src/tame-function-constructors.js +++ b/packages/ses/src/tame-function-constructors.js @@ -121,16 +121,12 @@ export default function tameFunctionConstructors() { '%InertGeneratorFunction%', '(function*(){})', ); + // Hermes doesn't support async arrow functions, is this ok? repairFunction( 'AsyncFunction', '%InertAsyncFunction%', '(async function(){})', ); - repairFunction( - 'AsyncGeneratorFunction', - '%InertAsyncGeneratorFunction%', - '(async function*(){})', - ); return newIntrinsics; } diff --git a/packages/ses/test/harden.test.js b/packages/ses/test/harden.test.js index d4ba4297ca..b20d342948 100644 --- a/packages/ses/test/harden.test.js +++ b/packages/ses/test/harden.test.js @@ -25,9 +25,6 @@ test('Compartment anonymous intrinsics are frozen', t => { t.throws(() => c.evaluate('(async function() {}).constructor.a = 10;'), { instanceOf: TypeError, }); - t.throws(() => c.evaluate('(async function*() {}).constructor.a = 10;'), { - instanceOf: TypeError, - }); t.throws(() => c.evaluate('(function*() {}).constructor.a = 10;'), { instanceOf: TypeError, }); diff --git a/packages/ses/test/ses.test.js b/packages/ses/test/ses.test.js index dc654beaf8..c3637ebf75 100644 --- a/packages/ses/test/ses.test.js +++ b/packages/ses/test/ses.test.js @@ -6,7 +6,7 @@ lockdown(); /* eslint-disable no-proto, no-empty-function */ test('tamed constructors', t => { - t.plan(12); + t.plan(10); function F() {} t.throws(() => F.__proto__.constructor(''), { instanceOf: TypeError }); @@ -17,9 +17,6 @@ test('tamed constructors', t => { function* G() {} t.throws(() => G.__proto__.constructor(''), { instanceOf: TypeError }); - async function* AG() {} - t.throws(() => AG.__proto__.constructor(''), { instanceOf: TypeError }); - t.throws(() => Error.__proto__.constructor(''), { instanceOf: TypeError }); t.throws(() => Function.prototype.constructor(''), { instanceOf: TypeError }); @@ -42,10 +39,6 @@ test('tamed constructors', t => { t.throws(() => c.evaluate("function* G() {}; G.__proto__.constructor('')"), { instanceOf: TypeError, }); - t.throws( - () => c.evaluate("async function* AG() {}; AG.__proto__.constructor('')"), - { instanceOf: TypeError }, - ); }); test('frozen', t => { diff --git a/packages/ses/test/tame-function-unit.test.js b/packages/ses/test/tame-function-unit.test.js index 8445b6d1f5..23b919000c 100644 --- a/packages/ses/test/tame-function-unit.test.js +++ b/packages/ses/test/tame-function-unit.test.js @@ -48,19 +48,3 @@ test('GeneratorFunction.constructor', t => { } } }); - -test('AsyncGeneratorFunction.constructor', t => { - t.plan(1); - - try { - // eslint-disable-next-line no-eval - const proto = Object.getPrototypeOf((0, eval)('(async function* () {})')); - t.throws(() => proto.constructor(''), { instanceOf: TypeError }); - } catch (e) { - if (e instanceof SyntaxError) { - t.pass('not supported'); - } else { - throw e; - } - } -});