OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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.h" | 5 #include "src/builtins.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/api-arguments.h" | 8 #include "src/api-arguments.h" |
9 #include "src/api-natives.h" | 9 #include "src/api-natives.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2000 | 2000 |
2001 // ES6 section 20.2.2.6 Math.atan ( x ) | 2001 // ES6 section 20.2.2.6 Math.atan ( x ) |
2002 BUILTIN(MathAtan) { | 2002 BUILTIN(MathAtan) { |
2003 HandleScope scope(isolate); | 2003 HandleScope scope(isolate); |
2004 DCHECK_EQ(2, args.length()); | 2004 DCHECK_EQ(2, args.length()); |
2005 Handle<Object> x = args.at<Object>(1); | 2005 Handle<Object> x = args.at<Object>(1); |
2006 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); | 2006 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); |
2007 return *isolate->factory()->NewHeapNumber(std::atan(x->Number())); | 2007 return *isolate->factory()->NewHeapNumber(std::atan(x->Number())); |
2008 } | 2008 } |
2009 | 2009 |
| 2010 // ES6 section 20.2.2.16 Math.floor ( x ) |
| 2011 void Builtins::Generate_MathFloor(compiler::CodeStubAssembler* assembler) { |
| 2012 typedef compiler::CodeStubAssembler::Label Label; |
| 2013 typedef compiler::Node Node; |
| 2014 typedef compiler::CodeStubAssembler::Variable Variable; |
| 2015 |
| 2016 Node* context = assembler->Parameter(4); |
| 2017 |
| 2018 // We might need to loop once for ToNumber conversion. |
| 2019 Variable var_x(assembler, MachineRepresentation::kTagged); |
| 2020 Label loop(assembler, &var_x); |
| 2021 var_x.Bind(assembler->Parameter(1)); |
| 2022 assembler->Goto(&loop); |
| 2023 assembler->Bind(&loop); |
| 2024 { |
| 2025 // Load the current {x} value. |
| 2026 Node* x = var_x.value(); |
| 2027 |
| 2028 // Check if {x} is a Smi or a HeapObject. |
| 2029 Label if_xissmi(assembler), if_xisnotsmi(assembler); |
| 2030 assembler->Branch(assembler->WordIsSmi(x), &if_xissmi, &if_xisnotsmi); |
| 2031 |
| 2032 assembler->Bind(&if_xissmi); |
| 2033 { |
| 2034 // Nothing to do when {x} is a Smi. |
| 2035 assembler->Return(x); |
| 2036 } |
| 2037 |
| 2038 assembler->Bind(&if_xisnotsmi); |
| 2039 { |
| 2040 // Check if {x} is a HeapNumber. |
| 2041 Label if_xisheapnumber(assembler), |
| 2042 if_xisnotheapnumber(assembler, Label::kDeferred); |
| 2043 assembler->Branch( |
| 2044 assembler->WordEqual(assembler->LoadMap(x), |
| 2045 assembler->HeapNumberMapConstant()), |
| 2046 &if_xisheapnumber, &if_xisnotheapnumber); |
| 2047 |
| 2048 assembler->Bind(&if_xisheapnumber); |
| 2049 { |
| 2050 Node* x_value = assembler->LoadHeapNumberValue(x); |
| 2051 Node* value = assembler->Float64Floor(x_value); |
| 2052 Node* result = assembler->ChangeFloat64ToTagged(value); |
| 2053 assembler->Return(result); |
| 2054 } |
| 2055 |
| 2056 assembler->Bind(&if_xisnotheapnumber); |
| 2057 { |
| 2058 // Need to convert {x} to a Number first. |
| 2059 Callable callable = |
| 2060 CodeFactory::NonNumberToNumber(assembler->isolate()); |
| 2061 var_x.Bind(assembler->CallStub(callable, context, x)); |
| 2062 assembler->Goto(&loop); |
| 2063 } |
| 2064 } |
| 2065 } |
| 2066 } |
2010 | 2067 |
2011 // ES6 section 20.2.2.17 Math.fround ( x ) | 2068 // ES6 section 20.2.2.17 Math.fround ( x ) |
2012 BUILTIN(MathFround) { | 2069 BUILTIN(MathFround) { |
2013 HandleScope scope(isolate); | 2070 HandleScope scope(isolate); |
2014 DCHECK_EQ(2, args.length()); | 2071 DCHECK_EQ(2, args.length()); |
2015 Handle<Object> x = args.at<Object>(1); | 2072 Handle<Object> x = args.at<Object>(1); |
2016 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); | 2073 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); |
2017 float x32 = DoubleToFloat32(x->Number()); | 2074 float x32 = DoubleToFloat32(x->Number()); |
2018 return *isolate->factory()->NewNumber(x32); | 2075 return *isolate->factory()->NewNumber(x32); |
2019 } | 2076 } |
2020 | 2077 |
2021 | |
2022 // ES6 section 20.2.2.19 Math.imul ( x, y ) | 2078 // ES6 section 20.2.2.19 Math.imul ( x, y ) |
2023 BUILTIN(MathImul) { | 2079 BUILTIN(MathImul) { |
2024 HandleScope scope(isolate); | 2080 HandleScope scope(isolate); |
2025 DCHECK_EQ(3, args.length()); | 2081 DCHECK_EQ(3, args.length()); |
2026 Handle<Object> x = args.at<Object>(1); | 2082 Handle<Object> x = args.at<Object>(1); |
2027 Handle<Object> y = args.at<Object>(2); | 2083 Handle<Object> y = args.at<Object>(2); |
2028 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); | 2084 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); |
2029 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, y, Object::ToNumber(y)); | 2085 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, y, Object::ToNumber(y)); |
2030 int product = static_cast<int>(NumberToUint32(*x) * NumberToUint32(*y)); | 2086 int product = static_cast<int>(NumberToUint32(*x) * NumberToUint32(*y)); |
2031 return *isolate->factory()->NewNumberFromInt(product); | 2087 return *isolate->factory()->NewNumberFromInt(product); |
2032 } | 2088 } |
2033 | 2089 |
2034 // ES6 section 20.2.2.32 Math.sqrt ( x ) | 2090 // ES6 section 20.2.2.32 Math.sqrt ( x ) |
2035 void Builtins::Generate_MathSqrt(compiler::CodeStubAssembler* assembler) { | 2091 void Builtins::Generate_MathSqrt(compiler::CodeStubAssembler* assembler) { |
2036 using compiler::Node; | 2092 using compiler::Node; |
2037 | 2093 |
2038 Node* x = assembler->Parameter(1); | 2094 Node* x = assembler->Parameter(1); |
2039 Node* context = assembler->Parameter(4); | 2095 Node* context = assembler->Parameter(4); |
2040 Node* x_value = assembler->TruncateTaggedToFloat64(context, x); | 2096 Node* x_value = assembler->TruncateTaggedToFloat64(context, x); |
2041 Node* value = assembler->Float64Sqrt(x_value); | 2097 Node* value = assembler->Float64Sqrt(x_value); |
2042 Node* result = assembler->AllocateHeapNumberWithValue(value); | 2098 Node* result = assembler->ChangeFloat64ToTagged(value); |
2043 assembler->Return(result); | 2099 assembler->Return(result); |
2044 } | 2100 } |
2045 | 2101 |
2046 // ----------------------------------------------------------------------------- | 2102 // ----------------------------------------------------------------------------- |
2047 // ES6 section 26.1 The Reflect Object | 2103 // ES6 section 26.1 The Reflect Object |
2048 | 2104 |
2049 | 2105 |
2050 // ES6 section 26.1.3 Reflect.defineProperty | 2106 // ES6 section 26.1.3 Reflect.defineProperty |
2051 BUILTIN(ReflectDefineProperty) { | 2107 BUILTIN(ReflectDefineProperty) { |
2052 HandleScope scope(isolate); | 2108 HandleScope scope(isolate); |
(...skipping 2507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4560 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 4616 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
4561 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4617 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4562 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4618 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4563 #undef DEFINE_BUILTIN_ACCESSOR_C | 4619 #undef DEFINE_BUILTIN_ACCESSOR_C |
4564 #undef DEFINE_BUILTIN_ACCESSOR_A | 4620 #undef DEFINE_BUILTIN_ACCESSOR_A |
4565 #undef DEFINE_BUILTIN_ACCESSOR_T | 4621 #undef DEFINE_BUILTIN_ACCESSOR_T |
4566 #undef DEFINE_BUILTIN_ACCESSOR_H | 4622 #undef DEFINE_BUILTIN_ACCESSOR_H |
4567 | 4623 |
4568 } // namespace internal | 4624 } // namespace internal |
4569 } // namespace v8 | 4625 } // namespace v8 |
OLD | NEW |