Changeset 15482 in webkit for trunk/JavaScriptCore/kjs/object.cpp


Ignore:
Timestamp:
Jul 17, 2006, 1:20:28 AM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


  • Changed JSObjectMakeConstructor to JSObjectMakeConstructorWithCallback, to match JSObjectMakeFunctionWithCallback.


  • Added prototype parameter, so the generated constructor automatically works with hasInstance / instanceof


  • Moved hasInstance implementation from InternalFunctionImp to JSObject so that subclasses can inherit it without inheriting function-related baggage. More refactoring here would be good, but this seems like a good short-term solution.

(KJS::JSCallbackFunction::implementsHasInstance): override and return false,
because callback functions aren't constructors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/object.cpp

    r15468 r15482  
    445445}
    446446
    447 bool JSObject::hasInstance(ExecState *, JSValue *)
    448 {
    449   assert(false);
    450   return false;
     447bool JSObject::hasInstance(ExecState* exec, JSValue* value)
     448{
     449    JSValue* proto = get(exec, prototypePropertyName);
     450    if (!proto->isObject()) {
     451        throwError(exec, TypeError, "intanceof called on an object with an invalid prototype property.");
     452        return false;
     453    }
     454   
     455    if (!value->isObject())
     456        return false;
     457   
     458    JSObject* o = static_cast<JSObject*>(value);
     459    while ((o = o->prototype()->getObject())) {
     460        if (o == proto)
     461            return true;
     462    }
     463    return false;
    451464}
    452465
Note: See TracChangeset for help on using the changeset viewer.