Changeset 15482 in webkit for trunk/JavaScriptCore/API
- Timestamp:
- Jul 17, 2006, 1:20:28 AM (19 years ago)
- Location:
- trunk/JavaScriptCore/API
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSCallbackConstructor.cpp
r15469 r15482 38 38 } 39 39 40 bool JSCallbackConstructor::implementsHasInstance() const 41 { 42 return true; 43 } 44 40 45 bool JSCallbackConstructor::implementsConstruct() const 41 46 { -
trunk/JavaScriptCore/API/JSCallbackConstructor.h
r15469 r15482 29 29 30 30 #include "JSObjectRef.h" 31 #include "object.h"31 #include <kjs/object.h> 32 32 33 33 namespace KJS { 34 34 35 35 class JSCallbackConstructor : public JSObject 36 36 { … … 38 38 JSCallbackConstructor(ExecState* exec, JSObjectCallAsConstructorCallback callback); 39 39 40 virtual bool implementsHasInstance() const; 41 40 42 virtual bool implementsConstruct() const; 41 43 virtual JSObject* construct(ExecState*, const List &args); 42 44 43 45 virtual const ClassInfo *classInfo() const { return &info; } 44 46 static const ClassInfo info; -
trunk/JavaScriptCore/API/JSCallbackFunction.cpp
r15469 r15482 40 40 } 41 41 42 // InternalFunctionImp mish-mashes constructor and function behavior -- we should 43 // refactor the code so this override isn't necessary 44 bool JSCallbackFunction::implementsHasInstance() const { 45 return false; 46 } 47 42 48 JSValue* JSCallbackFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List &args) 43 49 { -
trunk/JavaScriptCore/API/JSCallbackFunction.h
r15469 r15482 39 39 JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name); 40 40 41 virtual bool implementsHasInstance() const; 41 42 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List &args); 42 43 -
trunk/JavaScriptCore/API/JSNode.c
r15481 r15482 178 178 } 179 179 180 staticJSObjectRef JSNode_prototype(JSContextRef context)180 JSObjectRef JSNode_prototype(JSContextRef context) 181 181 { 182 182 static JSObjectRef prototype; -
trunk/JavaScriptCore/API/JSNode.h
r15464 r15482 32 32 33 33 extern JSObjectRef JSNode_new(JSContextRef context, Node* node); 34 extern JSObjectRef JSNode_prototype(JSContextRef context); 34 35 extern JSObjectRef JSNode_construct(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); 35 36 -
trunk/JavaScriptCore/API/JSObjectRef.cpp
r15481 r15482 85 85 } 86 86 87 JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSObjectCallAsConstructorCallback callAsConstructor) 88 { 89 JSLock lock; 90 ExecState* exec = toJS(ctx); 91 return toRef(new JSCallbackConstructor(exec, callAsConstructor)); 87 JSObjectRef JSObjectMakeConstructorWithCallback(JSContextRef ctx, JSValueRef prototype, JSObjectCallAsConstructorCallback callAsConstructor) 88 { 89 JSLock lock; 90 ExecState* exec = toJS(ctx); 91 JSValue* jsPrototype = toJS(prototype); 92 93 if (!jsPrototype) 94 jsPrototype = exec->dynamicInterpreter()->builtinObjectPrototype(); 95 96 JSObject* constructor = new JSCallbackConstructor(exec, callAsConstructor); 97 constructor->put(exec, prototypePropertyName, jsPrototype, DontEnum|DontDelete|ReadOnly); 98 return toRef(constructor); 92 99 } 93 100 -
trunk/JavaScriptCore/API/JSObjectRef.h
r15481 r15482 389 389 @param name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function. 390 390 @param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called. 391 @result A JSObject that is a n anonymousfunction. The object's prototype will be the default function prototype.391 @result A JSObject that is a function. The object's prototype will be the default function prototype. 392 392 */ 393 393 JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction); 394 394 395 /*! 395 396 @function 396 397 @abstract Convenience method for creating a JavaScript constructor with a given callback as its implementation. 397 398 @param ctx The execution context to use. 399 @param prototype A JSValue to use as the constructor's .prototype property. This should be the same value your constructor will set as the prototype of the objects it constructs. 398 400 @param callAsConstructor The JSObjectCallAsConstructorCallback to invoke when the constructor is used in a 'new' expression. 399 401 @result A JSObject that is a constructor. The object's prototype will be the default object prototype. 400 402 */ 401 JSObjectRef JSObjectMakeConstructor (JSContextRef ctx, JSObjectCallAsConstructorCallback callAsConstructor);403 JSObjectRef JSObjectMakeConstructorWithCallback(JSContextRef ctx, JSValueRef prototype, JSObjectCallAsConstructorCallback callAsConstructor); 402 404 403 405 /*! -
trunk/JavaScriptCore/API/minidom.c
r15481 r15482 45 45 46 46 JSStringRef node = JSStringCreateWithUTF8CString("Node"); 47 JSObjectSetProperty(context, globalObject, node, JSObjectMakeConstructor (context, JSNode_construct), kJSPropertyAttributeNone, NULL);47 JSObjectSetProperty(context, globalObject, node, JSObjectMakeConstructorWithCallback(context, JSNode_prototype(context), JSNode_construct), kJSPropertyAttributeNone, NULL); 48 48 JSStringRelease(node); 49 49 -
trunk/JavaScriptCore/API/minidom.js
r15473 r15482 241 241 node.nodeType = 1; 242 242 shouldBe("node.nodeType", oldNodeType); 243 244 shouldBe("node instanceof Node", true); 245 shouldBe("new Object() instanceof Node", false); 246 247 print(Node); 243 248 244 249 /* -
trunk/JavaScriptCore/API/testapi.c
r15481 r15482 610 610 611 611 JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor"); 612 JSObjectRef myConstructor = JSObjectMakeConstructor (context, myConstructor_callAsConstructor);612 JSObjectRef myConstructor = JSObjectMakeConstructorWithCallback(context, NULL, myConstructor_callAsConstructor); 613 613 JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone, NULL); 614 614 JSStringRelease(myConstructorIString);
Note:
See TracChangeset
for help on using the changeset viewer.