facebook / hermes

A JavaScript engine optimized for running React Native.
https://hermesengine.dev/
MIT License
9.68k stars 618 forks source link

Application crashes when trying to get info about some objects and functions during debugging #167

Open RedMickey opened 4 years ago

RedMickey commented 4 years ago

Hello, we are the development team of VS Code extension for debugging React Native apps (vscode-react-native). On debugging a Hermes application (React Native v0.61.5) in Google Chrome we tried to watch the contents of Map and Set Javascript objects and faced the problem of crashing of the debugged application. The error occurs when we are trying to extend __proto__ object content. This behavior is the same for Map and Set objects.

Is this an expected behavior?

For reference: the list of known issues with Hermes debugging for React Native Tools extension.

tmikov commented 4 years ago

Thank you for reporting this! We are excited to to help in any way possible, although, as I mentioned in the other report, there may be some delay during the holidays.

This error happens when the size getter is called before the constructor has initialized the object, which are first sight seems impossible. However construction is in fact a two-stage process - first we allocate the object and then we call the constructor. I guess it is theoretically possible that the debugger could be invoked between them. That would explain why the getter would observe an uninitialized state.

You said that you "are trying to extend __proto__ object content". What do you mean by that specifically?

RedMickey commented 4 years ago

@tmikov, I meant clicking on the dropdown icon on __proto__ view in Google Chrome Scope tab to watch detailed info about __proto__ object. This action triggers Google Chrome to send Chrome DevTools Protocol message to Hermes debugger to retrieve data about __proto__ object.

Screen Shot 2019-12-24 at 13 01 57

RedMickey commented 4 years ago

@tmikov, we've faced a new one problem similar to described earlier one. When we try to watch function info clicking the dropdown icon on its view in Google Chrome, the application crashes throwing the following error:

But not all functions cause such error, we are still able to watch info about some functions. For example we can watch the following functions' info: Screen Shot 2019-12-25 at 16 44 44

tmikov commented 4 years ago

One guess I have is the debugger is calling the size getter as part of inspecting the __proto__ object, which causes it to be invoked with an incorrect this. I think the problem here is not so much the behavior of the getter, but the exception propagating out of the debugger and into the app.

IIRC, we may have already fixed this. We will look into it and post an update.

willholen commented 4 years ago

I believe this was due to exceptions thrown while inspecting properties, which were not well handled in native. This has since been fixed and I'm unable to reproduce it as described.

RedMickey commented 3 years ago

Hello, we tested debugging of a React Native Hermes application (React Native v0.64.0 and Hermes engine v0.7.2) and could reproduce the problem with crashing of the debugged application. On debugging a Hermes application in Google Chrome we tried to inspect the contents of Map and Set Javascript objects as before. Currently the application being debugged doesn't show an error message, it shuts down without an error.

etatanova commented 2 years ago

Hello, we tested debugging of a new React Native Hermes application (React Native v0.66.0 and Hermes engine v0.9.0) and found out that this issue is no longer reproducible for Android applications. For iOS application we couldn't reproduce the issue in case of setTimeout function in the Global object. But we could reproduce the problem with crashing of the debugged iOS application when we’re trying to inspect the contents of Map and Set JavaScript objects as before. The application being debugged doesn’t show an error message, it just shuts down without an error.

Android app iOS app
android_hermes_map iOS_hermes_map
Android app iOS app
android_hermes_setTimeout iOS_hermes_setTimeout
EzioLi01 commented 2 years ago

Hey, I still can repro this issue on iOS app using Flipper, could you please have look on this?

mattbfb commented 2 years ago

Hello @EzioLi01, could you share some details on the specific steps (and builds) you're using? I can't seem to reproduce this locally using the descriptions above (e.g. inspecting __proto__ of a map on iOS

Screen Shot 2022-08-12 at 10 13 41 AM

).

If you can share the stack trace of the crash, that'd be very helpful as well. Thanks!

mattbfb commented 1 year ago

I cannot seem to reproduce this on current versions.

Starting with a new RN application created with npx react-native init, then adding the code in the examples above:

let timerId = setInterval(() => {
    let map = new Map();
    map.set(1, 'testValue');
    map.set('keyValue', 'test');

    let set = new Set([1, 2, 3, 4, 5]);
    console.log(map);
    console.log(set);
    console.log('hi');
}, 7000);

I can inspect both the __proto__ of maps, and setTimeout on Global:

inspect

Are there still steps that can reproduce the error?