De-virtualized JSCell::toNumber
authormhahnenberg@apple.com <mhahnenberg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Oct 2011 19:24:53 +0000 (19:24 +0000)
committermhahnenberg@apple.com <mhahnenberg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Oct 2011 19:24:53 +0000 (19:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=69858

Reviewed by Sam Weinig.

Source/JavaScriptCore:

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:
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.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/JavaScriptGlue:

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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@97381 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/JavaScriptCore/API/JSCallbackObject.h
Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
Source/JavaScriptCore/runtime/JSCell.cpp
Source/JavaScriptCore/runtime/JSCell.h
Source/JavaScriptCore/runtime/JSNotAnObject.cpp
Source/JavaScriptCore/runtime/JSNotAnObject.h
Source/JavaScriptCore/runtime/JSObject.h
Source/JavaScriptCore/runtime/JSString.h
Source/JavaScriptGlue/ChangeLog
Source/JavaScriptGlue/UserObjectImp.cpp
Source/JavaScriptGlue/UserObjectImp.h

index c946957..d46f231 100644 (file)
@@ -193,8 +193,6 @@ private:
 
     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&);
index fd8c8de..6bd8c31 100644 (file)
@@ -479,41 +479,6 @@ void JSCallbackObject<Parent>::getOwnPropertyNames(ExecState* exec, PropertyName
 }
 
 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;
index b3828b2..e47b539 100644 (file)
@@ -1,3 +1,30 @@
+2011-10-13  Mark Hahnenberg  <mhahnenberg@apple.com>
+
+        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:
+        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.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  <wangxianzhu@chromium.org>
 
         Use realloc() to expand/shrink StringBuilder buffer
index e250b5c..973bc38 100644 (file)
@@ -346,9 +346,6 @@ EXPORTS
     ?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
index 31121f3..fe0c527 100644 (file)
@@ -162,10 +162,11 @@ bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value)
     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
index 71c82a3..83619bd 100644 (file)
@@ -81,7 +81,7 @@ namespace JSC {
         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;
 
index 08f5f10..2af74fd 100644 (file)
@@ -45,12 +45,6 @@ JSValue JSNotAnObject::defaultValue(ExecState* exec, PreferredPrimitiveType) con
     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);
index 8e4f09c..934aa6c 100644 (file)
@@ -66,7 +66,6 @@ namespace JSC {
 
         // JSValue methods
         virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
-        virtual double toNumber(ExecState*) const;
 
         // JSObject methods
         virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
index 3a8409d..f7abf3e 100644 (file)
@@ -140,7 +140,7 @@ namespace JSC {
         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;
index 0c01633..3eed893 100644 (file)
@@ -431,6 +431,7 @@ namespace JSC {
         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 @@ namespace JSC {
             }
         }
 
-        virtual double toNumber(ExecState*) const;
-
         virtual JSObject* toThisObject(ExecState*) const;
 
         // Actually getPropertySlot, not getOwnPropertySlot (see JSCell).
index 8406d43..cf2ca34 100644 (file)
@@ -1,3 +1,15 @@
+2011-10-13  Mark Hahnenberg  <mhahnenberg@apple.com>
+
+        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  <mhahnenberg@apple.com>
 
         De-virtualize JSCell::toString
index abf8d0c..55570f0 100644 (file)
@@ -294,40 +294,6 @@ bool UserObjectImp::toBoolean(ExecState *exec) const
     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);
index 66b5fdd..790071b 100644 (file)
@@ -61,7 +61,6 @@ public:
 
     JSValue toPrimitive(ExecState*, PreferredPrimitiveType preferredType = NoPreference) const;
     virtual bool toBoolean(ExecState *exec) const;
-    virtual double toNumber(ExecState *exec) const;
 
     static void visitChildren(JSCell*, SlotVisitor&);