Closed Bug 1808171 Opened 1 year ago Closed 1 year ago

Add a protoClass argument to JS_InitClass

Categories

(Core :: JavaScript Engine, task, P1)

task

Tracking

()

RESOLVED FIXED
110 Branch
Tracking Status
firefox110 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

(Blocks 1 open bug)

Details

Attachments

(10 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

The pull request on GitHub here made me realize we should change this API to not use the same JSClass* argument for the constructor name and the prototype's JSClass.

Callers can then pass nullptr for protoClass to get a PlainObject prototype, which is preferable nowadays.

This also lets us use plain objects for most debugger object prototypes, which simplifies the code a bit because we can then get rid of the isInstance methods.

This decouples the two uses of the passed JSClass, to make it easier to use
JS_InitClass when you don't want to use the same JSClass for the prototype
and the instance objects.

Later patches will change most of the callers to pass nullptr for protoClass.

Also adds documentation for JS_InitClass.

This matches newer language features and lets us simplify the code a bit.

Depends on D165796

The test doesn't use AddPropertyTester from JS.

Depends on D165802

The Debugger.prototype object only needs slots for the proto objects.

Depends on D165804

Hello Jandem

In your patch it seems that clasp parameter has no more usage instead of clasp->name to give a name to the property that will be created, thus is it sane to replace it by a plain char const * and rename it to some think more accurate ?

Best regards

(In reply to gschwind from comment #11)

In your patch it seems that clasp parameter has no more usage instead of clasp->name to give a name to the property that will be created, thus is it sane to replace it by a plain char const * and rename it to some think more accurate ?

It crossed my mind earlier today but I decided to leave the clasp argument alone. However, thinking about it again, it probably make sense to change this at the same time as it does make the API strictly more powerful.

Attachment #9310363 - Attachment description: Bug 1808171 part 1 - Add protoClass argument to JS_InitClass. r?sfink! → Bug 1808171 part 1 - Replace JS_InitClass's clasp argument with protoClass/name arguments. r?sfink!

I updated the patch stack to replace clasp with name. I think it's a nice improvement.

Pushed by jdemooij@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/7e8db9e52c91
part 1 - Replace JS_InitClass's clasp argument with protoClass/name arguments. r=sfink
https://hg.mozilla.org/integration/autoland/rev/c74c5cad3260
part 2 - Use PlainObject for Debugger.Source prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/02caeaadffad
part 3 - Use PlainObject for Debugger.Script prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/748479513ae9
part 4 - Use PlainObject for Debugger.Environment prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/870fbc779738
part 5 - Use PlainObject for Debugger.Frame prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/504d4117adb6
part 6 - Use PlainObject for Debugger.Object prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/62c2b515ca18
part 7 - Use PlainObject for Debugger.Memory prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/f2ef812c01e3
part 8 - Remove unnecessary JS_InitClass in testAddPropertyHook. r=sfink
https://hg.mozilla.org/integration/autoland/rev/4b1da3137488
part 9 - Use PlainObject for some prototypes in jsapi-tests. r=sfink
https://hg.mozilla.org/integration/autoland/rev/731a5b8451e8
part 10 - Add separate JSClass for Debugger.prototype. r=sfink

I added the xpcshell-test tasks on Try but apparently the same X1 task on Try did not run this test :/

Maybe a side-effect of ./mach try auto like bug 1714984. That's unfortunate.

Flags: needinfo?(jdemooij)
Pushed by jdemooij@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/15e1e69037e3
part 1 - Replace JS_InitClass's clasp argument with protoClass/name arguments. r=sfink
https://hg.mozilla.org/integration/autoland/rev/ed74b518c904
part 2 - Use PlainObject for Debugger.Source prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/c3106692cf15
part 3 - Use PlainObject for Debugger.Script prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/7fa4a642d8cc
part 4 - Use PlainObject for Debugger.Environment prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/157ca8f34f3d
part 5 - Use PlainObject for Debugger.Frame prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/62adab0ec9eb
part 6 - Use PlainObject for Debugger.Object prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/a729cd4de5c4
part 7 - Use PlainObject for Debugger.Memory prototype object. r=sfink
https://hg.mozilla.org/integration/autoland/rev/54fbbeaf8477
part 8 - Remove unnecessary JS_InitClass in testAddPropertyHook. r=sfink
https://hg.mozilla.org/integration/autoland/rev/888062ee7777
part 9 - Use PlainObject for some prototypes in jsapi-tests. r=sfink
https://hg.mozilla.org/integration/autoland/rev/7527c113748d
part 10 - Add separate JSClass for Debugger.prototype. r=sfink
Blocks: sm-runtime
Severity: -- → N/A
Priority: -- → P1
No longer regressions: 1875363
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: