Skip to content
Permalink
Browse files
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.


Canonical link: https://commits.webkit.org/85434@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@96673 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
geoffreygaren committed Oct 5, 2011
1 parent e82a44c commit 4566a764e4d8c9d4dfbefad8c00180b8cc5e2872
Showing 31 changed files with 249 additions and 216 deletions.
@@ -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);
@@ -1,3 +1,76 @@
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 @@ class Graph : public Vector<Node, 64> {
}
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 @@ JSValue Interpreter::privateExecute(ExecutionFlag flag, RegisterFile* registerFi
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 @@ JSValue Interpreter::privateExecute(ExecutionFlag flag, RegisterFile* registerFi
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())

0 comments on commit 4566a76

Please sign in to comment.