Title: [97292] trunk/Source
Revision
97292
Author
[email protected]
Date
2011-10-12 13:23:08 -0700 (Wed, 12 Oct 2011)

Log Message

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

Reviewed by Sam Weinig.

Source/_javascript_Core:

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:
* _javascript_Core.vcproj/_javascript_Core/_javascript_Core.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/_javascript_Glue:

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:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSCallbackObject.h (97291 => 97292)


--- trunk/Source/_javascript_Core/API/JSCallbackObject.h	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/API/JSCallbackObject.h	2011-10-12 20:23:08 UTC (rev 97292)
@@ -194,7 +194,6 @@
     virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
 
     virtual double toNumber(ExecState*) const;
-    virtual UString toString(ExecState*) const;
 
     virtual ConstructType getConstructData(ConstructData&);
     static ConstructType getConstructData(JSCell*, ConstructData&);

Modified: trunk/Source/_javascript_Core/API/JSCallbackObjectFunctions.h (97291 => 97292)


--- trunk/Source/_javascript_Core/API/JSCallbackObjectFunctions.h	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/API/JSCallbackObjectFunctions.h	2011-10-12 20:23:08 UTC (rev 97292)
@@ -514,31 +514,6 @@
 }
 
 template <class Parent>
-UString JSCallbackObject<Parent>::toString(ExecState* exec) const
-{
-    JSContextRef ctx = toRef(exec);
-    JSObjectRef thisRef = toRef(this);
-    
-    for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
-        if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
-            JSValueRef exception = 0;
-            JSValueRef value;
-            {
-                APICallbackShim callbackShim(exec);
-                value = convertToType(ctx, thisRef, kJSTypeString, &exception);
-            }
-            if (exception) {
-                throwError(exec, toJS(exec, exception));
-                return "";
-            }
-            if (value)
-                return toJS(exec, value).getString(exec);
-        }
-            
-    return Parent::toString(exec);
-}
-
-template <class Parent>
 void JSCallbackObject<Parent>::setPrivate(void* data)
 {
     m_callbackObjectData->privateData = data;

Modified: trunk/Source/_javascript_Core/ChangeLog (97291 => 97292)


--- trunk/Source/_javascript_Core/ChangeLog	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-10-12 20:23:08 UTC (rev 97292)
@@ -1,3 +1,42 @@
+2011-10-12  Mark Hahnenberg  <[email protected]>
+
+        De-virtualize JSCell::toString
+        https://bugs.webkit.org/show_bug.cgi?id=69677
+
+        Reviewed by Sam Weinig.
+
+        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:
+        * _javascript_Core.vcproj/_javascript_Core/_javascript_Core.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:
+
 2011-10-12  Oliver Hunt  <[email protected]>
 
         Global stringStructure caches its prototype chain, abandoning a web page

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def (97291 => 97292)


--- trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def	2011-10-12 20:23:08 UTC (rev 97292)
@@ -352,9 +352,8 @@
     ?toNumberSlowCase@JSValue@JSC@@ABENPAVExecState@2@@Z
     ?toObject@JSCell@JSC@@QBEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z
     ?toObjectSlowCase@JSValue@JSC@@ABEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z
-    ?toString@JSCell@JSC@@UBE?AVUString@2@PAVExecState@2@@Z
-    ?toString@JSObject@JSC@@UBE?AVUString@2@PAVExecState@2@@Z
-    ?toString@JSString@JSC@@EBE?AVUString@2@PAVExecState@2@@Z
+    ?toString@JSCell@JSC@@QBE?AVUString@2@PAVExecState@2@@Z
+    ?toString@JSObject@JSC@@QBE?AVUString@2@PAVExecState@2@@Z
     ?toStringDecimal@DecimalNumber@WTF@@QBEIPA_WI@Z
     ?toStringExponential@DecimalNumber@WTF@@QBEIPA_WI@Z
     ?toThisObject@JSCell@JSC@@UBEPAVJSObject@2@PAVExecState@2@@Z

Modified: trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp (97291 => 97292)


--- trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp	2011-10-12 20:23:08 UTC (rev 97292)
@@ -43,9 +43,11 @@
 
 const ClassInfo InterruptedExecutionError::s_info = { "InterruptedExecutionError", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(InterruptedExecutionError) };
 
-UString InterruptedExecutionError::toString(ExecState*) const
+JSValue InterruptedExecutionError::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const
 {
-    return "_javascript_ execution exceeded timeout.";
+    if (hint == PreferString)
+        return jsNontrivialString(exec, "_javascript_ execution exceeded timeout.");
+    return JSValue(std::numeric_limits<double>::quiet_NaN());
 }
 
 JSObject* createInterruptedExecutionException(JSGlobalData* globalData)
@@ -66,9 +68,11 @@
 
 const ClassInfo TerminatedExecutionError::s_info = { "TerminatedExecutionError", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(TerminatedExecutionError) };
 
-UString TerminatedExecutionError::toString(ExecState*) const
+JSValue TerminatedExecutionError::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const
 {
-    return "_javascript_ execution terminated.";
+    if (hint == PreferString)
+        return jsNontrivialString(exec, "_javascript_ execution terminated.");
+    return JSValue(std::numeric_limits<double>::quiet_NaN());
 }
 
 JSObject* createTerminatedExecutionException(JSGlobalData* globalData)

Modified: trunk/Source/_javascript_Core/runtime/ExceptionHelpers.h (97291 => 97292)


--- trunk/Source/_javascript_Core/runtime/ExceptionHelpers.h	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/runtime/ExceptionHelpers.h	2011-10-12 20:23:08 UTC (rev 97292)
@@ -62,7 +62,7 @@
     {
     }
 
-    virtual UString toString(ExecState*) const;
+    virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
 
 public:
     typedef JSNonFinalObject Base;
@@ -89,7 +89,7 @@
     {
     }
 
-    virtual UString toString(ExecState*) const;
+    virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
 
 public:
     typedef JSNonFinalObject Base;

Modified: trunk/Source/_javascript_Core/runtime/JSCell.cpp (97291 => 97292)


--- trunk/Source/_javascript_Core/runtime/JSCell.cpp	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/runtime/JSCell.cpp	2011-10-12 20:23:08 UTC (rev 97292)
@@ -168,10 +168,11 @@
     return 0;
 }
 
-UString JSCell::toString(ExecState*) const
+UString JSCell::toString(ExecState* exec) const
 {
-    ASSERT_NOT_REACHED();
-    return UString();
+    if (isString())
+        return static_cast<const JSString*>(this)->toString(exec);
+    return static_cast<const JSObject*>(this)->toString(exec);
 }
 
 JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const

Modified: trunk/Source/_javascript_Core/runtime/JSCell.h (97291 => 97292)


--- trunk/Source/_javascript_Core/runtime/JSCell.h	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/runtime/JSCell.h	2011-10-12 20:23:08 UTC (rev 97292)
@@ -82,7 +82,7 @@
         bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
         bool toBoolean(ExecState*) const;
         virtual double toNumber(ExecState*) const;
-        virtual UString toString(ExecState*) const;
+        UString toString(ExecState*) const;
         JSObject* toObject(ExecState*, JSGlobalObject*) const;
 
         static void visitChildren(JSCell*, SlotVisitor&);

Modified: trunk/Source/_javascript_Core/runtime/JSNotAnObject.cpp (97291 => 97292)


--- trunk/Source/_javascript_Core/runtime/JSNotAnObject.cpp	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/runtime/JSNotAnObject.cpp	2011-10-12 20:23:08 UTC (rev 97292)
@@ -51,12 +51,6 @@
     return std::numeric_limits<double>::quiet_NaN();
 }
 
-UString JSNotAnObject::toString(ExecState* exec) const
-{
-    ASSERT_UNUSED(exec, exec->hadException());
-    return "";
-}
-
 bool JSNotAnObject::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot)
 {
     return getOwnPropertySlot(this, exec, identifier, slot);

Modified: trunk/Source/_javascript_Core/runtime/JSNotAnObject.h (97291 => 97292)


--- trunk/Source/_javascript_Core/runtime/JSNotAnObject.h	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/runtime/JSNotAnObject.h	2011-10-12 20:23:08 UTC (rev 97292)
@@ -67,7 +67,6 @@
         // JSValue methods
         virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
         virtual double toNumber(ExecState*) const;
-        virtual UString toString(ExecState*) const;
 
         // JSObject methods
         virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);

Modified: trunk/Source/_javascript_Core/runtime/JSObject.h (97291 => 97292)


--- trunk/Source/_javascript_Core/runtime/JSObject.h	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/runtime/JSObject.h	2011-10-12 20:23:08 UTC (rev 97292)
@@ -141,7 +141,7 @@
         bool toBoolean(ExecState*) const;
         bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
         virtual double toNumber(ExecState*) const;
-        virtual UString toString(ExecState*) const;
+        UString toString(ExecState*) const;
 
         virtual JSObject* toThisObject(ExecState*) const;
         virtual JSObject* unwrappedObject();

Modified: trunk/Source/_javascript_Core/runtime/JSString.h (97291 => 97292)


--- trunk/Source/_javascript_Core/runtime/JSString.h	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Core/runtime/JSString.h	2011-10-12 20:23:08 UTC (rev 97292)
@@ -430,6 +430,7 @@
         bool toBoolean(ExecState*) const;
         bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
         JSObject* toObject(ExecState*, JSGlobalObject*) const;
+        UString toString(ExecState*) const;
         
         bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
         bool getStringPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
@@ -502,7 +503,6 @@
         }
 
         virtual double toNumber(ExecState*) const;
-        virtual UString toString(ExecState*) const;
 
         virtual JSObject* toThisObject(ExecState*) const;
 

Modified: trunk/Source/_javascript_Glue/ChangeLog (97291 => 97292)


--- trunk/Source/_javascript_Glue/ChangeLog	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Glue/ChangeLog	2011-10-12 20:23:08 UTC (rev 97292)
@@ -1,3 +1,16 @@
+2011-10-12  Mark Hahnenberg  <[email protected]>
+
+        De-virtualize JSCell::toString
+        https://bugs.webkit.org/show_bug.cgi?id=69677
+
+        Reviewed by Sam Weinig.
+
+        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:
+
 2011-10-10  Mark Hahnenberg  <[email protected]>
 
         Remove getCallDataVirtual methods

Modified: trunk/Source/_javascript_Glue/UserObjectImp.cpp (97291 => 97292)


--- trunk/Source/_javascript_Glue/UserObjectImp.cpp	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Glue/UserObjectImp.cpp	2011-10-12 20:23:08 UTC (rev 97292)
@@ -328,95 +328,6 @@
     return result;
 }
 
-UString UserObjectImp::toString(ExecState *exec) const
-{
-    UString result;
-    JSUserObject* jsObjPtr = KJSValueToJSObject(toObject(exec, exec->lexicalGlobalObject()), exec);
-    CFTypeRef cfValue = jsObjPtr ? jsObjPtr->CopyCFValue() : 0;
-    if (cfValue)
-    {
-        CFTypeID cfType = CFGetTypeID(cfValue);
-        if (cfValue == GetCFNull())
-        {
-            //
-        }
-        else if (cfType == CFBooleanGetTypeID())
-        {
-            if (cfValue == kCFBooleanTrue)
-            {
-                result = "true";
-            }
-            else
-            {
-                result = "false";
-            }
-        }
-        else if (cfType == CFStringGetTypeID())
-        {
-            result = CFStringToUString((CFStringRef)cfValue);
-        }
-        else if (cfType == CFNumberGetTypeID())
-        {
-            if (cfValue == kCFNumberNaN)
-            {
-                result = "Nan";
-            }
-            else if (CFNumberCompare(kCFNumberPositiveInfinity, (CFNumberRef)cfValue, 0) == 0)
-            {
-                result = "Infinity";
-            }
-            else if (CFNumberCompare(kCFNumberNegativeInfinity, (CFNumberRef)cfValue, 0) == 0)
-            {
-                result = "-Infinity";
-            }
-            else
-            {
-                CFStringRef cfNumStr;
-                double d = 0;
-                CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d);
-                if (CFNumberIsFloatType((CFNumberRef)cfValue))
-                {
-                    cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%f"), d);
-                }
-                else
-                {
-                    cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%.0f"), d);
-                }
-                result = CFStringToUString(cfNumStr);
-                ReleaseCFType(cfNumStr);
-            }
-        }
-        else if (cfType == CFArrayGetTypeID())
-        {
-            //
-        }
-        else if (cfType == CFDictionaryGetTypeID())
-        {
-            //
-        }
-        else if (cfType == CFSetGetTypeID())
-        {
-            //
-        }
-        else if (cfType == CFURLGetTypeID())
-        {
-            CFURLRef absURL = CFURLCopyAbsoluteURL((CFURLRef)cfValue);
-            if (absURL)
-            {
-                CFStringRef cfStr = CFURLGetString(absURL);
-                if (cfStr)
-                {
-                    result = CFStringToUString(cfStr);
-                }
-                ReleaseCFType(absURL);
-            }
-        }
-    }
-    ReleaseCFType(cfValue);
-    if (jsObjPtr) jsObjPtr->Release();
-    return result;
-}
-
 void UserObjectImp::visitChildren(JSCell* cell, SlotVisitor& visitor)
 {
     UserObjectImp* thisObject = static_cast<UserObjectImp*>(cell);

Modified: trunk/Source/_javascript_Glue/UserObjectImp.h (97291 => 97292)


--- trunk/Source/_javascript_Glue/UserObjectImp.h	2011-10-12 19:51:46 UTC (rev 97291)
+++ trunk/Source/_javascript_Glue/UserObjectImp.h	2011-10-12 20:23:08 UTC (rev 97292)
@@ -62,7 +62,6 @@
     JSValue toPrimitive(ExecState*, PreferredPrimitiveType preferredType = NoPreference) const;
     virtual bool toBoolean(ExecState *exec) const;
     virtual double toNumber(ExecState *exec) const;
-    virtual UString toString(ExecState *exec) const;
 
     static void visitChildren(JSCell*, SlotVisitor&);
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to