Closed Bug 526491 Opened 15 years ago Closed 1 year ago

Define .constructor on DOM objects without needing a resolve hook

Categories

(Core :: DOM: Core & HTML, defect)

defect

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: peterv, Assigned: peterv)

Details

Attachments

(1 file, 1 obsolete file)

Attached patch v1 (obsolete) — Splinter Review
Still need to do something about Location, it doesn't have ALLOW_PROP_MODS_TO_PROTOTYPE and so I can't define a constructor property on its prototype. I might be able to just add a constructor attribute on nsIDOMLocation.
Blake, we can't trick hasOwnProperty using JSPROP_PERMANENT | JSPROP_SHARED because the wrapper and the prototype have different classes :-/.
So, I don't see an easy way around this... Either we have to bite the bullet and eagerly define .constructor on all nodes or have a resolve hook (they exist explicitly to avoid eagerly defining properties, after all).

Brendan, have I missed something?
Use a resolve hook if you must. This is all about location, a singleton, so paying up front (once per window/frame) whether in a prototype object or in the direct location object could hurt Tp, I take it. Has anyone measured?

/be
(In reply to comment #3)
> Use a resolve hook if you must. This is all about location, a singleton, so
> paying up front (once per window/frame) whether in a prototype object or in the
> direct location object could hurt Tp, I take it. Has anyone measured?

brendan, the problem is that this isn't just about location. We're talking about the resolve hook on all nodes (currently nsNodeSH::NewResolve). The property in question is .constructor, it's a property that's (probably) rarely used, but it isn't free to define and it has to be hasOwnProperty to the nodes.
Who ever said constructor has to be "own" for all nodes? Don't tell me some HTML5 or WebAPI crack-spec!

js> d = new Date
(new Date(1258478166310))
js> d.constructor
function Date() {[native code]}
js> d.hasOwnProperty('constructor')
false

Note that constructor is not "own", it is delegated to constructor.prototype. Do that and prosper.

/be
Attached patch v2Splinter Review
This just puts .constructor on the prototype. I also solved the problem for Location by allowing PostCreatePrototype to add a constructor property to a XPCWrappedNativeProto.
Attachment #410243 - Attachment is obsolete: true
Attachment #414310 - Flags: superreview?(mrbkap)
Attachment #414310 - Flags: review?(jst)
Attachment #414310 - Flags: superreview?(mrbkap)
Attachment #414310 - Flags: review?(jst)
Attachment #414310 - Flags: review-
Comment on attachment 414310 [details] [diff] [review]
v2

Actually, there's still some mochitest failures with this.
Component: DOM → DOM: Core & HTML
Severity: normal → S3

I think our new bindings already do this.

Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: