Ignore:
Timestamp:
Mar 22, 2009, 9:31:39 PM (16 years ago)
Author:
[email protected]
Message:

Fix instanceof implementation to handle API object overriding hasInstance

Reviewed by Cameron Zwarich.

We can only take the fast paths for instanceof if the object doesn't override
hasInstance, so we have to check for that.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/jit/JITStubs.cpp

    r41277 r41904  
    752752    }
    753753
    754     if (!asObject(baseVal)->structure()->typeInfo().implementsHasInstance())
     754    JSObject* baseObj = asObject(baseVal);
     755    TypeInfo typeInfo = baseObj->structure()->typeInfo();
     756    if (!typeInfo.implementsHasInstance())
    755757        return JSValuePtr::encode(jsBoolean(false));
    756758
    757     if (!proto.isObject()) {
    758         throwError(callFrame, TypeError, "instanceof called on an object with an invalid prototype property.");
    759         VM_THROW_EXCEPTION();
    760     }
    761        
    762     if (!value.isObject())
    763         return JSValuePtr::encode(jsBoolean(false));
    764 
    765     JSValuePtr result = jsBoolean(asObject(baseVal)->hasInstance(callFrame, value, proto));
     759    if (!typeInfo.overridesHasInstance()) {
     760        if (!proto.isObject()) {
     761            throwError(callFrame, TypeError, "instanceof called on an object with an invalid prototype property.");
     762            VM_THROW_EXCEPTION();
     763        }
     764
     765        if (!value.isObject())
     766            return JSValuePtr::encode(jsBoolean(false));
     767    }
     768
     769    JSValuePtr result = jsBoolean(baseObj->hasInstance(callFrame, value, proto));
    766770    CHECK_FOR_EXCEPTION_AT_END();
    767771
Note: See TracChangeset for help on using the changeset viewer.