Ignore:
Timestamp:
Jul 12, 2006, 2:55:55 AM (19 years ago)
Author:
mjs
Message:

4eviewed by Geoff.


  • add handling of hasInstance callback for API objects
  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::implementsHasInstance): Check if callback is present. (KJS::JSCallbackObject::hasInstance): Invoke appropriate callback.
  • API/JSCallbackObject.h:
  • API/JSClassRef.cpp:
  • API/JSObjectRef.h:
  • API/testapi.c: (MyObject_hasInstance): Test case; should match what construct would do.
  • API/testapi.js:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSObjectRef.h

    r15376 r15384  
    194194/*!
    195195@typedef JSObjectCallAsConstructorCallback
    196 @abstract The callback invoked when an object is used as a constructor in a 'new' statement.
     196@abstract The callback invoked when an object is used as a constructor in a 'new' expression.
    197197@param context The current execution context.
    198198@param constructor A JSObject that is the constructor being called.
     
    207207If your callback were invoked by the JavaScript expression 'new myConstructorFunction()', constructor would be set to myConstructorFunction.
    208208
    209 If this callback is NULL, using your object as a constructor in a 'new' statement will throw an exception.
     209If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.
    210210*/
    211211typedef JSObjectRef
    212212(*JSObjectCallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[], JSValueRef* exception);
     213
     214/*!
     215@typedef JSObjectHasInstanceCallback
     216@abstract The callback invoked when an object is used in an 'instanceof' expression.
     217@param context The current execution context.
     218@param constructor The JSObject receiving the hasInstance request
     219@param possibleInstance The JSValue being tested to determine if it is an instance of constructor.
     220@param exception A pointer to a JSValueRef in which to return an exception, if any.
     221@result true if possibleInstance is an instance of constructor, otherwise false
     222
     223@discussion If you named your function HasInstance, you would declare it like this:
     224
     225bool HasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
     226
     227If your callback were invoked by the JavaScript expression 'someValue instanceof myObject', constructor would be set to myObject and possibleInstance would be set to someValue..
     228
     229If this callback is NULL, using your object in an 'instanceof' will always return false.
     230
     231Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.
     232*/
     233typedef bool
     234(*JSObjectHasInstanceCallback)  (JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
    213235
    214236/*!
     
    241263@field getPropertyList The callback invoked when adding an object's properties to a property list.
    242264@field callAsFunction The callback invoked when an object is called as a function.
    243 @field callAsConstructor The callback invoked when an object is used as a constructor in a 'new' statement.
     265@field hasInstance The callback invoked when an object is used in an 'instanceof' expression.
     266@field callAsConstructor The callback invoked when an object is used as a constructor in a 'new' expression.
    244267@field convertToType The callback invoked when converting an object to a particular JavaScript type.
    245268*/
     
    255278    JSObjectCallAsFunctionCallback      callAsFunction;
    256279    JSObjectCallAsConstructorCallback   callAsConstructor;
     280    JSObjectHasInstanceCallback         hasInstance;
    257281    JSObjectConvertToTypeCallback       convertToType;
    258282} JSObjectCallbacks;
     
    344368@abstract Convenience method for creating a JavaScript constructor with a given callback as its implementation.
    345369@param context The execution context to use.
    346 @param callAsConstructor The JSObjectCallAsConstructorCallback to invoke when the constructor is used in a 'new' statement.
     370@param callAsConstructor The JSObjectCallAsConstructorCallback to invoke when the constructor is used in a 'new' expression.
    347371@result A JSObject that is a constructor. The object's prototype will be the default object prototype.
    348372*/
Note: See TracChangeset for help on using the changeset viewer.