feat(ses): fix undefined AsyncGenerator prototype on Hermes#2220
Conversation
- define async iterable - define async iterator - redefine async iterator prototype Or keep the original and fallback to this if undefined
4308b5d to
0d2f230
Compare
|
TODO: fix failing test Uncaught exception in test/test-static-module-record.js
TypeError: Unexpected intrinsic intrinsics.%AsyncGeneratorPrototype%.__proto__ at %AsyncIteratorPrototype%
TypeError: Unexpected intrinsic intrinsics.%AsyncGeneratorPrototype%.__proto__ at %AsyncIteratorPrototype%
at visitPrototype (file:///Users/leo/Documents/GitHub/endo/packages/ses/src/permits-intrinsics.js:160:11)
at visitProperties (file:///Users/leo/Documents/GitHub/endo/packages/ses/src/permits-intrinsics.js:272:5)
at isAllowedPropertyValue (file:///Users/leo/Documents/GitHub/endo/packages/ses/src/permits-intrinsics.js:170:7)
at isAllowedProperty (file:///Users/leo/Documents/GitHub/endo/packages/ses/src/permits-intrinsics.js:233:14)
at visitProperties (file:///Users/leo/Documents/GitHub/endo/packages/ses/src/permits-intrinsics.js:283:26)
at whitelistIntrinsics (file:///Users/leo/Documents/GitHub/endo/packages/ses/src/permits-intrinsics.js:323:5)
at repairIntrinsics (file:///Users/leo/Documents/GitHub/endo/packages/ses/src/lockdown.js:348:3)
at globalThis.lockdown (file:///Users/leo/Documents/GitHub/endo/packages/ses/src/lockdown-shim.js:16:28)
at file:///Users/leo/Documents/GitHub/endo/packages/static-module-record/test/lockdown.js:3:1
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
✘ test/test-static-module-record.js exited with a non-zero exit code: 1caused by importing lockdown (required otherwise Compartment is undefined) after our redefinition of the throwing at endo/packages/ses/src/permits-intrinsics.js Line 160 in dc486dc unable to clean the new
the error is confusing because and we can't simply skip throwing in this case, otherwise subsequent related test breaks so perhaps redefining or a hermes-flavour shim that excludes |
| const AsyncGeneratorPrototype = AsyncGenerator.prototype; | ||
| const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype); | ||
| const AsyncGeneratorPrototype = AsyncGenerator.prototype; // undefined on Hermes | ||
| const AsyncIteratorPrototype = getPrototypeOf(asyncIterator); |
There was a problem hiding this comment.
Wouldn't it be sufficient to do
| const AsyncIteratorPrototype = getPrototypeOf(asyncIterator); | |
| const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorFunctionInstance()); |
There was a problem hiding this comment.
That's likely. Worth testing if it falls into the category of what Hermes supports, but looks equivalent to what we've tried here.
There was a problem hiding this comment.
the suggestion works too ^ but still causes the test to fail, i've looked into it here #2220 (comment) if any thoughts
|
I think I'm getting confused by what the prototype chains of iterators/generators are in Hermes, and how they differ from the spec. The permits list really is a representation of the intrinsics graph a standards compliant engine is supposed to setup. Any way to summarize the difference? |
makes sense ^ i misread the SES permit // unexpected %AsyncGeneratorPrototype%.__proto__
const AsyncGeneratorFunction = async function* () {}.constructor;
const AsyncGenerator = AsyncGeneratorFunction.prototype;
const AsyncGeneratorPrototype = AsyncGenerator.prototype;
const AsyncGeneratorPrototype__proto__ = AsyncGeneratorPrototype.__proto__
// expected [object Object] in engines supporting async generatorsthe Hermes async (arrow)fn/generator/iterator is bit confusing w vague/old features list, but w the testsuite confirmed async functions supported some errors in the ses shim are surpressed so raised this here also Metro errors on RN 71.15 when bundling so think should close this pr and chase up with babel then update here |
closes: #XXXX
refs: #1891
Description
Context: Running SES on React Native on Android (Hermes)
The AsyncGenerator prototype
const AsyncGeneratorPrototype = AsyncGenerator.prototypeisundefinedon Hermesbut we could get round this by redefining the
AsyncIteratorPrototypeinsteadwe could also keep the original definition, but fallingback to this one
This is throwing an error calling
addIntrinsics(getAnonymousIntrinsics())at
const AsyncIteratorPrototype= getPrototypeOf(AsyncGeneratorPrototype);// TypeError: Cannot convert undefined value to object, js engine: hermesFixed in a repro here: leotm/RN07117SES@cb44efd
(ignoring the redefinition of
AsyncFunctionInstancefor now, which is coming as separate pr part2)TODO: fix failing test
Alternatives considered
AsyncGeneratorPrototypeand relevant parts removedSecurity Considerations
Scaling Considerations
Documentation Considerations
Testing Considerations
Compatibility Considerations
Upgrade Considerations
*BREAKING*:in the commit message with migration instructions for any breaking change.NEWS.mdfor user-facing changes.