Skip to content

Commit

Permalink
feat(ses): strip async generators for Hermes
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
leotm committed May 28, 2024
1 parent bb6e908 commit 0421ca7
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 78 deletions.
18 changes: 0 additions & 18 deletions packages/ses/src/get-anonymous-intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
28 changes: 0 additions & 28 deletions packages/ses/src/permits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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%',
Expand All @@ -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`
Expand Down
6 changes: 1 addition & 5 deletions packages/ses/src/tame-function-constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 0 additions & 3 deletions packages/ses/test/harden.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
9 changes: 1 addition & 8 deletions packages/ses/test/ses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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 });

Expand All @@ -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 => {
Expand Down
16 changes: 0 additions & 16 deletions packages/ses/test/tame-function-unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
});

0 comments on commit 0421ca7

Please sign in to comment.