Changeset 97292 in webkit
- Timestamp:
- Oct 12, 2011 1:23:08 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSCallbackObject.h
r97097 r97292 195 195 196 196 virtual double toNumber(ExecState*) const; 197 virtual UString toString(ExecState*) const;198 197 199 198 virtual ConstructType getConstructData(ConstructData&); -
trunk/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
r97097 r97292 515 515 516 516 template <class Parent> 517 UString JSCallbackObject<Parent>::toString(ExecState* exec) const518 {519 JSContextRef ctx = toRef(exec);520 JSObjectRef thisRef = toRef(this);521 522 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)523 if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {524 JSValueRef exception = 0;525 JSValueRef value;526 {527 APICallbackShim callbackShim(exec);528 value = convertToType(ctx, thisRef, kJSTypeString, &exception);529 }530 if (exception) {531 throwError(exec, toJS(exec, exception));532 return "";533 }534 if (value)535 return toJS(exec, value).getString(exec);536 }537 538 return Parent::toString(exec);539 }540 541 template <class Parent>542 517 void JSCallbackObject<Parent>::setPrivate(void* data) 543 518 { -
trunk/Source/JavaScriptCore/ChangeLog
r97291 r97292 1 2011-10-12 Mark Hahnenberg <mhahnenberg@apple.com> 2 3 De-virtualize JSCell::toString 4 https://bugs.webkit.org/show_bug.cgi?id=69677 5 6 Reviewed by Sam Weinig. 7 8 Removed toString from JSCallbackObject, since it is no 9 longer necessary since we now implicitly add toString and valueOf 10 functions to object prototypes when a convertToType callback 11 is provided, which is now the standard way to override toString 12 and valueOf in the JSC C API. 13 * API/JSCallbackObject.h: 14 * API/JSCallbackObjectFunctions.h: 15 * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: 16 17 Removed toString from InterruptedExecutionError and 18 TerminatedExecutionError and replaced it with defaultValue, 19 which JSObject::toString calls. We'll probably have to de-virtualize 20 defaultValue eventually, but we'll cross that bridge when we 21 come to it. 22 * runtime/ExceptionHelpers.cpp: 23 (JSC::InterruptedExecutionError::defaultValue): 24 (JSC::TerminatedExecutionError::defaultValue): 25 * runtime/ExceptionHelpers.h: 26 27 Removed toString from JSNotAnObject, since its return value doesn't 28 actually matter and JSObject::toString can cover it. 29 * runtime/JSNotAnObject.cpp: 30 * runtime/JSNotAnObject.h: 31 32 De-virtualized JSCell::toString, JSObject::toString and JSString::toString. 33 Added handling of all cases for JSCell to JSCell::toString. 34 * runtime/JSObject.h: 35 * runtime/JSString.h: 36 * runtime/JSCell.cpp: 37 (JSC::JSCell::toString): 38 * runtime/JSCell.h: 39 1 40 2011-10-12 Oliver Hunt <oliver@apple.com> 2 41 -
trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
r97097 r97292 353 353 ?toObject@JSCell@JSC@@QBEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z 354 354 ?toObjectSlowCase@JSValue@JSC@@ABEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z 355 ?toString@JSCell@JSC@@UBE?AVUString@2@PAVExecState@2@@Z 356 ?toString@JSObject@JSC@@UBE?AVUString@2@PAVExecState@2@@Z 357 ?toString@JSString@JSC@@EBE?AVUString@2@PAVExecState@2@@Z 355 ?toString@JSCell@JSC@@QBE?AVUString@2@PAVExecState@2@@Z 356 ?toString@JSObject@JSC@@QBE?AVUString@2@PAVExecState@2@@Z 358 357 ?toStringDecimal@DecimalNumber@WTF@@QBEIPA_WI@Z 359 358 ?toStringExponential@DecimalNumber@WTF@@QBEIPA_WI@Z -
trunk/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp
r95936 r97292 44 44 const ClassInfo InterruptedExecutionError::s_info = { "InterruptedExecutionError", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(InterruptedExecutionError) }; 45 45 46 UString InterruptedExecutionError::toString(ExecState*) const46 JSValue InterruptedExecutionError::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const 47 47 { 48 return "JavaScript execution exceeded timeout."; 48 if (hint == PreferString) 49 return jsNontrivialString(exec, "JavaScript execution exceeded timeout."); 50 return JSValue(std::numeric_limits<double>::quiet_NaN()); 49 51 } 50 52 … … 67 69 const ClassInfo TerminatedExecutionError::s_info = { "TerminatedExecutionError", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(TerminatedExecutionError) }; 68 70 69 UString TerminatedExecutionError::toString(ExecState*) const71 JSValue TerminatedExecutionError::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const 70 72 { 71 return "JavaScript execution terminated."; 73 if (hint == PreferString) 74 return jsNontrivialString(exec, "JavaScript execution terminated."); 75 return JSValue(std::numeric_limits<double>::quiet_NaN()); 72 76 } 73 77 -
trunk/Source/JavaScriptCore/runtime/ExceptionHelpers.h
r95901 r97292 63 63 } 64 64 65 virtual UString toString(ExecState*) const;65 virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const; 66 66 67 67 public: … … 90 90 } 91 91 92 virtual UString toString(ExecState*) const;92 virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const; 93 93 94 94 public: -
trunk/Source/JavaScriptCore/runtime/JSCell.cpp
r97097 r97292 169 169 } 170 170 171 UString JSCell::toString(ExecState* ) const171 UString JSCell::toString(ExecState* exec) const 172 172 { 173 ASSERT_NOT_REACHED(); 174 return UString(); 173 if (isString()) 174 return static_cast<const JSString*>(this)->toString(exec); 175 return static_cast<const JSObject*>(this)->toString(exec); 175 176 } 176 177 -
trunk/Source/JavaScriptCore/runtime/JSCell.h
r97097 r97292 83 83 bool toBoolean(ExecState*) const; 84 84 virtual double toNumber(ExecState*) const; 85 virtualUString toString(ExecState*) const;85 UString toString(ExecState*) const; 86 86 JSObject* toObject(ExecState*, JSGlobalObject*) const; 87 87 -
trunk/Source/JavaScriptCore/runtime/JSNotAnObject.cpp
r97015 r97292 50 50 ASSERT_UNUSED(exec, exec->hadException()); 51 51 return std::numeric_limits<double>::quiet_NaN(); 52 }53 54 UString JSNotAnObject::toString(ExecState* exec) const55 {56 ASSERT_UNUSED(exec, exec->hadException());57 return "";58 52 } 59 53 -
trunk/Source/JavaScriptCore/runtime/JSNotAnObject.h
r97015 r97292 68 68 virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const; 69 69 virtual double toNumber(ExecState*) const; 70 virtual UString toString(ExecState*) const;71 70 72 71 // JSObject methods -
trunk/Source/JavaScriptCore/runtime/JSObject.h
r97097 r97292 142 142 bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const; 143 143 virtual double toNumber(ExecState*) const; 144 virtualUString toString(ExecState*) const;144 UString toString(ExecState*) const; 145 145 146 146 virtual JSObject* toThisObject(ExecState*) const; -
trunk/Source/JavaScriptCore/runtime/JSString.h
r97015 r97292 431 431 bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const; 432 432 JSObject* toObject(ExecState*, JSGlobalObject*) const; 433 UString toString(ExecState*) const; 433 434 434 435 bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); … … 503 504 504 505 virtual double toNumber(ExecState*) const; 505 virtual UString toString(ExecState*) const;506 506 507 507 virtual JSObject* toThisObject(ExecState*) const; -
trunk/Source/JavaScriptGlue/ChangeLog
r97097 r97292 1 2011-10-12 Mark Hahnenberg <mhahnenberg@apple.com> 2 3 De-virtualize JSCell::toString 4 https://bugs.webkit.org/show_bug.cgi?id=69677 5 6 Reviewed by Sam Weinig. 7 8 Removed UserObjectImp::toString because it's no longer necessary since 9 clients can provide their own toString callback which will in turn be 10 called by JSObject::toString. 11 * UserObjectImp.cpp: 12 * UserObjectImp.h: 13 1 14 2011-10-10 Mark Hahnenberg <mhahnenberg@apple.com> 2 15 -
trunk/Source/JavaScriptGlue/UserObjectImp.cpp
r97097 r97292 329 329 } 330 330 331 UString UserObjectImp::toString(ExecState *exec) const332 {333 UString result;334 JSUserObject* jsObjPtr = KJSValueToJSObject(toObject(exec, exec->lexicalGlobalObject()), exec);335 CFTypeRef cfValue = jsObjPtr ? jsObjPtr->CopyCFValue() : 0;336 if (cfValue)337 {338 CFTypeID cfType = CFGetTypeID(cfValue);339 if (cfValue == GetCFNull())340 {341 //342 }343 else if (cfType == CFBooleanGetTypeID())344 {345 if (cfValue == kCFBooleanTrue)346 {347 result = "true";348 }349 else350 {351 result = "false";352 }353 }354 else if (cfType == CFStringGetTypeID())355 {356 result = CFStringToUString((CFStringRef)cfValue);357 }358 else if (cfType == CFNumberGetTypeID())359 {360 if (cfValue == kCFNumberNaN)361 {362 result = "Nan";363 }364 else if (CFNumberCompare(kCFNumberPositiveInfinity, (CFNumberRef)cfValue, 0) == 0)365 {366 result = "Infinity";367 }368 else if (CFNumberCompare(kCFNumberNegativeInfinity, (CFNumberRef)cfValue, 0) == 0)369 {370 result = "-Infinity";371 }372 else373 {374 CFStringRef cfNumStr;375 double d = 0;376 CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d);377 if (CFNumberIsFloatType((CFNumberRef)cfValue))378 {379 cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%f"), d);380 }381 else382 {383 cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%.0f"), d);384 }385 result = CFStringToUString(cfNumStr);386 ReleaseCFType(cfNumStr);387 }388 }389 else if (cfType == CFArrayGetTypeID())390 {391 //392 }393 else if (cfType == CFDictionaryGetTypeID())394 {395 //396 }397 else if (cfType == CFSetGetTypeID())398 {399 //400 }401 else if (cfType == CFURLGetTypeID())402 {403 CFURLRef absURL = CFURLCopyAbsoluteURL((CFURLRef)cfValue);404 if (absURL)405 {406 CFStringRef cfStr = CFURLGetString(absURL);407 if (cfStr)408 {409 result = CFStringToUString(cfStr);410 }411 ReleaseCFType(absURL);412 }413 }414 }415 ReleaseCFType(cfValue);416 if (jsObjPtr) jsObjPtr->Release();417 return result;418 }419 420 331 void UserObjectImp::visitChildren(JSCell* cell, SlotVisitor& visitor) 421 332 { -
trunk/Source/JavaScriptGlue/UserObjectImp.h
r97097 r97292 63 63 virtual bool toBoolean(ExecState *exec) const; 64 64 virtual double toNumber(ExecState *exec) const; 65 virtual UString toString(ExecState *exec) const;66 65 67 66 static void visitChildren(JSCell*, SlotVisitor&);
Note: See TracChangeset
for help on using the changeset viewer.