Changeset 15224 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jul 7, 2006, 7:02:47 PM (19 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSCallbackObject.cpp
r15168 r15224 81 81 bool JSCallbackObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 82 82 { 83 JSContextRef context = toRef(exec); 83 84 JSObjectRef thisRef = toRef(this); 84 85 JSStringBufferRef propertyNameRef = toRef(propertyName.ustring().rep()); … … 87 88 // optional optimization to bypass getProperty in cases when we only need to know if the property exists 88 89 if (JSHasPropertyCallback hasPropertyCallback = jsClass->callbacks.hasProperty) { 89 if (hasPropertyCallback( thisRef, propertyNameRef)) {90 if (hasPropertyCallback(context, thisRef, propertyNameRef)) { 90 91 slot.setCustom(this, callbackGetter); 91 92 return true; … … 93 94 } else if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty) { 94 95 JSValueRef returnValue; 95 if (getPropertyCallback( toRef(exec), thisRef, propertyNameRef, &returnValue)) {96 if (getPropertyCallback(context, thisRef, propertyNameRef, &returnValue)) { 96 97 // cache the value so we don't have to compute it again 97 98 // FIXME: This violates the PropertySlot design a little bit. … … 129 130 void JSCallbackObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr) 130 131 { 132 JSContextRef context = toRef(exec); 131 133 JSObjectRef thisRef = toRef(this); 132 134 JSStringBufferRef propertyNameRef = toRef(propertyName.ustring().rep()); … … 134 136 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 135 137 if (JSSetPropertyCallback setPropertyCallback = jsClass->callbacks.setProperty) { 136 if (setPropertyCallback( thisRef, propertyNameRef, value))138 if (setPropertyCallback(context, thisRef, propertyNameRef, value)) 137 139 return; 138 140 } … … 143 145 return; 144 146 if (JSSetPropertyCallback setPropertyCallback = entry->setProperty) { 145 if (setPropertyCallback( thisRef, propertyNameRef, value))147 if (setPropertyCallback(context, thisRef, propertyNameRef, value)) 146 148 return; 147 149 } … … 168 170 bool JSCallbackObject::deleteProperty(ExecState* exec, const Identifier& propertyName) 169 171 { 172 JSContextRef context = toRef(exec); 170 173 JSObjectRef thisRef = toRef(this); 171 174 JSStringBufferRef propertyNameRef = toRef(propertyName.ustring().rep()); … … 173 176 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 174 177 if (JSDeletePropertyCallback deletePropertyCallback = jsClass->callbacks.deleteProperty) { 175 if (deletePropertyCallback( thisRef, propertyNameRef))178 if (deletePropertyCallback(context, thisRef, propertyNameRef)) 176 179 return true; 177 180 } … … 260 263 void JSCallbackObject::getPropertyList(ExecState* exec, ReferenceList& propertyList, bool recursive) 261 264 { 265 JSContextRef context = toRef(exec); 262 266 JSObjectRef thisRef = toRef(this); 263 267 264 268 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 265 269 if (JSGetPropertyListCallback getPropertyListCallback = jsClass->callbacks.getPropertyList) 266 getPropertyListCallback( thisRef, toRef(&propertyList));270 getPropertyListCallback(context, thisRef, toRef(&propertyList)); 267 271 268 272 if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) { … … 294 298 bool JSCallbackObject::toBoolean(ExecState* exec) const 295 299 { 300 JSContextRef context = toRef(exec); 296 301 JSObjectRef thisRef = toRef(this); 297 302 … … 299 304 if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) { 300 305 JSValueRef returnValue; 301 if (convertToTypeCallback( thisRef, kJSTypeBoolean, &returnValue))306 if (convertToTypeCallback(context, thisRef, kJSTypeBoolean, &returnValue)) 302 307 return toJS(returnValue)->getBoolean(); 303 308 } … … 308 313 double JSCallbackObject::toNumber(ExecState* exec) const 309 314 { 315 JSContextRef context = toRef(exec); 310 316 JSObjectRef thisRef = toRef(this); 311 317 … … 313 319 if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) { 314 320 JSValueRef returnValue; 315 if (convertToTypeCallback( thisRef, kJSTypeNumber, &returnValue))321 if (convertToTypeCallback(context, thisRef, kJSTypeNumber, &returnValue)) 316 322 return toJS(returnValue)->getNumber(); 317 323 } … … 322 328 UString JSCallbackObject::toString(ExecState* exec) const 323 329 { 330 JSContextRef context = toRef(exec); 324 331 JSObjectRef thisRef = toRef(this); 325 332 … … 327 334 if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) { 328 335 JSValueRef returnValue; 329 if (convertToTypeCallback( thisRef, kJSTypeString, &returnValue))336 if (convertToTypeCallback(context, thisRef, kJSTypeString, &returnValue)) 330 337 return toJS(returnValue)->getString(); 331 338 } -
trunk/JavaScriptCore/API/JSClassRef.cpp
r15213 r15224 33 33 const JSObjectCallbacks kJSObjectCallbacksNone = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 34 34 35 JSClassRef JSClassCreate(JS ContextRef, JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass)35 JSClassRef JSClassCreate(JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass) 36 36 { 37 37 JSClassRef jsClass = new __JSClass; -
trunk/JavaScriptCore/API/JSContextRef.cpp
r15212 r15224 35 35 using namespace KJS; 36 36 37 JSContextRef JSContextCreate(JSClassRef globalObjectClass , JSObjectRef globalObjectPrototype)37 JSContextRef JSContextCreate(JSClassRef globalObjectClass) 38 38 { 39 39 JSLock lock; 40 40 41 JSObject* jsPrototype = toJS(globalObjectPrototype);42 43 41 JSObject* globalObject; 44 if (globalObjectClass) { 45 if (jsPrototype) 46 globalObject = new JSCallbackObject(globalObjectClass, jsPrototype); 47 else 48 globalObject = new JSCallbackObject(globalObjectClass); 49 } else { 50 // creates a slightly more efficient object 51 if (jsPrototype) 52 globalObject = new JSObject(jsPrototype); 53 else 54 globalObject = new JSObject(); 55 } 42 if (globalObjectClass) 43 globalObject = new JSCallbackObject(globalObjectClass); 44 else 45 globalObject = new JSObject(); 56 46 57 47 Interpreter* interpreter = new Interpreter(globalObject); // adds the built-in object prototype to the global object … … 131 121 exec->setException(jsValue); 132 122 } 133 -
trunk/JavaScriptCore/API/JSContextRef.h
r15212 r15224 35 35 #endif 36 36 37 JSContextRef JSContextCreate(JSClassRef globalObjectClass, JSObjectRef globalObjectPrototype); 37 /*! 38 @function 39 @abstract Creates a JavaScript execution context. 40 @discussion JSContextCreate allocates a global object and populates it with all the 41 built-in JavaScript objects, such as Object, Function, String, and Array. 42 @param globalObjectClass The class to use when creating the JSContext's global object. 43 Pass NULL to use the default object class. 44 @result A JSContext with a global object of class globalObjectClass. 45 */ 46 JSContextRef JSContextCreate(JSClassRef globalObjectClass); 47 48 /*! 49 @function 50 @abstract Destroys a JavaScript execution context, freeing its resources. 51 @param context The JSContext to destroy. 52 */ 38 53 void JSContextDestroy(JSContextRef context); 39 54 55 /*! 56 @function 57 @abstract Returns the global object of a JavaScript execution context. 58 @param context The JSContext whose global object you want to retrieve. 59 @result context's global object. 60 */ 40 61 JSObjectRef JSContextGetGlobalObject(JSContextRef context); 41 62 42 JSValueRef JSContextGetException(JSContextRef context); // NULL if there is no exception 63 /*! 64 @function 65 @abstract Returns the current exception in a JavaScript execution context. 66 @param context The JSContext whose exception you want to retrieve. 67 @result A JSValue representing context's exception, or NULL if no exception has been set. 68 */ 69 JSValueRef JSContextGetException(JSContextRef context); 70 /*! 71 @function 72 @abstract Sets an exception in a JavaScript execution context. 73 @param context The JSContext whose exception you want to set. 74 @param value The exception you want to set. 75 */ 43 76 void JSContextSetException(JSContextRef context, JSValueRef value); 77 /*! 78 @function 79 @abstract Clears the exception in a JavaScript execution context. 80 @param context The JSContext whose exception you want to clear. 81 */ 44 82 void JSContextClearException(JSContextRef context); 45 83 46 84 // Evaluation 47 85 /*! 48 @function JSEvaluate 49 Evaluates a string of JavaScript 50 @param context execution context to use 51 @param script a character buffer containing the JavaScript to evaluate 52 @param thisObject the object to use as "this," or NULL to use the global object as "this."53 @param sourceURL URL to the file containing the JavaScript, or NULL - this is only used for error reporting 54 @param startingLineNumber the JavaScript's starting line number in the file located at sourceURL - this is only used for error reporting 55 @param exception pointer to a JSValueRef in which to store an uncaught exception, if any; can be NULL 56 @result result of evaluation, or NULL if an uncaught exception was thrown 86 @function 87 @abstract Evaluates a string of JavaScript. 88 @param context The execution context to use. 89 @param script A JSStringBuffer containing the script to evaluate. 90 @param thisObject The object to use as "this," or NULL to use the global object as "this." 91 @param sourceURL A JSStringBuffer containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions. 92 @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. 93 @param exception A pointer to a JSValueRef in which to store an uncaught exception, if any. Pass NULL if you do not care to store an uncaught exception. 94 @result The JSValue that results from evaluating script, or NULL if an uncaught exception is thrown. 57 95 */ 58 96 JSValueRef JSEvaluate(JSContextRef context, JSStringBufferRef script, JSObjectRef thisObject, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception); 59 97 60 98 /*! 61 @function JSCheckSyntax 62 Check for syntax errors in a string of JavaScript 63 @param context execution context to use 64 @param script a character buffer containing the JavaScript to evaluate 65 @param sourceURL URL to the file containing the JavaScript, or NULL - this is only used for error reporting 66 @param startingLineNumber the JavaScript's starting line number in the file located at sourceURL - this is only used for error reporting 67 @param exception pointer to a JSValueRef in which to store a syntax error, if any; can be NULL 68 @result true if the script is syntactically correct, false otherwise 69 99 @function JSCheckSyntax 100 @abstract Checks for syntax errors in a string of JavaScript. 101 @param context The execution context to use. 102 @param script A JSStringBuffer containing the JavaScript to check for syntax errors. 103 @param sourceURL A JSStringBuffer containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions. 104 @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. 105 @param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception. 106 @result true if the script is syntactically correct, otherwise false. 70 107 */ 71 108 bool JSCheckSyntax(JSContextRef context, JSStringBufferRef script, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception); -
trunk/JavaScriptCore/API/JSNode.c
r15168 r15224 110 110 static JSClassRef nodePrototypeClass; 111 111 if (!nodePrototypeClass) 112 nodePrototypeClass = JSClassCreate( context,NULL, JSNodePrototype_staticFunctions, &kJSObjectCallbacksNone, NULL);112 nodePrototypeClass = JSClassCreate(NULL, JSNodePrototype_staticFunctions, &kJSObjectCallbacksNone, NULL); 113 113 return nodePrototypeClass; 114 114 } … … 170 170 JSNode_callbacks.finalize = JSNode_finalize; 171 171 172 nodeClass = JSClassCreate( context,JSNode_staticValues, NULL, &JSNode_callbacks, NULL);172 nodeClass = JSClassCreate(JSNode_staticValues, NULL, &JSNode_callbacks, NULL); 173 173 } 174 174 return nodeClass; -
trunk/JavaScriptCore/API/JSNodeList.c
r15168 r15224 51 51 static JSClassRef jsClass; 52 52 if (!jsClass) { 53 jsClass = JSClassCreate( context,NULL, JSNodeListPrototype_staticFunctions, &kJSObjectCallbacksNone, NULL);53 jsClass = JSClassCreate(NULL, JSNodeListPrototype_staticFunctions, &kJSObjectCallbacksNone, NULL); 54 54 } 55 55 … … 104 104 callbacks.finalize = JSNodeList_finalize; 105 105 106 jsClass = JSClassCreate( context,JSNodeList_staticValues, NULL, &callbacks, NULL);106 jsClass = JSClassCreate(JSNodeList_staticValues, NULL, &callbacks, NULL); 107 107 } 108 108 -
trunk/JavaScriptCore/API/JSObjectRef.cpp
r15168 r15224 71 71 } 72 72 73 JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber )73 JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception) 74 74 { 75 75 JSLock lock; … … 77 77 ExecState* exec = toJS(context); 78 78 UString::Rep* bodyRep = toJS(body); 79 UString::Rep* sourceURLRep = toJS(sourceURL); 79 UString jsSourceURL = UString(toJS(sourceURL)); 80 80 81 if (!bodyRep) 81 82 bodyRep = &UString::Rep::null; 82 RefPtr<FunctionBodyNode> bodyNode = Parser::parse(UString(sourceURLRep), startingLineNumber, bodyRep->data(), bodyRep->size(), NULL, NULL, NULL); 83 if (!bodyNode) 83 84 int sid; 85 int errLine; 86 UString errMsg; 87 RefPtr<FunctionBodyNode> bodyNode = Parser::parse(jsSourceURL, startingLineNumber, bodyRep->data(), bodyRep->size(), &sid, &errLine, &errMsg); 88 if (!bodyNode) { 89 if (exception) 90 *exception = Error::create(exec, SyntaxError, errMsg, errLine, sid, jsSourceURL); 84 91 return NULL; 92 } 85 93 86 94 ScopeChain scopeChain; … … 127 135 UString::Rep* nameRep = toJS(propertyName); 128 136 129 *value = toRef(jsObject->get(exec, Identifier(nameRep))); 130 return !JSValueIsUndefined(*value); 137 JSValue* jsValue = jsObject->get(exec, Identifier(nameRep)); 138 if (value) 139 *value = toRef(jsValue); 140 return !jsValue->isUndefined(); 131 141 } 132 142 … … 161 171 JSObject* jsObject = toJS(object); 162 172 163 if (!jsObject->inherits(&JSCallbackObject::info)) 164 return 0; 165 166 return static_cast<JSCallbackObject*>(jsObject)->getPrivate(); 173 if (jsObject->inherits(&JSCallbackObject::info)) 174 return static_cast<JSCallbackObject*>(jsObject)->getPrivate(); 175 176 if (jsObject->inherits(&JSCallbackFunction::info)) 177 return static_cast<JSCallbackFunction*>(jsObject)->getPrivate(); 178 179 if (jsObject->inherits(&JSCallbackConstructor::info)) 180 return static_cast<JSCallbackConstructor*>(jsObject)->getPrivate(); 181 182 return 0; 167 183 } 168 184 … … 171 187 JSObject* jsObject = toJS(object); 172 188 173 if (!jsObject->inherits(&JSCallbackObject::info)) 174 return false; 175 176 static_cast<JSCallbackObject*>(jsObject)->setPrivate(data); 177 return true; 189 if (jsObject->inherits(&JSCallbackObject::info)) { 190 static_cast<JSCallbackObject*>(jsObject)->setPrivate(data); 191 return true; 192 } 193 194 if (jsObject->inherits(&JSCallbackFunction::info)) { 195 static_cast<JSCallbackFunction*>(jsObject)->setPrivate(data); 196 return true; 197 } 198 199 if (jsObject->inherits(&JSCallbackConstructor::info)) { 200 static_cast<JSCallbackConstructor*>(jsObject)->setPrivate(data); 201 return true; 202 } 203 204 return false; 178 205 } 179 206 … … 194 221 for (size_t i = 0; i < argc; i++) 195 222 argList.append(toJS(argv[i])); 196 197 JSValueRef result = toRef(jsObject->call(exec, jsThisObject, argList)); 223 224 JSValueRef result = toRef(jsObject->call(exec, jsThisObject, argList)); // returns NULL if object->implementsCall() is false 198 225 if (exec->hadException()) { 199 226 if (exception) … … 221 248 argList.append(toJS(argv[i])); 222 249 223 JSObjectRef result = toRef(jsObject->construct(exec, argList)); 250 JSObjectRef result = toRef(jsObject->construct(exec, argList)); // returns NULL if object->implementsCall() is false 224 251 if (exec->hadException()) { 225 252 if (exception) … … 260 287 ReferenceListIterator& iterator = enumerator->iterator; 261 288 if (iterator != enumerator->list.end()) { 289 JSStringBufferRef result = toRef(iterator->getPropertyName(exec).ustring().rep()); 262 290 iterator++; 263 return toRef(iterator->getPropertyName(exec).ustring().rep());291 return result; 264 292 } 265 293 return 0; -
trunk/JavaScriptCore/API/JSObjectRef.h
r15168 r15224 35 35 #endif 36 36 37 /*! 38 @enum JSPropertyAttribute 39 @constant kJSPropertyAttributeNone Specifies that a property has no special attributes. 40 @constant kJSPropertyAttributeReadOnly Specifies that a property is read-only. 41 @constant kJSPropertyAttributeDontEnum Specifies that a property should not be enumerated by JSPropertyEnumerators and JavaScript for...in loops. 42 @constant kJSPropertyAttributeDontDelete Specifies that the delete operation should fail on a property. 43 */ 37 44 enum { 38 45 kJSPropertyAttributeNone = 0, … … 41 48 kJSPropertyAttributeDontDelete = 1 << 3 42 49 }; 50 51 /*! 52 @typedef JSPropertyAttributes 53 @abstract A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together. 54 */ 43 55 typedef unsigned JSPropertyAttributes; 44 56 57 /*! 58 @typedef JSInitializeCallback 59 @abstract The callback invoked when an object is first created. 60 @param object The JSObject being created. 61 @discussion If you named your function Initialize, you would declare it like this: 62 63 void Initialize(JSObjectRef object); 64 */ 65 66 // FIXME: Needs to take a context argument, but can't because no context exists when we're creating the global object 45 67 typedef void 46 68 (*JSInitializeCallback) (JSObjectRef object); 47 69 70 /*! 71 @typedef JSFinalizeCallback 72 @abstract The callback invoked when an object is finalized (prepared for garbage collection). 73 @param object The JSObject being finalized. 74 @discussion If you named your function Finalize, you would declare it like this: 75 76 void Finalize(JSObjectRef object); 77 */ 48 78 typedef void 49 79 (*JSFinalizeCallback) (JSObjectRef object); 50 80 81 /*! 82 @typedef JSHasPropertyCallback 83 @abstract The callback invoked when determining whether an object has a given property. 84 @param context The current execution context. 85 @param object The JSObject to search for the property. 86 @param propertyName A JSStringBuffer containing the name of the property look up. 87 @result true if object has the property, otherwise false. 88 @discussion If you named your function HasProperty, you would declare it like this: 89 90 bool HasProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName); 91 92 This callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value would be expensive. If this callback is NULL, the getProperty callback will be used to service hasProperty calls. 93 */ 51 94 typedef bool 52 (*JSHasPropertyCallback) (JSObjectRef object, JSStringBufferRef propertyName); 53 95 (*JSHasPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName); 96 97 /*! 98 @typedef JSGetPropertyCallback 99 @abstract The callback invoked when getting a property from an object. 100 @param context The current execution context. 101 @param object The JSObject to search for the property. 102 @param propertyName A JSStringBuffer containing the name of the property to get. 103 @param returnValue A pointer to a JSValue in which to store the property's value. 104 @result true if object has the property in question, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue. 105 @discussion If you named your function GetProperty, you would declare it like this: 106 107 bool GetProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef* returnValue); 108 109 If this function returns false, the get request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain. 110 */ 54 111 typedef bool 55 112 (*JSGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef* returnValue); 56 113 114 /*! 115 @typedef JSSetPropertyCallback 116 @abstract The callback invoked when setting the value of a given property. 117 @param context The current execution context. 118 @param object The JSObject on which to set the property's value. 119 @param propertyName A JSStringBuffer containing the name of the property to set. 120 @param value A JSValue to use as the property's value. 121 @result true if the property was successfully set, otherwise false. 122 @discussion If you named your function SetProperty, you would declare it like this: 123 124 bool SetProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value); 125 126 If this function returns false, the set request forwards to object's static property table, then its parent class chain (which includes the default object class). 127 */ 57 128 typedef bool 58 (*JSSetPropertyCallback) (JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value); 59 129 (*JSSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value); 130 131 /*! 132 @typedef JSDeletePropertyCallback 133 @abstract The callback invoked when deleting a given property. 134 @param context The current execution context. 135 @param object The JSObject in which to delete the property. 136 @param propertyName A JSStringBuffer containing the name of the property to delete. 137 @result true if propertyName was successfully deleted, otherwise false. 138 @discussion If you named your function DeleteProperty, you would declare it like this: 139 140 bool DeleteProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName); 141 142 If this function returns false, the delete request forwards to object's static property table, then its parent class chain (which includes the default object class). 143 */ 60 144 typedef bool 61 (*JSDeletePropertyCallback) (JSObjectRef object, JSStringBufferRef propertyName); 62 145 (*JSDeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName); 146 147 /*! 148 @typedef JSGetPropertyListCallback 149 @abstract The callback invoked when adding an object's properties to a property list. 150 @param context The current execution context. 151 @param object The JSObject whose properties need to be added to propertyList. 152 @param propertyList A JavaScript property list that will be used to enumerate object's properties. 153 @discussion If you named your function GetPropertyList, you would declare it like this: 154 155 void GetPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList); 156 157 Use JSPropertyListAdd to add properties to propertyList. 158 159 Property lists are used by JSPropertyEnumerators and JavaScript for...in loops. 160 */ 63 161 typedef void 64 (*JSGetPropertyListCallback) (JSObjectRef object, JSPropertyListRef propertyList); 65 162 (*JSGetPropertyListCallback) (JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList); 163 164 /*! 165 @typedef JSCallAsFunctionCallback 166 @abstract The callback invoked when an object is called as a function. 167 @param context The current execution context. 168 @param function A JSObject that is the function being called. 169 @param thisObject A JSObject that is the 'this' variable in the function's scope. 170 @param argc An integer count of the number of arguments in argv. 171 @param argv A JSValue array of the arguments passed to the function. 172 @result A JSValue that is the function's return value. 173 @discussion If you named your function CallAsFunction, you would declare it like this: 174 175 JSValueRef CallAsFunction(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[]); 176 177 If your callback were invoked by the JavaScript expression 'myObject.myMemberFunction()', function would be set to myMemberFunction, and thisObject would be set to myObject. 178 179 If this callback is NULL, calling your object as a function will throw an exception. 180 */ 66 181 typedef JSValueRef 67 (*JSCallAsFunctionCallback) (JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argc, JSValueRef argv[]); 68 182 (*JSCallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[]); 183 184 /*! 185 @typedef JSCallAsConstructorCallback 186 @abstract The callback invoked when an object is used as a constructor in a 'new' statement. 187 @param context The current execution context. 188 @param constructor A JSObject that is the constructor being called. 189 @param argc An integer count of the number of arguments in argv. 190 @param argv A JSValue array of the arguments passed to the function. 191 @result A JSObject that is the constructor's return value. 192 @discussion If you named your function CallAsConstructor, you would declare it like this: 193 194 JSObjectRef CallAsConstructor(JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[]); 195 196 If your callback were invoked by the JavaScript expression 'new myConstructorFunction()', constructor would be set to myConstructorFunction. 197 198 If this callback is NULL, using your object as a constructor in a 'new' statement will throw an exception. 199 */ 69 200 typedef JSObjectRef 70 (*JSCallAsConstructorCallback) (JSContextRef context, JSObjectRef object, size_t argc, JSValueRef argv[]); 71 201 (*JSCallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[]); 202 203 /*! 204 @typedef JSConvertToTypeCallback 205 @abstract The callback invoked when converting an object to a particular JavaScript type. 206 @param context The current execution context. 207 @param object The JSObject to convert. 208 @param typeCode A JSTypeCode specifying the JavaScript type to convert to. 209 @param returnValue A pointer to a JSValue in which to store the converted value. 210 @result true if the value was converted, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue. 211 @discussion If you named your function ConvertToType, you would declare it like this: 212 213 bool ConvertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue); 214 215 If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class). 216 */ 72 217 typedef bool 73 (*JSConvertToTypeCallback) (JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue); 74 75 typedef struct __JSObjectCallbacks { 218 (*JSConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue); 219 220 /*! 221 @struct JSObjectCallbacks 222 @abstract This structure contains optional callbacks for supplementing default object behavior. Any callback field can be NULL. 223 @field version The version number of this structure. The current version is 0. 224 @field initialize The callback invoked when an object is first created. Use this callback in conjunction with JSObjectSetPrivate to initialize private data in your object. 225 @field finalize The callback invoked when an object is finalized (prepared for garbage collection). Use this callback to release resources allocated for your object, and perform other cleanup. 226 @field hasProperty The callback invoked when determining whether an object has a given property. If this field is NULL, getProperty will be called instead. The hasProperty callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value would be expensive. 227 @field getProperty The callback invoked when getting the value of a given property. 228 @field setProperty The callback invoked when setting the value of a given property. 229 @field deleteProperty The callback invoked when deleting a given property. 230 @field getPropertyList The callback invoked when adding an object's properties to a property list. 231 @field callAsFunction The callback invoked when an object is called as a function. 232 @field callAsConstructor The callback invoked when an object is used as a constructor in a 'new' statement. 233 @field convertToType The callback invoked when converting an object to a particular JavaScript type. 234 */ 235 typedef struct { 76 236 int version; // current (and only) version is 0 77 237 JSInitializeCallback initialize; … … 87 247 } JSObjectCallbacks; 88 248 249 /*! 250 @const kJSObjectCallbacksNone 251 @abstract A JSObjectCallbacks structure of the current version, filled with NULL callbacks. 252 @discussion Use this constant as a convenience when creating callback structures. For example, to create a callback structure that has only a finalize method: 253 254 JSObjectCallbacks callbacks = kJSObjectCallbacksNone; 255 256 callbacks.finalize = Finalize; 257 */ 89 258 extern const JSObjectCallbacks kJSObjectCallbacksNone; 90 259 260 /*! 261 @struct JSStaticValue 262 @abstract This structure describes a static value property. 263 @field name A UTF8 buffer containing the property's name. 264 @field getProperty A JSGetPropertyCallback to invoke when getting the property's value. 265 @field setProperty A JSSetPropertyCallback to invoke when setting the property's value. 266 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. 267 */ 91 268 typedef struct { 92 269 const char* const name; // FIXME: convert UTF8 … … 96 273 } JSStaticValue; 97 274 275 /*! 276 @struct JSStaticFunction 277 @abstract This structure describes a static function property. 278 @field name A UTF8 buffer containing the property's name. 279 @field callAsFunction A JSCallAsFunctionCallback to invoke when the property is called as a function. 280 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. 281 */ 98 282 typedef struct { 99 283 const char* const name; // FIXME: convert UTF8 … … 102 286 } JSStaticFunction; 103 287 104 JSClassRef JSClassCreate(JSContextRef context, JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass); 288 /*! 289 @function 290 @abstract Creates a JavaScript class suitable for use with JSObjectMake. Ownership follows the create rule. 291 @param staticValues A JSStaticValue array representing the class's static value properties. Pass NULL to specify no static value properties. The array must be terminated by a JSStaticValue whose name field is NULL. 292 @param staticFunctions A JSStaticFunction array representing the class's static function properties. Pass NULL to specify no static function properties. The array must be terminated by a JSStaticFunction whose name field is NULL. 293 @param callbacks A pointer to a JSObjectCallbacks structure holding custom callbacks for supplementing default object behavior. Pass NULL to specify no custom behavior. 294 @param parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class. 295 @discussion The simplest and most efficient way to add custom properties to a class is by specifying static values and functions. Standard JavaScript practice calls for functions to be placed in prototype objects, so that they can be shared among objects. 296 */ 297 JSClassRef JSClassCreate(JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass); 298 /*! 299 @function 300 @abstract Retains a JavaScript class. 301 @param jsClass The JSClass to retain. 302 @result A JSClass that is the same as jsClass. 303 */ 304 JSClassRef JSClassRetain(JSClassRef jsClass); 305 /*! 306 @function 307 @abstract Releases a JavaScript class. 308 @param jsClass The JSClass to release. 309 */ 105 310 void JSClassRelease(JSClassRef jsClass); 106 JSClassRef JSClassRetain(JSClassRef jsClass); 107 108 // pass NULL as prototype to get the built-in object prototype 311 312 /*! 313 @function 314 @abstract Creates a JavaScript object with a given class and prototype. 315 @param context The execution context to use. 316 @param jsClass The JSClass to assign to the object. Pass NULL to use the default object class. 317 @param prototype The prototype to assign to the object. Pass NULL to use the default object prototype. 318 @result A JSObject with the given class and prototype. 319 */ 109 320 JSObjectRef JSObjectMake(JSContextRef context, JSClassRef jsClass, JSObjectRef prototype); 110 321 111 // Will be assigned the built-in function prototype 322 /*! 323 @function 324 @abstract Convenience method for creating a JavaScript function with a given callback as its implementation. 325 @param context The execution context to use. 326 @param callAsFunction The JSCallAsFunctionCallback to invoke when the function is called. 327 @result A JSObject that is an anonymous function. The object's prototype will be the default function prototype. 328 */ 112 329 JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction); 113 // Will be assigned the built-in object prototype 330 /*! 331 @function 332 @abstract Convenience method for creating a JavaScript constructor with a given callback as its implementation. 333 @param context The execution context to use. 334 @param callAsConstructor The JSCallAsConstructorCallback to invoke when the constructor is used in a 'new' statement. 335 @result A JSObject that is a constructor. The object's prototype will be the default object prototype. 336 */ 114 337 JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor); 115 338 116 // returns NULL if functionBody has a syntax error 117 JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber); 118 339 /*! 340 @function 341 @abstract Creates a function with a given script as its body. 342 @param context The execution context to use. 343 @param body A JSStringBuffer containing the script to use as the function's body. 344 @param sourceURL A JSStringBuffer containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions. 345 @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. 346 @param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception. 347 @result A JSObject that is an anonymous function, or NULL if body contains a syntax error. The returned object's prototype will be the default function prototype. 348 @discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution. 349 */ 350 JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception); 351 352 /*! 353 @function 354 @abstract Gets a short description of a JavaScript object. 355 @param context The execution context to use. 356 @param object The object whose description you want to get. 357 @result A JSStringBuffer containing the object's description. This is usually the object's class name. 358 */ 119 359 JSStringBufferRef JSObjectGetDescription(JSObjectRef object); 120 360 361 /*! 362 @function 363 @abstract Gets an object's prototype. 364 @param object A JSObject whose prototype you want to get. 365 @result A JSValue containing the object's prototype. 366 */ 121 367 JSValueRef JSObjectGetPrototype(JSObjectRef object); 368 /*! 369 @function 370 @abstract Sets an object's prototype. 371 @param object The JSObject whose prototype you want to set. 372 @param value A JSValue to set as the object's prototype. 373 */ 122 374 void JSObjectSetPrototype(JSObjectRef object, JSValueRef value); 123 375 376 /*! 377 @function 378 @abstract Tests whether an object has a certain property. 379 @param object The JSObject to test. 380 @param propertyName A JSStringBuffer containing the property's name. 381 @result true if the object has a property whose name matches propertyName, otherwise false. 382 */ 124 383 bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName); 384 /*! 385 @function 386 @abstract Gets a property from an object. 387 @param context The execution context to use. 388 @param object The JSObject whose property you want to get. 389 @param propertyName A JSStringBuffer containing the property's name. 390 @param value A pointer to a JSValueRef in which to store the property's value. On return, value will contain the property's value. Pass NULL if you do not care to store the property's value. 391 @result true if the object has a property whose name matches propertyName, otherwise false. If this function returns false, the contents of value will be unmodified. 392 */ 125 393 bool JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef* value); 394 /*! 395 @function 396 @abstract Sets a property on an object. 397 @param context The execution context to use. 398 @param object The JSObject whose property you want to set. 399 @param propertyName A JSStringBuffer containing the property's name. 400 @param value A JSValue to use as the property's value. 401 @param attributes A logically ORed set of JSPropertyAttributes to give to the property. 402 @result true if the set operation succeeds, otherwise false (for example, if the object already has a property of the given name with the kJSPropertyAttributeReadOnly attribute set). 403 */ 126 404 bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value, JSPropertyAttributes attributes); 405 /*! 406 @function 407 @abstract Deletes a property from an object. 408 @param context The execution context to use. 409 @param object The JSObject whose property you want to delete. 410 @param propertyName A JSStringBuffer containing the property's name. 411 @result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set). 412 */ 127 413 bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName); 128 414 129 // Only works with objects created by JSObjectMake 415 /*! 416 @function 417 @abstract Gets a pointer to private data from an object. 418 @param object A JSObject whose private data you want to get. 419 @result A void* that points to the object's private data, or NULL if the object has no private data. 420 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSFunctionMake, and JSConstructorMake. 421 */ 130 422 void* JSObjectGetPrivate(JSObjectRef object); 423 /*! 424 @function 425 @abstract Sets a pointer to private data on an object. 426 @param object A JSObject whose private data you want to set. 427 @param data A void* that points to the object's private data. 428 @result true if the set operation succeeds, otherwise false. 429 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSFunctionMake, and JSConstructorMake. 430 */ 131 431 bool JSObjectSetPrivate(JSObjectRef object, void* data); 132 432 433 /*! 434 @function 435 @abstract Tests whether an object is a function. 436 @param object The JSObject to test. 437 @result true if the object is a function, otherwise false. 438 */ 133 439 bool JSObjectIsFunction(JSObjectRef object); 440 /*! 441 @function 442 @abstract Calls an object as a function. 443 @param context The execution context to use. 444 @param object The JSObject to call as a function. 445 @param thisObject The JSObject to use as 'this' in the function call. 446 @param argc An integer count of the number of arguments in argv. 447 @param argv A JSValue array of the arguments to pass to the function. 448 @param exception A pointer to a JSValueRef in which to store an uncaught exception, if any. Pass NULL if you do not care to store an uncaught exception. 449 @result The JSValue that results from calling object as a function, or NULL if an uncaught exception is thrown or object is not a function. 450 */ 134 451 JSValueRef JSObjectCallAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception); 452 /*! 453 @function 454 @abstract Tests whether an object is a constructor. 455 @param object The JSObject to test. 456 @result true if the object is a constructor, otherwise false. 457 */ 135 458 bool JSObjectIsConstructor(JSObjectRef object); 459 /*! 460 @function 461 @abstract Calls an object as a constructor. 462 @param context The execution context to use. 463 @param object The JSObject to call as a constructor. 464 @param argc An integer count of the number of arguments in argv. 465 @param argv A JSValue array of the arguments to pass to the function. 466 @param exception A pointer to a JSValueRef in which to store an uncaught exception, if any. Pass NULL if you do not care to store an uncaught exception. 467 @result The JSObject that results from calling object as a constructor, or NULL if an uncaught exception is thrown or object is not a constructor. 468 */ 136 469 JSObjectRef JSObjectCallAsConstructor(JSContextRef context, JSObjectRef object, size_t argc, JSValueRef argv[], JSValueRef* exception); 137 470 138 // Used for enumerating the names of an object's properties like a for...in loop would 471 /*! 472 @function 473 @abstract Creates an enumerator for an object's properties. 474 @param context The execution context to use. 475 @param object The object whose properties you want to enumerate. 476 @result A JSPropertyEnumerator with a list of object's properties. Ownership follows the create rule. 477 */ 139 478 JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSContextRef context, JSObjectRef object); 479 /*! 480 @function 481 @abstract Retains a property enumerator. 482 @param enumerator The JSPropertyEnumerator to retain. 483 @result A JSPropertyEnumerator that is the same as enumerator. 484 */ 140 485 JSPropertyEnumeratorRef JSPropertyEnumeratorRetain(JSPropertyEnumeratorRef enumerator); 486 /*! 487 @function 488 @abstract Releases a property enumerator. 489 @param enumerator The JSPropertyEnumerator to release. 490 */ 141 491 void JSPropertyEnumeratorRelease(JSPropertyEnumeratorRef enumerator); 492 /*! 493 @function 494 @abstract Gets a property enumerator's next property. 495 @param context The execution context to use. 496 @param enumerator The JSPropertyEnumerator whose next property you want to get. 497 @result A JSStringBuffer containing the property's name, or NULL if all properties have been enumerated. 498 */ 142 499 JSStringBufferRef JSPropertyEnumeratorGetNext(JSContextRef context, JSPropertyEnumeratorRef enumerator); 143 500 144 // Used for adding property names to a for...in enumeration 501 /*! 502 @function 503 @abstract Adds a property to a property list. 504 @discussion Use this method inside a JSGetPropertyListCallback to add a custom property to an object's property list. 505 @param propertyList The JSPropertyList to which you want to add a property. 506 @param thisObject The JSObject to which the property belongs. 507 @param propertyName A JSStringBuffer specifying the property's name. 508 */ 145 509 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringBufferRef propertyName); 146 510 -
trunk/JavaScriptCore/API/JSStringBufferRef.cpp
r15168 r15224 140 140 141 141 #if defined(__APPLE__) 142 JSStringBufferRef JSStringBufferCreate WithCFString(CFStringRef string)142 JSStringBufferRef JSStringBufferCreateCF(CFStringRef string) 143 143 { 144 144 JSLock lock; -
trunk/JavaScriptCore/API/JSStringBufferRef.h
r15168 r15224 33 33 #endif 34 34 35 #if defined(WIN32) || defined(_WIN32) 35 /*! 36 @typedef JSChar 37 @abstract A Unicode character. 38 */ 39 #if !defined(WIN32) && !defined(_WIN32) 40 typedef unsigned short JSChar; 41 #else 36 42 typedef wchar_t JSChar; 37 #else38 typedef unsigned short JSChar;39 43 #endif 40 44 45 /*! 46 @function 47 @abstract Creates a JavaScript string buffer from a buffer of Unicode characters. 48 @param chars The buffer of Unicode characters to copy into the new JSStringBuffer. 49 @param numChars The number of characters to copy from the buffer pointed to by chars. 50 @result A JSStringBuffer containing chars. Ownership follows the create rule. 51 */ 41 52 JSStringBufferRef JSStringBufferCreate(const JSChar* chars, size_t numChars); 53 /*! 54 @function 55 @abstract Creates a JavaScript string buffer from a null-terminated UTF8 string. 56 @param string The null-terminated UTF8 string to copy into the new JSStringBuffer. 57 @result A JSStringBuffer containing string. Ownership follows the create rule. 58 */ 42 59 JSStringBufferRef JSStringBufferCreateUTF8(const char* string); 43 60 61 /*! 62 @function 63 @abstract Retains a JavaScript string buffer. 64 @param buffer The JSStringBuffer to retain. 65 @result A JSStringBuffer that is the same as buffer. 66 */ 44 67 JSStringBufferRef JSStringBufferRetain(JSStringBufferRef buffer); 68 /*! 69 @function 70 @abstract Releases a JavaScript string buffer. 71 @param buffer The JSStringBuffer to release. 72 */ 45 73 void JSStringBufferRelease(JSStringBufferRef buffer); 46 74 75 /*! 76 @function 77 @abstract Returns the number of Unicode characters in a JavaScript string buffer. 78 @param buffer The JSStringBuffer whose length (in Unicode characters) you want to know. 79 @result The number of Unicode characters stored in buffer. 80 */ 47 81 size_t JSStringBufferGetLength(JSStringBufferRef buffer); 82 /*! 83 @function 84 @abstract Quickly obtains a pointer to the Unicode character buffer that 85 serves as the backing store for a JavaScript string buffer. 86 @param buffer The JSStringBuffer whose backing store you want to access. 87 @result A pointer to the Unicode character buffer that serves as buffer's 88 backing store, which will be deallocated when buffer is deallocated. 89 */ 48 90 const JSChar* JSStringBufferGetCharactersPtr(JSStringBufferRef buffer); 91 /*! 92 @function 93 @abstract Copies a JavaScript string buffer's Unicode characters into an 94 external character buffer. 95 @param inBuffer The source JSStringBuffer. 96 @param outBuffer The destination JSChar buffer into which to copy inBuffer's 97 characters. On return, outBuffer contains the requested Unicode characters. 98 @param numChars The number of Unicode characters to copy. This number must not 99 exceed the length of the string buffer. 100 */ 49 101 void JSStringBufferGetCharacters(JSStringBufferRef inBuffer, JSChar* outBuffer, size_t numChars); 50 102 103 /*! 104 @function 105 @abstract Returns the maximum number of bytes required to encode the 106 contents of a JavaScript string buffer as a null-terminated UTF8 string. 107 @param buffer The JSStringBuffer whose maximum encoded length (in bytes) you 108 want to know. 109 @result The maximum number of bytes required to encode buffer's contents 110 as a null-terminated UTF8 string. 111 */ 51 112 size_t JSStringBufferGetMaxLengthUTF8(JSStringBufferRef buffer); 52 // Returns the number of bytes written into outBuffer, including the trailing '\0' 113 /*! 114 @function 115 @abstract Converts a JavaScript string buffer's contents into a 116 null-terminated UTF8 string, and copies the result into an external byte buffer. 117 @param inBuffer The source JSStringBuffer. 118 @param outBuffer The destination byte buffer into which to copy a UTF8 string 119 representation of inBuffer. The buffer must be at least bufferSize bytes in length. 120 On return, outBuffer contains a UTF8 string representation of inBuffer. 121 If bufferSize is too small, outBuffer will contain only partial results. 122 @param bufferSize The length of the external buffer in bytes. 123 @result The number of bytes written into outBuffer (including the null-terminator byte). 124 */ 53 125 size_t JSStringBufferGetCharactersUTF8(JSStringBufferRef inBuffer, char* outBuffer, size_t bufferSize); 54 126 127 /*! 128 @function 129 @abstract Tests whether the characters in two JavaScript string buffers match. 130 @param a The first JSStringBuffer to test. 131 @param b The second JSStringBuffer to test. 132 @result true if the characters in the two buffers match, otherwise false. 133 */ 55 134 bool JSStringBufferIsEqual(JSStringBufferRef a, JSStringBufferRef b); 135 /*! 136 @function 137 @abstract Tests whether the characters in a JavaScript string buffer match 138 the characters in a null-terminated UTF8 string. 139 @param a The JSStringBuffer to test. 140 @param b The null-terminated UTF8 string to test. 141 @result true if the characters in the two buffers match, otherwise false. 142 */ 56 143 bool JSStringBufferIsEqualUTF8(JSStringBufferRef a, const char* b); 57 144 … … 59 146 #include <CoreFoundation/CoreFoundation.h> 60 147 // CFString convenience methods 61 JSStringBufferRef JSStringBufferCreateWithCFString(CFStringRef string); 148 /*! 149 @function 150 @abstract Creates a JavaScript string buffer from a CFString. 151 @discussion This function is optimized to take advantage of cases when 152 CFStringGetCharactersPtr returns a valid pointer. 153 @param string The CFString to copy into the new JSStringBuffer. 154 @result A JSStringBuffer containing string. Ownership follows the create rule. 155 */ 156 JSStringBufferRef JSStringBufferCreateCF(CFStringRef string); 157 /*! 158 @function 159 @abstract Creates a CFString form a JavaScript string buffer. 160 @param alloc The alloc parameter to pass to CFStringCreate. 161 @param buffer The JSStringBuffer to copy into the new CFString. 162 @result A CFString containing buffer. Ownership follows the create rule. 163 */ 62 164 CFStringRef CFStringCreateWithJSStringBuffer(CFAllocatorRef alloc, JSStringBufferRef buffer); 63 165 #endif // __APPLE__ -
trunk/JavaScriptCore/API/JSValueRef.cpp
r15165 r15224 136 136 } 137 137 138 bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef object)139 { 140 ExecState* exec = toJS(context); 141 JSValue* jsValue = toJS(value); 142 JSObject* js Object = toJS(object);143 if (!js Object->implementsHasInstance())138 bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef constructor) 139 { 140 ExecState* exec = toJS(context); 141 JSValue* jsValue = toJS(value); 142 JSObject* jsConstructor = toJS(constructor); 143 if (!jsConstructor->implementsHasInstance()) 144 144 return false; 145 bool result = js Object->hasInstance(exec, jsValue);145 bool result = jsConstructor->hasInstance(exec, jsValue); 146 146 if (exec->hadException()) 147 147 exec->clearException(); -
trunk/JavaScriptCore/API/JSValueRef.h
r15168 r15224 22 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 25 */ 26 26 … … 31 31 32 32 /*! 33 34 A constant identifying the type of a JSValueRef.35 @constant kJSTypeUndefined the unique undefined value 36 @constant kJSTypeNull the unique null value 37 @constant kJSBoolean a primitive boolean value, one of true or false 38 @constant kJSTypeNumber a primitive number value 39 @constant kJSTypeString a primitive string value 40 @constant kJSTypeObject an object (meaning that this JSValueRef is a JSObjectRef) 33 @enum JSTypeCode 34 @abstract A constant identifying the type of a JSValue. 35 @constant kJSTypeUndefined The unique undefined value. 36 @constant kJSTypeNull The unique null value. 37 @constant kJSTypeBoolean A primitive boolean value, one of true or false. 38 @constant kJSTypeNumber A primitive number value. 39 @constant kJSTypeString A primitive string value. 40 @constant kJSTypeObject An object value (meaning that this JSValueRef is a JSObjectRef). 41 41 */ 42 42 typedef enum { … … 54 54 55 55 /*! 56 @function JSValueGetType 57 Get the type code for a particular JavaScript value 58 @param value the JS value for which the type should be determined 59 @result a type code identifying the type 56 @function 57 @abstract Returns a JavaScript value's type code. 58 @param value The JSValue whose type you want to obtain. 59 @result A value of type JSTypeCode that identifies value's type. 60 60 */ 61 61 JSTypeCode JSValueGetType(JSValueRef value); 62 62 63 63 /*! 64 @function JSValueIsUndefined 65 Determine if value is of type undefined 66 @param value the JS value to check for undefined type 67 @result true if the value is undefined, false otherwise 64 @function 65 @abstract Tests whether a JavaScript value's type is the undefined type. 66 @param value The JSValue to test. 67 @result true if value's type is the undefined type, otherwise false. 68 68 */ 69 69 bool JSValueIsUndefined(JSValueRef value); 70 70 71 71 /*! 72 @function JSValueIsNull 73 Determine if value is of type null 74 @param value the JS value to check for null type 75 @result true if the value is null, false otherwise 72 @function 73 @abstract Tests whether a JavaScript value's type is the null type. 74 @param value The JSValue to test. 75 @result true if value's type is the null type, otherwise false. 76 76 */ 77 77 bool JSValueIsNull(JSValueRef value); 78 78 79 79 /*! 80 @function JSValueIsBoolean81 Determine if value is of type boolean 82 @param value the JS value to check for boolean type 83 @result true if the value is a boolean, false otherwise 80 @function 81 @abstract Tests whether a JavaScript value's type is the boolean type. 82 @param value The JSValue to test. 83 @result true if value's type is the boolean type, otherwise false. 84 84 */ 85 85 bool JSValueIsBoolean(JSValueRef value); 86 86 87 87 /*! 88 @function JSValueIsNumber 89 Determine if value is of type number 90 @param value the JS value to check for number type 91 @result true if the value is a number, false otherwise 88 @function 89 @abstract Tests whether a JavaScript value's type is the number type. 90 @param value The JSValue to test. 91 @result true if value's type is the number type, otherwise false. 92 92 */ 93 93 bool JSValueIsNumber(JSValueRef value); 94 94 95 95 /*! 96 @function JSValueIsString 97 Determine if value is of type string 98 @param value the JS value to check for string type 99 @result true if the value is a string, false otherwise 96 @function 97 @abstract Tests whether a JavaScript value's type is the string type. 98 @param value The JSValue to test. 99 @result true if value's type is the string type, otherwise false. 100 100 */ 101 101 bool JSValueIsString(JSValueRef value); 102 102 103 103 /*! 104 @function JSValueIsObject 105 Determine if value is of type object 106 @param value the JS value to check for object type 107 @result true if the value is an object, false otherwise 104 @function 105 @abstract Tests whether a JavaScript value's type is the object type. 106 @param value The JSValue to test. 107 @result true if value's type is the object type, otherwise false. 108 108 */ 109 109 bool JSValueIsObject(JSValueRef value); 110 111 /*! 112 @function 113 @abstract Tests whether a JavaScript value is an object with a given 114 class in its class chain. 115 @param value The JSValue to test. 116 @result true if value is an object and has jsClass in its class chain, 117 otherwise false. 118 */ 110 119 bool JSValueIsObjectOfClass(JSValueRef value, JSClassRef jsClass); 111 120 … … 113 122 114 123 /*! 115 @function JSValueIsEqual 116 Check if two values are equal by JavaScript rules, as if compared by the JS == operator 117 @param context the execution context to use 118 @param a the first value to compare 119 @param b the second value to compare 120 @result true if the two values are equal, false otherwise 124 @function 125 @abstract Tests whether two JavaScript values are equal, as compared by the JS == operator. 126 @param context The execution context to use. 127 @param a The first value to test. 128 @param b The second value to test. 129 @result true if the two values are equal, otherwise false. 121 130 */ 122 131 bool JSValueIsEqual(JSContextRef context, JSValueRef a, JSValueRef b); 123 132 124 133 /*! 125 @function JSValueIsStrictEqual 126 Check if two values are strict equal by JavaScript rules, as if compared by the JS === operator 127 @param context the execution context to use 128 @param a the first value to compare 129 @param b the second value to compare 130 @result true if the two values are strict equal, false otherwise 134 @function 135 @abstract Tests whether two JavaScript values are strict equal, as compared by the JS === operator. 136 @param context The execution context to use. 137 @param a The first value to test. 138 @param b The second value to test. 139 @result true if the two values are strict equal, otherwise false. 131 140 */ 132 141 bool JSValueIsStrictEqual(JSContextRef context, JSValueRef a, JSValueRef b); 133 142 134 143 /*! 135 @function JSValueIsInstanceOf 136 Check if a value is an instance of a particular object; generally this means the object 137 was used as the constructor for that instance 138 @param context the execution context to use 139 @param value the possible instance 140 @param object the possible constructor 141 @result true if value is an instance of object 142 */ 143 bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef object); 144 @function 145 @abstract Tests whether a JavaScript value is an object constructed by 146 a given constructor, as compared by the JS instanceof operator. 147 @param context The execution context to use. 148 @param value The JSValue to test. 149 @param object The constructor to test against. 150 @result true if value is an object constructed by constructor, as compared 151 by the JS instanceof operator, otherwise false. 152 */ 153 bool JSValueIsInstanceOf(JSContextRef context, JSValueRef value, JSObjectRef constructor); 144 154 145 155 // Creating values 146 156 147 157 /*! 148 @function JSUndefinedMake 149 Make avalue of the undefined type.150 @resultThe unique undefined value.158 @function 159 @abstract Creates a JavaScript value of the undefined type. 160 @result The unique undefined value. 151 161 */ 152 162 JSValueRef JSUndefinedMake(void); 153 163 154 164 /*! 155 @function JSNullMake 156 Make avalue of the null type.157 @result the unique null value 165 @function 166 @abstract Creates a JavaScript value of the null type. 167 @result The unique null value. 158 168 */ 159 169 JSValueRef JSNullMake(void); 160 170 161 171 /*! 162 @function JSBooleanMake 163 Make avalue of the boolean type.164 @param value whether the returned value should be true or false 165 @result a JS true or false boolean value, as appropriate 172 @function 173 @abstract Creates a JavaScript value of the boolean type. 174 @param value The boolean value to assign to the newly created JSValue. 175 @result A JSValue of the boolean type, representing the boolean value of value. 166 176 */ 167 177 … … 169 179 170 180 /*! 171 @function JSNumberMake 172 Make avalue of the number type.173 @param value the numberic value of the number to make 174 @result a JS number corresponding to value 181 @function 182 @abstract Creates a JavaScript value of the number type. 183 @param value The numeric value to assign to the newly created JSValue. 184 @result A JSValue of the number type, representing the numeric value of value. 175 185 */ 176 186 JSValueRef JSNumberMake(double value); 177 187 178 188 /*! 179 @function JSStringMake 180 Make a value of the string type. 181 @param buffer the internal string contents for the string value 182 @result a JS string value that has the value of the buffer 189 @function 190 @abstract Creates a JavaScript value of the string type. 191 @param buffer The JSStringBuffer to assign to the newly created JSValue. The 192 newly created JSValue retains buffer, and releases it upon garbage collection. 193 @result A JSValue of the string type, representing the string value of buffer. 183 194 */ 184 195 JSValueRef JSStringMake(JSStringBufferRef buffer); … … 187 198 188 199 /*! 189 @function JSValueToBoolean190 Convert a JavaScript value to boolean and return the resulting boolean 191 @param context the execution context to use 192 @param value the value to convert 193 @result the boolean result of conversion 200 @function 201 @abstract Converts a JavaScript value to boolean and returns the resulting boolean. 202 @param context The execution context to use. 203 @param value The JSValue to convert. 204 @result The boolean result of conversion. 194 205 */ 195 206 bool JSValueToBoolean(JSContextRef context, JSValueRef value); 196 207 197 208 /*! 198 @function JSValueToNumber 199 Convert a JavaScript value to number and return the resulting number 200 @param context the execution context to use 201 @param value the value to convert 202 @result the numeric result of conversion, or NaN if conversion fails 209 @function 210 @abstract Converts a JavaScript value to number and returns the resulting number. 211 @param context The execution context to use. 212 @param value The JSValue to convert. 213 @result The numeric result of conversion, or NaN if conversion fails. 203 214 */ 204 215 double JSValueToNumber(JSContextRef context, JSValueRef value); 205 216 206 217 /*! 207 @function JSValueCopyStringValue 208 Convert a JavaScript value to string and copy the resulting string into a newly allocated character buffer 209 @param context the execution context to use 210 @param value the value to convert 211 @result a character buffer containing the result of conversion, or an empty character buffer if conversion fails 218 @function 219 @abstract Converts a JavaScript value to string and copies the resulting 220 string into a newly allocated JavaScript string buffer. 221 @param context The execution context to use. 222 @param value The JSValue to convert. 223 @result A JSStringBuffer containing the result of conversion, or an empty 224 string buffer if conversion fails. Ownership follows the copy rule. 212 225 */ 213 226 JSStringBufferRef JSValueCopyStringValue(JSContextRef context, JSValueRef value); 214 227 215 228 /*! 216 @function JSValueToObject 217 Convert a JavaScript value to object and return the resulting object 218 @param context the execution context to use 219 @param value the value to convert 220 @result the object result of conversion, or NULL if conversion fails 229 @function 230 @abstract Converts a JavaScript value to object and returns the resulting object. 231 @param context The execution context to use. 232 @param value The JSValue to convert. 233 @result The JSObject result of conversion, or NULL if conversion fails. 221 234 */ 222 235 JSObjectRef JSValueToObject(JSContextRef context, JSValueRef value); … … 224 237 // Garbage collection 225 238 /*! 226 @function JSGCProtect 227 Protect a JavaScript value from garbage collection; a value may be 228 protected multiple times and must be unprotected an equal number of 229 times to become collectable again. 239 @function 240 @abstract Protects a JavaScript value from garbage collection. 241 @param value The JSValue to protect. 242 @discussion A value may be protected multiple times and must be unprotected an 243 equal number of times before becoming eligible for garbage collection. 230 244 */ 231 245 void JSGCProtect(JSValueRef value); 232 246 233 247 /*! 234 @function JSGCProtect 235 Stop protecting a JavaScript value from garbage collection; a value may be 236 protected multiple times and must be unprotected an equal number of 237 times to become collectable again. 248 @function 249 @abstract Unprotects a JavaScript value from garbage collection. 250 @param value The JSValue to unprotect. 251 @discussion A value may be protected multiple times and must be unprotected an 252 equal number of times before becoming eligible for garbage collection. 238 253 */ 239 254 void JSGCUnprotect(JSValueRef value); 240 255 241 /*! 242 @function JSGCCollect 243 Immediately perform a JavaScript garbage collection. JavaScript 244 values that are on the machine stack, in a register, protected, set 245 as the global object of any interpreter, or reachable from any such 246 value will not be collected. It is not normally necessary to call 247 this function directly; the JS runtime will garbage collect as 248 needed. 256 /*! 257 @function 258 @abstract Performs a JavaScript garbage collection. 259 @discussion JavaScript values that are on the machine stack, in a register, 260 protected by JSGCProtect, set as the global object of an execution context, or reachable from any such 261 value will not be collected. It is not normally necessary to call this function 262 directly; the JS runtime will garbage collect as needed. 249 263 */ 250 264 void JSGCCollect(void); -
trunk/JavaScriptCore/API/minidom.c
r15168 r15224 37 37 UNUSED_PARAM(argv); 38 38 39 JSContextRef context = JSContextCreate(NULL , NULL);39 JSContextRef context = JSContextCreate(NULL); 40 40 JSObjectRef globalObject = JSContextGetGlobalObject(context); 41 41 -
trunk/JavaScriptCore/API/testapi.c
r15213 r15224 130 130 } 131 131 132 static bool MyObject_hasProperty(JSObjectRef object, JSStringBufferRef propertyName) 133 { 132 static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName) 133 { 134 UNUSED_PARAM(context); 134 135 UNUSED_PARAM(object); 135 136 … … 166 167 } 167 168 168 static bool MyObject_setProperty(JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value) 169 { 169 static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName, JSValueRef value) 170 { 171 UNUSED_PARAM(context); 170 172 UNUSED_PARAM(object); 171 173 UNUSED_PARAM(value); … … 177 179 } 178 180 179 static bool MyObject_deleteProperty(JSObjectRef object, JSStringBufferRef propertyName) 180 { 181 static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSStringBufferRef propertyName) 182 { 183 UNUSED_PARAM(context); 181 184 UNUSED_PARAM(object); 182 185 … … 187 190 } 188 191 189 static void MyObject_getPropertyList(JSObjectRef object, JSPropertyListRef propertyList) 190 { 192 static void MyObject_getPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList) 193 { 194 UNUSED_PARAM(context); 195 191 196 JSStringBufferRef propertyNameBuf; 192 197 … … 223 228 } 224 229 225 static bool MyObject_convertToType(JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue) 226 { 230 static bool MyObject_convertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue) 231 { 232 UNUSED_PARAM(context); 227 233 UNUSED_PARAM(object); 228 234 … … 268 274 static JSClassRef jsClass; 269 275 if (!jsClass) { 270 jsClass = JSClassCreate( context,NULL, NULL, &MyObject_callbacks, NULL);276 jsClass = JSClassCreate(NULL, NULL, &MyObject_callbacks, NULL); 271 277 } 272 278 … … 312 318 UNUSED_PARAM(argv); 313 319 314 context = JSContextCreate(NULL , NULL);320 context = JSContextCreate(NULL); 315 321 316 322 JSValueRef jsUndefined = JSUndefinedMake(); … … 339 345 kCFAllocatorNull); 340 346 341 JSStringBufferRef jsCFStringBuf = JSStringBufferCreate WithCFString(cfString);347 JSStringBufferRef jsCFStringBuf = JSStringBufferCreateCF(cfString); 342 348 JSValueRef jsCFString = JSStringMake(jsCFStringBuf); 343 349 344 350 CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8); 345 351 346 JSStringBufferRef jsCFEmptyStringBuf = JSStringBufferCreate WithCFString(cfEmptyString);352 JSStringBufferRef jsCFEmptyStringBuf = JSStringBufferCreateCF(cfEmptyString); 347 353 JSValueRef jsCFEmptyString = JSStringMake(jsCFEmptyStringBuf); 348 354 … … 500 506 JSValueRef result; 501 507 JSValueRef exception; 508 JSValueRef v; 509 JSObjectRef o; 502 510 503 511 result = JSEvaluate(context, goodSyntaxBuf, NULL, NULL, 1, NULL); 504 512 assert(result); 505 513 assert(JSValueIsEqual(context, result, jsOne)); 506 514 515 exception = NULL; 507 516 result = JSEvaluate(context, badSyntaxBuf, NULL, NULL, 1, &exception); 508 517 assert(!result); … … 527 536 JSStringBufferRelease(badSyntaxBuf); 528 537 538 v = NULL; 529 539 JSStringBufferRef arrayBuf = JSStringBufferCreateUTF8("Array"); 530 JSValueRef v;531 540 assert(JSObjectGetProperty(context, globalObject, arrayBuf, &v)); 532 541 JSObjectRef arrayConstructor = JSValueToObject(context, v); … … 539 548 JSStringBufferRef functionBuf; 540 549 550 v = NULL; 551 exception = NULL; 541 552 functionBuf = JSStringBufferCreateUTF8("rreturn Array;"); 542 assert(!JSFunctionMakeWithBody(context, functionBuf, NULL, 1)); 553 JSStringBufferRef lineBuf = JSStringBufferCreateUTF8("line"); 554 assert(!JSFunctionMakeWithBody(context, functionBuf, NULL, 1, &exception)); 555 assert(JSValueIsObject(exception)); 556 assert(JSObjectGetProperty(context, exception, lineBuf, &v)); 557 assertEqualsAsNumber(v, 2); // FIXME: Lexer::setCode bumps startingLineNumber by 1 -- we need to change internal callers so that it doesn't have to (saying '0' to mean '1' in the API would be really confusing -- it's really confusing internally, in fact) 543 558 JSStringBufferRelease(functionBuf); 559 JSStringBufferRelease(lineBuf); 544 560 545 561 functionBuf = JSStringBufferCreateUTF8("return Array;"); 546 JSObjectRef function = JSFunctionMakeWithBody(context, functionBuf, NULL, 1 );562 JSObjectRef function = JSFunctionMakeWithBody(context, functionBuf, NULL, 1, NULL); 547 563 JSStringBufferRelease(functionBuf); 548 564 … … 558 574 559 575 JSStringBufferRef printBuf = JSStringBufferCreateUTF8("print"); 560 JSObjectSetProperty(context, globalObject, printBuf, JSFunctionMake(context, print_callAsFunction), kJSPropertyAttributeNone); 576 JSValueRef printFunction = JSFunctionMake(context, print_callAsFunction); 577 JSObjectSetProperty(context, globalObject, printBuf, printFunction, kJSPropertyAttributeNone); 561 578 JSStringBufferRelease(printBuf); 579 580 assert(JSObjectSetPrivate(printFunction, (void*)1)); 581 assert(JSObjectGetPrivate(printFunction) == (void*)1); 562 582 563 583 JSStringBufferRef myConstructorBuf = JSStringBufferCreateUTF8("MyConstructor"); 564 JSObjectSetProperty(context, globalObject, myConstructorBuf, JSConstructorMake(context, myConstructor_callAsConstructor), kJSPropertyAttributeNone); 584 JSValueRef myConstructor = JSConstructorMake(context, myConstructor_callAsConstructor); 585 JSObjectSetProperty(context, globalObject, myConstructorBuf, myConstructor, kJSPropertyAttributeNone); 565 586 JSStringBufferRelease(myConstructorBuf); 566 567 JSClassRef nullCallbacksClass = JSClassCreate(context, NULL, NULL, NULL, NULL); 587 588 assert(JSObjectSetPrivate(myConstructor, (void*)1)); 589 assert(JSObjectGetPrivate(myConstructor) == (void*)1); 590 591 o = JSObjectMake(context, NULL, NULL); 592 JSObjectSetProperty(context, o, jsOneString, JSNumberMake(1), kJSPropertyAttributeNone); 593 JSObjectSetProperty(context, o, jsCFString, JSNumberMake(1), kJSPropertyAttributeDontEnum); 594 JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(context, o); 595 int count = 0; 596 while (JSPropertyEnumeratorGetNext(context, enumerator)) 597 ++count; 598 JSPropertyEnumeratorRelease(enumerator); 599 assert(count == 1); // jsCFString should not be enumerated 600 601 JSClassRef nullCallbacksClass = JSClassCreate(NULL, NULL, NULL, NULL); 568 602 JSClassRelease(nullCallbacksClass); 569 603 -
trunk/JavaScriptCore/ChangeLog
r15213 r15224 1 2006-07-06 Geoffrey Garen <[email protected]> 2 3 Reviewed by Maciej. 4 5 More API action. 6 7 - Headerdoc finished 8 9 Semantic Changes: 10 - Added a JSContextRef argument to many functions, because you need a 11 JSContextRef for doing virtually anything. I expect to add this argument 12 to even more functions in a future patch. 13 14 - Removed the globalObjectPrototype argument to JSContextCreate because 15 you can't create an object until you have a context, so it's impossible 16 to pass a prototype object to JSContextCreate. That's OK because (1) there's 17 no reason to give the global object a prototype and (2) if you really want 18 to, you can just use a separate call to JSObjectSetPrototype. 19 20 - Removed the JSClassRef argument to JSClassCreate because it was unnecessary, 21 and you need to be able to make the global object's class before you've 22 created a JSContext. 23 24 - Added an optional exception parameter to JSFunctionMakeWithBody because anything 25 less would be uncivilized. 26 27 - Made the return value parameter to JSObjectGetProperty optional to match 28 all other return value parameters in the API. 29 30 - Made JSObjectSetPrivate/JSObjectGetPrivate work on JSCallbackFunctions 31 and JSCallbackConstructors. You could use an abstract base class or strategic 32 placement of m_privateData in the class structure to implement this, but 33 the former seemed like overkill, and the latter seemed too dangerous. 34 35 - Fixed a bug where JSPropertyEnumeratorGetNext would skip the first property. 36 37 Cosmetic Changes: 38 - Reversed the logic of the JSChar #ifdef to avoid confusing headerdoc 39 40 - Removed function names from @function declarations because headeroc 41 can parse them automatically, and I wanted to rule out manual mismatch. 42 43 - Changed Error::create to take a const UString& instead of a UString* 44 because it was looking at me funny. 45 46 - Renamed JSStringBufferCreateWithCFString to JSStringBufferCreateCF 47 because the latter is more concise and it matches JSStringBufferCreateUTF8. 48 49 * API/JSCallbackObject.cpp: 50 (KJS::JSCallbackObject::getOwnPropertySlot): 51 (KJS::JSCallbackObject::put): 52 (KJS::JSCallbackObject::deleteProperty): 53 (KJS::JSCallbackObject::getPropertyList): 54 (KJS::JSCallbackObject::toBoolean): 55 (KJS::JSCallbackObject::toNumber): 56 (KJS::JSCallbackObject::toString): 57 * API/JSClassRef.cpp: 58 (JSClassCreate): 59 * API/JSContextRef.cpp: 60 (JSContextCreate): 61 (JSContextSetException): 62 * API/JSContextRef.h: 63 * API/JSNode.c: 64 (JSNodePrototype_class): 65 (JSNode_class): 66 * API/JSNodeList.c: 67 (JSNodeListPrototype_class): 68 (JSNodeList_class): 69 * API/JSObjectRef.cpp: 70 (JSObjectGetProperty): 71 (JSObjectGetPrivate): 72 (JSObjectSetPrivate): 73 (JSObjectCallAsFunction): 74 (JSObjectCallAsConstructor): 75 (JSPropertyEnumeratorGetNext): 76 * API/JSObjectRef.h: 77 * API/JSStringBufferRef.cpp: 78 (JSStringBufferCreateCF): 79 * API/JSStringBufferRef.h: 80 * API/JSValueRef.cpp: 81 (JSValueIsInstanceOf): 82 * API/JSValueRef.h: 83 * API/minidom.c: 84 (main): 85 * API/minidom.js: 86 * API/testapi.c: 87 (MyObject_hasProperty): 88 (MyObject_setProperty): 89 (MyObject_deleteProperty): 90 (MyObject_getPropertyList): 91 (MyObject_convertToType): 92 (MyObject_class): 93 (main): 94 * JavaScriptCore.exp: 95 1 96 2006-07-07 Geoffrey Garen <[email protected]> 2 97 -
trunk/JavaScriptCore/JavaScriptCore.exp
r15168 r15224 44 44 _JSStringBufferCreate 45 45 _JSStringBufferCreateUTF8 46 _JSStringBufferCreate WithCFString46 _JSStringBufferCreateCF 47 47 _JSStringBufferGetCharacters 48 48 _JSStringBufferGetCharactersPtr -
trunk/JavaScriptCore/kjs/function_object.cpp
r15026 r15224 202 202 // we can't return a Completion(Throw) here, so just set the exception 203 203 // and return it 204 return throwError(exec, SyntaxError, errMsg, errLine, sid, &sourceURL);204 return throwError(exec, SyntaxError, errMsg, errLine, sid, sourceURL); 205 205 206 206 ScopeChain scopeChain; -
trunk/JavaScriptCore/kjs/interpreter.cpp
r15163 r15224 426 426 RefPtr<ProgramNode> progNode = Parser::parse(sourceURL, startingLineNumber, code, codeLength, 0, &errLine, &errMsg); 427 427 if (!progNode) 428 return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, 0, &sourceURL));428 return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, 0, sourceURL)); 429 429 return Completion(Normal); 430 430 } … … 458 458 // no program node means a syntax error occurred 459 459 if (!progNode) 460 return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sid, &sourceURL));460 return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sid, sourceURL)); 461 461 462 462 m_globalExec.clearException(); -
trunk/JavaScriptCore/kjs/nodes.cpp
r15155 r15224 196 196 Completion Node::createErrorCompletion(ExecState* exec, ErrorType e, const char *msg) 197 197 { 198 return Completion(Throw, Error::create(exec, e, msg, lineNo(), currentSourceId(exec), ¤tSourceURL(exec)));198 return Completion(Throw, Error::create(exec, e, msg, lineNo(), currentSourceId(exec), currentSourceURL(exec))); 199 199 } 200 200 … … 203 203 UString message = msg; 204 204 substitute(message, ident.ustring()); 205 return Completion(Throw, Error::create(exec, e, message, lineNo(), currentSourceId(exec), ¤tSourceURL(exec)));205 return Completion(Throw, Error::create(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec))); 206 206 } 207 207 208 208 JSValue *Node::throwError(ExecState* exec, ErrorType e, const char *msg) 209 209 { 210 return KJS::throwError(exec, e, msg, lineNo(), currentSourceId(exec), ¤tSourceURL(exec));210 return KJS::throwError(exec, e, msg, lineNo(), currentSourceId(exec), currentSourceURL(exec)); 211 211 } 212 212 … … 216 216 substitute(message, v->toString(exec)); 217 217 substitute(message, expr->toString()); 218 return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), ¤tSourceURL(exec));218 return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec)); 219 219 } 220 220 … … 224 224 UString message = msg; 225 225 substitute(message, label.ustring()); 226 return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), ¤tSourceURL(exec));226 return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec)); 227 227 } 228 228 … … 233 233 substitute(message, e1->toString()); 234 234 substitute(message, e2->toString()); 235 return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), ¤tSourceURL(exec));235 return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec)); 236 236 } 237 237 … … 242 242 substitute(message, expr->toString()); 243 243 substitute(message, label.ustring()); 244 return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), ¤tSourceURL(exec));244 return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec)); 245 245 } 246 246 … … 250 250 substitute(message, v->toString(exec)); 251 251 substitute(message, label.ustring()); 252 return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), ¤tSourceURL(exec));252 return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec)); 253 253 } 254 254 -
trunk/JavaScriptCore/kjs/object.cpp
r14951 r15224 563 563 564 564 JSObject *Error::create(ExecState *exec, ErrorType errtype, const UString &message, 565 int lineno, int sourceId, const UString *sourceURL)565 int lineno, int sourceId, const UString &sourceURL) 566 566 { 567 567 JSObject *cons; … … 602 602 err->put(exec, "sourceId", jsNumber(sourceId)); 603 603 604 if( sourceURL)605 err->put(exec,"sourceURL", jsString(*sourceURL));604 if(!sourceURL.isNull()) 605 err->put(exec, "sourceURL", jsString(sourceURL)); 606 606 607 607 return err; … … 646 646 } 647 647 648 JSObject *throwError(ExecState *exec, ErrorType type, const UString &message, int line, int sourceId, const UString *sourceURL)648 JSObject *throwError(ExecState *exec, ErrorType type, const UString &message, int line, int sourceId, const UString &sourceURL) 649 649 { 650 650 JSObject *error = Error::create(exec, type, message, line, sourceId, sourceURL); -
trunk/JavaScriptCore/kjs/object.h
r14951 r15224 554 554 * @param sourceURL Optional source URL. 555 555 */ 556 static JSObject *create(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString *sourceURL);556 static JSObject *create(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString &sourceURL); 557 557 static JSObject *create(ExecState *, ErrorType, const char *message); 558 558 … … 563 563 }; 564 564 565 JSObject *throwError(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString *sourceURL);565 JSObject *throwError(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString &sourceURL); 566 566 JSObject *throwError(ExecState *, ErrorType, const UString &message); 567 567 JSObject *throwError(ExecState *, ErrorType, const char *message);
Note:
See TracChangeset
for help on using the changeset viewer.