port
09de997b3504368d40644afa7310b90faff5d09c (r30442).
original commit message:
This adds a new ToString runtime function and a fast-path ToStringStub
(which is just a simple dispatcher for existing functionality), and also
implements %_ToName using the ToStringStub.
R=weiliang.lin@intel.com
BUG=
Review URL: https://codereview.chromium.org/
1326473002
Cr-Commit-Position: refs/heads/master@{#30460}
}
+void FullCodeGenerator::EmitToString(CallRuntime* expr) {
+ ZoneList<Expression*>* args = expr->arguments();
+ DCHECK_EQ(1, args->length());
+
+ // Load the argument into eax and convert it.
+ VisitForAccumulatorValue(args->at(0));
+
+ ToStringStub stub(isolate());
+ __ CallStub(&stub);
+ context()->Plug(eax);
+}
+
+
+void FullCodeGenerator::EmitToName(CallRuntime* expr) {
+ ZoneList<Expression*>* args = expr->arguments();
+ DCHECK_EQ(1, args->length());
+
+ // Load the argument into eax and convert it.
+ VisitForAccumulatorValue(args->at(0));
+
+ // Convert the object to a name.
+ Label convert, done_convert;
+ __ JumpIfSmi(eax, &convert, Label::kNear);
+ STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
+ __ CmpObjectType(eax, LAST_NAME_TYPE, ecx);
+ __ j(below_equal, &done_convert, Label::kNear);
+ __ bind(&convert);
+ ToStringStub stub(isolate());
+ __ CallStub(&stub);
+ __ bind(&done_convert);
+ context()->Plug(eax);
+}
+
+
void FullCodeGenerator::EmitToObject(CallRuntime* expr) {
ZoneList<Expression*>* args = expr->arguments();
DCHECK_EQ(1, args->length());
{
FrameScope scope(masm, StackFrame::INTERNAL);
__ push(edi); // Preserve the function.
- __ push(eax);
- __ InvokeBuiltin(Context::TO_STRING_BUILTIN_INDEX, CALL_FUNCTION);
+ ToStringStub stub(masm->isolate());
+ __ CallStub(&stub);
__ pop(edi);
}
__ mov(ebx, eax);
}
+void ToStringStub::Generate(MacroAssembler* masm) {
+ // The ToString stub takes one argument in eax.
+ Label is_number;
+ __ JumpIfSmi(eax, &is_number, Label::kNear);
+
+ Label not_string;
+ __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi);
+ // eax: receiver
+ // edi: receiver map
+ __ j(above_equal, ¬_string, Label::kNear);
+ __ Ret();
+ __ bind(¬_string);
+
+ Label not_heap_number;
+ __ CompareMap(eax, masm->isolate()->factory()->heap_number_map());
+ __ j(not_equal, ¬_heap_number, Label::kNear);
+ __ bind(&is_number);
+ NumberToStringStub stub(isolate());
+ __ TailCallStub(&stub);
+ __ bind(¬_heap_number);
+
+ Label not_oddball;
+ __ CmpInstanceType(edi, ODDBALL_TYPE);
+ __ j(not_equal, ¬_oddball, Label::kNear);
+ __ mov(eax, FieldOperand(eax, Oddball::kToStringOffset));
+ __ Ret();
+ __ bind(¬_oddball);
+
+ __ pop(ecx); // Pop return address.
+ __ push(eax); // Push argument.
+ __ push(ecx); // Push return address.
+ __ TailCallRuntime(Runtime::kToString, 1, 1);
+}
+
+
void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
Register left,
Register right,
}
+// static
+const Register ToStringDescriptor::ReceiverRegister() { return eax; }
+
+
// static
const Register ToObjectDescriptor::ReceiverRegister() { return eax; }