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.h" | 5 #include "src/builtins/builtins.h" |
6 #include "src/builtins/builtins-utils.h" | 6 #include "src/builtins/builtins-utils.h" |
7 | 7 |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 // ES6 section 20.2.2.18 Math.hypot ( value1, value2, ...values ) | 357 // ES6 section 20.2.2.18 Math.hypot ( value1, value2, ...values ) |
358 BUILTIN(MathHypot) { | 358 BUILTIN(MathHypot) { |
359 HandleScope scope(isolate); | 359 HandleScope scope(isolate); |
360 int const length = args.length() - 1; | 360 int const length = args.length() - 1; |
361 if (length == 0) return Smi::kZero; | 361 if (length == 0) return Smi::kZero; |
362 DCHECK_LT(0, length); | 362 DCHECK_LT(0, length); |
363 double max = 0; | 363 double max = 0; |
364 bool one_arg_is_nan = false; | 364 bool one_arg_is_nan = false; |
365 List<double> abs_values(length); | 365 List<double> abs_values(length); |
366 for (int i = 0; i < length; i++) { | 366 for (int i = 0; i < length; i++) { |
367 Handle<Object> x = args.at<Object>(i + 1); | 367 Handle<Object> x = args.at(i + 1); |
368 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); | 368 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); |
369 double abs_value = std::abs(x->Number()); | 369 double abs_value = std::abs(x->Number()); |
370 | 370 |
371 if (std::isnan(abs_value)) { | 371 if (std::isnan(abs_value)) { |
372 one_arg_is_nan = true; | 372 one_arg_is_nan = true; |
373 } else { | 373 } else { |
374 abs_values.Add(abs_value); | 374 abs_values.Add(abs_value); |
375 if (max < abs_value) { | 375 if (max < abs_value) { |
376 max = abs_value; | 376 max = abs_value; |
377 } | 377 } |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 void Builtins::Generate_MathMax(MacroAssembler* masm) { | 574 void Builtins::Generate_MathMax(MacroAssembler* masm) { |
575 Generate_MathMaxMin(masm, MathMaxMinKind::kMax); | 575 Generate_MathMaxMin(masm, MathMaxMinKind::kMax); |
576 } | 576 } |
577 | 577 |
578 void Builtins::Generate_MathMin(MacroAssembler* masm) { | 578 void Builtins::Generate_MathMin(MacroAssembler* masm) { |
579 Generate_MathMaxMin(masm, MathMaxMinKind::kMin); | 579 Generate_MathMaxMin(masm, MathMaxMinKind::kMin); |
580 } | 580 } |
581 | 581 |
582 } // namespace internal | 582 } // namespace internal |
583 } // namespace v8 | 583 } // namespace v8 |
OLD | NEW |