Index: src/hydrogen.cc |
diff --git a/src/hydrogen.cc b/src/hydrogen.cc |
index 54c3451fb475b0af6b709e992993f7853e0854c5..e38d9f3b92ee9cb98536ced584d48d2f309b1520 100644 |
--- a/src/hydrogen.cc |
+++ b/src/hydrogen.cc |
@@ -10313,9 +10313,27 @@ void HOptimizedGraphBuilder::GenerateClassOf(CallRuntime* call) { |
void HOptimizedGraphBuilder::GenerateValueOf(CallRuntime* call) { |
ASSERT(call->arguments()->length() == 1); |
CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
- HValue* value = Pop(); |
- HValueOf* result = New<HValueOf>(value); |
- return ast_context()->ReturnInstruction(result, call->id()); |
+ HValue* object = Pop(); |
+ |
+ IfBuilder if_objectisvalue(this); |
+ HValue* objectisvalue = if_objectisvalue.If<HHasInstanceTypeAndBranch>( |
+ object, JS_VALUE_TYPE); |
+ if_objectisvalue.Then(); |
+ { |
+ // Return the actual value. |
+ Push(Add<HLoadNamedField>( |
+ object, objectisvalue, |
+ HObjectAccess::ForJSObjectOffset(JSValue::kValueOffset))); |
+ Add<HSimulate>(call->id(), FIXED_SIMULATE); |
+ } |
+ if_objectisvalue.Else(); |
+ { |
+ // If the object is not a value return the object. |
+ Push(object); |
+ Add<HSimulate>(call->id(), FIXED_SIMULATE); |
+ } |
+ if_objectisvalue.End(); |
+ return ast_context()->ReturnValue(Pop()); |
} |