Closed Bug 1473473 Opened 6 years ago Closed 5 years ago

Expose isClassConstructor in Debugger.Object

Categories

(DevTools :: Debugger, enhancement, P2)

enhancement

Tracking

(firefox72 fixed)

RESOLVED FIXED
Firefox 72
Tracking Status
firefox72 --- fixed

People

(Reporter: nchevobbe, Assigned: nchevobbe)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

It would be more helpful if it would return "Class", or if not possible, if we had a `isES6Class` or similar so we can expose such information to the end user (for now we represent classes as functions)
Priority: -- → P2
Component: General → Debugger
Blocks: dbg-server

:nchevobbe Do you have a samle snippet or good STR so I can see if a contributor wants to take this?

Flags: needinfo?(nchevobbe)

Steps to reproduce

  1. Open the console
  2. Evaluate the following:
class MyClass {};
MyClass;

Expected results

The result is class MyClass

Actual results

The result is function MyClass()


I remember looking into that at some point, and you have to go pretty deep in C++ code to see what's happening.
The underlying issue seems to be that classes are only syntax sugar on top of functions.

The attribute is describe in Debugger.Object.md#65-66

Flags: needinfo?(nchevobbe)

If someone wants to give it a try:

The property is retrieved from js/src/debugger/Object.cpp#290-298, using DebuggerObject::getClassName which is defined in js/src/debugger/Object.cpp#1573-1592

That calls GetObjectClassName defined in js/src/vm/JSObject-inl.h#613-620, which seems to use js/src/vm/JSObject.h#106.

If we want to do this, I think adding .isClassConstructor would be better than changing .class to return Class. From a runtime perspective, a constructor is just a function.

Implementation-wise, JSFunction objects already have an isClassConstructor() method, so the same way we do the other isX checks for function types should also work here, like https://searchfox.org/mozilla-central/rev/11d9c7b7fa82fdfb8ac2a8f0864e9d8d5fe2b926/js/src/debugger/Object.cpp#1544

(In reply to Logan Smyth [:loganfsmyth] from comment #4)

If we want to do this, I think adding .isClassConstructor would be better than changing .class to return Class. From a runtime perspective, a constructor is just a function.

Implementation-wise, JSFunction objects already have an isClassConstructor() method, so the same way we do the other isX checks for function types should also work here, like https://searchfox.org/mozilla-central/rev/11d9c7b7fa82fdfb8ac2a8f0864e9d8d5fe2b926/js/src/debugger/Object.cpp#1544

Awesome! I might give it a try then :)

Summary: Debugger.Object.class returns "Function" for ES6 classes → Expose isClassConstructor in Debugger.Object
Assignee: nobody → nchevobbe
Status: NEW → ASSIGNED
Attachment #9104904 - Attachment description: Bug 1473473 - Expose isClassConstructor in Debugger.Object. r=lfsmyth. → Bug 1473473 - Expose isClassConstructor in Debugger.Object. r=loganfsmyth.
Pushed by nchevobbe@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/68ab3d76c355 Expose isClassConstructor in Debugger.Object. r=loganfsmyth.
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 72
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: