Ignore:
Timestamp:
Jul 30, 2009, 1:57:44 PM (16 years ago)
Author:
[email protected]
Message:

Merged nitro-extreme branch into trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSCell.h

    r46528 r46598  
    4141        friend class JSString;
    4242        friend class JSValue;
     43        friend class JSAPIValueWrapper;
    4344        friend struct VPtrSet;
    4445
     
    4950    public:
    5051        // Querying the type.
     52#if USE(JSVALUE32)
    5153        bool isNumber() const;
     54#endif
    5255        bool isString() const;
    5356        bool isObject() const;
    5457        virtual bool isGetterSetter() const;
    5558        virtual bool isObject(const ClassInfo*) const;
     59        virtual bool isAPIValueWrapper() const { return false; }
    5660
    5761        Structure* structure() const;
     
    6973        // FIXME: remove these methods, can check isNumberCell in JSValue && then call asNumberCell::*.
    7074        virtual bool getUInt32(uint32_t&) const;
    71         virtual bool getTruncatedInt32(int32_t&) const;
    72         virtual bool getTruncatedUInt32(uint32_t&) const;
    7375
    7476        // Basic conversions.
     
    125127    }
    126128
     129#if USE(JSVALUE32)
    127130    inline bool JSCell::isNumber() const
    128131    {
    129132        return Heap::isNumber(const_cast<JSCell*>(this));
    130133    }
     134#endif
    131135
    132136    inline bool JSCell::isObject() const
     
    153157    {
    154158        return Heap::markCell(this);
    155     }
    156 
    157     ALWAYS_INLINE JSCell* JSValue::asCell() const
    158     {
    159         ASSERT(isCell());
    160         return m_ptr;
    161159    }
    162160
     
    174172    inline bool JSValue::isString() const
    175173    {
    176         return !JSImmediate::isImmediate(asValue()) && asCell()->isString();
     174        return isCell() && asCell()->isString();
    177175    }
    178176
    179177    inline bool JSValue::isGetterSetter() const
    180178    {
    181         return !JSImmediate::isImmediate(asValue()) && asCell()->isGetterSetter();
     179        return isCell() && asCell()->isGetterSetter();
    182180    }
    183181
    184182    inline bool JSValue::isObject() const
    185183    {
    186         return !JSImmediate::isImmediate(asValue()) && asCell()->isObject();
     184        return isCell() && asCell()->isObject();
    187185    }
    188186
    189187    inline bool JSValue::getString(UString& s) const
    190188    {
    191         return !JSImmediate::isImmediate(asValue()) && asCell()->getString(s);
     189        return isCell() && asCell()->getString(s);
    192190    }
    193191
    194192    inline UString JSValue::getString() const
    195193    {
    196         return JSImmediate::isImmediate(asValue()) ? UString() : asCell()->getString();
     194        return isCell() ? asCell()->getString() : UString();
    197195    }
    198196
    199197    inline JSObject* JSValue::getObject() const
    200198    {
    201         return JSImmediate::isImmediate(asValue()) ? 0 : asCell()->getObject();
     199        return isCell() ? asCell()->getObject() : 0;
    202200    }
    203201
    204202    inline CallType JSValue::getCallData(CallData& callData)
    205203    {
    206         return JSImmediate::isImmediate(asValue()) ? CallTypeNone : asCell()->getCallData(callData);
     204        return isCell() ? asCell()->getCallData(callData) : CallTypeNone;
    207205    }
    208206
    209207    inline ConstructType JSValue::getConstructData(ConstructData& constructData)
    210208    {
    211         return JSImmediate::isImmediate(asValue()) ? ConstructTypeNone : asCell()->getConstructData(constructData);
     209        return isCell() ? asCell()->getConstructData(constructData) : ConstructTypeNone;
    212210    }
    213211
    214212    ALWAYS_INLINE bool JSValue::getUInt32(uint32_t& v) const
    215213    {
    216         return JSImmediate::isImmediate(asValue()) ? JSImmediate::getUInt32(asValue(), v) : asCell()->getUInt32(v);
    217     }
    218 
    219     ALWAYS_INLINE bool JSValue::getTruncatedInt32(int32_t& v) const
    220     {
    221         return JSImmediate::isImmediate(asValue()) ? JSImmediate::getTruncatedInt32(asValue(), v) : asCell()->getTruncatedInt32(v);
    222     }
    223 
    224     inline bool JSValue::getTruncatedUInt32(uint32_t& v) const
    225     {
    226         return JSImmediate::isImmediate(asValue()) ? JSImmediate::getTruncatedUInt32(asValue(), v) : asCell()->getTruncatedUInt32(v);
     214        if (isInt32()) {
     215            int32_t i = asInt32();
     216            v = static_cast<uint32_t>(i);
     217            return i >= 0;
     218        }
     219        if (isDouble()) {
     220            double d = asDouble();
     221            v = static_cast<uint32_t>(d);
     222            return v == d;
     223        }
     224        return false;
    227225    }
    228226
     
    234232    inline bool JSValue::marked() const
    235233    {
    236         return JSImmediate::isImmediate(asValue()) || asCell()->marked();
    237     }
     234        return !isCell() || asCell()->marked();
     235    }
     236
     237#if !USE(JSVALUE32_64)
     238    ALWAYS_INLINE JSCell* JSValue::asCell() const
     239    {
     240        ASSERT(isCell());
     241        return m_ptr;
     242    }
     243#endif // !USE(JSVALUE32_64)
    238244
    239245    inline JSValue JSValue::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
    240246    {
    241         return JSImmediate::isImmediate(asValue()) ? asValue() : asCell()->toPrimitive(exec, preferredType);
     247        return isCell() ? asCell()->toPrimitive(exec, preferredType) : asValue();
    242248    }
    243249
    244250    inline bool JSValue::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value)
    245251    {
    246         if (JSImmediate::isImmediate(asValue())) {
    247             number = JSImmediate::toDouble(asValue());
    248             value = asValue();
    249             return true;
    250         }
    251         return asCell()->getPrimitiveNumber(exec, number, value);
     252        if (isInt32()) {
     253            number = asInt32();
     254            value = *this;
     255            return true;
     256        }
     257        if (isDouble()) {
     258            number = asDouble();
     259            value = *this;
     260            return true;
     261        }
     262        if (isCell())
     263            return asCell()->getPrimitiveNumber(exec, number, value);
     264        if (isTrue()) {
     265            number = 1.0;
     266            value = *this;
     267            return true;
     268        }
     269        if (isFalse() || isNull()) {
     270            number = 0.0;
     271            value = *this;
     272            return true;
     273        }
     274        ASSERT(isUndefined());
     275        number = nonInlineNaN();
     276        value = *this;
     277        return true;
    252278    }
    253279
    254280    inline bool JSValue::toBoolean(ExecState* exec) const
    255281    {
    256         return JSImmediate::isImmediate(asValue()) ? JSImmediate::toBoolean(asValue()) : asCell()->toBoolean(exec);
     282        if (isInt32())
     283            return asInt32() != 0;
     284        if (isDouble())
     285            return asDouble() > 0.0 || asDouble() < 0.0; // false for NaN
     286        if (isCell())
     287            return asCell()->toBoolean(exec);
     288        return isTrue(); // false, null, and undefined all convert to false.
    257289    }
    258290
    259291    ALWAYS_INLINE double JSValue::toNumber(ExecState* exec) const
    260292    {
    261         return JSImmediate::isImmediate(asValue()) ? JSImmediate::toDouble(asValue()) : asCell()->toNumber(exec);
     293        if (isInt32())
     294            return asInt32();
     295        if (isDouble())
     296            return asDouble();
     297        if (isCell())
     298            return asCell()->toNumber(exec);
     299        if (isTrue())
     300            return 1.0;
     301        return isUndefined() ? nonInlineNaN() : 0; // null and false both convert to 0.
    262302    }
    263303
    264304    inline UString JSValue::toString(ExecState* exec) const
    265305    {
    266         return JSImmediate::isImmediate(asValue()) ? JSImmediate::toString(asValue()) : asCell()->toString(exec);
     306        if (isCell())
     307            return asCell()->toString(exec);
     308        if (isInt32())
     309            return UString::from(asInt32());
     310        if (isDouble())
     311            return asDouble() == 0.0 ? "0" : UString::from(asDouble());
     312        if (isTrue())
     313            return "true";
     314        if (isFalse())
     315            return "false";
     316        if (isNull())
     317            return "null";
     318        ASSERT(isUndefined());
     319        return "undefined";
     320    }
     321
     322    inline bool JSValue::needsThisConversion() const
     323    {
     324        if (UNLIKELY(!isCell()))
     325            return true;
     326        return asCell()->structure()->typeInfo().needsThisConversion();
     327    }
     328
     329    inline UString JSValue::toThisString(ExecState* exec) const
     330    {
     331        return isCell() ? asCell()->toThisString(exec) : toString(exec);
     332    }
     333
     334    inline JSValue JSValue::getJSNumber()
     335    {
     336        if (isInt32() || isDouble())
     337            return *this;
     338        if (isCell())
     339            return asCell()->getJSNumber();
     340        return JSValue();
    267341    }
    268342
    269343    inline JSObject* JSValue::toObject(ExecState* exec) const
    270344    {
    271         return JSImmediate::isImmediate(asValue()) ? JSImmediate::toObject(asValue(), exec) : asCell()->toObject(exec);
     345        return isCell() ? asCell()->toObject(exec) : toObjectSlowCase(exec);
    272346    }
    273347
    274348    inline JSObject* JSValue::toThisObject(ExecState* exec) const
    275349    {
    276         if (UNLIKELY(JSImmediate::isImmediate(asValue())))
    277             return JSImmediate::toThisObject(asValue(), exec);
    278         return asCell()->toThisObject(exec);
    279     }
    280 
    281     inline bool JSValue::needsThisConversion() const
    282     {
    283         if (UNLIKELY(JSImmediate::isImmediate(asValue())))
    284             return true;
    285         return asCell()->structure()->typeInfo().needsThisConversion();
    286     }
    287 
    288     inline UString JSValue::toThisString(ExecState* exec) const
    289     {
    290         return JSImmediate::isImmediate(asValue()) ? JSImmediate::toString(asValue()) : asCell()->toThisString(exec);
    291     }
    292 
    293     inline JSValue JSValue::getJSNumber()
    294     {
    295         return JSImmediate::isNumber(asValue()) ? asValue() : JSImmediate::isImmediate(asValue()) ? JSValue() : asCell()->getJSNumber();
     350        return isCell() ? asCell()->toThisObject(exec) : toThisObjectSlowCase(exec);
    296351    }
    297352
Note: See TracChangeset for help on using the changeset viewer.