Closed Bug 370098 Opened 13 years ago Closed 13 years ago

Some constructors raise a "XXX is not a function" exception when called (DOMParser, XMLSerializer, XMLHttpRequest, XPathEvaluator, XSLTProcessor)

Categories

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

x86
Windows XP
defect
Not set

Tracking

()

VERIFIED FIXED
mozilla1.9alpha5

People

(Reporter: asqueella, Assigned: peterv)

References

Details

(Keywords: testcase)

Attachments

(2 files, 4 obsolete files)

Attached file testcase (obsolete) —
> typeof DOMParser 
function
> DOMParser()
TypeError on line 1: DOMParser is not a function

At least the following constructors are affected: DOMParser, XMLSerializer, XMLHttpRequest, XPathEvaluator, XSLTProcessor. Might be worth checking constructors registered via "JavaScript global constructor" category.

Calling these constructors definitely shouldn't say they are not functions, since they are. shaver says they should either throw or just create an object as when called as constructors (this is what some of native JS objects do).
Attached patch v1 (obsolete) — Splinter Review
This makes calling them as functions work. Note that all DOM prototype objects are of type function, even when they're not callable/constructable. We could easily change that, but not sure what the side-effects will be or whether we care.
Assignee: general → peterv
Status: NEW → ASSIGNED
Attached patch v1.1 (obsolete) — Splinter Review
This one makes only constructable DOM classes return "Function" for typeof, others return "Object".
Brendan or Blake: any idea what |typeof Element| should return if you can't really call |Element()| or |new Element()|?
(In reply to comment #3)
> Brendan or Blake: any idea what |typeof Element| should return if you can't
> really call |Element()| or |new Element()|?

"object"

If you can call Element(), then ECMA-262 says "function", but real-world browsers do not agree. We should err on the side of reality here and go with "object" unless IE and another browser or two say "function".

/be
Attached patch v1.1 (obsolete) — Splinter Review
Attachment #254799 - Attachment is obsolete: true
Attachment #255928 - Attachment is obsolete: true
Attachment #264044 - Flags: superreview?(jst)
Attachment #264044 - Flags: review?(jst)
Comment on attachment 264044 [details] [diff] [review]
v1.1

 private:
+  nsresult GetNameStruct(const nsGlobalNameStruct **aNameStruct)

Looks like this, and the other method with the same signature, always return either NS_OK an a non-null aNameStruct, or NS_ERROR_UNEXPECTED on failure. Any reason not to make this method return a const nsGlobalNameStruct* and make the callers throw when necessary?

r+sr=jst with that considered.
Attachment #264044 - Flags: superreview?(jst)
Attachment #264044 - Flags: superreview+
Attachment #264044 - Flags: review?(jst)
Attachment #264044 - Flags: review+
(In reply to comment #6)
> Looks like this, and the other method with the same signature, always return
> either NS_OK an a non-null aNameStruct, or NS_ERROR_UNEXPECTED on failure. Any
> reason not to make this method return a const nsGlobalNameStruct* and make the
> callers throw when necessary?

Did that for the first, but not the second function, because that one sometimes returns NS_OK for a null aNameStruct (looking up the name worked but didn't return anything, so shouldn't throw).
Attachment #264044 - Attachment is obsolete: true
Attached patch MochitestSplinter Review
Attachment #254757 - Attachment is obsolete: true
Attachment #264235 - Flags: review?(jst)
Flags: in-testsuite?
Target Milestone: --- → mozilla1.9alpha5
Comment on attachment 264235 [details] [diff] [review]
Mochitest

r+sr=jst
Attachment #264235 - Flags: superreview+
Attachment #264235 - Flags: review?(jst)
Attachment #264235 - Flags: review+
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
The mochitest was checked in on 2007-05-25 09:06 and is passing here and on the tinderbox.
Status: RESOLVED → VERIFIED
Flags: in-testsuite? → in-testsuite+
Could this have caused bug 400366? I can't seem to find any relevant bugs in the regression window.

javascript:typeof Prototype

.. results in "object"
Yes, probably.
Depends on: 400366
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.