Changeset 15469 in webkit for trunk/JavaScriptCore/API
- Timestamp:
- Jul 16, 2006, 3:17:04 PM (19 years ago)
- Location:
- trunk/JavaScriptCore/API
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSCallbackConstructor.cpp
r15444 r15469 55 55 } 56 56 57 void JSCallbackConstructor::setPrivate(void* data)58 {59 m_privateData = data;60 }61 62 void* JSCallbackConstructor::getPrivate()63 {64 return m_privateData;65 }66 67 57 } // namespace KJS -
trunk/JavaScriptCore/API/JSCallbackConstructor.h
r15376 r15469 41 41 virtual JSObject* construct(ExecState*, const List &args); 42 42 43 void setPrivate(void* data);44 void* getPrivate();45 46 43 virtual const ClassInfo *classInfo() const { return &info; } 47 44 static const ClassInfo info; … … 51 48 JSCallbackConstructor(const JSCallbackConstructor&); 52 49 53 void* m_privateData;54 50 JSObjectCallAsConstructorCallback m_callback; 55 51 }; -
trunk/JavaScriptCore/API/JSCallbackFunction.cpp
r15444 r15469 34 34 const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunctionImp::info, 0, 0 }; 35 35 36 JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback )37 : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()) )36 JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name) 37 : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name) 38 38 , m_callback(callback) 39 39 { 40 }41 42 bool JSCallbackFunction::implementsCall() const43 {44 return true;45 40 } 46 41 … … 58 53 } 59 54 60 void JSCallbackFunction::setPrivate(void* data)61 {62 m_privateData = data;63 }64 65 void* JSCallbackFunction::getPrivate()66 {67 return m_privateData;68 }69 70 55 } // namespace KJS -
trunk/JavaScriptCore/API/JSCallbackFunction.h
r15376 r15469 37 37 { 38 38 public: 39 JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback );39 JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name); 40 40 41 virtual bool implementsCall() const;42 41 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List &args); 43 44 void setPrivate(void* data);45 void* getPrivate();46 42 47 43 virtual const ClassInfo *classInfo() const { return &info; } … … 52 48 JSCallbackFunction(const JSCallbackFunction&); 53 49 54 void* m_privateData;55 50 JSObjectCallAsFunctionCallback m_callback; 56 51 }; -
trunk/JavaScriptCore/API/JSCallbackObject.cpp
r15468 r15469 26 26 27 27 #include "APICast.h" 28 #include "JSCallbackFunction.h" 28 29 #include "JSCallbackObject.h" 29 30 #include "JSStringRef.h" … … 406 407 if (__JSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) { 407 408 if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) { 408 JS Value* v = toJS(JSObjectMakeFunction(toRef(exec), entry->callAsFunction));409 thisObj->putDirect(propertyName, v, entry->attributes);410 return v;409 JSObject* o = new JSCallbackFunction(exec, entry->callAsFunction, propertyName); 410 thisObj->putDirect(propertyName, o, entry->attributes); 411 return o; 411 412 } 412 413 } -
trunk/JavaScriptCore/API/JSObjectRef.cpp
r15468 r15469 76 76 } 77 77 78 JSObjectRef JSObjectMakeFunction(JSContextRef context, JSObjectCallAsFunctionCallback callAsFunction) 79 { 80 JSLock lock; 81 ExecState* exec = toJS(context); 82 return toRef(new JSCallbackFunction(exec, callAsFunction)); 78 JSObjectRef JSObjectMakeFunction(JSContextRef context, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction) 79 { 80 JSLock lock; 81 ExecState* exec = toJS(context); 82 Identifier nameID = name ? Identifier(toJS(name)) : Identifier("anonymous"); 83 84 return toRef(new JSCallbackFunction(exec, callAsFunction, nameID)); 83 85 } 84 86 … … 95 97 96 98 ExecState* exec = toJS(context); 97 UString::Rep* nameRep = name ? toJS(name) : &UString::Rep::null;98 99 UString::Rep* bodyRep = toJS(body); 99 100 UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null; 100 101 101 Identifier nameI dentifier = nameRep ? Identifier(nameRep) : Identifier("anonymous");102 Identifier nameID = name ? Identifier(toJS(name)) : Identifier("anonymous"); 102 103 103 104 List args; … … 106 107 args.append(jsString(UString(bodyRep))); 107 108 108 JSObject* result = exec->dynamicInterpreter()->builtinFunction()->construct(exec, args, nameI dentifier, UString(sourceURLRep), startingLineNumber);109 JSObject* result = exec->dynamicInterpreter()->builtinFunction()->construct(exec, args, nameID, UString(sourceURLRep), startingLineNumber); 109 110 if (exec->hadException()) { 110 111 if (exception) … … 220 221 return static_cast<JSCallbackObject*>(jsObject)->getPrivate(); 221 222 222 if (jsObject->inherits(&JSCallbackFunction::info))223 return static_cast<JSCallbackFunction*>(jsObject)->getPrivate();224 225 if (jsObject->inherits(&JSCallbackConstructor::info))226 return static_cast<JSCallbackConstructor*>(jsObject)->getPrivate();227 228 223 return 0; 229 224 } … … 238 233 } 239 234 240 if (jsObject->inherits(&JSCallbackFunction::info)) {241 static_cast<JSCallbackFunction*>(jsObject)->setPrivate(data);242 return true;243 }244 245 if (jsObject->inherits(&JSCallbackConstructor::info)) {246 static_cast<JSCallbackConstructor*>(jsObject)->setPrivate(data);247 return true;248 }249 250 235 return false; 251 236 } -
trunk/JavaScriptCore/API/JSObjectRef.h
r15468 r15469 387 387 @abstract Convenience method for creating a JavaScript function with a given callback as its implementation. 388 388 @param context The execution context to use. 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. 389 390 @param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called. 390 391 @result A JSObject that is an anonymous function. The object's prototype will be the default function prototype. 391 392 */ 392 JSObjectRef JSObjectMakeFunction(JSContextRef context, JS ObjectCallAsFunctionCallback callAsFunction);393 JSObjectRef JSObjectMakeFunction(JSContextRef context, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction); 393 394 /*! 394 395 @function … … 404 405 @abstract Creates a function with a given script as its body. 405 406 @param context The execution context to use. 406 @param name A JSString containing the function's name. Pass NULL to create an anonymous function.407 @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. 407 408 @param parameterCount An integer count of the number of parameter names in parameterNames. 408 409 @param parameterNames A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0. … … 501 502 @param object A JSObject whose private data you want to get. 502 503 @result A void* that points to the object's private data, if the object has private data, otherwise NULL. 503 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor.504 504 */ 505 505 void* JSObjectGetPrivate(JSObjectRef object); … … 510 510 @param object A JSObject whose private data you want to set. 511 511 @param data A void* that points to the object's private data. 512 @result true if the set operation succeeds, otherwise false.513 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor.512 @result true if the object can store private data, otherwise false. 513 @discussion Only custom objects created with a JSClass can store private data. 514 514 */ 515 515 bool JSObjectSetPrivate(JSObjectRef object, void* data); -
trunk/JavaScriptCore/API/minidom.c
r15465 r15469 41 41 42 42 JSStringRef printIString = JSStringCreateWithUTF8CString("print"); 43 JSObjectSetProperty(context, globalObject, printIString, JSObjectMakeFunction(context, print ), kJSPropertyAttributeNone, NULL);43 JSObjectSetProperty(context, globalObject, printIString, JSObjectMakeFunction(context, printIString, print), kJSPropertyAttributeNone, NULL); 44 44 JSStringRelease(printIString); 45 45 -
trunk/JavaScriptCore/API/testapi.c
r15468 r15469 571 571 572 572 JSStringRef print = JSStringCreateWithUTF8CString("print"); 573 JSObjectRef printFunction = JSObjectMakeFunction(context, print _callAsFunction);573 JSObjectRef printFunction = JSObjectMakeFunction(context, print, print_callAsFunction); 574 574 JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone, NULL); 575 575 JSStringRelease(print); 576 576 577 assert( JSObjectSetPrivate(printFunction, (void*)1));578 assert( JSObjectGetPrivate(printFunction) == (void*)1);577 assert(!JSObjectSetPrivate(printFunction, (void*)1)); 578 assert(!JSObjectGetPrivate(printFunction)); 579 579 580 580 JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor"); … … 583 583 JSStringRelease(myConstructorIString); 584 584 585 assert( JSObjectSetPrivate(myConstructor, (void*)1));586 assert( JSObjectGetPrivate(myConstructor) == (void*)1);585 assert(!JSObjectSetPrivate(myConstructor, (void*)1)); 586 assert(!JSObjectGetPrivate(myConstructor)); 587 587 588 588 o = JSObjectMake(context, NULL, NULL);
Note:
See TracChangeset
for help on using the changeset viewer.