Index: src/builtins/builtins-conversion.cc |
diff --git a/src/builtins/builtins-conversion.cc b/src/builtins/builtins-conversion.cc |
index 77a3e2f2eb6fdca3bc696673a31289f01a6d4986..eccec6b8b9e01b572926324c385fd87372055224 100644 |
--- a/src/builtins/builtins-conversion.cc |
+++ b/src/builtins/builtins-conversion.cc |
@@ -151,6 +151,63 @@ void Builtins::Generate_ToNumber(CodeStubAssembler* assembler) { |
assembler->Return(assembler->ToNumber(context, input)); |
} |
+void Builtins::Generate_ToString(CodeStubAssembler* assembler) { |
+ typedef CodeStubAssembler::Label Label; |
+ typedef compiler::Node Node; |
+ typedef TypeConversionDescriptor Descriptor; |
+ |
+ Node* input = assembler->Parameter(Descriptor::kArgument); |
+ Node* context = assembler->Parameter(Descriptor::kContext); |
+ |
+ Label is_number(assembler); |
+ Label runtime(assembler); |
+ |
+ assembler->GotoIf(assembler->WordIsSmi(input), &is_number); |
+ |
+ Node* input_map = assembler->LoadMap(input); |
+ Node* input_instance_type = assembler->LoadMapInstanceType(input_map); |
+ |
+ Label not_string(assembler); |
+ assembler->GotoIf( |
+ assembler->Int32GreaterThanOrEqual( |
+ input_instance_type, assembler->Int32Constant(FIRST_NONSTRING_TYPE)), |
+ ¬_string); |
+ assembler->Return(input); |
+ |
+ Label not_heap_number(assembler); |
+ |
+ assembler->Bind(¬_string); |
+ { |
+ assembler->GotoUnless( |
+ assembler->WordEqual(input_map, assembler->HeapNumberMapConstant()), |
+ ¬_heap_number); |
+ assembler->Goto(&is_number); |
+ } |
+ |
+ assembler->Bind(&is_number); |
+ { |
+ // TODO(tebbi): inline as soon as NumberToString is in the CodeStubAssembler |
+ Callable callable = CodeFactory::NumberToString(assembler->isolate()); |
+ assembler->Return(assembler->CallStub(callable, context, input)); |
+ } |
+ |
+ assembler->Bind(¬_heap_number); |
+ { |
+ assembler->GotoIf( |
+ assembler->Word32NotEqual(input_instance_type, |
+ assembler->Int32Constant(ODDBALL_TYPE)), |
+ &runtime); |
+ assembler->Return( |
+ assembler->LoadObjectField(input, Oddball::kToStringOffset)); |
+ } |
+ |
+ assembler->Bind(&runtime); |
+ { |
+ assembler->Return( |
+ assembler->CallRuntime(Runtime::kToString, context, input)); |
+ } |
+} |
+ |
Handle<Code> Builtins::OrdinaryToPrimitive(OrdinaryToPrimitiveHint hint) { |
switch (hint) { |
case OrdinaryToPrimitiveHint::kNumber: |