Can't create xmlhttprequest from within JS component

RESOLVED FIXED

Status

()

RESOLVED FIXED
10 years ago
9 years ago

People

(Reporter: geekboy, Assigned: mrbkap)

Tracking

Trunk
x86
All
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 1 obsolete attachment)

(Reporter)

Description

10 years ago
I have a JS XPCOM component that wants to create an XMLHttpRequest:
var req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]  
             .createInstance(Components.interfaces.nsIXMLHttpRequest);  

It fails to do so with the assertion:

###!!! ASSERTION: Hmm, somebody did something evil?: '::JS_GetPrototype(cx, proto) && JS_GET_CLASS(cx, ::JS_GetPrototype(cx, proto)) == sObjectClass', file /Users/sstamm/Documents/src/firefox-csp3/dom/base/nsDOMClassInfo.cpp, line 4145
Created attachment 385525 [details] [diff] [review]
Proposed fix

Sid, want to try this?

The problem here is that components don't have windows, so we need to do this initialization somewhere else. Of course, when we *do* have windows, we end up needing sObjectClass when we're initializing the window, so we need to initialize sObjectClass in two places.
Assignee: nobody → mrbkap
Status: NEW → ASSIGNED
Attachment #385525 - Flags: superreview?(bzbarsky)
Attachment #385525 - Flags: review?(bzbarsky)
Comment on attachment 385525 [details] [diff] [review]
Proposed fix

Looks ok, but is this a regression from something?  If so, from what?
Attachment #385525 - Flags: superreview?(bzbarsky)
Attachment #385525 - Flags: superreview+
Attachment #385525 - Flags: review?(bzbarsky)
Attachment #385525 - Flags: review+
(Reporter)

Comment 3

10 years ago
Thanks for the quick patch!

With the patch applied, I am still getting the assertion failure:

###!!! ASSERTION: Hmm, somebody did something evil?: '::JS_GetPrototype(cx, proto) && JS_GET_CLASS(cx, ::JS_GetPrototype(cx, proto)) == sObjectClass', file /Users/sstamm/Documents/src/firefox-csp3/dom/base/nsDOMClassInfo.cpp, line 4133

Breakpoint 1, nsDOMClassInfo::PostCreatePrototype (this=0x76d7b0, cx=0x893c00, proto=0x36259e0) at /Users/sstamm/Documents/src/firefox-csp3/dom/base/nsDOMClassInfo.cpp:4136
4136	  if (mData->mHasClassInterface) {
(gdb) list
4131	  NS_ASSERTION(::JS_GetPrototype(cx, proto) &&
4132	               JS_GET_CLASS(cx, ::JS_GetPrototype(cx, proto)) == sObjectClass,
4133	               "Hmm, somebody did something evil?");
4134	 
4135	#ifdef DEBUG
4136	  if (mData->mHasClassInterface) {
4137	    nsCOMPtr<nsIInterfaceInfoManager>
4138	      iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
4139	
4140	    if (iim) {
(gdb) p sObjectClass
$1 = (const JSClass *) 0x0
(gdb) p proto
$2 = <unknown type>
(gdb) call js_DumpObject ($)
object 0x0

I'll double check with a clean clone of the tree on Monday when I'm back at my desk.  If it still fails, I'll work up a reduced test case, and paste details here.
Sid, did you build in dom/base AND layout/build?

Boris, this was a regression from bug 484764
Blocks: 484764
Duplicate of this bug: 500071
Thanks for taking care of this.
(Reporter)

Comment 7

9 years ago
Created attachment 385587 [details]
reduced test case for xpcshell

Here's a small test case to reproduce assertion failure.  I run it like this:
[~/$MOZ_SRC/]% ff-dbg/dist/bin/xpcshell bug500846-test.js

The assertion fails both before and after mrbkap's patch is applied (but at different locations).  

mrbkap: yes, I built both dom/base and layout/build.  I also attempted a clean build, and ended up with the same result.  Same assertion failure on the most recent mozilla-central rev d4bd5186451e:
dom/base/nsDOMClassInfo.cpp, line 4145 (before patch applied)
dom/base/nsDOMClassInfo.cpp, line 4133 (after patch applied)
(Reporter)

Updated

9 years ago
OS: Mac OS X → All
Created attachment 385869 [details] [diff] [review]
Proposed fix v2
Attachment #385525 - Attachment is obsolete: true
Attachment #385869 - Flags: superreview?(bzbarsky)
Attachment #385869 - Flags: review?(bzbarsky)
(Reporter)

Comment 9

9 years ago
Thanks, mrbkap.  Fix v2 works!
Attachment #385869 - Flags: superreview?(bzbarsky)
Attachment #385869 - Flags: superreview+
Attachment #385869 - Flags: review?(bzbarsky)
Attachment #385869 - Flags: review+
Comment on attachment 385869 [details] [diff] [review]
Proposed fix v2

Looks ok, though it looks like sObjectClass can go back to being file-static...
http://hg.mozilla.org/mozilla-central/rev/9e01b09a82a4 and I had to check http://hg.mozilla.org/mozilla-central/rev/608f66b040bd in because my reversion to file-static sObjectClass was mildly incomplete.
Status: ASSIGNED → RESOLVED
Last Resolved: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.