Ignore:
Timestamp:
Sep 14, 2011, 10:15:16 PM (14 years ago)
Author:
[email protected]
Message:

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

Reviewed by Sam Weinig.

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):

  • runtime/StringObjectThatMasqueradesAsUndefined.h:
File:
1 edited

Legend:

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

    r94929 r95167  
    6363    public:
    6464        friend class JIT;
     65        friend class JSCell;
    6566        friend class JSGlobalData;
     67        friend class JSValue;
    6668        friend class SpecializedThunkJIT;
    6769        friend struct ThunkHelpers;
     
    495497        virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
    496498        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
    497         virtual bool toBoolean(ExecState*) const;
     499        bool toBoolean(ExecState*) const;
    498500        virtual double toNumber(ExecState*) const;
    499501        virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
     
    681683    inline bool isJSString(JSGlobalData* globalData, JSValue v) { return v.isCell() && v.asCell()->vptr() == globalData->jsStringVPtr; }
    682684
     685    inline bool JSCell::toBoolean(ExecState* exec) const
     686    {
     687        if (isString())
     688            return static_cast<const JSString*>(this)->toBoolean(exec);
     689        return !structure()->typeInfo().masqueradesAsUndefined();
     690    }
     691
    683692    // --- JSValue inlines ----------------------------
     693   
     694    inline bool JSValue::toBoolean(ExecState* exec) const
     695    {
     696        if (isInt32())
     697            return asInt32();
     698        if (isDouble())
     699            return asDouble() > 0.0 || asDouble() < 0.0; // false for NaN
     700        if (isCell())
     701            return asCell()->toBoolean(exec);
     702        return isTrue(); // false, null, and undefined all convert to false.
     703    }
    684704
    685705    inline UString JSValue::toString(ExecState* exec) const
Note: See TracChangeset for help on using the changeset viewer.