Changeset 15376 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jul 12, 2006, 1:12:08 AM (19 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/APICast.h
r15317 r15376 50 50 } 51 51 52 inline KJS::UString::Rep* toJS(JS InternalStringRef b)52 inline KJS::UString::Rep* toJS(JSStringRef b) 53 53 { 54 54 return reinterpret_cast<KJS::UString::Rep*>(b); … … 75 75 } 76 76 77 inline JS InternalStringRef toRef(KJS::UString::Rep* s)77 inline JSStringRef toRef(KJS::UString::Rep* s) 78 78 { 79 return reinterpret_cast<JS InternalStringRef>(s);79 return reinterpret_cast<JSStringRef>(s); 80 80 } 81 81 -
trunk/JavaScriptCore/API/JSBase.h
r15310 r15376 32 32 /*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */ 33 33 typedef struct __JSContext* JSContextRef; 34 /*! @typedef JS InternalString A UTF16 character buffer. The fundamental string representation in JavaScript. */35 typedef struct __JS InternalString* JSInternalStringRef;34 /*! @typedef JSString A UTF16 character buffer. The fundamental string representation in JavaScript. */ 35 typedef struct __JSString* JSStringRef; 36 36 /*! @typedef JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior. */ 37 37 typedef struct __JSClass* JSClassRef; … … 46 46 /*! @typedef JSValueRef A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them. */ 47 47 typedef const struct __JSValue* JSValueRef; 48 49 48 /*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */ 50 49 typedef struct __JSValue* JSObjectRef; -
trunk/JavaScriptCore/API/JSCallbackConstructor.cpp
r15317 r15376 32 32 const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0, 0 }; 33 33 34 JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JS CallAsConstructorCallback callback)34 JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JSObjectCallAsConstructorCallback callback) 35 35 : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()) 36 36 , m_callback(callback) -
trunk/JavaScriptCore/API/JSCallbackConstructor.h
r15133 r15376 36 36 { 37 37 public: 38 JSCallbackConstructor(ExecState* exec, JS CallAsConstructorCallback callback);38 JSCallbackConstructor(ExecState* exec, JSObjectCallAsConstructorCallback callback); 39 39 40 40 virtual bool implementsConstruct() const; … … 52 52 53 53 void* m_privateData; 54 JS CallAsConstructorCallback m_callback;54 JSObjectCallAsConstructorCallback m_callback; 55 55 }; 56 56 -
trunk/JavaScriptCore/API/JSCallbackFunction.cpp
r15317 r15376 34 34 const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunctionImp::info, 0, 0 }; 35 35 36 JSCallbackFunction::JSCallbackFunction(ExecState* exec, JS CallAsFunctionCallback callback)36 JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback) 37 37 : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype())) 38 38 , m_callback(callback) -
trunk/JavaScriptCore/API/JSCallbackFunction.h
r15133 r15376 37 37 { 38 38 public: 39 JSCallbackFunction(ExecState* exec, JS CallAsFunctionCallback callback);39 JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback); 40 40 41 41 virtual bool implementsCall() const; … … 53 53 54 54 void* m_privateData; 55 JS CallAsFunctionCallback m_callback;55 JSObjectCallAsFunctionCallback m_callback; 56 56 }; 57 57 -
trunk/JavaScriptCore/API/JSCallbackObject.cpp
r15317 r15376 60 60 61 61 do { 62 if (JS InitializeCallback initialize = jsClass->callbacks.initialize)62 if (JSObjectInitializeCallback initialize = jsClass->callbacks.initialize) 63 63 initialize(context, thisRef, toRef(exec->exceptionSlot())); 64 64 } while ((jsClass = jsClass->parent)); … … 70 70 71 71 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) 72 if (JS FinalizeCallback finalize = jsClass->callbacks.finalize)72 if (JSObjectFinalizeCallback finalize = jsClass->callbacks.finalize) 73 73 finalize(thisRef); 74 74 … … 85 85 JSContextRef context = toRef(exec); 86 86 JSObjectRef thisRef = toRef(this); 87 JS InternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());87 JSStringRef propertyNameRef = toRef(propertyName.ustring().rep()); 88 88 89 89 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 90 90 // optional optimization to bypass getProperty in cases when we only need to know if the property exists 91 if (JS HasPropertyCallback hasPropertyCallback= jsClass->callbacks.hasProperty) {92 if (hasProperty Callback(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {91 if (JSObjectHasPropertyCallback hasProperty = jsClass->callbacks.hasProperty) { 92 if (hasProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) { 93 93 slot.setCustom(this, callbackGetter); 94 94 return true; 95 95 } 96 } else if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty) { 97 JSValueRef returnValue; 98 if (getPropertyCallback(context, thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot()))) { 96 } else if (JSObjectGetPropertyCallback getProperty = jsClass->callbacks.getProperty) { 97 if (JSValueRef value = getProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) { 99 98 // cache the value so we don't have to compute it again 100 99 // FIXME: This violates the PropertySlot design a little bit. 101 100 // We should either use this optimization everywhere, or nowhere. 102 slot.setCustom(reinterpret_cast<JSObject*>(toJS( returnValue)), cachedValueGetter);101 slot.setCustom(reinterpret_cast<JSObject*>(toJS(value)), cachedValueGetter); 103 102 return true; 104 103 } … … 134 133 JSContextRef context = toRef(exec); 135 134 JSObjectRef thisRef = toRef(this); 136 JS InternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());135 JSStringRef propertyNameRef = toRef(propertyName.ustring().rep()); 137 136 JSValueRef valueRef = toRef(value); 138 137 139 138 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 140 if (JS SetPropertyCallback setPropertyCallback= jsClass->callbacks.setProperty) {141 if (setProperty Callback(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))139 if (JSObjectSetPropertyCallback setProperty = jsClass->callbacks.setProperty) { 140 if (setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot()))) 142 141 return; 143 142 } … … 147 146 if (entry->attributes & kJSPropertyAttributeReadOnly) 148 147 return; 149 if (JS SetPropertyCallback setPropertyCallback= entry->setProperty) {150 if (setProperty Callback(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))148 if (JSObjectSetPropertyCallback setProperty = entry->setProperty) { 149 if (setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot()))) 151 150 return; 152 151 } … … 163 162 } 164 163 } 164 165 165 return JSObject::put(exec, propertyName, value, attr); 166 166 } … … 175 175 JSContextRef context = toRef(exec); 176 176 JSObjectRef thisRef = toRef(this); 177 JS InternalStringRef propertyNameRef = toRef(propertyName.ustring().rep());178 179 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 180 if (JS DeletePropertyCallback deletePropertyCallback= jsClass->callbacks.deleteProperty) {181 if (deleteProperty Callback(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))177 JSStringRef propertyNameRef = toRef(propertyName.ustring().rep()); 178 179 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 180 if (JSObjectDeletePropertyCallback deleteProperty = jsClass->callbacks.deleteProperty) { 181 if (deleteProperty(context, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) 182 182 return true; 183 183 } … … 199 199 } 200 200 } 201 201 202 return JSObject::deleteProperty(exec, propertyName); 202 203 } … … 222 223 223 224 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 224 if (JS CallAsConstructorCallback callAsConstructorCallback= jsClass->callbacks.callAsConstructor) {225 if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callbacks.callAsConstructor) { 225 226 size_t argc = args.size(); 226 227 JSValueRef argv[argc]; 227 228 for (size_t i = 0; i < argc; i++) 228 229 argv[i] = toRef(args[i]); 229 return toJS(callAsConstructor Callback(execRef, thisRef, argc, argv, toRef(exec->exceptionSlot())));230 return toJS(callAsConstructor(execRef, thisRef, argc, argv, toRef(exec->exceptionSlot()))); 230 231 } 231 232 } … … 251 252 252 253 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 253 if (JS CallAsFunctionCallback callAsFunctionCallback= jsClass->callbacks.callAsFunction) {254 if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callbacks.callAsFunction) { 254 255 size_t argc = args.size(); 255 256 JSValueRef argv[argc]; 256 257 for (size_t i = 0; i < argc; i++) 257 258 argv[i] = toRef(args[i]); 258 return toJS(callAsFunction Callback(execRef, thisRef, thisObjRef, argc, argv, toRef(exec->exceptionSlot())));259 return toJS(callAsFunction(execRef, thisRef, thisObjRef, argc, argv, toRef(exec->exceptionSlot()))); 259 260 } 260 261 } … … 270 271 271 272 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 272 if (JS GetPropertyListCallback getPropertyListCallback = jsClass->callbacks.getPropertyList)273 getPropertyListCallback(context, thisRef, toRef(&propertyList), toRef(exec->exceptionSlot()));273 if (JSObjectAddPropertiesToListCallback addPropertiesToList = jsClass->callbacks.addPropertiesToList) 274 addPropertiesToList(context, thisRef, toRef(&propertyList), toRef(exec->exceptionSlot())); 274 275 275 276 if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) { … … 304 305 JSObjectRef thisRef = toRef(this); 305 306 306 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 307 if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) { 308 JSValueRef returnValue; 309 if (convertToTypeCallback(context, thisRef, kJSTypeBoolean, &returnValue, toRef(exec->exceptionSlot()))) 310 return toJS(returnValue)->getBoolean(); 311 } 312 } 307 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) 308 if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType) 309 if (JSValueRef value = convertToType(context, thisRef, kJSTypeBoolean, toRef(exec->exceptionSlot()))) 310 return toJS(value)->getBoolean(); 311 313 312 return JSObject::toBoolean(exec); 314 313 } … … 319 318 JSObjectRef thisRef = toRef(this); 320 319 321 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 322 if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) { 323 JSValueRef returnValue; 324 if (convertToTypeCallback(context, thisRef, kJSTypeNumber, &returnValue, toRef(exec->exceptionSlot()))) 325 return toJS(returnValue)->getNumber(); 326 } 327 } 320 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) 321 if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType) 322 if (JSValueRef value = convertToType(context, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot()))) 323 return toJS(value)->getNumber(); 324 328 325 return JSObject::toNumber(exec); 329 326 } … … 334 331 JSObjectRef thisRef = toRef(this); 335 332 336 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) { 337 if (JSConvertToTypeCallback convertToTypeCallback = jsClass->callbacks.convertToType) { 338 JSValueRef returnValue; 339 if (convertToTypeCallback(context, thisRef, kJSTypeString, &returnValue, toRef(exec->exceptionSlot()))) 340 return toJS(returnValue)->getString(); 341 } 342 } 333 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parent) 334 if (JSObjectConvertToTypeCallback convertToType = jsClass->callbacks.convertToType) 335 if (JSValueRef value = convertToType(context, thisRef, kJSTypeString, toRef(exec->exceptionSlot()))) 336 return toJS(value)->getString(); 337 343 338 return JSObject::toString(exec); 344 339 } … … 359 354 if (jsClass == c) 360 355 return true; 356 361 357 return false; 362 358 } … … 375 371 376 372 JSObjectRef thisRef = toRef(thisObj); 377 JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep()); 378 379 for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent) { 380 JSValueRef returnValue; 381 373 JSStringRef propertyNameRef = toRef(propertyName.ustring().rep()); 374 375 for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent) 382 376 if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) 383 377 if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) 384 if (JSGetPropertyCallback getPropertyCallback = entry->getProperty) 385 if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot()))) 386 return toJS(returnValue); 387 } 378 if (JSObjectGetPropertyCallback getProperty = entry->getProperty) 379 if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) 380 return toJS(value); 388 381 389 382 return jsUndefined(); … … 401 394 if (__JSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) { 402 395 if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) { 403 JSValue* v = toJS(JS FunctionMake(toRef(exec), entry->callAsFunction));396 JSValue* v = toJS(JSObjectMakeFunction(toRef(exec), entry->callAsFunction)); 404 397 thisObj->putDirect(propertyName, v, entry->attributes); 405 398 return v; … … 417 410 418 411 JSObjectRef thisRef = toRef(thisObj); 419 JSInternalStringRef propertyNameRef = toRef(propertyName.ustring().rep()); 420 421 for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent) { 422 JSValueRef returnValue; 423 424 if (JSGetPropertyCallback getPropertyCallback = jsClass->callbacks.getProperty) 425 if (getPropertyCallback(toRef(exec), thisRef, propertyNameRef, &returnValue, toRef(exec->exceptionSlot()))) 426 return toJS(returnValue); 427 } 412 JSStringRef propertyNameRef = toRef(propertyName.ustring().rep()); 413 414 for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parent) 415 if (JSObjectGetPropertyCallback getProperty = jsClass->callbacks.getProperty) 416 if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) 417 return toJS(value); 428 418 429 419 return jsUndefined(); -
trunk/JavaScriptCore/API/JSClassRef.h
r15133 r15376 33 33 34 34 struct StaticValueEntry { 35 StaticValueEntry(JS GetPropertyCallback _getProperty, JSSetPropertyCallback _setProperty, JSPropertyAttributes _attributes)35 StaticValueEntry(JSObjectGetPropertyCallback _getProperty, JSObjectSetPropertyCallback _setProperty, JSPropertyAttributes _attributes) 36 36 : getProperty(_getProperty), setProperty(_setProperty), attributes(_attributes) 37 37 { 38 38 } 39 39 40 JS GetPropertyCallback getProperty;41 JS SetPropertyCallback setProperty;40 JSObjectGetPropertyCallback getProperty; 41 JSObjectSetPropertyCallback setProperty; 42 42 JSPropertyAttributes attributes; 43 43 }; 44 44 45 45 struct StaticFunctionEntry { 46 StaticFunctionEntry(JS CallAsFunctionCallback _callAsFunction, JSPropertyAttributes _attributes)47 : callAsFunction(_callAsFunction), attributes(_attributes)46 StaticFunctionEntry(JSObjectCallAsFunctionCallback _callAsFunction, JSPropertyAttributes _attributes) 47 : callAsFunction(_callAsFunction), attributes(_attributes) 48 48 { 49 49 } 50 50 51 JS CallAsFunctionCallback callAsFunction;51 JSObjectCallAsFunctionCallback callAsFunction; 52 52 JSPropertyAttributes attributes; 53 53 }; 54 54 55 55 struct __JSClass { 56 __JSClass() : refCount(0), staticValues(0), staticFunctions(0) 56 __JSClass() 57 : refCount(0), staticValues(0), staticFunctions(0) 57 58 { 58 59 } -
trunk/JavaScriptCore/API/JSContextRef.cpp
r15317 r15376 63 63 } 64 64 65 JSValueRef JSEvaluate(JSContextRef context, JS InternalStringRef script, JSObjectRef thisObject, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception)65 JSValueRef JSEvaluate(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) 66 66 { 67 67 JSLock lock; … … 86 86 } 87 87 88 bool JSCheckSyntax(JSContextRef context, JS InternalStringRef script, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception)88 bool JSCheckSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) 89 89 { 90 90 JSLock lock; -
trunk/JavaScriptCore/API/JSContextRef.h
r15328 r15376 31 31 #include <JavaScriptCore/JSValueRef.h> 32 32 33 #include <stdbool.h> 34 33 35 #ifdef __cplusplus 34 36 extern "C" { … … 55 57 /*! 56 58 @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 @abstract Gets the global object of a JavaScript execution context. 60 @param context The JSContext whose global object you want to get. 59 61 @result context's global object. 60 62 */ … … 66 68 @abstract Evaluates a string of JavaScript. 67 69 @param context The execution context to use. 68 @param script A JS InternalString containing the script to evaluate.70 @param script A JSString containing the script to evaluate. 69 71 @param thisObject The object to use as "this," or NULL to use the global object as "this." 70 @param sourceURL A JS InternalString 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.72 @param sourceURL A JSString 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. 71 73 @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. 72 74 @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. 73 75 @result The JSValue that results from evaluating script, or NULL if an uncaught exception is thrown. 74 76 */ 75 JSValueRef JSEvaluate(JSContextRef context, JS InternalStringRef script, JSObjectRef thisObject, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception);77 JSValueRef JSEvaluate(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception); 76 78 77 79 /*! … … 79 81 @abstract Checks for syntax errors in a string of JavaScript. 80 82 @param context The execution context to use. 81 @param script A JS InternalString containing the JavaScript to check for syntax errors.82 @param sourceURL A JS InternalString 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.83 @param script A JSString containing the script to check for syntax errors. 84 @param sourceURL A JSString 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. 83 85 @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. 84 86 @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. 85 87 @result true if the script is syntactically correct, otherwise false. 86 88 */ 87 bool JSCheckSyntax(JSContextRef context, JS InternalStringRef script, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception);89 bool JSCheckSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception); 88 90 89 91 #ifdef __cplusplus -
trunk/JavaScriptCore/API/JSInternalStringRef.cpp
r15328 r15376 37 37 using namespace KJS; 38 38 39 JSValueRef JS StringMake(JSInternalStringRef string)39 JSValueRef JSValueMakeString(JSStringRef string) 40 40 { 41 41 JSLock lock; … … 44 44 } 45 45 46 JS InternalStringRef JSInternalStringCreate(const JSChar* chars, size_t numChars)46 JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars) 47 47 { 48 48 JSLock lock; … … 50 50 } 51 51 52 JS InternalStringRef JSInternalStringCreateUTF8(const char* string)52 JSStringRef JSStringCreateWithUTF8CString(const char* string) 53 53 { 54 54 JSLock lock; … … 58 58 } 59 59 60 JS InternalStringRef JSInternalStringRetain(JSInternalStringRef string)60 JSStringRef JSStringRetain(JSStringRef string) 61 61 { 62 62 UString::Rep* rep = toJS(string); … … 64 64 } 65 65 66 void JS InternalStringRelease(JSInternalStringRef string)66 void JSStringRelease(JSStringRef string) 67 67 { 68 68 JSLock lock; … … 71 71 } 72 72 73 JS InternalStringRef JSValueCopyStringValue(JSContextRef context, JSValueRef value)73 JSStringRef JSValueToStringCopy(JSContextRef context, JSValueRef value) 74 74 { 75 75 JSLock lock; … … 77 77 ExecState* exec = toJS(context); 78 78 79 JS InternalStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref());79 JSStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref()); 80 80 if (exec->hadException()) 81 81 exec->clearException(); … … 83 83 } 84 84 85 size_t JS InternalStringGetLength(JSInternalStringRef string)85 size_t JSStringGetLength(JSStringRef string) 86 86 { 87 87 UString::Rep* rep = toJS(string); … … 89 89 } 90 90 91 const JSChar* JS InternalStringGetCharactersPtr(JSInternalStringRef string)91 const JSChar* JSStringGetCharactersPtr(JSStringRef string) 92 92 { 93 93 UString::Rep* rep = toJS(string); … … 95 95 } 96 96 97 void JSInternalStringGetCharacters(JSInternalStringRef string, JSChar* buffer, size_t numChars) 98 { 99 UString::Rep* rep = toJS(string); 100 const JSChar* data = reinterpret_cast<const JSChar*>(rep->data()); 101 102 memcpy(buffer, data, numChars * sizeof(JSChar)); 103 } 104 105 size_t JSInternalStringGetMaxLengthUTF8(JSInternalStringRef string) 97 size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string) 106 98 { 107 99 UString::Rep* rep = toJS(string); … … 111 103 } 112 104 113 size_t JS InternalStringGetCharactersUTF8(JSInternalStringRef string, char* buffer, size_t bufferSize)105 size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize) 114 106 { 115 107 JSLock lock; … … 122 114 } 123 115 124 bool JS InternalStringIsEqual(JSInternalStringRef a, JSInternalStringRef b)116 bool JSStringIsEqual(JSStringRef a, JSStringRef b) 125 117 { 126 118 UString::Rep* aRep = toJS(a); … … 130 122 } 131 123 132 bool JS InternalStringIsEqualUTF8(JSInternalStringRef a, const char* b)124 bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b) 133 125 { 134 JS InternalStringRef bBuf = JSInternalStringCreateUTF8(b);135 bool result = JS InternalStringIsEqual(a, bBuf);136 JS InternalStringRelease(bBuf);126 JSStringRef bBuf = JSStringCreateWithUTF8CString(b); 127 bool result = JSStringIsEqual(a, bBuf); 128 JSStringRelease(bBuf); 137 129 138 130 return result; … … 140 132 141 133 #if defined(__APPLE__) 142 JS InternalStringRef JSInternalStringCreateCF(CFStringRef string)134 JSStringRef JSStringCreateWithCFString(CFStringRef string) 143 135 { 144 136 JSLock lock; … … 157 149 } 158 150 159 CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef string)151 CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string) 160 152 { 161 153 UString::Rep* rep = toJS(string); -
trunk/JavaScriptCore/API/JSInternalStringRef.h
r15328 r15376 29 29 30 30 #include <JavaScriptCore/JSValueRef.h> 31 32 #include <stdbool.h> 33 #include <stddef.h> // for size_t 34 31 35 #ifdef __cplusplus 32 36 extern "C" { … … 46 50 @function 47 51 @abstract Creates a JavaScript string from a buffer of Unicode characters. 48 @param chars The buffer of Unicode characters to copy into the new JS InternalString.52 @param chars The buffer of Unicode characters to copy into the new JSString. 49 53 @param numChars The number of characters to copy from the buffer pointed to by chars. 50 @result A JS InternalString containing chars. Ownership follows the create rule.54 @result A JSString containing chars. Ownership follows the Create Rule. 51 55 */ 52 JS InternalStringRef JSInternalStringCreate(const JSChar* chars, size_t numChars);56 JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars); 53 57 /*! 54 58 @function 55 59 @abstract Creates a JavaScript string from a null-terminated UTF8 string. 56 @param string The null-terminated UTF8 string to copy into the new JS InternalString.57 @result A JS InternalString containing string. Ownership follows the create rule.60 @param string The null-terminated UTF8 string to copy into the new JSString. 61 @result A JSString containing string. Ownership follows the Create Rule. 58 62 */ 59 JS InternalStringRef JSInternalStringCreateUTF8(const char* string);63 JSStringRef JSStringCreateWithUTF8CString(const char* string); 60 64 61 65 /*! 62 66 @function 63 67 @abstract Retains a JavaScript string. 64 @param string The JS InternalString to retain.65 @result A JS InternalString that is the same as buffer.68 @param string The JSString to retain. 69 @result A JSString that is the same as string. 66 70 */ 67 JS InternalStringRef JSInternalStringRetain(JSInternalStringRef string);71 JSStringRef JSStringRetain(JSStringRef string); 68 72 /*! 69 73 @function 70 74 @abstract Releases a JavaScript string. 71 @param string The JS InternalString to release.75 @param string The JSString to release. 72 76 */ 73 void JS InternalStringRelease(JSInternalStringRef string);77 void JSStringRelease(JSStringRef string); 74 78 75 79 /*! 76 80 @function 77 81 @abstract Returns the number of Unicode characters in a JavaScript string. 78 @param string The JS InternalString whose length (in Unicode characters) you want to know.82 @param string The JSString whose length (in Unicode characters) you want to know. 79 83 @result The number of Unicode characters stored in string. 80 84 */ 81 size_t JS InternalStringGetLength(JSInternalStringRef string);85 size_t JSStringGetLength(JSStringRef string); 82 86 /*! 83 87 @function 84 @abstract Quickly obtains a pointer to the Unicode character buffer that88 @abstract Returns a pointer to the Unicode character buffer that 85 89 serves as the backing store for a JavaScript string. 86 @param string The JS InternalString whose backing store you want to access.90 @param string The JSString whose backing store you want to access. 87 91 @result A pointer to the Unicode character buffer that serves as string's 88 92 backing store, which will be deallocated when string is deallocated. 89 93 */ 90 const JSChar* JSInternalStringGetCharactersPtr(JSInternalStringRef string); 91 /*! 92 @function 93 @abstract Copies a JavaScript string's Unicode characters into an 94 external character buffer. 95 @param string The source JSInternalString. 96 @param buffer The destination JSChar buffer into which to copy string's 97 characters. On return, buffer 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. 100 */ 101 void JSInternalStringGetCharacters(JSInternalStringRef string, JSChar* buffer, size_t numChars); 94 const JSChar* JSStringGetCharactersPtr(JSStringRef string); 102 95 103 96 /*! 104 97 @function 105 @abstract Returns the maximum number of bytes required to encode the106 contents of a JavaScript string asa null-terminated UTF8 string.107 @param string The JSInternalString whose maximum encoded length(in bytes) you98 @abstract Returns the maximum number of bytes a JavaScript string will 99 take up if converted into a null-terminated UTF8 string. 100 @param string The JSString whose maximum converted size (in bytes) you 108 101 want to know. 109 @result The maximum number of bytes required to encode string's contents 110 as a null-terminated UTF8 string. 102 @result The maximum number of bytes that could be required to convert string into a 103 null-terminated UTF8 string. The number of bytes that the conversion actually ends 104 up requiring could be less than this, but never more. 111 105 */ 112 size_t JS InternalStringGetMaxLengthUTF8(JSInternalStringRef string);106 size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string); 113 107 /*! 114 108 @function 115 @abstract Converts a JavaScript string's contents into a116 null-terminated UTF8 string,and copies the result into an external byte buffer.117 @param string The source JSInternalString.118 @param buffer The destination byte buffer into which to copy a UTF8 string119 representation of string. The buffer must be at least bufferSize bytes in length.120 On return, buffer contains a UTF8 string representation of string.109 @abstract Converts a JavaScript string into a null-terminated UTF8 string, 110 and copies the result into an external byte buffer. 111 @param string The source JSString. 112 @param buffer The destination byte buffer into which to copy a null-terminated 113 UTF8 string representation of string. The buffer must be at least bufferSize 114 bytes in size. On return, buffer contains a UTF8 string representation of string. 121 115 If bufferSize is too small, buffer will contain only partial results. 122 @param bufferSize The lengthof the external buffer in bytes.123 @result 116 @param bufferSize The size of the external buffer in bytes. 117 @result The number of bytes written into buffer (including the null-terminator byte). 124 118 */ 125 size_t JS InternalStringGetCharactersUTF8(JSInternalStringRef string, char* buffer, size_t bufferSize);119 size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize); 126 120 127 121 /*! 128 122 @function 129 @abstract Tests whether t he characters in two JavaScript strings match.130 @param a The first JS InternalString to test.131 @param b The second JS InternalString to test.132 @result true if the characters in thetwo strings match, otherwise false.123 @abstract Tests whether two JavaScript strings match. 124 @param a The first JSString to test. 125 @param b The second JSString to test. 126 @result true if the two strings match, otherwise false. 133 127 */ 134 bool JS InternalStringIsEqual(JSInternalStringRef a, JSInternalStringRef b);128 bool JSStringIsEqual(JSStringRef a, JSStringRef b); 135 129 /*! 136 130 @function 137 @abstract Tests whether the characters in a JavaScript string match 138 the characters in a null-terminated UTF8 string. 139 @param a The JSInternalString to test. 131 @abstract Tests whether a JavaScript string matches a null-terminated UTF8 string. 132 @param a The JSString to test. 140 133 @param b The null-terminated UTF8 string to test. 141 @result true if the characters in thetwo strings match, otherwise false.134 @result true if the two strings match, otherwise false. 142 135 */ 143 bool JS InternalStringIsEqualUTF8(JSInternalStringRef a, const char* b);136 bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b); 144 137 145 138 #if defined(__APPLE__) … … 151 144 @discussion This function is optimized to take advantage of cases when 152 145 CFStringGetCharactersPtr returns a valid pointer. 153 @param string The CFString to copy into the new JS InternalString.154 @result A JS InternalString containing string. Ownership follows the create rule.146 @param string The CFString to copy into the new JSString. 147 @result A JSString containing string. Ownership follows the Create Rule. 155 148 */ 156 JS InternalStringRef JSInternalStringCreateCF(CFStringRef string);149 JSStringRef JSStringCreateWithCFString(CFStringRef string); 157 150 /*! 158 151 @function 159 152 @abstract Creates a CFString form a JavaScript string. 160 153 @param alloc The alloc parameter to pass to CFStringCreate. 161 @param string The JS InternalString to copy into the new CFString.162 @result A CFString containing string. Ownership follows the create rule.154 @param string The JSString to copy into the new CFString. 155 @result A CFString containing string. Ownership follows the Create Rule. 163 156 */ 164 CFStringRef CFStringCreateWithJSInternalString(CFAllocatorRef alloc, JSInternalStringRef string);157 CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string); 165 158 #endif // __APPLE__ 166 159 -
trunk/JavaScriptCore/API/JSNode.c
r15328 r15376 40 40 // Example of throwing a type error for invalid values 41 41 if (!JSValueIsObjectOfClass(thisObject, JSNode_class(context))) { 42 JS InternalStringRef message = JSInternalStringCreateUTF8("TypeError: appendChild can only be called on nodes");43 *exception = JS StringMake(message);44 JS InternalStringRelease(message);42 JSStringRef message = JSStringCreateWithUTF8CString("TypeError: appendChild can only be called on nodes"); 43 *exception = JSValueMakeString(message); 44 JSStringRelease(message); 45 45 } else if (argc < 1 || !JSValueIsObjectOfClass(argv[0], JSNode_class(context))) { 46 JS InternalStringRef message = JSInternalStringCreateUTF8("TypeError: first argument to appendChild must be a node");47 *exception = JS StringMake(message);48 JS InternalStringRelease(message);46 JSStringRef message = JSStringCreateWithUTF8CString("TypeError: first argument to appendChild must be a node"); 47 *exception = JSValueMakeString(message); 48 JSStringRelease(message); 49 49 } else { 50 50 Node* node = JSObjectGetPrivate(thisObject); … … 54 54 } 55 55 56 return JS UndefinedMake();56 return JSValueMakeUndefined(); 57 57 } 58 58 … … 74 74 } 75 75 76 return JS UndefinedMake();76 return JSValueMakeUndefined(); 77 77 } 78 78 … … 96 96 } 97 97 98 return JS UndefinedMake();98 return JSValueMakeUndefined(); 99 99 } 100 100 … … 114 114 } 115 115 116 static bool JSNode_getNodeType(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)116 static JSValueRef JSNode_getNodeType(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) 117 117 { 118 118 UNUSED_PARAM(context); … … 121 121 Node* node = JSObjectGetPrivate(object); 122 122 if (node) { 123 JSInternalStringRef nodeType = JSInternalStringCreateUTF8(node->nodeType); 124 *returnValue = JSStringMake(nodeType); 125 JSInternalStringRelease(nodeType); 126 return true; 127 } 128 return false; 129 } 130 131 static bool JSNode_getChildNodes(JSContextRef context, JSObjectRef thisObject, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception) 123 JSStringRef nodeType = JSStringCreateWithUTF8CString(node->nodeType); 124 JSValueRef value = JSValueMakeString(nodeType); 125 JSStringRelease(nodeType); 126 return value; 127 } 128 129 return NULL; 130 } 131 132 static JSValueRef JSNode_getChildNodes(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) 132 133 { 133 134 UNUSED_PARAM(propertyName); 134 135 Node* node = JSObjectGetPrivate(thisObject); 135 136 assert(node); 136 *returnValue = JSNodeList_new(context, NodeList_new(node)); 137 return true; 138 } 139 140 static bool JSNode_getFirstChild(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception) 137 return JSNodeList_new(context, NodeList_new(node)); 138 } 139 140 static JSValueRef JSNode_getFirstChild(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) 141 141 { 142 142 UNUSED_PARAM(context); … … 144 144 UNUSED_PARAM(object); 145 145 146 *returnValue = JSUndefinedMake(); 147 return true; 146 return JSValueMakeUndefined(); 148 147 } 149 148 … … 180 179 if (!prototype) { 181 180 prototype = JSObjectMake(context, JSNodePrototype_class(context), NULL); 182 JS GCProtect(prototype);181 JSValueProtect(prototype); 183 182 } 184 183 return prototype; -
trunk/JavaScriptCore/API/JSNodeList.c
r15317 r15376 39 39 } 40 40 41 return JS UndefinedMake();41 return JSValueMakeUndefined(); 42 42 } 43 43 … … 57 57 } 58 58 59 static bool JSNodeList_length(JSContextRef context, JSObjectRef thisObject, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)59 static JSValueRef JSNodeList_length(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) 60 60 { 61 61 UNUSED_PARAM(context); … … 63 63 NodeList* nodeList = JSObjectGetPrivate(thisObject); 64 64 assert(nodeList); 65 *returnValue = JSNumberMake(NodeList_length(nodeList)); 66 return true; 65 return JSValueMakeNumber(NodeList_length(nodeList)); 67 66 } 68 67 … … 72 71 }; 73 72 74 static bool JSNodeList_getProperty(JSContextRef context, JSObjectRef thisObject, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)73 static JSValueRef JSNodeList_getProperty(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) 75 74 { 76 75 NodeList* nodeList = JSObjectGetPrivate(thisObject); 77 76 assert(nodeList); 78 double index = JSValueToNumber(context, JS StringMake(propertyName));77 double index = JSValueToNumber(context, JSValueMakeString(propertyName)); 79 78 unsigned uindex = index; 80 79 if (uindex == index) { // false for NaN 81 80 Node* node = NodeList_item(nodeList, uindex); 82 81 if (node) { 83 *returnValue = JSNode_new(context, node); 84 return true; 82 return JSNode_new(context, node); 85 83 } 86 84 } 87 85 88 return false;86 return NULL; 89 87 } 90 88 … … 115 113 if (!prototype) { 116 114 prototype = JSObjectMake(context, JSNodeListPrototype_class(context), NULL); 117 JS GCProtect(prototype);115 JSValueProtect(prototype); 118 116 } 119 117 return prototype; -
trunk/JavaScriptCore/API/JSObjectRef.cpp
r15310 r15376 57 57 } 58 58 59 JSObjectRef JS FunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction)59 JSObjectRef JSObjectMakeFunction(JSContextRef context, JSObjectCallAsFunctionCallback callAsFunction) 60 60 { 61 61 JSLock lock; … … 64 64 } 65 65 66 JSObjectRef JS ConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor)66 JSObjectRef JSObjectMakeConstructor(JSContextRef context, JSObjectCallAsConstructorCallback callAsConstructor) 67 67 { 68 68 JSLock lock; … … 71 71 } 72 72 73 JSObjectRef JS FunctionMakeWithBody(JSContextRef context, JSInternalStringRef body, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception)73 JSObjectRef JSObjectMakeFunctionWithBody(JSContextRef context, JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) 74 74 { 75 75 JSLock lock; … … 97 97 } 98 98 99 JS InternalStringRef JSObjectGetDescription(JSObjectRef object)99 JSStringRef JSObjectGetDescription(JSObjectRef object) 100 100 { 101 101 JSLock lock; … … 118 118 } 119 119 120 bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName)120 bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) 121 121 { 122 122 JSLock lock; … … 128 128 } 129 129 130 JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName)130 JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) 131 131 { 132 132 JSLock lock; … … 141 141 } 142 142 143 bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes)143 bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes) 144 144 { 145 145 JSLock lock; … … 157 157 } 158 158 159 bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName)159 bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) 160 160 { 161 161 JSLock lock; … … 285 285 } 286 286 287 JS InternalStringRef JSPropertyEnumeratorGetNext(JSPropertyEnumeratorRef enumerator)287 JSStringRef JSPropertyEnumeratorGetNextName(JSPropertyEnumeratorRef enumerator) 288 288 { 289 289 ReferenceListIterator& iterator = enumerator->iterator; 290 290 if (iterator != enumerator->list.end()) { 291 JS InternalStringRef result = toRef(iterator->getPropertyName().ustring().rep());291 JSStringRef result = toRef(iterator->getPropertyName().ustring().rep()); 292 292 iterator++; 293 293 return result; … … 308 308 } 309 309 310 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JS InternalStringRef propertyName)310 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringRef propertyName) 311 311 { 312 312 JSLock lock; -
trunk/JavaScriptCore/API/JSObjectRef.h
r15328 r15376 31 31 #include <JavaScriptCore/JSValueRef.h> 32 32 33 #include <stdbool.h> 34 #include <stddef.h> // for size_t 35 33 36 #ifdef __cplusplus 34 37 extern "C" { … … 56 59 57 60 /*! 58 @typedef JS InitializeCallback61 @typedef JSObjectInitializeCallback 59 62 @abstract The callback invoked when an object is first created. 60 63 @param context The execution context to use. … … 66 69 */ 67 70 typedef void 68 (*JS InitializeCallback) (JSContextRef context, JSObjectRef object, JSValueRef* exception);69 70 /*! 71 @typedef JS FinalizeCallback71 (*JSObjectInitializeCallback) (JSContextRef context, JSObjectRef object, JSValueRef* exception); 72 73 /*! 74 @typedef JSObjectFinalizeCallback 72 75 @abstract The callback invoked when an object is finalized (prepared for garbage collection). 73 76 @param object The JSObject being finalized. … … 77 80 */ 78 81 typedef void 79 (*JS FinalizeCallback) (JSObjectRef object);80 81 /*! 82 @typedef JS HasPropertyCallback82 (*JSObjectFinalizeCallback) (JSObjectRef object); 83 84 /*! 85 @typedef JSObjectHasPropertyCallback 83 86 @abstract The callback invoked when determining whether an object has a given property. 84 87 @param context The current execution context. 85 88 @param object The JSObject to search for the property. 86 @param propertyName A JS InternalString containing the name of the property look up.89 @param propertyName A JSString containing the name of the property look up. 87 90 @param exception A pointer to a JSValueRef in which to return an exception, if any. 88 91 @result true if object has the property, otherwise false. 89 92 @discussion If you named your function HasProperty, you would declare it like this: 90 93 91 bool HasProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception); 92 93 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. 94 bool HasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 95 96 If this function returns false, the hasProperty request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain. 97 98 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 requests. 94 99 */ 95 100 typedef bool 96 (*JS HasPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);97 98 /*! 99 @typedef JS GetPropertyCallback101 (*JSObjectHasPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 102 103 /*! 104 @typedef JSObjectGetPropertyCallback 100 105 @abstract The callback invoked when getting a property from an object. 101 106 @param context The current execution context. 102 107 @param object The JSObject to search for the property. 103 @param propertyName A JSInternalString containing the name of the property to get. 104 @param returnValue A pointer to a JSValue in which to store the property's value. 105 @param exception A pointer to a JSValueRef in which to return an exception, if any. 106 @result true if object has the property in question, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue. 108 @param propertyName A JSString containing the name of the property to get. 109 @param exception A pointer to a JSValueRef in which to return an exception, if any. 110 @result The property's value if object has the property, otherwise NULL. 107 111 @discussion If you named your function GetProperty, you would declare it like this: 108 112 109 bool GetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception); 110 111 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. 113 JSValueRef GetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 114 115 If this function returns NULL, 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. 116 */ 117 typedef JSValueRef 118 (*JSObjectGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 119 120 /*! 121 @typedef JSObjectSetPropertyCallback 122 @abstract The callback invoked when setting the value of a given property. 123 @param context The current execution context. 124 @param object The JSObject on which to set the property's value. 125 @param propertyName A JSString containing the name of the property to set. 126 @param value A JSValue to use as the property's value. 127 @param exception A pointer to a JSValueRef in which to return an exception, if any. 128 @result true if the property was set, otherwise false. 129 @discussion If you named your function SetProperty, you would declare it like this: 130 131 bool SetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); 132 133 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). 112 134 */ 113 135 typedef bool 114 (*JSGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception); 115 116 /*! 117 @typedef JSSetPropertyCallback 118 @abstract The callback invoked when setting the value of a given property. 119 @param context The current execution context. 120 @param object The JSObject on which to set the property's value. 121 @param propertyName A JSInternalString containing the name of the property to set. 122 @param value A JSValue to use as the property's value. 123 @param exception A pointer to a JSValueRef in which to return an exception, if any. 124 @result true if the property was successfully set, otherwise false. 125 @discussion If you named your function SetProperty, you would declare it like this: 126 127 bool SetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception); 128 129 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). 130 */ 131 typedef bool 132 (*JSSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception); 133 134 /*! 135 @typedef JSDeletePropertyCallback 136 (*JSObjectSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); 137 138 /*! 139 @typedef JSObjectDeletePropertyCallback 136 140 @abstract The callback invoked when deleting a given property. 137 141 @param context The current execution context. 138 142 @param object The JSObject in which to delete the property. 139 @param propertyName A JS InternalString containing the name of the property to delete.143 @param propertyName A JSString containing the name of the property to delete. 140 144 @param exception A pointer to a JSValueRef in which to return an exception, if any. 141 145 @result true if propertyName was successfully deleted, otherwise false. 142 146 @discussion If you named your function DeleteProperty, you would declare it like this: 143 147 144 bool DeleteProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName, JSValueRef* exception);148 bool DeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 145 149 146 150 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). 147 151 */ 148 152 typedef bool 149 (*JS DeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);150 151 /*! 152 @typedef JS GetPropertyListCallback153 (*JSObjectDeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 154 155 /*! 156 @typedef JSObjectAddPropertiesToListCallback 153 157 @abstract The callback invoked when adding an object's properties to a property list. 154 158 @param context The current execution context. … … 158 162 @discussion If you named your function GetPropertyList, you would declare it like this: 159 163 160 void GetPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);164 void AddPropertiesToList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception); 161 165 162 166 Use JSPropertyListAdd to add properties to propertyList. … … 165 169 */ 166 170 typedef void 167 (*JS GetPropertyListCallback) (JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);168 169 /*! 170 @typedef JS CallAsFunctionCallback171 (*JSObjectAddPropertiesToListCallback) (JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception); 172 173 /*! 174 @typedef JSObjectCallAsFunctionCallback 171 175 @abstract The callback invoked when an object is called as a function. 172 176 @param context The current execution context. … … 186 190 */ 187 191 typedef JSValueRef 188 (*JS CallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception);189 190 /*! 191 @typedef JS CallAsConstructorCallback192 (*JSObjectCallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception); 193 194 /*! 195 @typedef JSObjectCallAsConstructorCallback 192 196 @abstract The callback invoked when an object is used as a constructor in a 'new' statement. 193 197 @param context The current execution context. … … 206 210 */ 207 211 typedef JSObjectRef 208 (*JS CallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[], JSValueRef* exception);209 210 /*! 211 @typedef JS ConvertToTypeCallback212 (*JSObjectCallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[], JSValueRef* exception); 213 214 /*! 215 @typedef JSObjectConvertToTypeCallback 212 216 @abstract The callback invoked when converting an object to a particular JavaScript type. 213 217 @param context The current execution context. 214 218 @param object The JSObject to convert. 215 @param typeCode A JSTypeCode specifying the JavaScript type to convert to. 216 @param returnValue A pointer to a JSValue in which to store the converted value. 217 @param exception A pointer to a JSValueRef in which to return an exception, if any. 218 @result true if the value was converted, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue. 219 @param type A JSType specifying the JavaScript type to convert to. 220 @param exception A pointer to a JSValueRef in which to return an exception, if any. 221 @result The objects's converted value, or NULL if the object was not converted. 219 222 @discussion If you named your function ConvertToType, you would declare it like this: 220 223 221 bool ConvertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception);224 JSValueRef ConvertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception); 222 225 223 226 If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class). 224 227 */ 225 typedef bool226 (*JS ConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception);228 typedef JSValueRef 229 (*JSObjectConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception); 227 230 228 231 /*! … … 242 245 */ 243 246 typedef struct { 244 int version; // current (and only) version is 0245 JS InitializeCallbackinitialize;246 JS FinalizeCallbackfinalize;247 JS HasPropertyCallbackhasProperty;248 JS GetPropertyCallbackgetProperty;249 JS SetPropertyCallbacksetProperty;250 JS DeletePropertyCallbackdeleteProperty;251 JS GetPropertyListCallback getPropertyList;252 JS CallAsFunctionCallbackcallAsFunction;253 JS CallAsConstructorCallbackcallAsConstructor;254 JS ConvertToTypeCallbackconvertToType;247 int version; // current (and only) version is 0 248 JSObjectInitializeCallback initialize; 249 JSObjectFinalizeCallback finalize; 250 JSObjectHasPropertyCallback hasProperty; 251 JSObjectGetPropertyCallback getProperty; 252 JSObjectSetPropertyCallback setProperty; 253 JSObjectDeletePropertyCallback deleteProperty; 254 JSObjectAddPropertiesToListCallback addPropertiesToList; 255 JSObjectCallAsFunctionCallback callAsFunction; 256 JSObjectCallAsConstructorCallback callAsConstructor; 257 JSObjectConvertToTypeCallback convertToType; 255 258 } JSObjectCallbacks; 256 259 … … 270 273 @abstract This structure describes a static value property. 271 274 @field name A null-terminated UTF8 string containing the property's name. 272 @field getProperty A JS GetPropertyCallback to invoke when getting the property's value.273 @field setProperty A JS SetPropertyCallback to invoke when setting the property's value.275 @field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value. 276 @field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. 274 277 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. 275 278 */ 276 279 typedef struct { 277 280 const char* const name; // FIXME: convert UTF8 278 JS GetPropertyCallback getProperty;279 JS SetPropertyCallback setProperty;281 JSObjectGetPropertyCallback getProperty; 282 JSObjectSetPropertyCallback setProperty; 280 283 JSPropertyAttributes attributes; 281 284 } JSStaticValue; … … 285 288 @abstract This structure describes a static function property. 286 289 @field name A null-terminated UTF8 string containing the property's name. 287 @field callAsFunction A JS CallAsFunctionCallback to invoke when the property is called as a function.290 @field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function. 288 291 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. 289 292 */ 290 293 typedef struct { 291 294 const char* const name; // FIXME: convert UTF8 292 JS CallAsFunctionCallback callAsFunction;295 JSObjectCallAsFunctionCallback callAsFunction; 293 296 JSPropertyAttributes attributes; 294 297 } JSStaticFunction; … … 296 299 /*! 297 300 @function 298 @abstract Creates a JavaScript class suitable for use with JSObjectMake . Ownership follows the create rule.301 @abstract Creates a JavaScript class suitable for use with JSObjectMake 299 302 @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. 300 303 @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. 301 304 @param callbacks A pointer to a JSObjectCallbacks structure holding custom callbacks for supplementing default object behavior. Pass NULL to specify no custom behavior. 302 305 @param parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class. 306 @result A JSClass with the given properties, callbacks, and parent class. Ownership follows the Create Rule. 303 307 @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. 304 308 */ … … 332 336 @abstract Convenience method for creating a JavaScript function with a given callback as its implementation. 333 337 @param context The execution context to use. 334 @param callAsFunction The JS CallAsFunctionCallback to invoke when the function is called.338 @param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called. 335 339 @result A JSObject that is an anonymous function. The object's prototype will be the default function prototype. 336 340 */ 337 JSObjectRef JS FunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction);341 JSObjectRef JSObjectMakeFunction(JSContextRef context, JSObjectCallAsFunctionCallback callAsFunction); 338 342 /*! 339 343 @function 340 344 @abstract Convenience method for creating a JavaScript constructor with a given callback as its implementation. 341 345 @param context The execution context to use. 342 @param callAsConstructor The JS CallAsConstructorCallback to invoke when the constructor is used in a 'new' statement.346 @param callAsConstructor The JSObjectCallAsConstructorCallback to invoke when the constructor is used in a 'new' statement. 343 347 @result A JSObject that is a constructor. The object's prototype will be the default object prototype. 344 348 */ 345 JSObjectRef JS ConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor);349 JSObjectRef JSObjectMakeConstructor(JSContextRef context, JSObjectCallAsConstructorCallback callAsConstructor); 346 350 347 351 /*! … … 349 353 @abstract Creates a function with a given script as its body. 350 354 @param context The execution context to use. 351 @param body A JS InternalString containing the script to use as the function's body.352 @param sourceURL A JS InternalString 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.355 @param body A JSString containing the script to use as the function's body. 356 @param sourceURL A JSString 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. 353 357 @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. 354 358 @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. … … 356 360 @discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution. 357 361 */ 358 JSObjectRef JS FunctionMakeWithBody(JSContextRef context, JSInternalStringRef body, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception);362 JSObjectRef JSObjectMakeFunctionWithBody(JSContextRef context, JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception); 359 363 360 364 /*! … … 363 367 @param context The execution context to use. 364 368 @param object The object whose description you want to get. 365 @result A JS InternalString containing the object's description. This is usually the object's class name.366 */ 367 JS InternalStringRef JSObjectGetDescription(JSObjectRef object);369 @result A JSString containing the object's description. This is usually the object's class name. 370 */ 371 JSStringRef JSObjectGetDescription(JSObjectRef object); 368 372 369 373 /*! … … 386 390 @abstract Tests whether an object has a certain property. 387 391 @param object The JSObject to test. 388 @param propertyName A JS InternalString containing the property's name.392 @param propertyName A JSString containing the property's name. 389 393 @result true if the object has a property whose name matches propertyName, otherwise false. 390 394 */ 391 bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName);395 bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName); 392 396 /*! 393 397 @function … … 395 399 @param context The execution context to use. 396 400 @param object The JSObject whose property you want to get. 397 @param propertyName A JS InternalString containing the property's name.398 @result The property's value , or NULL if the object does not have a property whose name matches propertyName.399 */ 400 JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName);401 @param propertyName A JSString containing the property's name. 402 @result The property's value if object has the property, otherwise NULL. 403 */ 404 JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName); 401 405 /*! 402 406 @function … … 404 408 @param context The execution context to use. 405 409 @param object The JSObject whose property you want to set. 406 @param propertyName A JS InternalString containing the property's name.410 @param propertyName A JSString containing the property's name. 407 411 @param value A JSValue to use as the property's value. 408 412 @param attributes A logically ORed set of JSPropertyAttributes to give to the property. 409 413 @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). 410 414 */ 411 bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes);415 bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes); 412 416 /*! 413 417 @function … … 415 419 @param context The execution context to use. 416 420 @param object The JSObject whose property you want to delete. 417 @param propertyName A JS InternalString containing the property's name.421 @param propertyName A JSString containing the property's name. 418 422 @result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set). 419 423 */ 420 bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName);424 bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName); 421 425 422 426 /*! … … 424 428 @abstract Gets a pointer to private data from an object. 425 429 @param object A JSObject whose private data you want to get. 426 @result A void* that points to the object's private data, or NULL if the object has no private data.427 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JS FunctionMake, and JSConstructorMake.430 @result A void* that points to the object's private data, if the object has private data, otherwise NULL. 431 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor. 428 432 */ 429 433 void* JSObjectGetPrivate(JSObjectRef object); … … 434 438 @param data A void* that points to the object's private data. 435 439 @result true if the set operation succeeds, otherwise false. 436 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JS FunctionMake, and JSConstructorMake.440 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor. 437 441 */ 438 442 bool JSObjectSetPrivate(JSObjectRef object, void* data); … … 481 485 @param context The execution context to use. 482 486 @param object The object whose properties you want to enumerate. 483 @result A JSPropertyEnumerator with a list of object's properties. Ownership follows the create rule.487 @result A JSPropertyEnumerator with a list of object's properties. Ownership follows the Create Rule. 484 488 */ 485 489 JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSContextRef context, JSObjectRef object); … … 501 505 @abstract Gets a property enumerator's next property. 502 506 @param enumerator The JSPropertyEnumerator whose next property you want to get. 503 @result A JS InternalString containing the property's name, or NULL if all properties have been enumerated.504 */ 505 JS InternalStringRef JSPropertyEnumeratorGetNext(JSPropertyEnumeratorRef enumerator);507 @result A JSString containing the property's name, or NULL if all properties have been enumerated. 508 */ 509 JSStringRef JSPropertyEnumeratorGetNextName(JSPropertyEnumeratorRef enumerator); 506 510 507 511 /*! 508 512 @function 509 513 @abstract Adds a property to a property list. 510 @discussion Use this method inside a JS GetPropertyListCallback to add a custom property to an object's property list.514 @discussion Use this method inside a JSObjectAddPropertiesToListCallback to add a custom property to an object's property list. 511 515 @param propertyList The JSPropertyList to which you want to add a property. 512 516 @param thisObject The JSObject to which the property belongs. 513 @param propertyName A JS InternalString specifying the property's name.514 */ 515 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JS InternalStringRef propertyName);517 @param propertyName A JSString specifying the property's name. 518 */ 519 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringRef propertyName); 516 520 517 521 #ifdef __cplusplus -
trunk/JavaScriptCore/API/JSValueRef.cpp
r15234 r15376 40 40 #include <algorithm> // for std::min 41 41 42 using namespace KJS; 43 44 JSTypeCode JSValueGetType(JSValueRef value) 45 { 46 JSValue* jsValue = toJS(value); 42 JSType JSValueGetType(JSValueRef value) 43 { 44 KJS::JSValue* jsValue = toJS(value); 47 45 switch (jsValue->type()) { 48 case UndefinedType:46 case KJS::UndefinedType: 49 47 return kJSTypeUndefined; 50 case NullType:48 case KJS::NullType: 51 49 return kJSTypeNull; 52 case BooleanType:50 case KJS::BooleanType: 53 51 return kJSTypeBoolean; 54 case NumberType:52 case KJS::NumberType: 55 53 return kJSTypeNumber; 56 case StringType:54 case KJS::StringType: 57 55 return kJSTypeString; 58 case ObjectType:56 case KJS::ObjectType: 59 57 return kJSTypeObject; 60 58 default: … … 64 62 } 65 63 64 using namespace KJS; // placed here to avoid conflict between KJS::JSType and JSType, above. 65 66 66 bool JSValueIsUndefined(JSValueRef value) 67 67 { … … 136 136 } 137 137 138 bool JSValueIsInstanceOf (JSContextRef context, JSValueRef value, JSObjectRef constructor)138 bool JSValueIsInstanceOfConstructor(JSContextRef context, JSValueRef value, JSObjectRef constructor) 139 139 { 140 140 ExecState* exec = toJS(context); … … 149 149 } 150 150 151 JSValueRef JSUndefinedMake() 152 { 153 JSLock lock; 151 JSValueRef JSValueMakeUndefined() 152 { 154 153 return toRef(jsUndefined()); 155 154 } 156 155 157 JSValueRef JSNullMake() 158 { 159 JSLock lock; 156 JSValueRef JSValueMakeNull() 157 { 160 158 return toRef(jsNull()); 161 159 } 162 160 163 JSValueRef JSBooleanMake(bool value) 164 { 165 JSLock lock; 161 JSValueRef JSValueMakeBoolean(bool value) 162 { 166 163 return toRef(jsBoolean(value)); 167 164 } 168 165 169 JSValueRef JS NumberMake(double value)166 JSValueRef JSValueMakeNumber(double value) 170 167 { 171 168 JSLock lock; … … 179 176 JSValue* jsValue = toJS(value); 180 177 181 return jsValue->toBoolean(exec); 178 bool boolean = jsValue->toBoolean(exec); 179 if (exec->hadException()) { 180 exec->clearException(); 181 boolean = false; 182 } 183 return boolean; 182 184 } 183 185 … … 210 212 } 211 213 212 void JS GCProtect(JSValueRef value)214 void JSValueProtect(JSValueRef value) 213 215 { 214 216 JSLock lock; … … 217 219 } 218 220 219 void JS GCUnprotect(JSValueRef value)221 void JSValueUnprotect(JSValueRef value) 220 222 { 221 223 JSLock lock; … … 224 226 } 225 227 226 void JSG CCollect()228 void JSGarbageCollect() 227 229 { 228 230 JSLock lock; -
trunk/JavaScriptCore/API/JSValueRef.h
r15328 r15376 30 30 #include <JavaScriptCore/JSBase.h> 31 31 32 /*! 33 @enum JSTypeCode 32 #include <stdbool.h> 33 34 /*! 35 @enum JSType 34 36 @abstract A constant identifying the type of a JSValue. 35 37 @constant kJSTypeUndefined The unique undefined value. … … 47 49 kJSTypeString, 48 50 kJSTypeObject 49 } JSType Code;51 } JSType; 50 52 51 53 #ifdef __cplusplus … … 55 57 /*! 56 58 @function 57 @abstract Returns a JavaScript value's type code.59 @abstract Returns a JavaScript value's type. 58 60 @param value The JSValue whose type you want to obtain. 59 @result A value of type JSType Codethat identifies value's type.60 */ 61 JSType CodeJSValueGetType(JSValueRef value);61 @result A value of type JSType that identifies value's type. 62 */ 63 JSType JSValueGetType(JSValueRef value); 62 64 63 65 /*! … … 151 153 by the JS instanceof operator, otherwise false. 152 154 */ 153 bool JSValueIsInstanceOf (JSContextRef context, JSValueRef value, JSObjectRef constructor);155 bool JSValueIsInstanceOfConstructor(JSContextRef context, JSValueRef value, JSObjectRef constructor); 154 156 155 157 // Creating values … … 160 162 @result The unique undefined value. 161 163 */ 162 JSValueRef JS UndefinedMake(void);164 JSValueRef JSValueMakeUndefined(void); 163 165 164 166 /*! … … 167 169 @result The unique null value. 168 170 */ 169 JSValueRef JS NullMake(void);171 JSValueRef JSValueMakeNull(void); 170 172 171 173 /*! 172 174 @function 173 175 @abstract Creates a JavaScript value of the boolean type. 174 @param value The boolean valueto assign to the newly created JSValue.175 @result A JSValue of the boolean type, representing the boolean value of value.176 */ 177 178 JSValueRef JS BooleanMake(bool value);176 @param boolean The bool to assign to the newly created JSValue. 177 @result A JSValue of the boolean type, representing the value of boolean. 178 */ 179 180 JSValueRef JSValueMakeBoolean(bool boolean); 179 181 180 182 /*! 181 183 @function 182 184 @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.185 */ 186 JSValueRef JS NumberMake(double value);185 @param number The double to assign to the newly created JSValue. 186 @result A JSValue of the number type, representing the value of number. 187 */ 188 JSValueRef JSValueMakeNumber(double number); 187 189 188 190 /*! 189 191 @function 190 192 @abstract Creates a JavaScript value of the string type. 191 @param string The JS InternalString to assign to the newly created JSValue. The193 @param string The JSString to assign to the newly created JSValue. The 192 194 newly created JSValue retains string, and releases it upon garbage collection. 193 @result A JSValue of the string type, representing the stringvalue of string.194 */ 195 JSValueRef JS StringMake(JSInternalStringRef string);195 @result A JSValue of the string type, representing the value of string. 196 */ 197 JSValueRef JSValueMakeString(JSStringRef string); 196 198 197 199 // Converting to primitive values … … 217 219 /*! 218 220 @function 219 @abstract Converts a JavaScript value to string and copies the resulting 220 string into a newly allocated JavaScript string. 221 @param context The execution context to use. 222 @param value The JSValue to convert. 223 @result A JSInternalString containing the result of conversion, or an empty 224 string if conversion fails. Ownership follows the copy rule. 225 */ 226 JSInternalStringRef JSValueCopyStringValue(JSContextRef context, JSValueRef value); 221 @abstract Converts a JavaScript value to string and copies the result into a JavaScript string. 222 @param context The execution context to use. 223 @param value The JSValue to convert. 224 @result A JSString with the result of conversion, or an empty string if conversion fails. Ownership follows the Create Rule. 225 */ 226 JSStringRef JSValueToStringCopy(JSContextRef context, JSValueRef value); 227 227 228 228 /*! … … 243 243 equal number of times before becoming eligible for garbage collection. 244 244 */ 245 void JS GCProtect(JSValueRef value);245 void JSValueProtect(JSValueRef value); 246 246 247 247 /*! … … 252 252 equal number of times before becoming eligible for garbage collection. 253 253 */ 254 void JS GCUnprotect(JSValueRef value);254 void JSValueUnprotect(JSValueRef value); 255 255 256 256 /*! … … 258 258 @abstract Performs a JavaScript garbage collection. 259 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. 263 */ 264 void JSGCCollect(void); 260 protected by JSValueProtect, set as the global object of an execution context, 261 or reachable from any such value will not be collected. 262 263 You are not required to call this function; the JavaScript engine will garbage 264 collect as needed. 265 */ 266 void JSGarbageCollect(void); 265 267 266 268 #ifdef __cplusplus -
trunk/JavaScriptCore/API/JavaScriptCore.h
r15328 r15376 28 28 #define JavaScriptCore_h 29 29 30 #include <stdbool.h>31 #include <stddef.h> // for size_t32 33 30 #include <JavaScriptCore/JSBase.h> 31 #include <JavaScriptCore/JSContextRef.h> 34 32 #include <JavaScriptCore/JSInternalStringRef.h> 35 #include <JavaScriptCore/JSContextRef.h>36 33 #include <JavaScriptCore/JSObjectRef.h> 37 34 #include <JavaScriptCore/JSValueRef.h> -
trunk/JavaScriptCore/API/minidom.c
r15328 r15376 40 40 JSObjectRef globalObject = JSContextGetGlobalObject(context); 41 41 42 JS InternalStringRef printIString = JSInternalStringCreateUTF8("print");43 JSObjectSetProperty(context, globalObject, printIString, JS FunctionMake(context, print), kJSPropertyAttributeNone);44 JS InternalStringRelease(printIString);42 JSStringRef printIString = JSStringCreateWithUTF8CString("print"); 43 JSObjectSetProperty(context, globalObject, printIString, JSObjectMakeFunction(context, print), kJSPropertyAttributeNone); 44 JSStringRelease(printIString); 45 45 46 JS InternalStringRef node = JSInternalStringCreateUTF8("Node");47 JSObjectSetProperty(context, globalObject, node, JS ConstructorMake(context, JSNode_construct), kJSPropertyAttributeNone);48 JS InternalStringRelease(node);46 JSStringRef node = JSStringCreateWithUTF8CString("Node"); 47 JSObjectSetProperty(context, globalObject, node, JSObjectMakeConstructor(context, JSNode_construct), kJSPropertyAttributeNone); 48 JSStringRelease(node); 49 49 50 50 char* scriptUTF8 = createStringWithContentsOfFile("minidom.js"); 51 JS InternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8);51 JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8); 52 52 JSValueRef exception; 53 53 JSValueRef result = JSEvaluate(context, script, NULL, NULL, 0, &exception); … … 56 56 else { 57 57 printf("FAIL: Test script threw exception:\n"); 58 JS InternalStringRef exceptionIString = JSValueCopyStringValue(context, exception);59 CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString);58 JSStringRef exceptionIString = JSValueToStringCopy(context, exception); 59 CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString); 60 60 CFShow(exceptionCF); 61 61 CFRelease(exceptionCF); 62 JS InternalStringRelease(exceptionIString);62 JSStringRelease(exceptionIString); 63 63 } 64 JS InternalStringRelease(script);64 JSStringRelease(script); 65 65 free(scriptUTF8); 66 66 … … 71 71 (void)o; 72 72 } 73 JSG CCollect();73 JSGarbageCollect(); 74 74 #endif 75 75 … … 82 82 { 83 83 if (argc > 0) { 84 JS InternalStringRef string = JSValueCopyStringValue(context, argv[0]);85 size_t numChars = JS InternalStringGetMaxLengthUTF8(string);84 JSStringRef string = JSValueToStringCopy(context, argv[0]); 85 size_t numChars = JSStringGetMaximumUTF8CStringSize(string); 86 86 char stringUTF8[numChars]; 87 JS InternalStringGetCharactersUTF8(string, stringUTF8, numChars);87 JSStringGetUTF8CString(string, stringUTF8, numChars); 88 88 printf("%s\n", stringUTF8); 89 89 } 90 90 91 return JS UndefinedMake();91 return JSValueMakeUndefined(); 92 92 } 93 93 -
trunk/JavaScriptCore/API/testapi.c
r15328 r15376 52 52 static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue) 53 53 { 54 JS InternalStringRef valueAsString = JSValueCopyStringValue(context, value);55 56 size_t jsSize = JS InternalStringGetMaxLengthUTF8(valueAsString);54 JSStringRef valueAsString = JSValueToStringCopy(context, value); 55 56 size_t jsSize = JSStringGetMaximumUTF8CStringSize(valueAsString); 57 57 char jsBuffer[jsSize]; 58 JS InternalStringGetCharactersUTF8(valueAsString, jsBuffer, jsSize);58 JSStringGetUTF8CString(valueAsString, jsBuffer, jsSize); 59 59 60 60 if (strcmp(jsBuffer, expectedValue) != 0) … … 64 64 fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n"); 65 65 66 JS InternalStringRelease(valueAsString);66 JSStringRelease(valueAsString); 67 67 } 68 68 … … 70 70 static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedValue) 71 71 { 72 JS InternalStringRef valueAsString = JSValueCopyStringValue(context, value);73 74 size_t jsLength = JS InternalStringGetLength(valueAsString);75 const JSChar* jsBuffer = JS InternalStringGetCharactersPtr(valueAsString);72 JSStringRef valueAsString = JSValueToStringCopy(context, value); 73 74 size_t jsLength = JSStringGetLength(valueAsString); 75 const JSChar* jsBuffer = JSStringGetCharactersPtr(valueAsString); 76 76 77 77 CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault, … … 89 89 fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength); 90 90 91 JSInternalStringRelease(valueAsString); 92 } 93 94 static void assertEqualsAsCharacters(JSValueRef value, const char* expectedValue) 95 { 96 JSInternalStringRef valueAsString = JSValueCopyStringValue(context, value); 97 98 size_t jsLength = JSInternalStringGetLength(valueAsString); 99 JSChar jsBuffer[jsLength]; 100 JSInternalStringGetCharacters(valueAsString, jsBuffer, jsLength); 101 102 CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault, 103 expectedValue, 104 kCFStringEncodingUTF8); 105 CFIndex cfLength = CFStringGetLength(expectedValueAsCFString); 106 UniChar cfBuffer[cfLength]; 107 CFStringGetCharacters(expectedValueAsCFString, CFRangeMake(0, cfLength), cfBuffer); 108 CFRelease(expectedValueAsCFString); 109 110 if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0) 111 fprintf(stderr, "assertEqualsAsCharacters failed: jsBuffer != cfBuffer\n"); 112 113 if (jsLength != (size_t)cfLength) 114 fprintf(stderr, "assertEqualsAsCharacters failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength); 115 116 JSInternalStringRelease(valueAsString); 117 } 118 #endif // __APPLE__ 119 120 static JSValueRef jsGlobalValue; // non-stack value for testing JSGCProtect() 91 JSStringRelease(valueAsString); 92 } 93 94 #endif // __APPLE__ 95 96 static JSValueRef jsGlobalValue; // non-stack value for testing JSValueProtect() 121 97 122 98 /* MyObject pseudo-class */ … … 130 106 } 131 107 132 static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName, JSValueRef* exception)133 { 134 UNUSED_PARAM(context); 135 UNUSED_PARAM(object); 136 137 if (JS InternalStringIsEqualUTF8(propertyName, "alwaysOne")138 || JS InternalStringIsEqualUTF8(propertyName, "cantFind")139 || JS InternalStringIsEqualUTF8(propertyName, "myPropertyName")) {108 static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) 109 { 110 UNUSED_PARAM(context); 111 UNUSED_PARAM(object); 112 113 if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne") 114 || JSStringIsEqualToUTF8CString(propertyName, "cantFind") 115 || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) { 140 116 return true; 141 117 } … … 144 120 } 145 121 146 static bool MyObject_getProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception) 147 { 148 UNUSED_PARAM(context); 149 UNUSED_PARAM(object); 150 151 if (JSInternalStringIsEqualUTF8(propertyName, "alwaysOne")) { 152 *returnValue = JSNumberMake(1); 122 static JSValueRef MyObject_getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) 123 { 124 UNUSED_PARAM(context); 125 UNUSED_PARAM(object); 126 127 if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")) { 128 return JSValueMakeNumber(1); 129 } 130 131 if (JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) { 132 return JSValueMakeNumber(1); 133 } 134 135 if (JSStringIsEqualToUTF8CString(propertyName, "cantFind")) { 136 return JSValueMakeUndefined(); 137 } 138 139 return NULL; 140 } 141 142 static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) 143 { 144 UNUSED_PARAM(context); 145 UNUSED_PARAM(object); 146 UNUSED_PARAM(value); 147 148 if (JSStringIsEqualToUTF8CString(propertyName, "cantSet")) 149 return true; // pretend we set the property in order to swallow it 150 151 return false; 152 } 153 154 static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) 155 { 156 UNUSED_PARAM(context); 157 UNUSED_PARAM(object); 158 159 if (JSStringIsEqualToUTF8CString(propertyName, "cantDelete")) 153 160 return true; 154 }155 156 if (JSInternalStringIsEqualUTF8(propertyName, "myPropertyName")) {157 *returnValue = JSNumberMake(1);158 return true;159 }160 161 if (JSInternalStringIsEqualUTF8(propertyName, "cantFind")) {162 *returnValue = JSUndefinedMake();163 return true;164 }165 161 166 162 return false; 167 163 } 168 164 169 static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception)170 {171 UNUSED_PARAM(context);172 UNUSED_PARAM(object);173 UNUSED_PARAM(value);174 175 if (JSInternalStringIsEqualUTF8(propertyName, "cantSet"))176 return true; // pretend we set the property in order to swallow it177 178 return false;179 }180 181 static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception)182 {183 UNUSED_PARAM(context);184 UNUSED_PARAM(object);185 186 if (JSInternalStringIsEqualUTF8(propertyName, "cantDelete"))187 return true;188 189 return false;190 }191 192 165 static void MyObject_getPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception) 193 166 { 194 167 UNUSED_PARAM(context); 195 168 196 JS InternalStringRef propertyName;197 198 propertyName = JS InternalStringCreateUTF8("alwaysOne");169 JSStringRef propertyName; 170 171 propertyName = JSStringCreateWithUTF8CString("alwaysOne"); 199 172 JSPropertyListAdd(propertyList, object, propertyName); 200 JS InternalStringRelease(propertyName);201 202 propertyName = JS InternalStringCreateUTF8("myPropertyName");173 JSStringRelease(propertyName); 174 175 propertyName = JSStringCreateWithUTF8CString("myPropertyName"); 203 176 JSPropertyListAdd(propertyList, object, propertyName); 204 JS InternalStringRelease(propertyName);177 JSStringRelease(propertyName); 205 178 } 206 179 … … 211 184 UNUSED_PARAM(thisObject); 212 185 213 if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JS NumberMake(0)))214 return JS NumberMake(1);215 216 return JS UndefinedMake();186 if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSValueMakeNumber(0))) 187 return JSValueMakeNumber(1); 188 189 return JSValueMakeUndefined(); 217 190 } 218 191 … … 222 195 UNUSED_PARAM(object); 223 196 224 if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JS NumberMake(0)))225 return JSValueToObject(context, JS NumberMake(1));226 227 return JSValueToObject(context, JS NumberMake(0));228 } 229 230 static bool MyObject_convertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception)231 { 232 UNUSED_PARAM(context); 233 UNUSED_PARAM(object); 234 235 switch (type Code) {197 if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSValueMakeNumber(0))) 198 return JSValueToObject(context, JSValueMakeNumber(1)); 199 200 return JSValueToObject(context, JSValueMakeNumber(0)); 201 } 202 203 static JSValueRef MyObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception) 204 { 205 UNUSED_PARAM(context); 206 UNUSED_PARAM(object); 207 208 switch (type) { 236 209 case kJSTypeBoolean: 237 *returnValue = JSBooleanMake(false); // default object conversion is 'true' 238 return true; 210 return JSValueMakeBoolean(false); // default object conversion is 'true' 239 211 case kJSTypeNumber: 240 *returnValue = JSNumberMake(1); 241 return true; 212 return JSValueMakeNumber(1); 242 213 default: 243 214 break; 244 215 } 245 216 246 // string 247 return false;217 // string conversion -- forward to default object class 218 return NULL; 248 219 } 249 220 … … 286 257 287 258 if (argc > 0) { 288 JS InternalStringRef string = JSValueCopyStringValue(context, argv[0]);289 size_t sizeUTF8 = JS InternalStringGetMaxLengthUTF8(string);259 JSStringRef string = JSValueToStringCopy(context, argv[0]); 260 size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string); 290 261 char stringUTF8[sizeUTF8]; 291 JS InternalStringGetCharactersUTF8(string, stringUTF8, sizeUTF8);262 JSStringGetUTF8CString(string, stringUTF8, sizeUTF8); 292 263 printf("%s\n", stringUTF8); 293 JS InternalStringRelease(string);294 } 295 296 return JS UndefinedMake();264 JSStringRelease(string); 265 } 266 267 return JSValueMakeUndefined(); 297 268 } 298 269 … … 303 274 JSObjectRef result = JSObjectMake(context, NULL, 0); 304 275 if (argc > 0) { 305 JS InternalStringRef value = JSInternalStringCreateUTF8("value");276 JSStringRef value = JSStringCreateWithUTF8CString("value"); 306 277 JSObjectSetProperty(context, result, value, argv[0], kJSPropertyAttributeNone); 307 JS InternalStringRelease(value);278 JSStringRelease(value); 308 279 } 309 280 … … 320 291 context = JSContextCreate(NULL); 321 292 322 JSValueRef jsUndefined = JS UndefinedMake();323 JSValueRef jsNull = JS NullMake();324 JSValueRef jsTrue = JS BooleanMake(true);325 JSValueRef jsFalse = JS BooleanMake(false);326 JSValueRef jsZero = JS NumberMake(0);327 JSValueRef jsOne = JS NumberMake(1);328 JSValueRef jsOneThird = JS NumberMake(1.0 / 3.0);329 JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JS NullMake());293 JSValueRef jsUndefined = JSValueMakeUndefined(); 294 JSValueRef jsNull = JSValueMakeNull(); 295 JSValueRef jsTrue = JSValueMakeBoolean(true); 296 JSValueRef jsFalse = JSValueMakeBoolean(false); 297 JSValueRef jsZero = JSValueMakeNumber(0); 298 JSValueRef jsOne = JSValueMakeNumber(1); 299 JSValueRef jsOneThird = JSValueMakeNumber(1.0 / 3.0); 300 JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSValueMakeNull()); 330 301 331 302 // FIXME: test funny utf8 characters 332 JS InternalStringRef jsEmptyIString = JSInternalStringCreateUTF8("");333 JSValueRef jsEmptyString = JS StringMake(jsEmptyIString);334 335 JS InternalStringRef jsOneIString = JSInternalStringCreateUTF8("1");336 JSValueRef jsOneString = JS StringMake(jsOneIString);303 JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString(""); 304 JSValueRef jsEmptyString = JSValueMakeString(jsEmptyIString); 305 306 JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1"); 307 JSValueRef jsOneString = JSValueMakeString(jsOneIString); 337 308 338 309 #if defined(__APPLE__) … … 345 316 kCFAllocatorNull); 346 317 347 JS InternalStringRef jsCFIString = JSInternalStringCreateCF(cfString);348 JSValueRef jsCFString = JS StringMake(jsCFIString);318 JSStringRef jsCFIString = JSStringCreateWithCFString(cfString); 319 JSValueRef jsCFString = JSValueMakeString(jsCFIString); 349 320 350 321 CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8); 351 322 352 JS InternalStringRef jsCFEmptyIString = JSInternalStringCreateCF(cfEmptyString);353 JSValueRef jsCFEmptyString = JS StringMake(jsCFEmptyIString);323 JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString); 324 JSValueRef jsCFEmptyString = JSValueMakeString(jsCFEmptyIString); 354 325 355 326 CFIndex cfStringLength = CFStringGetLength(cfString); … … 358 329 CFRangeMake(0, cfStringLength), 359 330 buffer); 360 JS InternalStringRef jsCFIStringWithCharacters = JSInternalStringCreate(buffer, cfStringLength);361 JSValueRef jsCFStringWithCharacters = JS StringMake(jsCFIStringWithCharacters);362 363 JS InternalStringRef jsCFEmptyIStringWithCharacters = JSInternalStringCreate(buffer, CFStringGetLength(cfEmptyString));364 JSValueRef jsCFEmptyStringWithCharacters = JS StringMake(jsCFEmptyIStringWithCharacters);331 JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters(buffer, cfStringLength); 332 JSValueRef jsCFStringWithCharacters = JSValueMakeString(jsCFIStringWithCharacters); 333 334 JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters(buffer, CFStringGetLength(cfEmptyString)); 335 JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(jsCFEmptyIStringWithCharacters); 365 336 #endif // __APPLE__ 366 337 … … 435 406 #endif // __APPLE__ 436 407 437 assertEqualsAsCharacters(jsUndefined, "undefined");438 assertEqualsAsCharacters(jsNull, "null");439 assertEqualsAsCharacters(jsTrue, "true");440 assertEqualsAsCharacters(jsFalse, "false");441 assertEqualsAsCharacters(jsZero, "0");442 assertEqualsAsCharacters(jsOne, "1");443 assertEqualsAsCharacters(jsOneThird, "0.3333333333333333");444 assertEqualsAsCharacters(jsEmptyString, "");445 assertEqualsAsCharacters(jsOneString, "1");446 #if defined(__APPLE__)447 assertEqualsAsCharacters(jsCFString, "A");448 assertEqualsAsCharacters(jsCFStringWithCharacters, "A");449 assertEqualsAsCharacters(jsCFEmptyString, "");450 assertEqualsAsCharacters(jsCFEmptyStringWithCharacters, "");451 #endif // __APPLE__452 453 408 assertEqualsAsUTF8String(jsUndefined, "undefined"); 454 409 assertEqualsAsUTF8String(jsNull, "null"); … … 474 429 475 430 #if defined(__APPLE__) 476 CFStringRef cfJSString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFIString);477 CFStringRef cfJSEmptyString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFEmptyIString);431 CFStringRef cfJSString = JSStringCopyCFString(kCFAllocatorDefault, jsCFIString); 432 CFStringRef cfJSEmptyString = JSStringCopyCFString(kCFAllocatorDefault, jsCFEmptyIString); 478 433 assert(CFEqual(cfJSString, cfString)); 479 434 assert(CFEqual(cfJSEmptyString, cfEmptyString)); … … 486 441 487 442 jsGlobalValue = JSObjectMake(context, NULL, NULL); 488 JS GCProtect(jsGlobalValue);489 JSG CCollect();443 JSValueProtect(jsGlobalValue); 444 JSGarbageCollect(); 490 445 assert(JSValueIsObject(jsGlobalValue)); 491 JS GCUnprotect(jsGlobalValue);446 JSValueUnprotect(jsGlobalValue); 492 447 493 448 /* JSInterpreter.h */ … … 496 451 assert(JSValueIsObject(globalObject)); 497 452 498 JS InternalStringRef goodSyntax = JSInternalStringCreateUTF8("x = 1;");499 JS InternalStringRef badSyntax = JSInternalStringCreateUTF8("x := 1;");453 JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;"); 454 JSStringRef badSyntax = JSStringCreateWithUTF8CString("x := 1;"); 500 455 assert(JSCheckSyntax(context, goodSyntax, NULL, 0, NULL)); 501 456 assert(!JSCheckSyntax(context, badSyntax, NULL, 0, NULL)); … … 515 470 assert(JSValueIsObject(exception)); 516 471 517 JS InternalStringRef array = JSInternalStringCreateUTF8("Array");472 JSStringRef array = JSStringCreateWithUTF8CString("Array"); 518 473 v = JSObjectGetProperty(context, globalObject, array); 519 474 assert(v); 520 475 JSObjectRef arrayConstructor = JSValueToObject(context, v); 521 JS InternalStringRelease(array);476 JSStringRelease(array); 522 477 result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL); 523 478 assert(result); 524 assert(JSValueIsInstanceOf (context, result, arrayConstructor));525 assert(!JSValueIsInstanceOf (context, JSNullMake(), arrayConstructor));526 527 JS InternalStringRef functionBody;479 assert(JSValueIsInstanceOfConstructor(context, result, arrayConstructor)); 480 assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(), arrayConstructor)); 481 482 JSStringRef functionBody; 528 483 529 484 exception = NULL; 530 functionBody = JS InternalStringCreateUTF8("rreturn Array;");531 JS InternalStringRef line = JSInternalStringCreateUTF8("line");532 assert(!JS FunctionMakeWithBody(context, functionBody, NULL, 1, &exception));485 functionBody = JSStringCreateWithUTF8CString("rreturn Array;"); 486 JSStringRef line = JSStringCreateWithUTF8CString("line"); 487 assert(!JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, &exception)); 533 488 assert(JSValueIsObject(exception)); 534 489 v = JSObjectGetProperty(context, JSValueToObject(context, exception), line); 535 490 assert(v); 536 491 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) 537 JS InternalStringRelease(functionBody);538 JS InternalStringRelease(line);539 540 functionBody = JS InternalStringCreateUTF8("return Array;");541 JSObjectRef function = JS FunctionMakeWithBody(context, functionBody, NULL, 1, NULL);542 JS InternalStringRelease(functionBody);492 JSStringRelease(functionBody); 493 JSStringRelease(line); 494 495 functionBody = JSStringCreateWithUTF8CString("return Array;"); 496 JSObjectRef function = JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, NULL); 497 JSStringRelease(functionBody); 543 498 544 499 assert(JSObjectIsFunction(function)); … … 548 503 JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL); 549 504 assert(didInitialize); 550 JS InternalStringRef myObjectIString = JSInternalStringCreateUTF8("MyObject");505 JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject"); 551 506 JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone); 552 JS InternalStringRelease(myObjectIString);553 554 JS InternalStringRef print = JSInternalStringCreateUTF8("print");555 JSObjectRef printFunction = JS FunctionMake(context, print_callAsFunction);507 JSStringRelease(myObjectIString); 508 509 JSStringRef print = JSStringCreateWithUTF8CString("print"); 510 JSObjectRef printFunction = JSObjectMakeFunction(context, print_callAsFunction); 556 511 JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone); 557 JS InternalStringRelease(print);512 JSStringRelease(print); 558 513 559 514 assert(JSObjectSetPrivate(printFunction, (void*)1)); 560 515 assert(JSObjectGetPrivate(printFunction) == (void*)1); 561 516 562 JS InternalStringRef myConstructorIString = JSInternalStringCreateUTF8("MyConstructor");563 JSObjectRef myConstructor = JS ConstructorMake(context, myConstructor_callAsConstructor);517 JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor"); 518 JSObjectRef myConstructor = JSObjectMakeConstructor(context, myConstructor_callAsConstructor); 564 519 JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone); 565 JS InternalStringRelease(myConstructorIString);520 JSStringRelease(myConstructorIString); 566 521 567 522 assert(JSObjectSetPrivate(myConstructor, (void*)1)); … … 569 524 570 525 o = JSObjectMake(context, NULL, NULL); 571 JSObjectSetProperty(context, o, jsOneIString, JS NumberMake(1), kJSPropertyAttributeNone);572 JSObjectSetProperty(context, o, jsCFIString, JS NumberMake(1), kJSPropertyAttributeDontEnum);526 JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(1), kJSPropertyAttributeNone); 527 JSObjectSetProperty(context, o, jsCFIString, JSValueMakeNumber(1), kJSPropertyAttributeDontEnum); 573 528 JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(context, o); 574 529 int count = 0; 575 while (JSPropertyEnumeratorGetNext (enumerator))530 while (JSPropertyEnumeratorGetNextName(enumerator)) 576 531 ++count; 577 532 JSPropertyEnumeratorRelease(enumerator); … … 581 536 JSClassRelease(nullCallbacksClass); 582 537 583 functionBody = JS InternalStringCreateUTF8("return this;");584 function = JS FunctionMakeWithBody(context, functionBody, NULL, 1, NULL);585 JS InternalStringRelease(functionBody);538 functionBody = JSStringCreateWithUTF8CString("return this;"); 539 function = JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, NULL); 540 JSStringRelease(functionBody); 586 541 v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); 587 542 assert(JSValueIsEqual(context, v, globalObject)); … … 590 545 591 546 char* scriptUTF8 = createStringWithContentsOfFile("testapi.js"); 592 JS InternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8);547 JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8); 593 548 result = JSEvaluate(context, script, NULL, NULL, 1, &exception); 594 549 if (JSValueIsUndefined(result)) … … 596 551 else { 597 552 printf("FAIL: Test script returned unexcpected value:\n"); 598 JS InternalStringRef exceptionIString = JSValueCopyStringValue(context, exception);599 CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString);553 JSStringRef exceptionIString = JSValueToStringCopy(context, exception); 554 CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString); 600 555 CFShow(exceptionCF); 601 556 CFRelease(exceptionCF); 602 JS InternalStringRelease(exceptionIString);603 } 604 JS InternalStringRelease(script);557 JSStringRelease(exceptionIString); 558 } 559 JSStringRelease(script); 605 560 free(scriptUTF8); 606 561 … … 608 563 JSObjectMake(context, MyObject_class(context), 0); 609 564 JSObjectMake(context, MyObject_class(context), 0); 610 JSG CCollect();565 JSGarbageCollect(); 611 566 assert(didFinalize); 612 567 613 JS InternalStringRelease(jsEmptyIString);614 JS InternalStringRelease(jsOneIString);615 #if defined(__APPLE__) 616 JS InternalStringRelease(jsCFIString);617 JS InternalStringRelease(jsCFEmptyIString);618 JS InternalStringRelease(jsCFIStringWithCharacters);619 JS InternalStringRelease(jsCFEmptyIStringWithCharacters);620 #endif // __APPLE__ 621 JS InternalStringRelease(goodSyntax);622 JS InternalStringRelease(badSyntax);568 JSStringRelease(jsEmptyIString); 569 JSStringRelease(jsOneIString); 570 #if defined(__APPLE__) 571 JSStringRelease(jsCFIString); 572 JSStringRelease(jsCFEmptyIString); 573 JSStringRelease(jsCFIStringWithCharacters); 574 JSStringRelease(jsCFEmptyIStringWithCharacters); 575 #endif // __APPLE__ 576 JSStringRelease(goodSyntax); 577 JSStringRelease(badSyntax); 623 578 624 579 JSContextDestroy(context); -
trunk/JavaScriptCore/ChangeLog
r15328 r15376 1 2006-07-11 Geoffrey Garen <[email protected]> 2 3 Reviewed by Maciej. 4 5 - Implemented a vast number of renames and comment clarifications 6 suggested during API review. 7 8 JSInternalString -> JSString 9 JS*Make -> JSValueMake*, JSObjectMake* 10 JSTypeCode -> JSType 11 JSValueIsInstanceOf -> JSValueIsInstanceOfConstructor (reads strangely well in client code) 12 JSGC*Protect -> JSValue*Protect 13 JS*Callback -> JSObject*Callback 14 JSGetPropertyListCallback -> JSObjectAddPropertiesToListCallback 15 JSPropertyEnumeratorGetNext -> JSPropertyEnumeratorGetNextName 16 JSString* -> 17 JSStringCreateWithUTF8CString, JSStringGetUTF8CString, 18 JSStringGetMaximumUTF8CStringSize JSStringIsEqualToUTF8CString, 19 JSStringCreateWithCFString, JSStringCopyCFString, JSStringCreateWithCharacters. 20 21 - Changed functions taking a JSValue out arg and returning a bool indicating 22 whether it was set to simply return a JSValue or NULL. 23 24 - Removed JSStringGetCharacters because it's more documentation than code, 25 and it's just a glorified memcpy built on existing API functionality. 26 27 - Moved standard library includes into the headers that actually require them. 28 29 - Standardized use of the phrase "Create Rule." 30 31 - Removed JSLock from make functions that don't allocate. 32 33 - Added exception handling to JSValueToBoolean, since we now allow 34 callback objects to throw exceptions upon converting to boolean. 35 36 - Renamed JSGCCollect to JSGarbageCollect. 37 1 38 2006-07-10 Geoffrey Garen <[email protected]> 2 39 -
trunk/JavaScriptCore/JavaScriptCore.exp
r15321 r15376 2 2 .objc_class_name_WebScriptObjectPrivate 3 3 .objc_class_name_WebUndefined 4 _CFStringCreateWithJSInternalString5 _JSBooleanMake6 4 _JSCheckSyntax 7 5 _JSClassCreate 8 6 _JSClassRelease 9 7 _JSClassRetain 10 _JSConstructorMake11 8 _JSContextCreate 12 9 _JSContextDestroy 13 10 _JSContextGetGlobalObject 14 11 _JSEvaluate 15 _JSFunctionMake 16 _JSFunctionMakeWithBody 17 _JSGCCollect 18 _JSGCProtect 19 _JSGCUnprotect 20 _JSInternalStringCreate 21 _JSInternalStringCreateCF 22 _JSInternalStringCreateUTF8 23 _JSInternalStringGetCharacters 24 _JSInternalStringGetCharactersPtr 25 _JSInternalStringGetCharactersUTF8 26 _JSInternalStringGetLength 27 _JSInternalStringGetMaxLengthUTF8 28 _JSInternalStringIsEqual 29 _JSInternalStringIsEqualUTF8 30 _JSInternalStringRelease 31 _JSInternalStringRetain 32 _JSNullMake 33 _JSNumberMake 12 _JSGarbageCollect 34 13 _JSObjectCallAsConstructor 35 14 _JSObjectCallAsFunction … … 44 23 _JSObjectIsFunction 45 24 _JSObjectMake 25 _JSObjectMakeConstructor 26 _JSObjectMakeFunction 27 _JSObjectMakeFunctionWithBody 46 28 _JSObjectSetPrivate 47 29 _JSObjectSetProperty 48 30 _JSObjectSetPrototype 49 _JSPropertyEnumeratorGetNext 31 _JSPropertyEnumeratorGetNextName 50 32 _JSPropertyEnumeratorRelease 51 33 _JSPropertyEnumeratorRetain 52 34 _JSPropertyListAdd 53 _JSStringMake 54 _JSUndefinedMake 55 _JSValueCopyStringValue 35 _JSStringCopyCFString 36 _JSStringCreateWithCFString 37 _JSStringCreateWithCharacters 38 _JSStringCreateWithUTF8CString 39 _JSStringGetCharactersPtr 40 _JSStringGetLength 41 _JSStringGetMaximumUTF8CStringSize 42 _JSStringGetUTF8CString 43 _JSStringIsEqual 44 _JSStringIsEqualToUTF8CString 45 _JSStringRelease 46 _JSStringRetain 56 47 _JSValueGetType 57 48 _JSValueIsBoolean 58 49 _JSValueIsEqual 59 _JSValueIsInstanceOf 50 _JSValueIsInstanceOfConstructor 60 51 _JSValueIsNull 61 52 _JSValueIsNumber … … 65 56 _JSValueIsString 66 57 _JSValueIsUndefined 58 _JSValueMakeBoolean 59 _JSValueMakeNull 60 _JSValueMakeNumber 61 _JSValueMakeString 62 _JSValueMakeUndefined 63 _JSValueProtect 67 64 _JSValueToBoolean 68 65 _JSValueToNumber 69 66 _JSValueToObject 67 _JSValueToStringCopy 68 _JSValueUnprotect 70 69 _KJS_JSCreateNativeJSObject 71 70 _KJS_JSObject_JSFinalize
Note:
See TracChangeset
for help on using the changeset viewer.