Ignore:
Timestamp:
Sep 26, 2011, 4:53:42 PM (14 years ago)
Author:
[email protected]
Message:

Make JSCell::toBoolean non-virtual
https://bugs.webkit.org/show_bug.cgi?id=67727

Reviewed by Geoffrey Garen.

JSCell::toBoolean now manually performs the toBoolean check for objects and strings (where
before it was simply virtual and would crash if its implementation was called).
Its descendants in JSObject and JSString have also been made non-virtual. JSCell now
explicitly covers all cases of toBoolean, so having a virtual implementation of
JSCell::toBoolean is no longer necessary. This is part of a larger process of un-virtualizing JSCell.

  • JavaScriptCore.exp:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
  • runtime/JSCell.cpp:
  • runtime/JSCell.h:
  • runtime/JSNotAnObject.cpp:
  • runtime/JSNotAnObject.h:
  • runtime/JSObject.h:
  • runtime/JSString.h:

(JSC::JSCell::toBoolean):
(JSC::JSValue::toBoolean):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r95516 r96045  
    428428
    429429        JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
     430        bool toBoolean(ExecState*) const;
     431       
    430432        bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
    431433        bool getStringPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
     
    495497
    496498        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
    497         virtual bool toBoolean(ExecState*) const;
    498499        virtual double toNumber(ExecState*) const;
    499500        virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
     
    681682    inline bool isJSString(JSGlobalData* globalData, JSValue v) { return v.isCell() && v.asCell()->vptr() == globalData->jsStringVPtr; }
    682683
     684    inline bool JSCell::toBoolean(ExecState* exec) const
     685    {
     686        if (isString())
     687            return static_cast<const JSString*>(this)->toBoolean(exec);
     688        return !structure()->typeInfo().masqueradesAsUndefined();
     689    }
     690
    683691    // --- JSValue inlines ----------------------------
     692   
     693    inline bool JSValue::toBoolean(ExecState* exec) const
     694    {
     695        if (isInt32())
     696            return asInt32();
     697        if (isDouble())
     698            return asDouble() > 0.0 || asDouble() < 0.0; // false for NaN
     699        if (isCell())
     700            return asCell()->toBoolean(exec);
     701        return isTrue(); // false, null, and undefined all convert to false.
     702    }
    684703
    685704    inline UString JSValue::toString(ExecState* exec) const
Note: See TracChangeset for help on using the changeset viewer.