Changeset 15474 in webkit for trunk/JavaScriptCore/API
- Timestamp:
- Jul 16, 2006, 7:00:40 PM (19 years ago)
- Location:
- trunk/JavaScriptCore/API
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSObjectRef.cpp
r15469 r15474 149 149 150 150 JSValue* jsValue = jsObject->get(exec, Identifier(nameRep)); 151 if (jsValue->isUndefined())152 jsValue = 0;153 151 if (exec->hadException()) { 154 152 if (exception) … … 175 173 } 176 174 177 JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex )175 JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception) 178 176 { 179 177 JSLock lock; … … 182 180 183 181 JSValue* jsValue = jsObject->get(exec, propertyIndex); 184 if (jsValue->isUndefined()) 185 return 0; 182 if (exec->hadException()) { 183 if (exception) 184 *exception = toRef(exec->exception()); 185 exec->clearException(); 186 } 186 187 return toRef(jsValue); 187 188 } 188 189 189 190 190 void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value )191 void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception) 191 192 { 192 193 JSLock lock; … … 196 197 197 198 jsObject->put(exec, propertyIndex, jsValue); 199 if (exec->hadException()) { 200 if (exception) 201 *exception = toRef(exec->exception()); 202 exec->clearException(); 203 } 198 204 } 199 205 -
trunk/JavaScriptCore/API/JSObjectRef.h
r15473 r15474 448 448 @param propertyName A JSString containing the property's name. 449 449 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. 450 @result The property's value if object has the property, otherwise NULL.450 @result The property's value if object has the property, otherwise the undefined value. 451 451 */ 452 452 JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); … … 481 481 @param object The JSObject whose property you want to get. 482 482 @param propertyIndex The property's name as a number 483 @result The property's value if object has the property, otherwise NULL. 484 @discussion This is equivalent to getting a property by a string name containing the number, but allows faster access to JS arrays. 485 */ 486 JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex); 483 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. 484 @result The property's value if object has the property, otherwise the undefined value. 485 @discussion Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but it enables optimized access to JavaScript arrays. 486 */ 487 JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception); 487 488 488 489 /*! … … 493 494 @param propertyIndex The property's name as a number 494 495 @param value A JSValue to use as the property's value. 495 @discussion This is equivalent to setting a property by a string name containing the number, but allows faster access to JS arrays. 496 */ 497 void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value); 496 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. 497 @discussion Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but it enables optimized access to JavaScript arrays. 498 */ 499 void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception); 498 500 499 501 /*! -
trunk/JavaScriptCore/API/testapi.c
r15473 r15474 116 116 || JSStringIsEqualToUTF8CString(propertyName, "cantFind") 117 117 || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName") 118 || JSStringIsEqualToUTF8CString(propertyName, "hasPropertyLie")) { 118 || JSStringIsEqualToUTF8CString(propertyName, "hasPropertyLie") 119 || JSStringIsEqualToUTF8CString(propertyName, "0")) { 119 120 return true; 120 121 } … … 138 139 if (JSStringIsEqualToUTF8CString(propertyName, "cantFind")) { 139 140 return JSValueMakeUndefined(); 141 } 142 143 if (JSStringIsEqualToUTF8CString(propertyName, "0")) { 144 *exception = JSValueMakeNumber(1); 145 return JSValueMakeNumber(1); 140 146 } 141 147 … … 415 421 assert(!JSValueIsEqual(context, jsObjectNoProto, JSValueMakeNumber(1), &exception)); 416 422 assert(exception); 423 424 exception = NULL; 425 JSObjectGetPropertyAtIndex(context, myObject, 0, &exception); 426 assert(1 == JSValueToNumber(context, exception, NULL)); 417 427 418 428 assertEqualsAsBoolean(jsUndefined, false); … … 525 535 526 536 JSStringRef array = JSStringCreateWithUTF8CString("Array"); 527 v = JSObjectGetProperty(context, globalObject, array, NULL); 528 assert(v); 529 JSObjectRef arrayConstructor = JSValueToObject(context, v, NULL); 537 JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL); 530 538 JSStringRelease(array); 531 539 result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL); 532 540 assert(result); 541 assert(JSValueIsObject(result)); 533 542 assert(JSValueIsInstanceOfConstructor(context, result, arrayConstructor, NULL)); 534 543 assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(), arrayConstructor, NULL)); 535 544 545 o = JSValueToObject(context, result, NULL); 546 exception = NULL; 547 assert(JSValueIsUndefined(JSObjectGetPropertyAtIndex(context, o, 0, &exception))); 548 assert(!exception); 549 550 JSObjectSetPropertyAtIndex(context, o, 0, JSValueMakeNumber(1), &exception); 551 assert(!exception); 552 553 exception = NULL; 554 assert(1 == JSValueToNumber(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception), &exception)); 555 assert(!exception); 556 536 557 JSStringRef functionBody; 537 558 JSObjectRef function; … … 543 564 assert(JSValueIsObject(exception)); 544 565 v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line, NULL); 545 assert(v);546 566 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) 547 567 JSStringRelease(functionBody); … … 619 639 v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL); 620 640 assert(JSValueIsEqual(context, v, o, NULL)); 641 642 621 643 622 644 char* scriptUTF8 = createStringWithContentsOfFile("testapi.js");
Note:
See TracChangeset
for help on using the changeset viewer.