Skip to content

[ddc] Add an API for the debugger to easily identify native JS objects and errors #51583

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

Closed
annagrin opened this issue Mar 1, 2023 · 7 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. dev-compiler-eval dev-compiler-sdk web-js-interop Issues that impact all js interop

Comments

@annagrin
Copy link
Contributor

annagrin commented Mar 1, 2023

The debugger (dwds) needs to

  • find if the type of the variable is not related to dart so the variable does not need to be displayed in the UI

    • note that we do want do display certain JS types such as JS arrays, maps, sets, bools, ints, etc.
  • find if the type of the variable corresponds to a JS error and needs to be mapped to dart stack trace.

Currently we rely on type names for identifying those, which was proven to be fragile in the past.

See the latest example in dart-lang/webdev#1821

Suggestion:

  • define ddc runtime API, ie isNativeJavaScriptError(object) and isNativeJavaScriptObject(object).
  • we can evaluate expressions like require('dart_sdk').dart.isNativeJavaScriptError(object) to use them in the debugger.
@annagrin annagrin added dev-compiler-sdk dev-compiler-eval area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. labels Mar 1, 2023
@nshahan
Copy link
Contributor

nshahan commented Mar 1, 2023

@srujzs
We should add this API to the DDC runtime and have tests that break when we make changes to the JS interop representations.

@nshahan nshahan added the web-js-interop Issues that impact all js interop label Mar 1, 2023
@srujzs
Copy link
Contributor

srujzs commented Mar 2, 2023

Would we still need this API if we start exposing JS types e.g. JSMap, JSObject, etc.? I think in the past this was fragile because we were relying on internal representations (Interceptors), and not external representations.

If I'm understanding this correctly, we'd like to tell if this is not a Dart type and also not one of several JS types. We also want to tell if a variable is a JS Error type.

I think this is doable with a combination of is checks and instanceof with the JS types.

@annagrin
Copy link
Contributor Author

annagrin commented Mar 2, 2023

@srujzs I think using JS types and instanceOf is more stable, as long as we never need to detect an internal type. Will all the current errors be direct instances of Error, or is there going to be a class hierarchy similar to what we have now?

@annagrin
Copy link
Contributor Author

annagrin commented Mar 6, 2023

@srujzs what needs to be done here to expose JS types? Could adding a ddc runtime API be an easier (even if temporary) solution for now so we prevent dwds from breaking on such changes?

@srujzs
Copy link
Contributor

srujzs commented Mar 7, 2023

Will all the current errors be direct instances of Error, or is there going to be a class hierarchy similar to what we have now?

Can you explain a bit more what you're looking for here? Like subtypes of Error? I'm not sure if we're going to introduce a JS type for Error (although we certainly could), so I'd like to make sure I understand all the use cases here.

what needs to be done here to expose JS types? Could adding a ddc runtime API be an easier (even if temporary) solution for now so we prevent dwds from breaking on such changes?

We have some JS types exposed via dart:js_interop, but they're very much in flux for the next few months, so I think adding an API to DDC is certainly reasonable in the meantime. I remember coming across this in the past too, so it's worth it to not break dwds.

@sigmundch
Copy link
Member

FYI - I just came across this issue while investigating #52572. My current change to address that other issue is to remove the coupling between NativeError and Error in the DDC layer, doing this may affect some of the behavior in dwds because we are asking queries about JavaScript using the internal Dart types.

Exposing helpers in the DDC runtime seems like it may be the most robust way to improve this. Another option here is to directly identify native objects within JavaScript, but I get the impression it will not be as robust, since we do sometimes map native types to Dart types.

@annagrin
Copy link
Contributor Author

This is superseded by work in dart-lang/webdev#1949

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. dev-compiler-eval dev-compiler-sdk web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

4 participants