mozilla-spidermonkey / spidermonkey-embedding-examples

Documentation and examples for embedding the SpiderMonkey JavaScript / WebAssembly engine in their applications.
Other
197 stars 34 forks source link

Clarify the purpose of JSClass #66

Open gschwind opened 1 year ago

gschwind commented 1 year ago

The current document does not explain the usage of JSClass clearly. This patch try to give more detail about the purpose of JSClass, how to use it, and it's internal constraint.

Note that I did this documentation based on my own investigation within the current spidermonkey code, thus I maybe wrong.

jandem commented 1 year ago

I always thought it was a peculiarity of JSClass that the instances and prototype had to have the same one.

It used to be that builtin prototype objects in JS had the same type as the instance (e.g. Array.prototype is an array object in JS). The spec has been moving away from that and now generally prefers plain objects for prototypes.

JS_InitClass still uses the JSClass for both the proto and constructor name. It would probably make sense to change this API to default to using a plain object for the prototype.

jandem commented 1 year ago

I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1808171 to improve JS_InitClass.

jandem commented 1 year ago

I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1808171 to improve JS_InitClass.

These changes have now landed, so with the next ESR release we can improve this more.