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/JSValue.cpp

    r43122 r46598  
    2424#include "JSValue.h"
    2525
     26#include "BooleanConstructor.h"
     27#include "BooleanPrototype.h"
     28#include "ExceptionHelpers.h"
     29#include "JSGlobalObject.h"
    2630#include "JSFunction.h"
     31#include "JSNotAnObject.h"
     32#include "NumberObject.h"
    2733#include <wtf/MathExtras.h>
     34#include <wtf/StringExtras.h>
    2835
    2936namespace JSC {
     
    3441double JSValue::toInteger(ExecState* exec) const
    3542{
    36     if (isInt32Fast())
    37         return getInt32Fast();
     43    if (isInt32())
     44        return asInt32();
    3845    double d = toNumber(exec);
    3946    return isnan(d) ? 0.0 : trunc(d);
     
    4249double JSValue::toIntegerPreserveNaN(ExecState* exec) const
    4350{
    44     if (isInt32Fast())
    45         return getInt32Fast();
     51    if (isInt32())
     52        return asInt32();
    4653    return trunc(toNumber(exec));
    4754}
     55
     56JSObject* JSValue::toObjectSlowCase(ExecState* exec) const
     57{
     58    ASSERT(!isCell());
     59
     60    if (isInt32() || isDouble())
     61        return constructNumber(exec, asValue());
     62    if (isTrue() || isFalse())
     63        return constructBooleanFromImmediateBoolean(exec, asValue());
     64    ASSERT(isUndefinedOrNull());
     65    JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull());
     66    exec->setException(exception);
     67    return new (exec) JSNotAnObject(exec, exception);
     68}
     69
     70JSObject* JSValue::toThisObjectSlowCase(ExecState* exec) const
     71{
     72    ASSERT(!isCell());
     73
     74    if (isInt32() || isDouble())
     75        return constructNumber(exec, asValue());
     76    if (isTrue() || isFalse())
     77        return constructBooleanFromImmediateBoolean(exec, asValue());
     78    ASSERT(isUndefinedOrNull());
     79    return exec->globalThisValue();
     80}
     81
     82JSObject* JSValue::synthesizeObject(ExecState* exec) const
     83{
     84    ASSERT(!isCell());
     85    if (isNumber())
     86        return constructNumber(exec, asValue());
     87    if (isBoolean())
     88        return constructBooleanFromImmediateBoolean(exec, asValue());
     89   
     90    JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull());
     91    exec->setException(exception);
     92    return new (exec) JSNotAnObject(exec, exception);
     93}
     94
     95JSObject* JSValue::synthesizePrototype(ExecState* exec) const
     96{
     97    ASSERT(!isCell());
     98    if (isNumber())
     99        return exec->lexicalGlobalObject()->numberPrototype();
     100    if (isBoolean())
     101        return exec->lexicalGlobalObject()->booleanPrototype();
     102
     103    JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull());
     104    exec->setException(exception);
     105    return new (exec) JSNotAnObject(exec, exception);
     106}
     107
     108#ifndef NDEBUG
     109char* JSValue::description()
     110{
     111    static const size_t size = 32;
     112    static char description[size];
     113    if (isInt32())
     114        snprintf(description, size, "Int32: %d", asInt32());
     115    else if (isDouble())
     116        snprintf(description, size, "Double: %lf", asDouble());
     117    else if (isCell())
     118        snprintf(description, size, "Cell: %p", asCell());
     119    else if (isTrue())
     120        snprintf(description, size, "True");
     121    else if (isFalse())
     122        snprintf(description, size, "False");
     123    else if (isNull())
     124        snprintf(description, size, "Null");
     125    else {
     126        ASSERT(isUndefined());
     127        snprintf(description, size, "Undefined");
     128    }
     129
     130    return description;
     131}
     132#endif
    48133
    49134int32_t toInt32SlowCase(double d, bool& ok)
     
    85170}
    86171
     172NEVER_INLINE double nonInlineNaN()
     173{
     174    return std::numeric_limits<double>::quiet_NaN();
     175}
     176
    87177} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.