Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial async generator support present in Hermes isn't spec compliant #1380

Closed
1 of 2 tasks
leotm opened this issue Apr 25, 2024 · 2 comments
Closed
1 of 2 tasks

Partial async generator support present in Hermes isn't spec compliant #1380

leotm opened this issue Apr 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@leotm
Copy link

leotm commented Apr 25, 2024

Bug Description

  • I have run gradle clean and confirmed this bug does not occur with JSC
  • The issue is reproducible with the latest version of React Native.

Hermes git revision (if applicable): hermes-2023-03-07-RNv0.71.4-ee25883ea34374f687883a641c8101ac0d292fc6
React Native version: 71.17
OS: Android (running on macOS)
Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): arm64-v8a

Steps To Reproduce

Attempt to access async iterator proto

code example:

async function* AsyncGeneratorFunctionInstance() {}
const AsyncGeneratorFunction = Object.getPrototypeOf(
  AsyncGeneratorFunctionInstance,
).constructor
const AsyncGenerator = AsyncGeneratorFunction.prototype;

const asyncIterable = {
  async *[Symbol.asyncIterator]() {},
};
var results = [
  typeof asyncIterable[Symbol.asyncIterator].prototype.__proto__ === 'object', // it's an object even in Hermes, but looks a different shape
  typeof AsyncGenerator.prototype, // undefined on hermes
  asyncIterable[Symbol.asyncIterator].prototype.__proto__ === AsyncGenerator.prototype, // true in other engines
  asyncIterable[Symbol.asyncIterator].prototype.__proto__.__proto__ // null in Hermes, object with an iterator fn in other engines
];

// Node 18.18.2
// console.log(Object.getOwnPropertyDescriptors(asyncIterable[Symbol.asyncIterator].prototype.__proto__.__proto__))
// {
//   [Symbol(Symbol.asyncIterator)]: {
//     value: [Function: [Symbol.asyncIterator]],
//     writable: true,
//     enumerable: false,
//     configurable: true
//   }
// }

throw JSON.stringify(results);

The Expected Behavior

Other engines: [true,"object",true,{}]
Hermes: [true,"undefined",false,null]

@leotm leotm added the bug Something isn't working label Apr 25, 2024
@tmikov
Copy link
Contributor

tmikov commented Apr 25, 2024

Sorry, Hermes has no async iterator support at the moment (though we will add it to Static Hermes). I think you are essentially testing a Babel transformation.

@tmikov tmikov closed this as completed Apr 25, 2024
@leotm
Copy link
Author

leotm commented Apr 29, 2024

thanks for clarifying ^ and great news it will be in Static Hermes 🎉

my mistaken assumption was node_modules/react-native/Libraries/Core/InitializeCore.js is running Babel-free

for anyone else to run in the React Native environment w/o Babel you could

new Function('{var}', String.raw`
  // my code (should be same result as Hermes CLI/REPL)
`)({var: 1});

or the usual way

// babel.config.js
module.exports = {
  ignore: [/myFile\.cjs/],
  presets: ['module:metro-react-native-babel-preset'],
};

or outside the React Native environment, directly via the Hermes CLI or building the static_h branch for latest

otherwise yes in this example we can see inspecting the bundle Babel transforms with few helpers

  • @babel/runtime/helpers/AsyncGenerator
  • @babel/runtime/helpers/OverloadYield
  • @babel/runtime/helpers/wrapAsyncGenerator

coming from various transform plugins in the preset

Babel REPL example with preset: here

@leotm leotm changed the title Partial async generator support persent in Hermes isn't spec compliant Partial async generator support present in Hermes isn't spec compliant May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants