Title: [97381] trunk/Source
Revision
97381
Author
[email protected]
Date
2011-10-13 12:24:53 -0700 (Thu, 13 Oct 2011)

Log Message

De-virtualized JSCell::toNumber
https://bugs.webkit.org/show_bug.cgi?id=69858

Reviewed by Sam Weinig.

Source/_javascript_Core:

Removed JSCallbackObject::toNumber because its no longer necessary since
JSObject::toNumber now suffices since we implicitly add valueOf to an object's
prototype whenever a convertToType callback is provided.
* API/JSCallbackObject.h:
* API/JSCallbackObjectFunctions.h:
* _javascript_Core.vcproj/_javascript_Core/_javascript_Core.def:

De-virtualized JSCell::toNumber, JSObject::toNumber, and JSString::toNumber.
* runtime/JSCell.cpp:
(JSC::JSCell::toNumber):
* runtime/JSCell.h:
* runtime/JSObject.h:
* runtime/JSString.h:

Removed JSNotAnObject::toNumber because its result doesn't matter and it implements
defaultValue, therefore JSObject::toNumber can cover its case.
* runtime/JSNotAnObject.cpp:
* runtime/JSNotAnObject.h:

Source/_javascript_Glue:

Removed UserObjectImp::toNumber because it's no longer necessary since
JSObject::toNumber can cover this case.
* UserObjectImp.cpp:
* UserObjectImp.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSCallbackObject.h (97380 => 97381)


--- trunk/Source/_javascript_Core/API/JSCallbackObject.h	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Core/API/JSCallbackObject.h	2011-10-13 19:24:53 UTC (rev 97381)
@@ -193,8 +193,6 @@
 
     virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
 
-    virtual double toNumber(ExecState*) const;
-
     virtual ConstructType getConstructData(ConstructData&);
     static ConstructType getConstructData(JSCell*, ConstructData&);
     static CallType getCallData(JSCell*, CallData&);

Modified: trunk/Source/_javascript_Core/API/JSCallbackObjectFunctions.h (97380 => 97381)


--- trunk/Source/_javascript_Core/API/JSCallbackObjectFunctions.h	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Core/API/JSCallbackObjectFunctions.h	2011-10-13 19:24:53 UTC (rev 97381)
@@ -479,41 +479,6 @@
 }
 
 template <class Parent>
-double JSCallbackObject<Parent>::toNumber(ExecState* exec) const
-{
-    // We need this check to guard against the case where this object is rhs of
-    // a binary _expression_ where lhs threw an exception in its conversion to
-    // primitive
-    if (exec->hadException())
-        return std::numeric_limits<double>::quiet_NaN();
-    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, kJSTypeNumber, &exception);
-            }
-            if (exception) {
-                throwError(exec, toJS(exec, exception));
-                return 0;
-            }
-            if (!value)
-                continue;
-                
-            JSValue jsValue = toJS(exec, value);
-            if (!jsValue.isNumber())
-                return std::numeric_limits<double>::quiet_NaN();
-            return jsValue.asNumber();
-        }
-            
-    return Parent::toNumber(exec);
-}
-
-template <class Parent>
 void JSCallbackObject<Parent>::setPrivate(void* data)
 {
     m_callbackObjectData->privateData = data;

Modified: trunk/Source/_javascript_Core/ChangeLog (97380 => 97381)


--- trunk/Source/_javascript_Core/ChangeLog	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-10-13 19:24:53 UTC (rev 97381)
@@ -1,3 +1,30 @@
+2011-10-13  Mark Hahnenberg  <[email protected]>
+
+        De-virtualized JSCell::toNumber
+        https://bugs.webkit.org/show_bug.cgi?id=69858
+
+        Reviewed by Sam Weinig.
+
+
+        Removed JSCallbackObject::toNumber because its no longer necessary since 
+        JSObject::toNumber now suffices since we implicitly add valueOf to an object's
+        prototype whenever a convertToType callback is provided.
+        * API/JSCallbackObject.h:
+        * API/JSCallbackObjectFunctions.h:
+        * _javascript_Core.vcproj/_javascript_Core/_javascript_Core.def:
+
+        De-virtualized JSCell::toNumber, JSObject::toNumber, and JSString::toNumber.
+        * runtime/JSCell.cpp:
+        (JSC::JSCell::toNumber):
+        * runtime/JSCell.h:
+        * runtime/JSObject.h:
+        * runtime/JSString.h:
+
+        Removed JSNotAnObject::toNumber because its result doesn't matter and it implements 
+        defaultValue, therefore JSObject::toNumber can cover its case.
+        * runtime/JSNotAnObject.cpp:
+        * runtime/JSNotAnObject.h:
+
 2011-10-13  Xianzhu Wang  <[email protected]>
 
         Use realloc() to expand/shrink StringBuilder buffer

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def (97380 => 97381)


--- trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def	2011-10-13 19:24:53 UTC (rev 97381)
@@ -346,9 +346,6 @@
     ?tlsKeys@WTF@@YAPAKXZ
     ?toInt32@JSC@@YAHN@Z
     ?toInteger@JSValue@JSC@@QBENPAVExecState@2@@Z
-    ?toNumber@JSCell@JSC@@UBENPAVExecState@2@@Z
-    ?toNumber@JSObject@JSC@@UBENPAVExecState@2@@Z
-    ?toNumber@JSString@JSC@@EBENPAVExecState@2@@Z
     ?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

Modified: trunk/Source/_javascript_Core/runtime/JSCell.cpp (97380 => 97381)


--- trunk/Source/_javascript_Core/runtime/JSCell.cpp	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Core/runtime/JSCell.cpp	2011-10-13 19:24:53 UTC (rev 97381)
@@ -162,10 +162,11 @@
     return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value);
 }
 
-double JSCell::toNumber(ExecState*) const
-{
-    ASSERT_NOT_REACHED();
-    return 0;
+double JSCell::toNumber(ExecState* exec) const
+{ 
+    if (isString())
+        return static_cast<const JSString*>(this)->toNumber(exec);
+    return static_cast<const JSObject*>(this)->toNumber(exec);
 }
 
 UString JSCell::toString(ExecState* exec) const

Modified: trunk/Source/_javascript_Core/runtime/JSCell.h (97380 => 97381)


--- trunk/Source/_javascript_Core/runtime/JSCell.h	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Core/runtime/JSCell.h	2011-10-13 19:24:53 UTC (rev 97381)
@@ -81,7 +81,7 @@
         JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
         bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
         bool toBoolean(ExecState*) const;
-        virtual double toNumber(ExecState*) const;
+        double toNumber(ExecState*) const;
         UString toString(ExecState*) const;
         JSObject* toObject(ExecState*, JSGlobalObject*) const;
 

Modified: trunk/Source/_javascript_Core/runtime/JSNotAnObject.cpp (97380 => 97381)


--- trunk/Source/_javascript_Core/runtime/JSNotAnObject.cpp	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Core/runtime/JSNotAnObject.cpp	2011-10-13 19:24:53 UTC (rev 97381)
@@ -45,12 +45,6 @@
     return jsNumber(0);
 }
 
-double JSNotAnObject::toNumber(ExecState* exec) const
-{
-    ASSERT_UNUSED(exec, exec->hadException());
-    return std::numeric_limits<double>::quiet_NaN();
-}
-
 bool JSNotAnObject::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot)
 {
     return getOwnPropertySlot(this, exec, identifier, slot);

Modified: trunk/Source/_javascript_Core/runtime/JSNotAnObject.h (97380 => 97381)


--- trunk/Source/_javascript_Core/runtime/JSNotAnObject.h	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Core/runtime/JSNotAnObject.h	2011-10-13 19:24:53 UTC (rev 97381)
@@ -66,7 +66,6 @@
 
         // JSValue methods
         virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
-        virtual double toNumber(ExecState*) const;
 
         // JSObject methods
         virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);

Modified: trunk/Source/_javascript_Core/runtime/JSObject.h (97380 => 97381)


--- trunk/Source/_javascript_Core/runtime/JSObject.h	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Core/runtime/JSObject.h	2011-10-13 19:24:53 UTC (rev 97381)
@@ -140,7 +140,7 @@
         JSValue toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
         bool toBoolean(ExecState*) const;
         bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
-        virtual double toNumber(ExecState*) const;
+        double toNumber(ExecState*) const;
         UString toString(ExecState*) const;
 
         virtual JSObject* toThisObject(ExecState*) const;

Modified: trunk/Source/_javascript_Core/runtime/JSString.h (97380 => 97381)


--- trunk/Source/_javascript_Core/runtime/JSString.h	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Core/runtime/JSString.h	2011-10-13 19:24:53 UTC (rev 97381)
@@ -431,6 +431,7 @@
         bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
         JSObject* toObject(ExecState*, JSGlobalObject*) const;
         UString toString(ExecState*) const;
+        double toNumber(ExecState*) const;
         
         bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
         bool getStringPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
@@ -502,8 +503,6 @@
             }
         }
 
-        virtual double toNumber(ExecState*) const;
-
         virtual JSObject* toThisObject(ExecState*) const;
 
         // Actually getPropertySlot, not getOwnPropertySlot (see JSCell).

Modified: trunk/Source/_javascript_Glue/ChangeLog (97380 => 97381)


--- trunk/Source/_javascript_Glue/ChangeLog	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Glue/ChangeLog	2011-10-13 19:24:53 UTC (rev 97381)
@@ -1,3 +1,15 @@
+2011-10-13  Mark Hahnenberg  <[email protected]>
+
+        De-virtualized JSCell::toNumber
+        https://bugs.webkit.org/show_bug.cgi?id=69858
+
+        Reviewed by Sam Weinig.
+
+        Removed UserObjectImp::toNumber because it's no longer necessary since 
+        JSObject::toNumber can cover this case.
+        * UserObjectImp.cpp:
+        * UserObjectImp.h:
+
 2011-10-12  Mark Hahnenberg  <[email protected]>
 
         De-virtualize JSCell::toString

Modified: trunk/Source/_javascript_Glue/UserObjectImp.cpp (97380 => 97381)


--- trunk/Source/_javascript_Glue/UserObjectImp.cpp	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Glue/UserObjectImp.cpp	2011-10-13 19:24:53 UTC (rev 97381)
@@ -294,40 +294,6 @@
     return result;
 }
 
-double UserObjectImp::toNumber(ExecState *exec) const
-{
-    double result = 0;
-    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 = 1;
-            }
-        }
-        else if (cfType == CFStringGetTypeID())
-        {
-            result = CFStringGetDoubleValue((CFStringRef)cfValue);
-        }
-        else if (cfType == CFNumberGetTypeID())
-        {
-            CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &result);
-        }
-    }
-    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 (97380 => 97381)


--- trunk/Source/_javascript_Glue/UserObjectImp.h	2011-10-13 19:07:00 UTC (rev 97380)
+++ trunk/Source/_javascript_Glue/UserObjectImp.h	2011-10-13 19:24:53 UTC (rev 97381)
@@ -61,7 +61,6 @@
 
     JSValue toPrimitive(ExecState*, PreferredPrimitiveType preferredType = NoPreference) const;
     virtual bool toBoolean(ExecState *exec) const;
-    virtual double toNumber(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