Changeset 37333 in webkit for trunk/JavaScriptCore
- Timestamp:
- Oct 6, 2008, 10:50:08 AM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSValueRef.cpp
r37215 r37333 189 189 } 190 190 191 bool JSValueToBoolean(JSContextRef ctx, JSValueRef value) 192 { 193 ExecState* exec = toJS(ctx); 194 JSValue* jsValue = toJS(value); 195 return jsValue->toBoolean(exec); 191 bool JSValueToBoolean(JSContextRef, JSValueRef value) 192 { 193 return toJS(value)->toBoolean(); 196 194 } 197 195 -
trunk/JavaScriptCore/ChangeLog
r37331 r37333 1 2008-10-06 Maciej Stachowiak <[email protected]> 2 3 Reviewed by Sam Weinig. 4 5 - optimize op_jtrue, op_loop_if_true and op_not in various ways 6 https://bugs.webkit.org/show_bug.cgi?id=21404 7 8 1) Make JSValue::toBoolean nonvirtual and completely inline by 9 making use of the StructureID type field. 10 11 2) Make JSValue::toBoolean not take an ExecState; doesn't need it. 12 13 3) Make op_not, op_loop_if_true and op_jtrue not read the 14 ExecState (toBoolean doesn't need it any more) and not check 15 exceptions (toBoolean can't throw). 16 17 * API/JSValueRef.cpp: 18 (JSValueToBoolean): 19 * JavaScriptCore.exp: 20 * VM/CodeBlock.cpp: 21 (JSC::CodeBlock::dump): 22 * VM/Machine.cpp: 23 (JSC::Machine::privateExecute): 24 (JSC::Machine::cti_op_loop_if_true): 25 (JSC::Machine::cti_op_not): 26 (JSC::Machine::cti_op_jtrue): 27 * kjs/ArrayPrototype.cpp: 28 (JSC::arrayProtoFuncFilter): 29 (JSC::arrayProtoFuncEvery): 30 (JSC::arrayProtoFuncSome): 31 * kjs/BooleanConstructor.cpp: 32 (JSC::constructBoolean): 33 (JSC::callBooleanConstructor): 34 * kjs/GetterSetter.h: 35 * kjs/JSCell.h: 36 (JSC::JSValue::toBoolean): 37 * kjs/JSNumberCell.cpp: 38 * kjs/JSNumberCell.h: 39 (JSC::JSNumberCell::toBoolean): 40 * kjs/JSObject.cpp: 41 * kjs/JSObject.h: 42 (JSC::JSObject::toBoolean): 43 (JSC::JSCell::toBoolean): 44 * kjs/JSString.cpp: 45 * kjs/JSString.h: 46 (JSC::JSString::toBoolean): 47 * kjs/JSValue.h: 48 * kjs/RegExpConstructor.cpp: 49 (JSC::setRegExpConstructorMultiline): 50 * kjs/RegExpObject.cpp: 51 (JSC::RegExpObject::match): 52 * kjs/RegExpPrototype.cpp: 53 (JSC::regExpProtoFuncToString): 54 1 55 2008-10-06 Ariya Hidayat <[email protected]> 2 56 -
trunk/JavaScriptCore/JavaScriptCore.exp
r37323 r37333 336 336 __ZNK3JSC8JSObject8toStringEPNS_9ExecStateE 337 337 __ZNK3JSC8JSObject9classNameEv 338 __ZNK3JSC8JSObject9toBooleanEPNS_9ExecStateE339 338 __ZNK3JSC9CodeBlock17derefStructureIDsEPNS_11InstructionE 340 339 __ZNK3JSC9HashTable11createTableEPNS_12JSGlobalDataE -
trunk/JavaScriptCore/VM/CodeBlock.cpp
r37324 r37333 811 811 } 812 812 case op_tear_off_activation: { 813 int r0 = (++it)->u.operand; 814 printf("[%4d] tear_off_activation\t %s\n", location, registerName(r0).c_str()); 813 printf("[%4d] tear_off_activation\n", location); 815 814 break; 816 815 } 817 816 case op_tear_off_arguments: { 818 int r0 = (++it)->u.operand; 819 printf("[%4d] tear_off_arguments\t %s\n", location, registerName(r0).c_str()); 817 printf("[%4d] tear_off_arguments\n", location); 820 818 break; 821 819 } -
trunk/JavaScriptCore/VM/Machine.cpp
r37325 r37333 2128 2128 int dst = (++vPC)->u.operand; 2129 2129 int src = (++vPC)->u.operand; 2130 JSValue* result = jsBoolean(!r[src].jsValue(exec)->toBoolean(exec)); 2131 VM_CHECK_EXCEPTION(); 2130 JSValue* result = jsBoolean(!r[src].jsValue(exec)->toBoolean()); 2132 2131 r[dst] = result; 2133 2132 … … 2987 2986 int cond = (++vPC)->u.operand; 2988 2987 int target = (++vPC)->u.operand; 2989 if (r[cond].jsValue(exec)->toBoolean( exec)) {2988 if (r[cond].jsValue(exec)->toBoolean()) { 2990 2989 vPC += target; 2991 2990 CHECK_FOR_TIMEOUT(); … … 3004 3003 int cond = (++vPC)->u.operand; 3005 3004 int target = (++vPC)->u.operand; 3006 if (r[cond].jsValue(exec)->toBoolean( exec)) {3005 if (r[cond].jsValue(exec)->toBoolean()) { 3007 3006 vPC += target; 3008 3007 NEXT_OPCODE; … … 3020 3019 int cond = (++vPC)->u.operand; 3021 3020 int target = (++vPC)->u.operand; 3022 if (!r[cond].jsValue(exec)->toBoolean( exec)) {3021 if (!r[cond].jsValue(exec)->toBoolean()) { 3023 3022 vPC += target; 3024 3023 NEXT_OPCODE; … … 4989 4988 JSValue* src1 = ARG_src1; 4990 4989 4991 ExecState* exec = ARG_exec; 4992 4993 bool result = src1->toBoolean(exec); 4994 VM_CHECK_EXCEPTION_AT_END(); 4995 return result; 4990 return src1->toBoolean(); 4996 4991 } 4997 4992 … … 5116 5111 JSValue* Machine::cti_op_not(CTI_ARGS) 5117 5112 { 5118 JSValue* src = ARG_src1; 5119 5120 ExecState* exec = ARG_exec; 5121 5122 JSValue* result = jsBoolean(!src->toBoolean(exec)); 5123 VM_CHECK_EXCEPTION_AT_END(); 5124 return result; 5113 return jsBoolean(!ARG_src1->toBoolean()); 5125 5114 } 5126 5115 5127 5116 int SFX_CALL Machine::cti_op_jtrue(CTI_ARGS) 5128 5117 { 5129 JSValue* src1 = ARG_src1; 5130 5131 ExecState* exec = ARG_exec; 5132 5133 bool result = src1->toBoolean(exec); 5134 VM_CHECK_EXCEPTION_AT_END(); 5135 return result; 5118 return ARG_src1->toBoolean(); 5136 5119 } 5137 5120 -
trunk/JavaScriptCore/kjs/ArrayPrototype.cpp
r37175 r37333 583 583 JSValue* result = call(exec, function, callType, callData, applyThis, eachArguments); 584 584 585 if (result->toBoolean( exec))585 if (result->toBoolean()) 586 586 resultArray->put(exec, filterIndex++, v); 587 587 } … … 657 657 eachArguments.append(thisObj); 658 658 659 bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean( exec);659 bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean(); 660 660 661 661 if (!predicateResult) { … … 721 721 eachArguments.append(thisObj); 722 722 723 bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean( exec);723 bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean(); 724 724 725 725 if (predicateResult) { -
trunk/JavaScriptCore/kjs/BooleanConstructor.cpp
r37257 r37333 42 42 { 43 43 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())); 45 45 return obj; 46 46 } … … 60 60 static JSValue* callBooleanConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 61 61 { 62 return jsBoolean(args.at(exec, 0)->toBoolean( exec));62 return jsBoolean(args.at(exec, 0)->toBoolean()); 63 63 } 64 64 -
trunk/JavaScriptCore/kjs/GetterSetter.h
r36316 r37333 53 53 virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const; 54 54 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value); 55 virtualbool toBoolean(ExecState*) const;55 bool toBoolean(ExecState*) const; 56 56 virtual double toNumber(ExecState*) const; 57 57 virtual UString toString(ExecState*) const; -
trunk/JavaScriptCore/kjs/JSCell.h
r37285 r37333 73 73 virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const = 0; 74 74 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*&) = 0; 75 virtual bool toBoolean(ExecState*) const = 0;75 bool toBoolean() const; 76 76 virtual double toNumber(ExecState*) const = 0; 77 77 virtual UString toString(ExecState*) const = 0; … … 273 273 } 274 274 275 inline bool JSValue::toBoolean( ExecState* exec) const276 { 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(); 278 278 } 279 279 -
trunk/JavaScriptCore/kjs/JSNumberCell.cpp
r37257 r37333 39 39 value = this; 40 40 return true; 41 }42 43 bool JSNumberCell::toBoolean(ExecState*) const44 {45 return m_value < 0.0 || m_value > 0.0; // false for NaN46 41 } 47 42 -
trunk/JavaScriptCore/kjs/JSNumberCell.h
r37285 r37333 53 53 virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const; 54 54 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 */ } 56 56 virtual double toNumber(ExecState*) const; 57 57 virtual UString toString(ExecState*) const; -
trunk/JavaScriptCore/kjs/JSObject.cpp
r37297 r37333 431 431 } 432 432 433 bool JSObject::toBoolean(ExecState*) const434 {435 return true;436 }437 438 433 double JSObject::toNumber(ExecState* exec) const 439 434 { -
trunk/JavaScriptCore/kjs/JSObject.h
r37068 r37333 29 29 #include "ExecState.h" 30 30 #include "JSNumberCell.h" 31 #include "JSString.h" 31 32 #include "PropertyMap.h" 32 33 #include "PropertySlot.h" … … 110 111 virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const; 111 112 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value); 112 virtual bool toBoolean(ExecState*) const;113 bool toBoolean() const { return true; } 113 114 virtual double toNumber(ExecState*) const; 114 115 virtual UString toString(ExecState*) const; … … 245 246 } 246 247 return false; 248 } 249 250 inline 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(); 247 259 } 248 260 -
trunk/JavaScriptCore/kjs/JSString.cpp
r37257 r37333 41 41 number = m_value.toDouble(); 42 42 return false; 43 }44 45 bool JSString::toBoolean(ExecState*) const46 {47 return !m_value.isEmpty();48 43 } 49 44 -
trunk/JavaScriptCore/kjs/JSString.h
r37285 r37333 93 93 static PassRefPtr<StructureID> createStructureID(JSValue* proto) { return StructureID::create(proto, TypeInfo(StringType, NeedsThisConversion)); } 94 94 95 bool toBoolean() const { return !m_value.isEmpty(); } 96 95 97 private: 96 98 enum VPtrStealingHackType { VPtrStealingHack }; … … 102 104 virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const; 103 105 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value); 104 virtual bool toBoolean(ExecState*) const;105 106 virtual double toNumber(ExecState*) const; 106 107 virtual JSObject* toObject(ExecState*) const; -
trunk/JavaScriptCore/kjs/JSValue.h
r37285 r37333 97 97 bool getPrimitiveNumber(ExecState*, double& number, JSValue*&); 98 98 99 bool toBoolean( ExecState*) const;99 bool toBoolean() const; 100 100 101 101 // toNumber conversion is expected to be side effect free if an exception has -
trunk/JavaScriptCore/kjs/RegExpConstructor.cpp
r37257 r37333 312 312 } 313 313 314 void setRegExpConstructorMultiline(ExecState* exec, JSObject* baseObject, JSValue* value)315 { 316 static_cast<RegExpConstructor*>(baseObject)->setMultiline(value->toBoolean( exec));314 void setRegExpConstructorMultiline(ExecState*, JSObject* baseObject, JSValue* value) 315 { 316 static_cast<RegExpConstructor*>(baseObject)->setMultiline(value->toBoolean()); 317 317 } 318 318 -
trunk/JavaScriptCore/kjs/RegExpObject.cpp
r36977 r37333 122 122 } 123 123 124 bool global = get(exec, exec->propertyNames().global)->toBoolean( exec);124 bool global = get(exec, exec->propertyNames().global)->toBoolean(); 125 125 int lastIndex = 0; 126 126 if (global) { -
trunk/JavaScriptCore/kjs/RegExpPrototype.cpp
r36726 r37333 107 107 UString result = "/" + static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().source)->toString(exec); 108 108 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()) 110 110 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()) 112 112 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()) 114 114 result.append('m'); 115 115 return jsNontrivialString(exec, result);
Note:
See TracChangeset
for help on using the changeset viewer.