| OLD | NEW | 
|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "src/builtins/builtins-utils.h" | 5 #include "src/builtins/builtins-utils.h" | 
| 6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" | 
| 7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" | 
| 8 | 8 | 
| 9 namespace v8 { | 9 namespace v8 { | 
| 10 namespace internal { | 10 namespace internal { | 
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 249           // TODO(bmeurer): This could be more efficient if necessary. | 249           // TODO(bmeurer): This could be more efficient if necessary. | 
| 250           Callable callable = CodeFactory::ToString(assembler->isolate()); | 250           Callable callable = CodeFactory::ToString(assembler->isolate()); | 
| 251           var_input.Bind(assembler->CallStub(callable, context, input)); | 251           var_input.Bind(assembler->CallStub(callable, context, input)); | 
| 252           assembler->Goto(&loop); | 252           assembler->Goto(&loop); | 
| 253         } | 253         } | 
| 254       } | 254       } | 
| 255     } | 255     } | 
| 256   } | 256   } | 
| 257 } | 257 } | 
| 258 | 258 | 
|  | 259 // ES6 section 20.1.2.13 Number.parseInt ( string, radix ) | 
|  | 260 void Builtins::Generate_NumberParseInt(CodeStubAssembler* assembler) { | 
|  | 261   typedef CodeStubAssembler::Label Label; | 
|  | 262   typedef compiler::Node Node; | 
|  | 263 | 
|  | 264   Node* input = assembler->Parameter(1); | 
|  | 265   Node* radix = assembler->Parameter(2); | 
|  | 266   Node* context = assembler->Parameter(5); | 
|  | 267 | 
|  | 268   // Check if {radix} is treated as 10 (i.e. undefined, 0 or 10). | 
|  | 269   Label if_radix10(assembler), if_generic(assembler, Label::kDeferred); | 
|  | 270   assembler->GotoIf(assembler->WordEqual(radix, assembler->UndefinedConstant()), | 
|  | 271                     &if_radix10); | 
|  | 272   assembler->GotoIf( | 
|  | 273       assembler->WordEqual(radix, assembler->SmiConstant(Smi::FromInt(10))), | 
|  | 274       &if_radix10); | 
|  | 275   assembler->GotoIf( | 
|  | 276       assembler->WordEqual(radix, assembler->SmiConstant(Smi::FromInt(0))), | 
|  | 277       &if_radix10); | 
|  | 278   assembler->Goto(&if_generic); | 
|  | 279 | 
|  | 280   assembler->Bind(&if_radix10); | 
|  | 281   { | 
|  | 282     // Check if we can avoid the ToString conversion on {input}. | 
|  | 283     Label if_inputissmi(assembler), if_inputisheapnumber(assembler), | 
|  | 284         if_inputisstring(assembler); | 
|  | 285     assembler->GotoIf(assembler->TaggedIsSmi(input), &if_inputissmi); | 
|  | 286     Node* input_map = assembler->LoadMap(input); | 
|  | 287     assembler->GotoIf( | 
|  | 288         assembler->WordEqual(input_map, assembler->UndefinedConstant()), | 
|  | 289         &if_inputisheapnumber); | 
|  | 290     Node* input_instance_type = assembler->LoadMapInstanceType(input_map); | 
|  | 291     assembler->Branch(assembler->IsStringInstanceType(input_instance_type), | 
|  | 292                       &if_inputisstring, &if_generic); | 
|  | 293 | 
|  | 294     assembler->Bind(&if_inputissmi); | 
|  | 295     { | 
|  | 296       // Just return the {input}. | 
|  | 297       assembler->Return(input); | 
|  | 298     } | 
|  | 299 | 
|  | 300     assembler->Bind(&if_inputisheapnumber); | 
|  | 301     { | 
|  | 302       // Check if the absolute {input} value is in the ]0.01,1e9[ range. | 
|  | 303       Node* input_value = assembler->LoadHeapNumberValue(input); | 
|  | 304       Node* input_value_abs = assembler->Float64Abs(input_value); | 
|  | 305 | 
|  | 306       assembler->GotoIf(assembler->Float64LessThan( | 
|  | 307                             input_value_abs, assembler->Float64Constant(0.01)), | 
|  | 308                         &if_generic); | 
|  | 309       assembler->GotoIf(assembler->Float64LessThan( | 
|  | 310                             assembler->Float64Constant(1e9), input_value_abs), | 
|  | 311                         &if_generic); | 
|  | 312 | 
|  | 313       // Return the truncated int32 value, and return the tagged result. | 
|  | 314       Node* input_value32 = assembler->TruncateFloat64ToWord32(input_value); | 
|  | 315       Node* result = assembler->SmiFromWord32(input_value32); | 
|  | 316       assembler->Return(result); | 
|  | 317     } | 
|  | 318 | 
|  | 319     assembler->Bind(&if_inputisstring); | 
|  | 320     { | 
|  | 321       // Check if the String {input} has a cached array index. | 
|  | 322       Node* input_hash = assembler->LoadNameHashField(input); | 
|  | 323       Node* input_bit = assembler->Word32And( | 
|  | 324           input_hash, | 
|  | 325           assembler->Int32Constant(String::kContainsCachedArrayIndexMask)); | 
|  | 326       assembler->GotoIf( | 
|  | 327           assembler->Word32NotEqual(input_bit, assembler->Int32Constant(0)), | 
|  | 328           &if_generic); | 
|  | 329 | 
|  | 330       // Return the cached array index as result. | 
|  | 331       Node* input_index = | 
|  | 332           assembler->BitFieldDecode<String::ArrayIndexValueBits>(input_hash); | 
|  | 333       Node* result = assembler->SmiTag(input_index); | 
|  | 334       assembler->Return(result); | 
|  | 335     } | 
|  | 336   } | 
|  | 337 | 
|  | 338   assembler->Bind(&if_generic); | 
|  | 339   { | 
|  | 340     Node* result = | 
|  | 341         assembler->CallRuntime(Runtime::kStringParseInt, context, input, radix); | 
|  | 342     assembler->Return(result); | 
|  | 343   } | 
|  | 344 } | 
|  | 345 | 
| 259 // ES6 section 20.1.3.2 Number.prototype.toExponential ( fractionDigits ) | 346 // ES6 section 20.1.3.2 Number.prototype.toExponential ( fractionDigits ) | 
| 260 BUILTIN(NumberPrototypeToExponential) { | 347 BUILTIN(NumberPrototypeToExponential) { | 
| 261   HandleScope scope(isolate); | 348   HandleScope scope(isolate); | 
| 262   Handle<Object> value = args.at<Object>(0); | 349   Handle<Object> value = args.at<Object>(0); | 
| 263   Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1); | 350   Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1); | 
| 264 | 351 | 
| 265   // Unwrap the receiver {value}. | 352   // Unwrap the receiver {value}. | 
| 266   if (value->IsJSValue()) { | 353   if (value->IsJSValue()) { | 
| 267     value = handle(Handle<JSValue>::cast(value)->value(), isolate); | 354     value = handle(Handle<JSValue>::cast(value)->value(), isolate); | 
| 268   } | 355   } | 
| (...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1710   compiler::Node* lhs = assembler->Parameter(0); | 1797   compiler::Node* lhs = assembler->Parameter(0); | 
| 1711   compiler::Node* rhs = assembler->Parameter(1); | 1798   compiler::Node* rhs = assembler->Parameter(1); | 
| 1712   compiler::Node* context = assembler->Parameter(2); | 1799   compiler::Node* context = assembler->Parameter(2); | 
| 1713 | 1800 | 
| 1714   assembler->Return(assembler->StrictEqual(CodeStubAssembler::kNegateResult, | 1801   assembler->Return(assembler->StrictEqual(CodeStubAssembler::kNegateResult, | 
| 1715                                            lhs, rhs, context)); | 1802                                            lhs, rhs, context)); | 
| 1716 } | 1803 } | 
| 1717 | 1804 | 
| 1718 }  // namespace internal | 1805 }  // namespace internal | 
| 1719 }  // namespace v8 | 1806 }  // namespace v8 | 
| OLD | NEW | 
|---|