Changeset 97292 in webkit


Ignore:
Timestamp:
Oct 12, 2011 1:23:08 PM (13 years ago)
Author:
mhahnenberg@apple.com
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:
Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSCallbackObject.h

    r97097 r97292  
    195195
    196196    virtual double toNumber(ExecState*) const;
    197     virtual UString toString(ExecState*) const;
    198197
    199198    virtual ConstructType getConstructData(ConstructData&);
  • trunk/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h

    r97097 r97292  
    515515
    516516template <class Parent>
    517 UString JSCallbackObject<Parent>::toString(ExecState* exec) const
    518 {
    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>
    542517void JSCallbackObject<Parent>::setPrivate(void* data)
    543518{
  • trunk/Source/JavaScriptCore/ChangeLog

    r97291 r97292  
     12011-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
    1402011-10-12  Oliver Hunt  <oliver@apple.com>
    241
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r97097 r97292  
    353353    ?toObject@JSCell@JSC@@QBEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z
    354354    ?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
    358357    ?toStringDecimal@DecimalNumber@WTF@@QBEIPA_WI@Z
    359358    ?toStringExponential@DecimalNumber@WTF@@QBEIPA_WI@Z
  • trunk/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp

    r95936 r97292  
    4444const ClassInfo InterruptedExecutionError::s_info = { "InterruptedExecutionError", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(InterruptedExecutionError) };
    4545
    46 UString InterruptedExecutionError::toString(ExecState*) const
     46JSValue InterruptedExecutionError::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const
    4747{
    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());
    4951}
    5052
     
    6769const ClassInfo TerminatedExecutionError::s_info = { "TerminatedExecutionError", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(TerminatedExecutionError) };
    6870
    69 UString TerminatedExecutionError::toString(ExecState*) const
     71JSValue TerminatedExecutionError::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const
    7072{
    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());
    7276}
    7377
  • trunk/Source/JavaScriptCore/runtime/ExceptionHelpers.h

    r95901 r97292  
    6363    }
    6464
    65     virtual UString toString(ExecState*) const;
     65    virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
    6666
    6767public:
     
    9090    }
    9191
    92     virtual UString toString(ExecState*) const;
     92    virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
    9393
    9494public:
  • trunk/Source/JavaScriptCore/runtime/JSCell.cpp

    r97097 r97292  
    169169}
    170170
    171 UString JSCell::toString(ExecState*) const
     171UString JSCell::toString(ExecState* exec) const
    172172{
    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);
    175176}
    176177
  • trunk/Source/JavaScriptCore/runtime/JSCell.h

    r97097 r97292  
    8383        bool toBoolean(ExecState*) const;
    8484        virtual double toNumber(ExecState*) const;
    85         virtual UString toString(ExecState*) const;
     85        UString toString(ExecState*) const;
    8686        JSObject* toObject(ExecState*, JSGlobalObject*) const;
    8787
  • trunk/Source/JavaScriptCore/runtime/JSNotAnObject.cpp

    r97015 r97292  
    5050    ASSERT_UNUSED(exec, exec->hadException());
    5151    return std::numeric_limits<double>::quiet_NaN();
    52 }
    53 
    54 UString JSNotAnObject::toString(ExecState* exec) const
    55 {
    56     ASSERT_UNUSED(exec, exec->hadException());
    57     return "";
    5852}
    5953
  • trunk/Source/JavaScriptCore/runtime/JSNotAnObject.h

    r97015 r97292  
    6868        virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
    6969        virtual double toNumber(ExecState*) const;
    70         virtual UString toString(ExecState*) const;
    7170
    7271        // JSObject methods
  • trunk/Source/JavaScriptCore/runtime/JSObject.h

    r97097 r97292  
    142142        bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
    143143        virtual double toNumber(ExecState*) const;
    144         virtual UString toString(ExecState*) const;
     144        UString toString(ExecState*) const;
    145145
    146146        virtual JSObject* toThisObject(ExecState*) const;
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r97015 r97292  
    431431        bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
    432432        JSObject* toObject(ExecState*, JSGlobalObject*) const;
     433        UString toString(ExecState*) const;
    433434       
    434435        bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
     
    503504
    504505        virtual double toNumber(ExecState*) const;
    505         virtual UString toString(ExecState*) const;
    506506
    507507        virtual JSObject* toThisObject(ExecState*) const;
  • trunk/Source/JavaScriptGlue/ChangeLog

    r97097 r97292  
     12011-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
    1142011-10-10  Mark Hahnenberg  <mhahnenberg@apple.com>
    215
  • 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{
  • trunk/Source/JavaScriptGlue/UserObjectImp.h

    r97097 r97292  
    6363    virtual bool toBoolean(ExecState *exec) const;
    6464    virtual double toNumber(ExecState *exec) const;
    65     virtual UString toString(ExecState *exec) const;
    6665
    6766    static void visitChildren(JSCell*, SlotVisitor&);
Note: See TracChangeset for help on using the changeset viewer.