Ignore:
Timestamp:
Oct 12, 2011, 1:23:08 PM (14 years ago)
Author:
[email protected]
Message:

De-virtualize JSCell::toString
https://bugs.webkit.org/show_bug.cgi?id=69677

Reviewed by Sam Weinig.

Source/JavaScriptCore:

Removed toString from JSCallbackObject, since it is no
longer necessary since we now implicitly add toString and valueOf
functions to object prototypes when a convertToType callback
is provided, which is now the standard way to override toString
and valueOf in the JSC C API.

  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:

Removed toString from InterruptedExecutionError and
TerminatedExecutionError and replaced it with defaultValue,
which JSObject::toString calls. We'll probably have to de-virtualize
defaultValue eventually, but we'll cross that bridge when we
come to it.

  • runtime/ExceptionHelpers.cpp:

(JSC::InterruptedExecutionError::defaultValue):
(JSC::TerminatedExecutionError::defaultValue):

  • runtime/ExceptionHelpers.h:

Removed toString from JSNotAnObject, since its return value doesn't
actually matter and JSObject::toString can cover it.

  • runtime/JSNotAnObject.cpp:
  • runtime/JSNotAnObject.h:

De-virtualized JSCell::toString, JSObject::toString and JSString::toString.
Added handling of all cases for JSCell to JSCell::toString.

  • runtime/JSObject.h:
  • runtime/JSString.h:
  • runtime/JSCell.cpp:

(JSC::JSCell::toString):

  • runtime/JSCell.h:

Source/JavaScriptGlue:

Removed UserObjectImp::toString because it's no longer necessary since
clients can provide their own toString callback which will in turn be
called by JSObject::toString.

  • UserObjectImp.cpp:
  • UserObjectImp.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptGlue/UserObjectImp.cpp

    r97097 r97292  
    329329}
    330330
    331 UString UserObjectImp::toString(ExecState *exec) const
    332 {
    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             else
    350             {
    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             else
    373             {
    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                 else
    382                 {
    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 
    420331void UserObjectImp::visitChildren(JSCell* cell, SlotVisitor& visitor)
    421332{
Note: See TracChangeset for help on using the changeset viewer.