Bug 25205 - XMLHttpRequest instance is not an instanceof XMLHttpRequest
Summary: XMLHttpRequest instance is not an instanceof XMLHttpRequest
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Brent Fulgham
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-15 01:03 PDT by Michael A. Puls II
Modified: 2009-07-21 18:00 PDT (History)
6 users (show)

See Also:


Attachments
Fix for "instanceof XMLHttpRequest" (3.80 KB, patch)
2009-07-07 02:31 PDT, Yuzo Fujishima
no flags Details | Formatted Diff | Diff
This also fixes for XSTLProcessor, Audio, etc. (15.51 KB, patch)
2009-07-08 00:29 PDT, Yuzo Fujishima
darin: review-
Details | Formatted Diff | Diff
DOMConstructorObject approach. (20.05 KB, patch)
2009-07-08 19:29 PDT, Yuzo Fujishima
darin: review-
Details | Formatted Diff | Diff
Removed virtual destructor declaration of DOMConstructorObject. (19.98 KB, patch)
2009-07-09 18:33 PDT, Yuzo Fujishima
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael A. Puls II 2009-04-15 01:03:13 PDT
WebKit r42344

The following alerts true in FF, Opera and IE8, but alerts false in Safari.

javascript:alert((new XMLHttpRequest()) instanceof XMLHttpRequest)%3B

This causes (ProgressEvent_instance.target instanceof XMLHttpRequest) to evaluate to false in the load listener function for XHR.
Comment 1 Alexey Proskuryakov 2009-04-15 02:07:59 PDT
Same problem with e.g. XSLTProcessor.
Comment 2 Sam Weinig 2009-04-15 12:13:22 PDT
Interestingly, javascript:alert((new XMLHttpRequest).__proto__ == XMLHttpRequest.prototype) returns true.
Comment 3 Sam Weinig 2009-04-15 12:13:33 PDT
Is this a regression?
Comment 4 Alexey Proskuryakov 2009-04-15 12:21:03 PDT
(In reply to comment #3)
> Is this a regression?

Not from Safari 3.2.1.
Comment 5 Yuzo Fujishima 2009-07-07 02:31:57 PDT
Created attachment 32370 [details]
Fix for "instanceof XMLHttpRequest"

Hi,

Can you review the attached patch?
It attempts to fix this bug by setting JSC::ImplementsHasInstance flag for JSXMLHttpRequestConstructor.

Yuzo
Comment 6 Yuzo Fujishima 2009-07-07 03:12:29 PDT
If the proposed patch is the right fix, the same should be applicable to:

WebCore/bindings/js/JSAudioConstructor.cpp 
WebCore/bindings/js/JSImageConstructor.cpp 
WebCore/bindings/js/JSMessageChannelConstructor.cpp 
WebCore/bindings/js/JSOptionConstructor.cpp 
WebCore/bindings/js/JSWebKitCSSMatrixConstructor.cpp 
WebCore/bindings/js/JSWebKitPointConstructor.cpp 
WebCore/bindings/js/JSWorkerConstructor.cpp 
# WebCore/bindings/js/JSXMLHttpRequestConstructor.cpp 
WebCore/bindings/js/JSXSLTProcessorConstructor.cpp 

In that case, we should perhaps add:

static PassRefPtr<Structure> createStructureForConstructor(JSValue prototype);

to JavaScriptCore/runtime/JSObject.h
and call the method from the above classes.

Yuzo
Comment 7 Yuzo Fujishima 2009-07-08 00:29:08 PDT
Created attachment 32434 [details]
This also fixes for XSTLProcessor, Audio, etc.

Can anyone review this, please?

I've updated the patch to fix for XSLTProcessor, Audio, etc.

Yuzo
Comment 8 Darin Adler 2009-07-08 09:54:11 PDT
Comment on attachment 32434 [details]
This also fixes for XSTLProcessor, Audio, etc.

This seems OK, but not great. The design here is supposed to be that derived classes override createStructure if the base class version doesn't work right. Leaving behind a createStructure function that does the wrong thing and relying on the callers to call the correct one seems unnecessarily fragile to me. To share code, we could create a new base class, derived from DOMObject, and have all the constructor classes derive from this, and it would override createStructure to work properly.

Would you be willing to try that approach?

review- for now, but I'm open to landing this version if you don't like my suggestion and can convince me.
Comment 9 Yuzo Fujishima 2009-07-08 19:29:54 PDT
Created attachment 32499 [details]
DOMConstructorObject approach.

Thank you for your review.

I agree.

I've revised the patch such that all the classes in question derive from DOMConstructorObject, which in turn derives from DOMObject.

Can you take another look?

Yuzo
Comment 10 Darin Adler 2009-07-09 08:18:21 PDT
Comment on attachment 32499 [details]
DOMConstructorObject approach.

> +#ifndef NDEBUG
> +        virtual ~DOMConstructorObject();
> +#endif

What's the idea here? I don't see any definition of this destructor, so it seems like the change won't link. Have you tested yet?

Otherwise, everything looks great!
Comment 11 Yuzo Fujishima 2009-07-09 18:33:38 PDT
Created attachment 32547 [details]
Removed virtual destructor declaration of DOMConstructorObject.

Hi,

Thank you for reviewing this.

I've removed the virtual destructor declaration of DOMConstructorObject
and confirmed that the layout test succeeds for both Debug and Release.

Yuzo
Comment 12 Brent Fulgham 2009-07-15 12:55:30 PDT
Assign for landing.
Comment 13 Brent Fulgham 2009-07-15 13:09:14 PDT
Landed in http://trac.webkit.org/changeset/45938.
Comment 14 Eric Seidel (no email) 2009-07-21 15:28:55 PDT
This doesn't fix all constructors though.  This diff is still missing from the change:

@@ -2027,10 +2042,10 @@ sub constructorFor
     my $canConstruct = shift;
 
 my $implContent = << "EOF";
-class ${className}Constructor : public DOMObject {
+class ${className}Constructor : public DOMConstructorObject {
 public:
     ${className}Constructor(ExecState* exec, JSDOMGlobalObject* globalObject)
-        : DOMObject(${className}Constructor::createStructure(globalObject->objectPrototype()))
+        : DOMConstructorObject(${className}Constructor::createStructure(globalObject->objectPrototype()), globalObject)
     {
         putDirect(exec->propertyNames().prototype, ${protoClassName}::self(exec, globalObject), None);
     }

I guess I'll find a way to write a test and file a new bug for that change.
Comment 15 Eric Seidel (no email) 2009-07-21 15:29:55 PDT
Hum... I'm surprised Darin let you get away w/o a test case!
Comment 16 Yuzo Fujishima 2009-07-21 17:59:14 PDT
My patch contains:
LayoutTests/fast/js/instanceof-operator.html b/LayoutTests/fast/js/instanceof-operator.html

Do you mean a different kind of test?
Comment 17 Eric Seidel (no email) 2009-07-21 18:00:50 PDT
Sorry. I just missed them in the diff http://trac.webkit.org/changeset/45938.  I never remember to look for the special green squares.