Changeset 37333 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Oct 6, 2008, 10:50:08 AM (17 years ago)
Author:
[email protected]
Message:

2008-10-06 Maciej Stachowiak <[email protected]>

Reviewed by Sam Weinig.



1) Make JSValue::toBoolean nonvirtual and completely inline by
making use of the StructureID type field.


2) Make JSValue::toBoolean not take an ExecState; doesn't need it.


3) Make op_not, op_loop_if_true and op_jtrue not read the
ExecState (toBoolean doesn't need it any more) and not check
exceptions (toBoolean can't throw).

  • API/JSValueRef.cpp: (JSValueToBoolean):
  • JavaScriptCore.exp:
  • VM/CodeBlock.cpp: (JSC::CodeBlock::dump):
  • VM/Machine.cpp: (JSC::Machine::privateExecute): (JSC::Machine::cti_op_loop_if_true): (JSC::Machine::cti_op_not): (JSC::Machine::cti_op_jtrue):
  • kjs/ArrayPrototype.cpp: (JSC::arrayProtoFuncFilter): (JSC::arrayProtoFuncEvery): (JSC::arrayProtoFuncSome):
  • kjs/BooleanConstructor.cpp: (JSC::constructBoolean): (JSC::callBooleanConstructor):
  • kjs/GetterSetter.h:
  • kjs/JSCell.h: (JSC::JSValue::toBoolean):
  • kjs/JSNumberCell.cpp:
  • kjs/JSNumberCell.h: (JSC::JSNumberCell::toBoolean):
  • kjs/JSObject.cpp:
  • kjs/JSObject.h: (JSC::JSObject::toBoolean): (JSC::JSCell::toBoolean):
  • kjs/JSString.cpp:
  • kjs/JSString.h: (JSC::JSString::toBoolean):
  • kjs/JSValue.h:
  • kjs/RegExpConstructor.cpp: (JSC::setRegExpConstructorMultiline):
  • kjs/RegExpObject.cpp: (JSC::RegExpObject::match):
  • kjs/RegExpPrototype.cpp: (JSC::regExpProtoFuncToString):
Location:
trunk/JavaScriptCore/kjs
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/ArrayPrototype.cpp

    r37175 r37333  
    583583        JSValue* result = call(exec, function, callType, callData, applyThis, eachArguments);
    584584
    585         if (result->toBoolean(exec))
     585        if (result->toBoolean())
    586586            resultArray->put(exec, filterIndex++, v);
    587587    }
     
    657657        eachArguments.append(thisObj);
    658658
    659         bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean(exec);
     659        bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean();
    660660
    661661        if (!predicateResult) {
     
    721721        eachArguments.append(thisObj);
    722722
    723         bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean(exec);
     723        bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean();
    724724
    725725        if (predicateResult) {
  • trunk/JavaScriptCore/kjs/BooleanConstructor.cpp

    r37257 r37333  
    4242{
    4343    BooleanObject* obj = new (exec) BooleanObject(exec->lexicalGlobalObject()->booleanObjectStructure());
    44     obj->setInternalValue(jsBoolean(args.at(exec, 0)->toBoolean(exec)));
     44    obj->setInternalValue(jsBoolean(args.at(exec, 0)->toBoolean()));
    4545    return obj;
    4646}
     
    6060static JSValue* callBooleanConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
    6161{
    62     return jsBoolean(args.at(exec, 0)->toBoolean(exec));
     62    return jsBoolean(args.at(exec, 0)->toBoolean());
    6363}
    6464
  • trunk/JavaScriptCore/kjs/GetterSetter.h

    r36316 r37333  
    5353        virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const;
    5454        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
    55         virtual bool toBoolean(ExecState*) const;
     55        bool toBoolean(ExecState*) const;
    5656        virtual double toNumber(ExecState*) const;
    5757        virtual UString toString(ExecState*) const;
  • trunk/JavaScriptCore/kjs/JSCell.h

    r37285 r37333  
    7373        virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const = 0;
    7474        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*&) = 0;
    75         virtual bool toBoolean(ExecState*) const = 0;
     75        bool toBoolean() const;
    7676        virtual double toNumber(ExecState*) const = 0;
    7777        virtual UString toString(ExecState*) const = 0;
     
    273273    }
    274274
    275     inline bool JSValue::toBoolean(ExecState* exec) const
    276     {
    277         return JSImmediate::isImmediate(this) ? JSImmediate::toBoolean(this) : asCell()->toBoolean(exec);
     275    inline bool JSValue::toBoolean() const
     276    {
     277        return JSImmediate::isImmediate(this) ? JSImmediate::toBoolean(this) : asCell()->toBoolean();
    278278    }
    279279
  • trunk/JavaScriptCore/kjs/JSNumberCell.cpp

    r37257 r37333  
    3939    value = this;
    4040    return true;
    41 }
    42 
    43 bool JSNumberCell::toBoolean(ExecState*) const
    44 {
    45     return m_value < 0.0 || m_value > 0.0; // false for NaN
    4641}
    4742
  • trunk/JavaScriptCore/kjs/JSNumberCell.h

    r37285 r37333  
    5353        virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const;
    5454        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
    55         virtual bool toBoolean(ExecState*) const;
     55        bool toBoolean() const { return m_value < 0.0 || m_value > 0.0; /* false for NaN */ }
    5656        virtual double toNumber(ExecState*) const;
    5757        virtual UString toString(ExecState*) const;
  • trunk/JavaScriptCore/kjs/JSObject.cpp

    r37297 r37333  
    431431}
    432432
    433 bool JSObject::toBoolean(ExecState*) const
    434 {
    435     return true;
    436 }
    437 
    438433double JSObject::toNumber(ExecState* exec) const
    439434{
  • trunk/JavaScriptCore/kjs/JSObject.h

    r37068 r37333  
    2929#include "ExecState.h"
    3030#include "JSNumberCell.h"
     31#include "JSString.h"
    3132#include "PropertyMap.h"
    3233#include "PropertySlot.h"
     
    110111        virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
    111112        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
    112         virtual bool toBoolean(ExecState*) const;
     113        bool toBoolean() const { return true; }
    113114        virtual double toNumber(ExecState*) const;
    114115        virtual UString toString(ExecState*) const;
     
    245246    }
    246247    return false;
     248}
     249
     250inline bool JSCell::toBoolean() const
     251{
     252    JSType type = structureID()->typeInfo().type();
     253    if (type == NumberType)
     254        return static_cast<const JSNumberCell*>(this)->toBoolean();
     255    if (type == ObjectType)
     256        return static_cast<const JSObject*>(this)->toBoolean();
     257    ASSERT(type == StringType);
     258    return static_cast<const JSString*>(this)->toBoolean();
    247259}
    248260
  • trunk/JavaScriptCore/kjs/JSString.cpp

    r37257 r37333  
    4141    number = m_value.toDouble();
    4242    return false;
    43 }
    44 
    45 bool JSString::toBoolean(ExecState*) const
    46 {
    47     return !m_value.isEmpty();
    4843}
    4944
  • trunk/JavaScriptCore/kjs/JSString.h

    r37285 r37333  
    9393        static PassRefPtr<StructureID> createStructureID(JSValue* proto) { return StructureID::create(proto, TypeInfo(StringType, NeedsThisConversion)); }
    9494
     95        bool toBoolean() const { return !m_value.isEmpty(); }
     96
    9597    private:
    9698        enum VPtrStealingHackType { VPtrStealingHack };
     
    102104        virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const;
    103105        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
    104         virtual bool toBoolean(ExecState*) const;
    105106        virtual double toNumber(ExecState*) const;
    106107        virtual JSObject* toObject(ExecState*) const;
  • trunk/JavaScriptCore/kjs/JSValue.h

    r37285 r37333  
    9797        bool getPrimitiveNumber(ExecState*, double& number, JSValue*&);
    9898
    99         bool toBoolean(ExecState*) const;
     99        bool toBoolean() const;
    100100
    101101        // toNumber conversion is expected to be side effect free if an exception has
  • trunk/JavaScriptCore/kjs/RegExpConstructor.cpp

    r37257 r37333  
    312312}
    313313
    314 void setRegExpConstructorMultiline(ExecState* exec, JSObject* baseObject, JSValue* value)
    315 {
    316     static_cast<RegExpConstructor*>(baseObject)->setMultiline(value->toBoolean(exec));
     314void setRegExpConstructorMultiline(ExecState*, JSObject* baseObject, JSValue* value)
     315{
     316    static_cast<RegExpConstructor*>(baseObject)->setMultiline(value->toBoolean());
    317317}
    318318 
  • trunk/JavaScriptCore/kjs/RegExpObject.cpp

    r36977 r37333  
    122122    }
    123123
    124     bool global = get(exec, exec->propertyNames().global)->toBoolean(exec);
     124    bool global = get(exec, exec->propertyNames().global)->toBoolean();
    125125    int lastIndex = 0;
    126126    if (global) {
  • trunk/JavaScriptCore/kjs/RegExpPrototype.cpp

    r36726 r37333  
    107107    UString result = "/" + static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().source)->toString(exec);
    108108    result.append('/');
    109     if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().global)->toBoolean(exec))
     109    if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().global)->toBoolean())
    110110        result.append('g');
    111     if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().ignoreCase)->toBoolean(exec))
     111    if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().ignoreCase)->toBoolean())
    112112        result.append('i');
    113     if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().multiline)->toBoolean(exec))
     113    if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().multiline)->toBoolean())
    114114        result.append('m');
    115115    return jsNontrivialString(exec, result);
Note: See TracChangeset for help on using the changeset viewer.