Commit 7831f0c3 authored by ggaren@apple.com's avatar ggaren@apple.com

Some JSValue cleanup

https://bugs.webkit.org/show_bug.cgi?id=69320

../JavaScriptCore: 

Reviewed by Darin Adler.
        
No measurable performance change.

Removed some JSValue::get* functions. get* used to be an optimization
when every value operation was a virtual function call: get* would combine
two virtual calls into one. Now, with non-virtual, inlined functions, get*
isn't faster, and may be slightly slower.

Merged getBoolean(bool&) and getBoolean() into asBoolean().

Merged uncheckedGetNumber(), getJSNumber() and getNumber() into
asNumber().

* runtime/JSValue.h:
* runtime/JSValueInlineMethods.h:
(JSC::JSValue::asNumber):
(JSC::JSValue::asBoolean): As promised!

* runtime/NumberPrototype.cpp:
(JSC::toThisNumber):
(JSC::numberProtoFuncToExponential):
(JSC::numberProtoFuncToFixed):
(JSC::numberProtoFuncToPrecision):
(JSC::numberProtoFuncToString):
(JSC::numberProtoFuncToLocaleString):
(JSC::numberProtoFuncValueOf): Removed a bunch of uses of getJSNumber()
by switching to toThisNumber().

* API/JSCallbackObjectFunctions.h:
(JSC::::toNumber):
* dfg/DFGGraph.h:
(JSC::DFG::Graph::valueOfNumberConstant):
(JSC::DFG::Graph::valueOfBooleanConstant):
* dfg/DFGOperations.cpp:
(JSC::DFG::putByVal):
* interpreter/Interpreter.cpp:
(JSC::Interpreter::privateExecute):
* jit/JITStubs.cpp:
(JSC::DEFINE_STUB_FUNCTION):
* runtime/DateInstance.h:
(JSC::DateInstance::internalNumber):
* runtime/FunctionPrototype.cpp:
(JSC::functionProtoFuncBind):
* runtime/JSArray.cpp:
(JSC::compareNumbersForQSort): Replaced getNumber() => isNumber() / asNumber().
getBoolean() => isBoolean() / asBoolean(), uncheckedGetNumber() => asNumber().

* runtime/JSCell.cpp:
* runtime/JSCell.h: Nixed getJSNumber().

* runtime/JSGlobalObjectFunctions.cpp:
(JSC::globalFuncParseInt):
* runtime/JSONObject.cpp:
(JSC::gap):
(JSC::Stringifier::Stringifier):
(JSC::Stringifier::appendStringifiedValue):
* runtime/NumberObject.cpp:
* runtime/NumberObject.h:
(JSC::NumberObject::createStructure):
* runtime/Operations.h:
(JSC::JSValue::equalSlowCaseInline):
(JSC::JSValue::strictEqual):
(JSC::jsLess):
(JSC::jsLessEq):
(JSC::jsAdd): Replaced getNumber() => isNumber() / asNumber().
getBoolean() => isBoolean() / asBoolean(), uncheckedGetNumber() => asNumber().

../WebCore: 

Reviewed by Darin Adler.

* bindings/js/JSDOMBinding.cpp:
(WebCore::valueToDate):
* bindings/js/JSErrorHandler.cpp:
(WebCore::JSErrorHandler::handleEvent):
* bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::handleEvent):
* bindings/js/JSSQLTransactionCustom.cpp:
(WebCore::JSSQLTransaction::executeSql):
* bindings/js/JSSQLTransactionSyncCustom.cpp:
(WebCore::JSSQLTransactionSync::executeSql):
* bindings/js/ScriptValue.cpp:
(WebCore::jsToInspectorValue):
* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneSerializer::dumpIfTerminal):
* bindings/objc/WebScriptObject.mm:
(+[WebScriptObject _convertValueToObjcValue:originRootObject:rootObject:]):
* bridge/jni/jsc/JNIUtilityPrivate.cpp:
(JSC::Bindings::convertValueToJValue): Updated for JSC changes.

../WebKit/mac: 

Reviewed by Darin Adler.

