Changeset 41905 in webkit for trunk/JavaScriptCore/API/tests/testapi.c
- Timestamp:
- Mar 22, 2009, 11:01:46 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/tests/testapi.c
r41895 r41905 129 129 if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne") 130 130 || JSStringIsEqualToUTF8CString(propertyName, "cantFind") 131 || JSStringIsEqualToUTF8CString(propertyName, "throwOnGet") 131 132 || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName") 132 133 || JSStringIsEqualToUTF8CString(propertyName, "hasPropertyLie") … … 154 155 return JSValueMakeUndefined(context); 155 156 } 156 157 158 if (JSStringIsEqualToUTF8CString(propertyName, "throwOnGet")) { 159 return JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), object, JSStringCreateWithUTF8CString("test script"), 1, exception); 160 } 161 157 162 if (JSStringIsEqualToUTF8CString(propertyName, "0")) { 158 163 *exception = JSValueMakeNumber(context, 1); … … 173 178 return true; // pretend we set the property in order to swallow it 174 179 180 if (JSStringIsEqualToUTF8CString(propertyName, "throwOnSet")) { 181 JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), object, JSStringCreateWithUTF8CString("test script"), 1, exception); 182 } 183 175 184 return false; 176 185 } … … 185 194 186 195 if (JSStringIsEqualToUTF8CString(propertyName, "throwOnDelete")) { 187 *exception = JSValueMakeNumber(context, 2);196 JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), object, JSStringCreateWithUTF8CString("test script"), 1, exception); 188 197 return false; 189 198 } … … 215 224 UNUSED_PARAM(exception); 216 225 226 if (argumentCount > 0 && JSValueIsString(context, arguments[0]) && JSStringIsEqualToUTF8CString(JSValueToStringCopy(context, arguments[0], 0), "throwOnCall")) { 227 JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), object, JSStringCreateWithUTF8CString("test script"), 1, exception); 228 return JSValueMakeUndefined(context); 229 } 230 217 231 if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0))) 218 232 return JSValueMakeNumber(context, 1); … … 226 240 UNUSED_PARAM(object); 227 241 242 if (argumentCount > 0 && JSValueIsString(context, arguments[0]) && JSStringIsEqualToUTF8CString(JSValueToStringCopy(context, arguments[0], 0), "throwOnConstruct")) { 243 JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), object, JSStringCreateWithUTF8CString("test script"), 1, exception); 244 return object; 245 } 246 228 247 if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0))) 229 248 return JSValueToObject(context, JSValueMakeNumber(context, 1), exception); … … 236 255 UNUSED_PARAM(context); 237 256 UNUSED_PARAM(constructor); 257 258 if (JSValueIsString(context, possibleValue) && JSStringIsEqualToUTF8CString(JSValueToStringCopy(context, possibleValue, 0), "throwOnHasInstance")) { 259 JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), constructor, JSStringCreateWithUTF8CString("test script"), 1, exception); 260 return false; 261 } 238 262 239 263 JSStringRef numberString = JSStringCreateWithUTF8CString("Number"); … … 310 334 return jsClass; 311 335 } 336 337 static bool EvilExceptionObject_hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleValue, JSValueRef* exception) 338 { 339 UNUSED_PARAM(context); 340 UNUSED_PARAM(constructor); 341 342 JSStringRef hasInstanceName = JSStringCreateWithUTF8CString("hasInstance"); 343 JSValueRef hasInstance = JSObjectGetProperty(context, constructor, hasInstanceName, exception); 344 JSStringRelease(hasInstanceName); 345 346 JSObjectRef function = JSValueToObject(context, hasInstance, exception); 347 JSValueRef result = JSObjectCallAsFunction(context, function, constructor, 1, &possibleValue, exception); 348 return result && JSValueToBoolean(context, result); 349 } 350 351 static JSValueRef EvilExceptionObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception) 352 { 353 UNUSED_PARAM(object); 354 UNUSED_PARAM(exception); 355 JSStringRef funcName; 356 switch (type) { 357 case kJSTypeNumber: 358 funcName = JSStringCreateWithUTF8CString("toNumber"); 359 break; 360 case kJSTypeString: 361 funcName = JSStringCreateWithUTF8CString("toStringExplicit"); 362 break; 363 default: 364 return NULL; 365 break; 366 } 367 368 JSValueRef func = JSObjectGetProperty(context, object, funcName, exception); 369 JSStringRelease(funcName); 370 JSObjectRef function = JSValueToObject(context, func, exception); 371 if (!function) 372 return NULL; 373 JSValueRef value = JSObjectCallAsFunction(context, function, object, 0, NULL, exception); 374 if (!value) 375 return (JSValueRef)JSStringCreateWithUTF8CString("convertToType failed"); 376 return value; 377 } 378 379 JSClassDefinition EvilExceptionObject_definition = { 380 0, 381 kJSClassAttributeNone, 382 383 "EvilExceptionObject", 384 NULL, 385 386 NULL, 387 NULL, 388 389 NULL, 390 NULL, 391 NULL, 392 NULL, 393 NULL, 394 NULL, 395 NULL, 396 NULL, 397 NULL, 398 EvilExceptionObject_hasInstance, 399 EvilExceptionObject_convertToType, 400 }; 401 402 static JSClassRef EvilExceptionObject_class(JSContextRef context) 403 { 404 UNUSED_PARAM(context); 405 406 static JSClassRef jsClass; 407 if (!jsClass) 408 jsClass = JSClassCreate(&EvilExceptionObject_definition); 409 410 return jsClass; 411 } 412 312 413 313 414 static JSValueRef Base_get(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) … … 669 770 JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone, NULL); 670 771 JSStringRelease(myObjectIString); 772 773 JSObjectRef EvilExceptionObject = JSObjectMake(context, EvilExceptionObject_class(context), NULL); 774 JSStringRef EvilExceptionObjectIString = JSStringCreateWithUTF8CString("EvilExceptionObject"); 775 JSObjectSetProperty(context, globalObject, EvilExceptionObjectIString, EvilExceptionObject, kJSPropertyAttributeNone, NULL); 776 JSStringRelease(EvilExceptionObjectIString); 671 777 672 778 JSValueRef exception;
Note:
See TracChangeset
for help on using the changeset viewer.