* WebView/WebView.mm:
(aeDescFromJSValue): Updated for JSC changes.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96673 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b07c6f5e
......@@ -480,10 +480,13 @@ double JSCallbackObject<Parent>::toNumber(ExecState* exec) const
throwError(exec, toJS(exec, exception));
return 0;
}
double dValue;
if (value)
return toJS(exec, value).getNumber(dValue) ? dValue : std::numeric_limits<double>::quiet_NaN();
if (!value)
continue;
JSValue jsValue = toJS(exec, value);
if (!jsValue.isNumber())
return std::numeric_limits<double>::quiet_NaN();
return jsValue.asNumber();
}
return Parent::toNumber(exec);
......
2011-10-03 Geoffrey Garen <ggaren@apple.com>
Some JSValue cleanup
https://bugs.webkit.org/show_bug.cgi?id=69320
Reviewed by Darin Adler.
No measurable performance change.
Removed some JSValue::get* functions. get* used to be an optimization
when every value operation was a virtual function call: get* would combine
two virtual calls into one. Now, with non-virtual, inlined functions, get*
isn't faster, and may be slightly slower.
Merged getBoolean(bool&) and getBoolean() into asBoolean().
Merged uncheckedGetNumber(), getJSNumber() and getNumber() into
asNumber().
* runtime/JSValue.h:
* runtime/JSValueInlineMethods.h:
(JSC::JSValue::asNumber):
(JSC::JSValue::asBoolean): As promised!
* runtime/NumberPrototype.cpp:
(JSC::toThisNumber):
(JSC::numberProtoFuncToExponential):
(JSC::numberProtoFuncToFixed):
(JSC::numberProtoFuncToPrecision):
(JSC::numberProtoFuncToString):
(JSC::numberProtoFuncToLocaleString):
(JSC::numberProtoFuncValueOf): Removed a bunch of uses of getJSNumber()
by switching to toThisNumber().
* API/JSCallbackObjectFunctions.h:
(JSC::::toNumber):
* dfg/DFGGraph.h:
(JSC::DFG::Graph::valueOfNumberConstant):
(JSC::DFG::Graph::valueOfBooleanConstant):
* dfg/DFGOperations.cpp:
(JSC::DFG::putByVal):
* interpreter/Interpreter.cpp:
(JSC::Interpreter::privateExecute):
* jit/JITStubs.cpp:
(JSC::DEFINE_STUB_FUNCTION):
* runtime/DateInstance.h:
(JSC::DateInstance::internalNumber):
* runtime/FunctionPrototype.cpp:
(JSC::functionProtoFuncBind):
* runtime/JSArray.cpp:
(JSC::compareNumbersForQSort): Replaced getNumber() => isNumber() / asNumber().
getBoolean() => isBoolean() / asBoolean(), uncheckedGetNumber() => asNumber().
* runtime/JSCell.cpp:
* runtime/JSCell.h: Nixed getJSNumber().
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::globalFuncParseInt):
* runtime/JSONObject.cpp:
(JSC::gap):
(JSC::Stringifier::Stringifier):
(JSC::Stringifier::appendStringifiedValue):
* runtime/NumberObject.cpp:
* runtime/NumberObject.h:
(JSC::NumberObject::createStructure):
* runtime/Operations.h:
(JSC::JSValue::equalSlowCaseInline):
(JSC::JSValue::strictEqual):
(JSC::jsLess):
(JSC::jsLessEq):
(JSC::jsAdd): Replaced getNumber() => isNumber() / asNumber().
getBoolean() => isBoolean() / asBoolean(), uncheckedGetNumber() => asNumber().
2011-10-04 Scott Graham <scottmg@chromium.org>
Add GAMEPAD feature flag
......@@ -247,11 +247,11 @@ public:
}
double valueOfNumberConstant(CodeBlock* codeBlock, NodeIndex nodeIndex)
{
return valueOfJSConstantNode(codeBlock, nodeIndex).uncheckedGetNumber();
return valueOfJSConstantNode(codeBlock, nodeIndex).asNumber();
}
bool valueOfBooleanConstant(CodeBlock* codeBlock, NodeIndex nodeIndex)
{
return valueOfJSConstantNode(codeBlock, nodeIndex).getBoolean();
return valueOfJSConstantNode(codeBlock, nodeIndex).asBoolean();
}
JSFunction* valueOfFunctionConstant(CodeBlock* codeBlock, NodeIndex nodeIndex)
{
......
......@@ -88,9 +88,8 @@ static inline void putByVal(ExecState* exec, JSValue baseValue, uint32_t index,
return;
}
double dValue = 0;
if (value.getNumber(dValue)) {
byteArray->setIndex(index, dValue);
if (value.isNumber()) {
byteArray->setIndex(index, value.asNumber());
return;
}
}
......@@ -188,36 +187,36 @@ EncodedJSValue DFG_OPERATION operationValueAddNotNumber(ExecState* exec, Encoded
EncodedJSValue DFG_OPERATION operationArithAdd(EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
{
double num1 = JSValue::decode(encodedOp1).uncheckedGetNumber();
double num2 = JSValue::decode(encodedOp2).uncheckedGetNumber();
double num1 = JSValue::decode(encodedOp1).asNumber();
double num2 = JSValue::decode(encodedOp2).asNumber();
return JSValue::encode(jsNumber(num1 + num2));
}
EncodedJSValue DFG_OPERATION operationArithSub(EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
{
double num1 = JSValue::decode(encodedOp1).uncheckedGetNumber();
double num2 = JSValue::decode(encodedOp2).uncheckedGetNumber();
double num1 = JSValue::decode(encodedOp1).asNumber();
double num2 = JSValue::decode(encodedOp2).asNumber();
return JSValue::encode(jsNumber(num1 - num2));
}
EncodedJSValue DFG_OPERATION operationArithMul(EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
{
double num1 = JSValue::decode(encodedOp1).uncheckedGetNumber();
double num2 = JSValue::decode(encodedOp2).uncheckedGetNumber();
double num1 = JSValue::decode(encodedOp1).asNumber();
double num2 = JSValue::decode(encodedOp2).asNumber();
return JSValue::encode(jsNumber(num1 * num2));
}
EncodedJSValue DFG_OPERATION operationArithDiv(EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
{
double num1 = JSValue::decode(encodedOp1).uncheckedGetNumber();
double num2 = JSValue::decode(encodedOp2).uncheckedGetNumber();
double num1 = JSValue::decode(encodedOp1).asNumber();
double num2 = JSValue::decode(encodedOp2).asNumber();
return JSValue::encode(jsNumber(num1 / num2));
}
EncodedJSValue DFG_OPERATION operationArithMod(EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
{
double num1 = JSValue::decode(encodedOp1).uncheckedGetNumber();
double num2 = JSValue::decode(encodedOp2).uncheckedGetNumber();
double num1 = JSValue::decode(encodedOp1).asNumber();
double num2 = JSValue::decode(encodedOp2).asNumber();
return JSValue::encode(jsNumber(fmod(num1, num2)));
}
......
......@@ -1976,7 +1976,7 @@ JSValue Interpreter::privateExecute(ExecutionFlag flag, RegisterFile* registerFi
} else {
JSValue number = callFrame->r(srcDst).jsValue().toJSNumber(callFrame);
CHECK_FOR_EXCEPTION();
callFrame->uncheckedR(srcDst) = jsNumber(number.uncheckedGetNumber() + 1);
callFrame->uncheckedR(srcDst) = jsNumber(number.asNumber() + 1);
callFrame->uncheckedR(dst) = number;
}
......@@ -1999,7 +1999,7 @@ JSValue Interpreter::privateExecute(ExecutionFlag flag, RegisterFile* registerFi
} else {
JSValue number = callFrame->r(srcDst).jsValue().toJSNumber(callFrame);
CHECK_FOR_EXCEPTION();
callFrame->uncheckedR(srcDst) = jsNumber(number.uncheckedGetNumber() - 1);
callFrame->uncheckedR(srcDst) = jsNumber(number.asNumber() - 1);
callFrame->uncheckedR(dst) = number;
}
......@@ -3506,12 +3506,11 @@ skip_id_custom_self:
jsArray->JSArray::put(callFrame, i, callFrame->r(value).jsValue());
} else if (isJSByteArray(globalData, baseValue) && asByteArray(baseValue)->canAccessIndex(i)) {
JSByteArray* jsByteArray = asByteArray(baseValue);
double dValue = 0;
JSValue jsValue = callFrame->r(value).jsValue();
if (jsValue.isInt32())
jsByteArray->setIndex(i, jsValue.asInt32());
else if (jsValue.getNumber(dValue))
jsByteArray->setIndex(i, dValue);
else if (jsValue.isDouble())
jsByteArray->setIndex(i, jsValue.asDouble());
else
baseValue.put(callFrame, i, jsValue);
} else
......@@ -4049,14 +4048,10 @@ skip_id_custom_self:
JSValue scrutinee = callFrame->r(vPC[3].u.operand).jsValue();
if (scrutinee.isInt32())
vPC += codeBlock->immediateSwitchJumpTable(tableIndex).offsetForValue(scrutinee.asInt32(), defaultOffset);
else {
double value;
int32_t intValue;
if (scrutinee.getNumber(value) && ((intValue = static_cast<int32_t>(value)) == value))
vPC += codeBlock->immediateSwitchJumpTable(tableIndex).offsetForValue(intValue, defaultOffset);
else
vPC += defaultOffset;
}
else if (scrutinee.isDouble() && scrutinee.asDouble() == static_cast<int32_t>(scrutinee.asDouble()))
vPC += codeBlock->immediateSwitchJumpTable(tableIndex).offsetForValue(static_cast<int32_t>(scrutinee.asDouble()), defaultOffset);
else
vPC += defaultOffset;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_switch_char) {
......
......@@ -1312,9 +1312,8 @@ DEFINE_STUB_FUNCTION(EncodedJSValue, op_add)
return JSValue::encode(result);
}
double left = 0.0, right;
if (v1.getNumber(left) && v2.getNumber(right))
return JSValue::encode(jsNumber(left + right));
if (v1.isNumber() && v2.isNumber())
return JSValue::encode(jsNumber(v1.asNumber() + v2.asNumber()));
// All other cases are pretty uncommon
JSValue result = jsAddSlowCase(callFrame, v1, v2);
......@@ -2117,10 +2116,8 @@ DEFINE_STUB_FUNCTION(EncodedJSValue, op_mul)
JSValue src1 = stackFrame.args[0].jsValue();
JSValue src2 = stackFrame.args[1].jsValue();
double left;
double right;
if (src1.getNumber(left) && src2.getNumber(right))
return JSValue::encode(jsNumber(left * right));
if (src1.isNumber() && src2.isNumber())
return JSValue::encode(jsNumber(src1.asNumber() * src2.asNumber()));
CallFrame* callFrame = stackFrame.callFrame;
JSValue result = jsNumber(src1.toNumber(callFrame) * src2.toNumber(callFrame));
......@@ -2587,10 +2584,8 @@ DEFINE_STUB_FUNCTION(EncodedJSValue, op_sub)
JSValue src1 = stackFrame.args[0].jsValue();
JSValue src2 = stackFrame.args[1].jsValue();
double left;
double right;
if (src1.getNumber(left) && src2.getNumber(right))
return JSValue::encode(jsNumber(left - right));
if (src1.isNumber() && src2.isNumber())
return JSValue::encode(jsNumber(src1.asNumber() - src2.asNumber()));
CallFrame* callFrame = stackFrame.callFrame;
JSValue result = jsNumber(src1.toNumber(callFrame) - src2.toNumber(callFrame));
......@@ -2625,9 +2620,8 @@ DEFINE_STUB_FUNCTION(void, op_put_by_val)
jsByteArray->setIndex(i, value.asInt32());
return;
} else {
double dValue = 0;
if (value.getNumber(dValue)) {
jsByteArray->setIndex(i, dValue);
if (value.isNumber()) {
jsByteArray->setIndex(i, value.asNumber());
return;
}
}
......@@ -2667,9 +2661,8 @@ DEFINE_STUB_FUNCTION(void, op_put_by_val_byte_array)
jsByteArray->setIndex(i, value.asInt32());
return;
} else {
double dValue = 0;
if (value.getNumber(dValue)) {
jsByteArray->setIndex(i, dValue);
if (value.isNumber()) {
jsByteArray->setIndex(i, value.asNumber());
return;
}
}
......@@ -2833,9 +2826,8 @@ DEFINE_STUB_FUNCTION(EncodedJSValue, op_negate)
JSValue src = stackFrame.args[0].jsValue();
double v;
if (src.getNumber(v))
return JSValue::encode(jsNumber(-v));
if (src.isNumber())
return JSValue::encode(jsNumber(-src.asNumber()));
CallFrame* callFrame = stackFrame.callFrame;
JSValue result = jsNumber(-src.toNumber(callFrame));
......@@ -2950,10 +2942,8 @@ DEFINE_STUB_FUNCTION(EncodedJSValue, op_div)
JSValue src1 = stackFrame.args[0].jsValue();
JSValue src2 = stackFrame.args[1].jsValue();
double left;
double right;
if (src1.getNumber(left) && src2.getNumber(right))
return JSValue::encode(jsNumber(left / right));
if (src1.isNumber() && src2.isNumber())
return JSValue::encode(jsNumber(src1.asNumber() / src2.asNumber()));
CallFrame* callFrame = stackFrame.callFrame;
JSValue result = jsNumber(src1.toNumber(callFrame) / src2.toNumber(callFrame));
......@@ -3062,7 +3052,7 @@ DEFINE_STUB_FUNCTION(EncodedJSValue, op_post_inc)
JSValue number = v.toJSNumber(callFrame);
CHECK_FOR_EXCEPTION_AT_END();
callFrame->registers()[stackFrame.args[1].int32()] = jsNumber(number.uncheckedGetNumber() + 1);
callFrame->registers()[stackFrame.args[1].int32()] = jsNumber(number.asNumber() + 1);
return JSValue::encode(number);
}
......@@ -3361,7 +3351,7 @@ DEFINE_STUB_FUNCTION(EncodedJSValue, op_post_dec)
JSValue number = v.toJSNumber(callFrame);
CHECK_FOR_EXCEPTION_AT_END();
callFrame->registers()[stackFrame.args[1].int32()] = jsNumber(number.uncheckedGetNumber() - 1);
callFrame->registers()[stackFrame.args[1].int32()] = jsNumber(number.asNumber() - 1);
return JSValue::encode(number);
}
......@@ -3666,14 +3656,13 @@ DEFINE_STUB_FUNCTION(void*, op_switch_imm)
if (scrutinee.isInt32())
return codeBlock->immediateSwitchJumpTable(tableIndex).ctiForValue(scrutinee.asInt32()).executableAddress();
else {
double value;
int32_t intValue;
if (scrutinee.getNumber(value) && ((intValue = static_cast<int32_t>(value)) == value))
return codeBlock->immediateSwitchJumpTable(tableIndex).ctiForValue(intValue).executableAddress();
else
return codeBlock->immediateSwitchJumpTable(tableIndex).ctiDefault.executableAddress();
if (scrutinee.isDouble()) {
double value = scrutinee.asDouble();
int32_t int32Value = value;
if (int32Value == value)
return codeBlock->immediateSwitchJumpTable(tableIndex).ctiForValue(int32Value).executableAddress();
}
return codeBlock->immediateSwitchJumpTable(tableIndex).ctiDefault.executableAddress();
}
DEFINE_STUB_FUNCTION(void*, op_switch_char)
......
......@@ -52,7 +52,7 @@ namespace JSC {
return instance;
}
double internalNumber() const { return internalValue().uncheckedGetNumber(); }
double internalNumber() const { return internalValue().asNumber(); }
static JS_EXPORTDATA const ClassInfo s_info;
......
......@@ -194,7 +194,7 @@ EncodedJSValue JSC_HOST_CALL functionProtoFuncBind(ExecState* exec)
ASSERT(target.get(exec, exec->propertyNames().length).isNumber());
// a. Let L be the length property of Target minus the length of A.
// b. Set the length own property of F to either 0 or L, whichever is larger.
unsigned targetLength = (unsigned)target.get(exec, exec->propertyNames().length).uncheckedGetNumber();
unsigned targetLength = (unsigned)target.get(exec, exec->propertyNames().length).asNumber();
if (targetLength > numBoundArgs)
length = targetLength - numBoundArgs;
}
......
......@@ -882,8 +882,8 @@ void JSArray::visitChildren(JSCell* cell, SlotVisitor& visitor)
static int compareNumbersForQSort(const void* a, const void* b)
{
double da = static_cast<const JSValue*>(a)->uncheckedGetNumber();
double db = static_cast<const JSValue*>(b)->uncheckedGetNumber();
double da = static_cast<const JSValue*>(a)->asNumber();
double db = static_cast<const JSValue*>(b)->asNumber();
return (da > db) - (da < db);
}
......
......@@ -118,13 +118,6 @@ JSObject* JSCell::toThisObject(ExecState* exec) const
return toObject(exec, exec->lexicalGlobalObject());
}
JSValue JSCell::getJSNumber() const
{
if (structure()->typeInfo().isNumberObject())
return static_cast<const NumberObject*>(this)->getJSNumber();
return JSValue();
}
JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
{
if (isString())
......
......@@ -96,7 +96,6 @@ namespace JSC {
virtual bool deleteProperty(ExecState*, unsigned propertyName);
virtual JSObject* toThisObject(ExecState*) const;
JSValue getJSNumber() const;
void* vptr() const { ASSERT(!isZapped()); return *reinterpret_cast<void* const*>(this); }
void setVPtr(void* vptr) { *reinterpret_cast<void**>(this) = vptr; ASSERT(!isZapped()); }
......@@ -302,15 +301,6 @@ namespace JSC {
return toNumberSlowCase(exec);
}
inline JSValue JSValue::getJSNumber() const
{
if (isInt32() || isDouble())
return *this;
if (isCell())
return asCell()->getJSNumber();
return JSValue();
}
inline JSObject* JSValue::toObject(ExecState* exec) const
{
return isCell() ? asCell()->toObject(exec, exec->lexicalGlobalObject()) : toObjectSlowCase(exec, exec->lexicalGlobalObject());
......
......@@ -473,9 +473,11 @@ EncodedJSValue JSC_HOST_CALL globalFuncParseInt(ExecState* exec)
// values in the range -1 < n <= -10^-6 need to truncate to -0, not 0.
static const double tenToTheMinus6 = 0.000001;
static const double intMaxPlusOne = 2147483648.0;
double n;
if (value.getNumber(n) && ((n < intMaxPlusOne && n >= tenToTheMinus6) || !n) && radixValue.isUndefinedOrNull())
return JSValue::encode(jsNumber(static_cast<int32_t>(n)));
if (value.isNumber()) {
double n = value.asNumber();
if (((n < intMaxPlusOne && n >= tenToTheMinus6) || !n) && radixValue.isUndefinedOrNull())
return JSValue::encode(jsNumber(static_cast<int32_t>(n)));
}
// If ToString throws, we shouldn't call ToInt32.
UString s = value.toString(exec);
......
......@@ -153,8 +153,8 @@ static inline UString gap(ExecState* exec, JSValue space)
space = unwrapBoxedPrimitive(exec, space);
// If the space value is a number, create a gap string with that number of spaces.
double spaceCount;
if (space.getNumber(spaceCount)) {
if (space.isNumber()) {
double spaceCount = space.asNumber();
int count;
if (spaceCount > maxGapLength)
count = maxGapLength;
......@@ -228,9 +228,8 @@ Stringifier::Stringifier(ExecState* exec, const Local<Unknown>& replacer, const
continue;
}
double value = 0;
if (name.getNumber(value)) {
m_arrayReplacerPropertyNames.add(Identifier::from(exec, value));
if (name.isNumber()) {
m_arrayReplacerPropertyNames.add(Identifier::from(exec, name.asNumber()));
continue;
}
......@@ -376,7 +375,7 @@ Stringifier::StringifyResult Stringifier::appendStringifiedValue(UStringBuilder&
return StringifyFailed;
if (value.isBoolean()) {
builder.append(value.getBoolean() ? "true" : "false");
builder.append(value.isTrue() ? "true" : "false");
return StringifySucceeded;
}
......@@ -386,12 +385,12 @@ Stringifier::StringifyResult Stringifier::appendStringifiedValue(UStringBuilder&
return StringifySucceeded;
}
double numericValue;
if (value.getNumber(numericValue)) {
if (!isfinite(numericValue))
if (value.isNumber()) {
double number = value.asNumber();
if (!isfinite(number))
builder.append("null");
else
builder.append(UString::number(numericValue));
builder.append(UString::number(number));
return StringifySucceeded;
}
......
......@@ -157,6 +157,8 @@ namespace JSC {
int32_t asInt32() const;
uint32_t asUInt32() const;
double asDouble() const;
bool asBoolean() const;
double asNumber() const;
// Querying the type.
bool isUndefined() const;
......@@ -171,10 +173,6 @@ namespace JSC {
bool inherits(const ClassInfo*) const;
// Extracting the value.
bool getBoolean(bool&) const;
bool getBoolean() const; // false if not a boolean
bool getNumber(double&) const;
double uncheckedGetNumber() const;
bool getString(ExecState* exec, UString&) const;
UString getString(ExecState* exec) const; // null string if not a string
JSObject* getObject() const; // 0 if not an object
......@@ -225,8 +223,6 @@ namespace JSC {
static bool strictEqualSlowCase(ExecState* exec, JSValue v1, JSValue v2);
static bool strictEqualSlowCaseInline(ExecState* exec, JSValue v1, JSValue v2);
JSValue getJSNumber() const; // JSValue() if this is not a JSNumber or number object
bool isCell() const;
JSCell* asCell() const;
bool isValidCallee();
......
......@@ -54,7 +54,7 @@ namespace JSC {
return asInt32();
}
inline double JSValue::uncheckedGetNumber() const
inline double JSValue::asNumber() const
{
ASSERT(isNumber());
return isInt32() ? asInt32() : asDouble();
......@@ -70,33 +70,6 @@ namespace JSC {
return JSValue(std::numeric_limits<double>::quiet_NaN());
}
inline bool JSValue::getNumber(double& result) const
{
if (isInt32()) {
result = asInt32();
return true;
}
if (isDouble()) {
result = asDouble();
return true;
}
return false;
}
inline bool JSValue::getBoolean(bool& v) const
{
if (isTrue()) {
v = true;
return true;
}
if (isFalse()) {
v = false;
return true;
}
return false;
}
inline JSValue::JSValue(char i)
{
*this = JSValue(static_cast<int32_t>(i));
......@@ -344,7 +317,7 @@ namespace JSC {
return isTrue() || isFalse();
}
inline bool JSValue::getBoolean() const
inline bool JSValue::asBoolean() const
{
ASSERT(isBoolean());
return payload();
......@@ -402,12 +375,12 @@ namespace JSC {
inline bool JSValue::isUndefined() const
{
return asValue() == jsUndefined();
return asValue() == JSValue(JSUndefined);
}
inline bool JSValue::isNull() const
{
return asValue() == jsNull();
return asValue() == JSValue(JSNull);
}
inline bool JSValue::isTrue() const
......@@ -420,10 +393,10 @@ namespace JSC {
return asValue() == JSValue(JSFalse);
}
inline bool JSValue::getBoolean() const
inline bool JSValue::asBoolean() const
{
ASSERT(asValue() == jsBoolean(true) || asValue() == jsBoolean(false));
return asValue() == jsBoolean(true);
ASSERT(isBoolean());
return asValue() == JSValue(JSTrue);
}
inline int32_t JSValue::asInt32() const
......
......@@ -42,11 +42,6 @@ void NumberObject::finishCreation(JSGlobalData& globalData)
ASSERT(inherits(&s_info));
}
JSValue NumberObject::getJSNumber() const
{
return internalValue();
}
NumberObject* constructNumber(ExecState* exec, JSGlobalObject* globalObject, JSValue number)
{
NumberObject* object = NumberObject::create(exec->globalData(), globalObject->numberObjectStructure());
......
......@@ -46,8 +46,6 @@ namespace JSC {
{
return Structure::create(globalData, globalObject, prototype, TypeInfo(NumberObjectType, StructureFlags), &s_info);
}
JSValue getJSNumber() const;
};
NumberObject* constructNumber(ExecState*, JSGlobalObject*, JSValue);
......
......@@ -95,13 +95,24 @@ bool NumberPrototype::getOwnPropertyDescriptor(ExecState* exec, const Identifier
// ------------------------------ Functions ---------------------------
static ALWAYS_INLINE bool toThisNumber(JSValue thisValue, double &x)
static ALWAYS_INLINE bool toThisNumber(JSValue thisValue, double& x)
{
JSValue v = thisValue.getJSNumber();
if (UNLIKELY(!v))
return false;
x = v.uncheckedGetNumber();
return true;
if (thisValue.isInt32()) {
x = thisValue.asInt32();
return true;
}
if (thisValue.isDouble()) {
x = thisValue.asDouble();
return true;
}
if (thisValue.isCell() && thisValue.asCell()->structure()->typeInfo().isNumberObject()) {
x = static_cast<const NumberObject*>(thisValue.asCell())->internalValue().asNumber();
return true;
}
return false;
}
static ALWAYS_INLINE bool getIntegerArgumentInRange(ExecState* exec, int low, int high, int& result, bool& isUndefined)
......@@ -333,7 +344,6 @@ static char* toStringWithRadix(RadixBuffer& buffer, double number, unsigned radi
// to argument-plus-one significant figures).
EncodedJSValue JSC_HOST_CALL numberProtoFuncToExponential(ExecState* exec)
{
// Get x (the double value of this, which should be a Number).
double x;