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-arguments.h" | 7 #include "src/api-arguments.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 321 |
322 MUST_USE_RESULT static Object* CallJsIntrinsic( | 322 MUST_USE_RESULT static Object* CallJsIntrinsic( |
323 Isolate* isolate, Handle<JSFunction> function, | 323 Isolate* isolate, Handle<JSFunction> function, |
324 BuiltinArguments<BuiltinExtraArguments::kNone> args) { | 324 BuiltinArguments<BuiltinExtraArguments::kNone> args) { |
325 HandleScope handleScope(isolate); | 325 HandleScope handleScope(isolate); |
326 int argc = args.length() - 1; | 326 int argc = args.length() - 1; |
327 ScopedVector<Handle<Object> > argv(argc); | 327 ScopedVector<Handle<Object> > argv(argc); |
328 for (int i = 0; i < argc; ++i) { | 328 for (int i = 0; i < argc; ++i) { |
329 argv[i] = args.at<Object>(i + 1); | 329 argv[i] = args.at<Object>(i + 1); |
330 } | 330 } |
331 Handle<Object> result; | 331 RETURN_RESULT_OR_FAILURE( |
332 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 332 isolate, |
333 isolate, result, | 333 Execution::Call(isolate, function, args.receiver(), argc, argv.start())); |
334 Execution::Call(isolate, | |
335 function, | |
336 args.receiver(), | |
337 argc, | |
338 argv.start())); | |
339 return *result; | |
340 } | 334 } |
341 | 335 |
342 | 336 |
343 } // namespace | 337 } // namespace |
344 | 338 |
345 | 339 |
346 BUILTIN(Illegal) { | 340 BUILTIN(Illegal) { |
347 UNREACHABLE(); | 341 UNREACHABLE(); |
348 return isolate->heap()->undefined_value(); // Make compiler happy. | 342 return isolate->heap()->undefined_value(); // Make compiler happy. |
349 } | 343 } |
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 return *object; | 1689 return *object; |
1696 } | 1690 } |
1697 | 1691 |
1698 // ES6 section 19.1.2.3 Object.defineProperties | 1692 // ES6 section 19.1.2.3 Object.defineProperties |
1699 BUILTIN(ObjectDefineProperties) { | 1693 BUILTIN(ObjectDefineProperties) { |
1700 HandleScope scope(isolate); | 1694 HandleScope scope(isolate); |
1701 DCHECK_EQ(3, args.length()); | 1695 DCHECK_EQ(3, args.length()); |
1702 Handle<Object> target = args.at<Object>(1); | 1696 Handle<Object> target = args.at<Object>(1); |
1703 Handle<Object> properties = args.at<Object>(2); | 1697 Handle<Object> properties = args.at<Object>(2); |
1704 | 1698 |
1705 Handle<Object> result; | 1699 RETURN_RESULT_OR_FAILURE( |
1706 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1700 isolate, JSReceiver::DefineProperties(isolate, target, properties)); |
1707 isolate, result, | |
1708 JSReceiver::DefineProperties(isolate, target, properties)); | |
1709 return *result; | |
1710 } | 1701 } |
1711 | 1702 |
1712 // ES6 section 19.1.2.4 Object.defineProperty | 1703 // ES6 section 19.1.2.4 Object.defineProperty |
1713 BUILTIN(ObjectDefineProperty) { | 1704 BUILTIN(ObjectDefineProperty) { |
1714 HandleScope scope(isolate); | 1705 HandleScope scope(isolate); |
1715 DCHECK_EQ(4, args.length()); | 1706 DCHECK_EQ(4, args.length()); |
1716 Handle<Object> target = args.at<Object>(1); | 1707 Handle<Object> target = args.at<Object>(1); |
1717 Handle<Object> key = args.at<Object>(2); | 1708 Handle<Object> key = args.at<Object>(2); |
1718 Handle<Object> attributes = args.at<Object>(3); | 1709 Handle<Object> attributes = args.at<Object>(3); |
1719 | 1710 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1861 | 1852 |
1862 // ES section 19.1.2.9 Object.getPrototypeOf ( O ) | 1853 // ES section 19.1.2.9 Object.getPrototypeOf ( O ) |
1863 BUILTIN(ObjectGetPrototypeOf) { | 1854 BUILTIN(ObjectGetPrototypeOf) { |
1864 HandleScope scope(isolate); | 1855 HandleScope scope(isolate); |
1865 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1856 Handle<Object> object = args.atOrUndefined(isolate, 1); |
1866 | 1857 |
1867 Handle<JSReceiver> receiver; | 1858 Handle<JSReceiver> receiver; |
1868 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1859 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1869 isolate, receiver, Object::ToObject(isolate, object)); | 1860 isolate, receiver, Object::ToObject(isolate, object)); |
1870 | 1861 |
1871 Handle<Object> prototype; | 1862 RETURN_RESULT_OR_FAILURE(isolate, |
1872 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1863 JSReceiver::GetPrototype(isolate, receiver)); |
1873 isolate, prototype, JSReceiver::GetPrototype(isolate, receiver)); | |
1874 | |
1875 return *prototype; | |
1876 } | 1864 } |
1877 | 1865 |
1878 | 1866 |
1879 // ES6 section 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P ) | 1867 // ES6 section 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P ) |
1880 BUILTIN(ObjectGetOwnPropertyDescriptor) { | 1868 BUILTIN(ObjectGetOwnPropertyDescriptor) { |
1881 HandleScope scope(isolate); | 1869 HandleScope scope(isolate); |
1882 // 1. Let obj be ? ToObject(O). | 1870 // 1. Let obj be ? ToObject(O). |
1883 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1871 Handle<Object> object = args.atOrUndefined(isolate, 1); |
1884 Handle<JSReceiver> receiver; | 1872 Handle<JSReceiver> receiver; |
1885 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1873 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2104 return *object; | 2092 return *object; |
2105 } | 2093 } |
2106 | 2094 |
2107 // ES6 section 18.2.6.4 encodeURI (uri) | 2095 // ES6 section 18.2.6.4 encodeURI (uri) |
2108 BUILTIN(GlobalEncodeURI) { | 2096 BUILTIN(GlobalEncodeURI) { |
2109 HandleScope scope(isolate); | 2097 HandleScope scope(isolate); |
2110 Handle<String> uri; | 2098 Handle<String> uri; |
2111 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2099 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
2112 isolate, uri, Object::ToString(isolate, args.atOrUndefined(isolate, 1))); | 2100 isolate, uri, Object::ToString(isolate, args.atOrUndefined(isolate, 1))); |
2113 | 2101 |
2114 return Uri::EncodeUri(isolate, uri); | 2102 RETURN_RESULT_OR_FAILURE(isolate, Uri::EncodeUri(isolate, uri)); |
2115 } | 2103 } |
2116 | 2104 |
2117 // ES6 section 18.2.6.5 encodeURIComponenet (uriComponent) | 2105 // ES6 section 18.2.6.5 encodeURIComponenet (uriComponent) |
2118 BUILTIN(GlobalEncodeURIComponent) { | 2106 BUILTIN(GlobalEncodeURIComponent) { |
2119 HandleScope scope(isolate); | 2107 HandleScope scope(isolate); |
2120 Handle<String> uriComponent; | 2108 Handle<String> uriComponent; |
2121 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2109 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
2122 isolate, uriComponent, | 2110 isolate, uriComponent, |
2123 Object::ToString(isolate, args.atOrUndefined(isolate, 1))); | 2111 Object::ToString(isolate, args.atOrUndefined(isolate, 1))); |
2124 | 2112 |
2125 return Uri::EncodeUriComponent(isolate, uriComponent); | 2113 RETURN_RESULT_OR_FAILURE(isolate, |
| 2114 Uri::EncodeUriComponent(isolate, uriComponent)); |
2126 } | 2115 } |
2127 | 2116 |
2128 namespace { | 2117 namespace { |
2129 | 2118 |
2130 bool CodeGenerationFromStringsAllowed(Isolate* isolate, | 2119 bool CodeGenerationFromStringsAllowed(Isolate* isolate, |
2131 Handle<Context> context) { | 2120 Handle<Context> context) { |
2132 DCHECK(context->allow_code_gen_from_strings()->IsFalse()); | 2121 DCHECK(context->allow_code_gen_from_strings()->IsFalse()); |
2133 // Check with callback if set. | 2122 // Check with callback if set. |
2134 AllowCodeGenerationFromStringsCallback callback = | 2123 AllowCodeGenerationFromStringsCallback callback = |
2135 isolate->allow_code_gen_callback(); | 2124 isolate->allow_code_gen_callback(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2178 HandleScope scope(isolate); | 2167 HandleScope scope(isolate); |
2179 Handle<Object> x = args.atOrUndefined(isolate, 1); | 2168 Handle<Object> x = args.atOrUndefined(isolate, 1); |
2180 Handle<JSFunction> target = args.target<JSFunction>(); | 2169 Handle<JSFunction> target = args.target<JSFunction>(); |
2181 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); | 2170 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); |
2182 if (!x->IsString()) return *x; | 2171 if (!x->IsString()) return *x; |
2183 Handle<JSFunction> function; | 2172 Handle<JSFunction> function; |
2184 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2173 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
2185 isolate, function, | 2174 isolate, function, |
2186 CompileString(handle(target->native_context(), isolate), | 2175 CompileString(handle(target->native_context(), isolate), |
2187 Handle<String>::cast(x), NO_PARSE_RESTRICTION)); | 2176 Handle<String>::cast(x), NO_PARSE_RESTRICTION)); |
2188 Handle<Object> result; | 2177 RETURN_RESULT_OR_FAILURE( |
2189 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2178 isolate, |
2190 isolate, result, | |
2191 Execution::Call(isolate, function, target_global_proxy, 0, nullptr)); | 2179 Execution::Call(isolate, function, target_global_proxy, 0, nullptr)); |
2192 return *result; | |
2193 } | 2180 } |
2194 | 2181 |
2195 | 2182 |
2196 // ----------------------------------------------------------------------------- | 2183 // ----------------------------------------------------------------------------- |
2197 // ES6 section 20.2.2 Function Properties of the Math Object | 2184 // ES6 section 20.2.2 Function Properties of the Math Object |
2198 | 2185 |
2199 | 2186 |
2200 // ES6 section 20.2.2.2 Math.acos ( x ) | 2187 // ES6 section 20.2.2.2 Math.acos ( x ) |
2201 BUILTIN(MathAcos) { | 2188 BUILTIN(MathAcos) { |
2202 HandleScope scope(isolate); | 2189 HandleScope scope(isolate); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2602 THROW_NEW_ERROR_RETURN_FAILURE( | 2589 THROW_NEW_ERROR_RETURN_FAILURE( |
2603 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 2590 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
2604 isolate->factory()->NewStringFromAsciiChecked( | 2591 isolate->factory()->NewStringFromAsciiChecked( |
2605 "Reflect.get"))); | 2592 "Reflect.get"))); |
2606 } | 2593 } |
2607 | 2594 |
2608 Handle<Name> name; | 2595 Handle<Name> name; |
2609 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, | 2596 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, |
2610 Object::ToName(isolate, key)); | 2597 Object::ToName(isolate, key)); |
2611 | 2598 |
2612 Handle<Object> result; | 2599 RETURN_RESULT_OR_FAILURE( |
2613 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2600 isolate, Object::GetPropertyOrElement(receiver, name, |
2614 isolate, result, Object::GetPropertyOrElement( | 2601 Handle<JSReceiver>::cast(target))); |
2615 receiver, name, Handle<JSReceiver>::cast(target))); | |
2616 | |
2617 return *result; | |
2618 } | 2602 } |
2619 | 2603 |
2620 | 2604 |
2621 // ES6 section 26.1.7 Reflect.getOwnPropertyDescriptor | 2605 // ES6 section 26.1.7 Reflect.getOwnPropertyDescriptor |
2622 BUILTIN(ReflectGetOwnPropertyDescriptor) { | 2606 BUILTIN(ReflectGetOwnPropertyDescriptor) { |
2623 HandleScope scope(isolate); | 2607 HandleScope scope(isolate); |
2624 DCHECK_EQ(3, args.length()); | 2608 DCHECK_EQ(3, args.length()); |
2625 Handle<Object> target = args.at<Object>(1); | 2609 Handle<Object> target = args.at<Object>(1); |
2626 Handle<Object> key = args.at<Object>(2); | 2610 Handle<Object> key = args.at<Object>(2); |
2627 | 2611 |
(...skipping 22 matching lines...) Expand all Loading... |
2650 HandleScope scope(isolate); | 2634 HandleScope scope(isolate); |
2651 DCHECK_EQ(2, args.length()); | 2635 DCHECK_EQ(2, args.length()); |
2652 Handle<Object> target = args.at<Object>(1); | 2636 Handle<Object> target = args.at<Object>(1); |
2653 | 2637 |
2654 if (!target->IsJSReceiver()) { | 2638 if (!target->IsJSReceiver()) { |
2655 THROW_NEW_ERROR_RETURN_FAILURE( | 2639 THROW_NEW_ERROR_RETURN_FAILURE( |
2656 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 2640 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
2657 isolate->factory()->NewStringFromAsciiChecked( | 2641 isolate->factory()->NewStringFromAsciiChecked( |
2658 "Reflect.getPrototypeOf"))); | 2642 "Reflect.getPrototypeOf"))); |
2659 } | 2643 } |
2660 Handle<Object> prototype; | |
2661 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(target); | 2644 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(target); |
2662 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2645 RETURN_RESULT_OR_FAILURE(isolate, |
2663 isolate, prototype, JSReceiver::GetPrototype(isolate, receiver)); | 2646 JSReceiver::GetPrototype(isolate, receiver)); |
2664 return *prototype; | |
2665 } | 2647 } |
2666 | 2648 |
2667 | 2649 |
2668 // ES6 section 26.1.9 Reflect.has | 2650 // ES6 section 26.1.9 Reflect.has |
2669 BUILTIN(ReflectHas) { | 2651 BUILTIN(ReflectHas) { |
2670 HandleScope scope(isolate); | 2652 HandleScope scope(isolate); |
2671 DCHECK_EQ(3, args.length()); | 2653 DCHECK_EQ(3, args.length()); |
2672 Handle<Object> target = args.at<Object>(1); | 2654 Handle<Object> target = args.at<Object>(1); |
2673 Handle<Object> key = args.at<Object>(2); | 2655 Handle<Object> key = args.at<Object>(2); |
2674 | 2656 |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3173 | 3155 |
3174 } // namespace | 3156 } // namespace |
3175 | 3157 |
3176 | 3158 |
3177 // ES6 section 20.3.2 The Date Constructor for the [[Call]] case. | 3159 // ES6 section 20.3.2 The Date Constructor for the [[Call]] case. |
3178 BUILTIN(DateConstructor) { | 3160 BUILTIN(DateConstructor) { |
3179 HandleScope scope(isolate); | 3161 HandleScope scope(isolate); |
3180 double const time_val = JSDate::CurrentTimeValue(isolate); | 3162 double const time_val = JSDate::CurrentTimeValue(isolate); |
3181 char buffer[128]; | 3163 char buffer[128]; |
3182 ToDateString(time_val, ArrayVector(buffer), isolate->date_cache()); | 3164 ToDateString(time_val, ArrayVector(buffer), isolate->date_cache()); |
3183 Handle<String> result; | 3165 RETURN_RESULT_OR_FAILURE( |
3184 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3166 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
3185 isolate, result, | |
3186 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | |
3187 return *result; | |
3188 } | 3167 } |
3189 | 3168 |
3190 | 3169 |
3191 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. | 3170 // ES6 section 20.3.2 The Date Constructor for the [[Construct]] case. |
3192 BUILTIN(DateConstructor_ConstructStub) { | 3171 BUILTIN(DateConstructor_ConstructStub) { |
3193 HandleScope scope(isolate); | 3172 HandleScope scope(isolate); |
3194 int const argc = args.length() - 1; | 3173 int const argc = args.length() - 1; |
3195 Handle<JSFunction> target = args.target<JSFunction>(); | 3174 Handle<JSFunction> target = args.target<JSFunction>(); |
3196 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); | 3175 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); |
3197 double time_val; | 3176 double time_val; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3259 double const day = MakeDay(year, month, date); | 3238 double const day = MakeDay(year, month, date); |
3260 double const time = MakeTime(hours, minutes, seconds, ms); | 3239 double const time = MakeTime(hours, minutes, seconds, ms); |
3261 time_val = MakeDate(day, time); | 3240 time_val = MakeDate(day, time); |
3262 if (time_val >= -DateCache::kMaxTimeBeforeUTCInMs && | 3241 if (time_val >= -DateCache::kMaxTimeBeforeUTCInMs && |
3263 time_val <= DateCache::kMaxTimeBeforeUTCInMs) { | 3242 time_val <= DateCache::kMaxTimeBeforeUTCInMs) { |
3264 time_val = isolate->date_cache()->ToUTC(static_cast<int64_t>(time_val)); | 3243 time_val = isolate->date_cache()->ToUTC(static_cast<int64_t>(time_val)); |
3265 } else { | 3244 } else { |
3266 time_val = std::numeric_limits<double>::quiet_NaN(); | 3245 time_val = std::numeric_limits<double>::quiet_NaN(); |
3267 } | 3246 } |
3268 } | 3247 } |
3269 Handle<JSDate> result; | 3248 RETURN_RESULT_OR_FAILURE(isolate, JSDate::New(target, new_target, time_val)); |
3270 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | |
3271 JSDate::New(target, new_target, time_val)); | |
3272 return *result; | |
3273 } | 3249 } |
3274 | 3250 |
3275 | 3251 |
3276 // ES6 section 20.3.3.1 Date.now ( ) | 3252 // ES6 section 20.3.3.1 Date.now ( ) |
3277 BUILTIN(DateNow) { | 3253 BUILTIN(DateNow) { |
3278 HandleScope scope(isolate); | 3254 HandleScope scope(isolate); |
3279 return *isolate->factory()->NewNumber(JSDate::CurrentTimeValue(isolate)); | 3255 return *isolate->factory()->NewNumber(JSDate::CurrentTimeValue(isolate)); |
3280 } | 3256 } |
3281 | 3257 |
3282 | 3258 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3757 } | 3733 } |
3758 | 3734 |
3759 | 3735 |
3760 // ES6 section 20.3.4.35 Date.prototype.toDateString ( ) | 3736 // ES6 section 20.3.4.35 Date.prototype.toDateString ( ) |
3761 BUILTIN(DatePrototypeToDateString) { | 3737 BUILTIN(DatePrototypeToDateString) { |
3762 HandleScope scope(isolate); | 3738 HandleScope scope(isolate); |
3763 CHECK_RECEIVER(JSDate, date, "Date.prototype.toDateString"); | 3739 CHECK_RECEIVER(JSDate, date, "Date.prototype.toDateString"); |
3764 char buffer[128]; | 3740 char buffer[128]; |
3765 ToDateString(date->value()->Number(), ArrayVector(buffer), | 3741 ToDateString(date->value()->Number(), ArrayVector(buffer), |
3766 isolate->date_cache(), kDateOnly); | 3742 isolate->date_cache(), kDateOnly); |
3767 Handle<String> result; | 3743 RETURN_RESULT_OR_FAILURE( |
3768 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3744 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
3769 isolate, result, | |
3770 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | |
3771 return *result; | |
3772 } | 3745 } |
3773 | 3746 |
3774 | 3747 |
3775 // ES6 section 20.3.4.36 Date.prototype.toISOString ( ) | 3748 // ES6 section 20.3.4.36 Date.prototype.toISOString ( ) |
3776 BUILTIN(DatePrototypeToISOString) { | 3749 BUILTIN(DatePrototypeToISOString) { |
3777 HandleScope scope(isolate); | 3750 HandleScope scope(isolate); |
3778 CHECK_RECEIVER(JSDate, date, "Date.prototype.toISOString"); | 3751 CHECK_RECEIVER(JSDate, date, "Date.prototype.toISOString"); |
3779 double const time_val = date->value()->Number(); | 3752 double const time_val = date->value()->Number(); |
3780 if (std::isnan(time_val)) { | 3753 if (std::isnan(time_val)) { |
3781 THROW_NEW_ERROR_RETURN_FAILURE( | 3754 THROW_NEW_ERROR_RETURN_FAILURE( |
(...skipping 18 matching lines...) Expand all Loading... |
3800 } | 3773 } |
3801 | 3774 |
3802 | 3775 |
3803 // ES6 section 20.3.4.41 Date.prototype.toString ( ) | 3776 // ES6 section 20.3.4.41 Date.prototype.toString ( ) |
3804 BUILTIN(DatePrototypeToString) { | 3777 BUILTIN(DatePrototypeToString) { |
3805 HandleScope scope(isolate); | 3778 HandleScope scope(isolate); |
3806 CHECK_RECEIVER(JSDate, date, "Date.prototype.toString"); | 3779 CHECK_RECEIVER(JSDate, date, "Date.prototype.toString"); |
3807 char buffer[128]; | 3780 char buffer[128]; |
3808 ToDateString(date->value()->Number(), ArrayVector(buffer), | 3781 ToDateString(date->value()->Number(), ArrayVector(buffer), |
3809 isolate->date_cache()); | 3782 isolate->date_cache()); |
3810 Handle<String> result; | 3783 RETURN_RESULT_OR_FAILURE( |
3811 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3784 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
3812 isolate, result, | |
3813 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | |
3814 return *result; | |
3815 } | 3785 } |
3816 | 3786 |
3817 | 3787 |
3818 // ES6 section 20.3.4.42 Date.prototype.toTimeString ( ) | 3788 // ES6 section 20.3.4.42 Date.prototype.toTimeString ( ) |
3819 BUILTIN(DatePrototypeToTimeString) { | 3789 BUILTIN(DatePrototypeToTimeString) { |
3820 HandleScope scope(isolate); | 3790 HandleScope scope(isolate); |
3821 CHECK_RECEIVER(JSDate, date, "Date.prototype.toTimeString"); | 3791 CHECK_RECEIVER(JSDate, date, "Date.prototype.toTimeString"); |
3822 char buffer[128]; | 3792 char buffer[128]; |
3823 ToDateString(date->value()->Number(), ArrayVector(buffer), | 3793 ToDateString(date->value()->Number(), ArrayVector(buffer), |
3824 isolate->date_cache(), kTimeOnly); | 3794 isolate->date_cache(), kTimeOnly); |
3825 Handle<String> result; | 3795 RETURN_RESULT_OR_FAILURE( |
3826 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3796 isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); |
3827 isolate, result, | |
3828 isolate->factory()->NewStringFromUtf8(CStrVector(buffer))); | |
3829 return *result; | |
3830 } | 3797 } |
3831 | 3798 |
3832 | 3799 |
3833 // ES6 section 20.3.4.43 Date.prototype.toUTCString ( ) | 3800 // ES6 section 20.3.4.43 Date.prototype.toUTCString ( ) |
3834 BUILTIN(DatePrototypeToUTCString) { | 3801 BUILTIN(DatePrototypeToUTCString) { |
3835 HandleScope scope(isolate); | 3802 HandleScope scope(isolate); |
3836 CHECK_RECEIVER(JSDate, date, "Date.prototype.toUTCString"); | 3803 CHECK_RECEIVER(JSDate, date, "Date.prototype.toUTCString"); |
3837 double const time_val = date->value()->Number(); | 3804 double const time_val = date->value()->Number(); |
3838 if (std::isnan(time_val)) { | 3805 if (std::isnan(time_val)) { |
3839 return *isolate->factory()->NewStringFromAsciiChecked("Invalid Date"); | 3806 return *isolate->factory()->NewStringFromAsciiChecked("Invalid Date"); |
(...skipping 17 matching lines...) Expand all Loading... |
3857 return date->value(); | 3824 return date->value(); |
3858 } | 3825 } |
3859 | 3826 |
3860 | 3827 |
3861 // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) | 3828 // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) |
3862 BUILTIN(DatePrototypeToPrimitive) { | 3829 BUILTIN(DatePrototypeToPrimitive) { |
3863 HandleScope scope(isolate); | 3830 HandleScope scope(isolate); |
3864 DCHECK_EQ(2, args.length()); | 3831 DCHECK_EQ(2, args.length()); |
3865 CHECK_RECEIVER(JSReceiver, receiver, "Date.prototype [ @@toPrimitive ]"); | 3832 CHECK_RECEIVER(JSReceiver, receiver, "Date.prototype [ @@toPrimitive ]"); |
3866 Handle<Object> hint = args.at<Object>(1); | 3833 Handle<Object> hint = args.at<Object>(1); |
3867 Handle<Object> result; | 3834 RETURN_RESULT_OR_FAILURE(isolate, JSDate::ToPrimitive(receiver, hint)); |
3868 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | |
3869 JSDate::ToPrimitive(receiver, hint)); | |
3870 return *result; | |
3871 } | 3835 } |
3872 | 3836 |
3873 | 3837 |
3874 // ES6 section B.2.4.1 Date.prototype.getYear ( ) | 3838 // ES6 section B.2.4.1 Date.prototype.getYear ( ) |
3875 BUILTIN(DatePrototypeGetYear) { | 3839 BUILTIN(DatePrototypeGetYear) { |
3876 HandleScope scope(isolate); | 3840 HandleScope scope(isolate); |
3877 CHECK_RECEIVER(JSDate, date, "Date.prototype.getYear"); | 3841 CHECK_RECEIVER(JSDate, date, "Date.prototype.getYear"); |
3878 double time_val = date->value()->Number(); | 3842 double time_val = date->value()->Number(); |
3879 if (std::isnan(time_val)) return date->value(); | 3843 if (std::isnan(time_val)) return date->value(); |
3880 int64_t time_ms = static_cast<int64_t>(time_val); | 3844 int64_t time_ms = static_cast<int64_t>(time_val); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4242 THROW_NEW_ERROR_RETURN_FAILURE( | 4206 THROW_NEW_ERROR_RETURN_FAILURE( |
4243 isolate, NewTypeError(MessageTemplate::kNotGeneric, | 4207 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
4244 isolate->factory()->NewStringFromAsciiChecked( | 4208 isolate->factory()->NewStringFromAsciiChecked( |
4245 "Function.prototype.toString"))); | 4209 "Function.prototype.toString"))); |
4246 } | 4210 } |
4247 | 4211 |
4248 | 4212 |
4249 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body) | 4213 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body) |
4250 BUILTIN(GeneratorFunctionConstructor) { | 4214 BUILTIN(GeneratorFunctionConstructor) { |
4251 HandleScope scope(isolate); | 4215 HandleScope scope(isolate); |
4252 Handle<JSFunction> result; | 4216 RETURN_RESULT_OR_FAILURE(isolate, |
4253 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 4217 CreateDynamicFunction(isolate, args, "function*")); |
4254 isolate, result, CreateDynamicFunction(isolate, args, "function*")); | |
4255 return *result; | |
4256 } | 4218 } |
4257 | 4219 |
4258 BUILTIN(AsyncFunctionConstructor) { | 4220 BUILTIN(AsyncFunctionConstructor) { |
4259 HandleScope scope(isolate); | 4221 HandleScope scope(isolate); |
4260 Handle<JSFunction> result; | 4222 RETURN_RESULT_OR_FAILURE( |
4261 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 4223 isolate, CreateDynamicFunction(isolate, args, "async function")); |
4262 isolate, result, CreateDynamicFunction(isolate, args, "async function")); | |
4263 return *result; | |
4264 } | 4224 } |
4265 | 4225 |
4266 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. | 4226 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. |
4267 BUILTIN(SymbolConstructor) { | 4227 BUILTIN(SymbolConstructor) { |
4268 HandleScope scope(isolate); | 4228 HandleScope scope(isolate); |
4269 Handle<Symbol> result = isolate->factory()->NewSymbol(); | 4229 Handle<Symbol> result = isolate->factory()->NewSymbol(); |
4270 Handle<Object> description = args.atOrUndefined(isolate, 1); | 4230 Handle<Object> description = args.atOrUndefined(isolate, 1); |
4271 if (!description->IsUndefined()) { | 4231 if (!description->IsUndefined()) { |
4272 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, | 4232 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, |
4273 Object::ToString(isolate, description)); | 4233 Object::ToString(isolate, description)); |
4274 result->set_name(*description); | 4234 result->set_name(*description); |
4275 } | 4235 } |
4276 return *result; | 4236 return *result; |
4277 } | 4237 } |
4278 | 4238 |
4279 | 4239 |
4280 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. | 4240 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. |
4281 BUILTIN(SymbolConstructor_ConstructStub) { | 4241 BUILTIN(SymbolConstructor_ConstructStub) { |
4282 HandleScope scope(isolate); | 4242 HandleScope scope(isolate); |
4283 THROW_NEW_ERROR_RETURN_FAILURE( | 4243 THROW_NEW_ERROR_RETURN_FAILURE( |
4284 isolate, NewTypeError(MessageTemplate::kNotConstructor, | 4244 isolate, NewTypeError(MessageTemplate::kNotConstructor, |
4285 isolate->factory()->Symbol_string())); | 4245 isolate->factory()->Symbol_string())); |
4286 } | 4246 } |
4287 | 4247 |
4288 | 4248 |
4289 // ES6 19.1.3.6 Object.prototype.toString | 4249 // ES6 19.1.3.6 Object.prototype.toString |
4290 BUILTIN(ObjectProtoToString) { | 4250 BUILTIN(ObjectProtoToString) { |
4291 HandleScope scope(isolate); | 4251 HandleScope scope(isolate); |
4292 Handle<Object> object = args.at<Object>(0); | 4252 Handle<Object> object = args.at<Object>(0); |
4293 Handle<String> result; | 4253 RETURN_RESULT_OR_FAILURE(isolate, |
4294 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 4254 Object::ObjectProtoToString(isolate, object)); |
4295 isolate, result, Object::ObjectProtoToString(isolate, object)); | |
4296 return *result; | |
4297 } | 4255 } |
4298 | 4256 |
4299 // ----------------------------------------------------------------------------- | 4257 // ----------------------------------------------------------------------------- |
4300 // ES6 section 21.1 String Objects | 4258 // ES6 section 21.1 String Objects |
4301 | 4259 |
4302 namespace { | 4260 namespace { |
4303 | 4261 |
4304 bool ToUint16(Handle<Object> value, uint16_t* result) { | 4262 bool ToUint16(Handle<Object> value, uint16_t* result) { |
4305 if (value->IsNumber() || Object::ToNumber(value).ToHandle(&value)) { | 4263 if (value->IsNumber() || Object::ToNumber(value).ToHandle(&value)) { |
4306 *result = DoubleToUint32(value->Number()); | 4264 *result = DoubleToUint32(value->Number()); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4619 isolate->factory()->NewStringFromAsciiChecked("Proxy"))); | 4577 isolate->factory()->NewStringFromAsciiChecked("Proxy"))); |
4620 } | 4578 } |
4621 | 4579 |
4622 | 4580 |
4623 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Construct]] case. | 4581 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Construct]] case. |
4624 BUILTIN(ProxyConstructor_ConstructStub) { | 4582 BUILTIN(ProxyConstructor_ConstructStub) { |
4625 HandleScope scope(isolate); | 4583 HandleScope scope(isolate); |
4626 DCHECK(isolate->proxy_function()->IsConstructor()); | 4584 DCHECK(isolate->proxy_function()->IsConstructor()); |
4627 Handle<Object> target = args.atOrUndefined(isolate, 1); | 4585 Handle<Object> target = args.atOrUndefined(isolate, 1); |
4628 Handle<Object> handler = args.atOrUndefined(isolate, 2); | 4586 Handle<Object> handler = args.atOrUndefined(isolate, 2); |
4629 Handle<JSProxy> result; | 4587 RETURN_RESULT_OR_FAILURE(isolate, JSProxy::New(isolate, target, handler)); |
4630 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | |
4631 JSProxy::New(isolate, target, handler)); | |
4632 return *result; | |
4633 } | 4588 } |
4634 | 4589 |
4635 | 4590 |
4636 // ----------------------------------------------------------------------------- | 4591 // ----------------------------------------------------------------------------- |
4637 // Throwers for restricted function properties and strict arguments object | 4592 // Throwers for restricted function properties and strict arguments object |
4638 // properties | 4593 // properties |
4639 | 4594 |
4640 | 4595 |
4641 BUILTIN(RestrictedFunctionPropertiesThrower) { | 4596 BUILTIN(RestrictedFunctionPropertiesThrower) { |
4642 HandleScope scope(isolate); | 4597 HandleScope scope(isolate); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4740 } | 4695 } |
4741 | 4696 |
4742 return scope.CloseAndEscape(receiver); | 4697 return scope.CloseAndEscape(receiver); |
4743 } | 4698 } |
4744 | 4699 |
4745 } // namespace | 4700 } // namespace |
4746 | 4701 |
4747 | 4702 |
4748 BUILTIN(HandleApiCall) { | 4703 BUILTIN(HandleApiCall) { |
4749 HandleScope scope(isolate); | 4704 HandleScope scope(isolate); |
4750 Handle<Object> result; | 4705 RETURN_RESULT_OR_FAILURE(isolate, HandleApiCallHelper(isolate, args)); |
4751 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | |
4752 HandleApiCallHelper(isolate, args)); | |
4753 return *result; | |
4754 } | 4706 } |
4755 | 4707 |
4756 | 4708 |
4757 Handle<Code> Builtins::CallFunction(ConvertReceiverMode mode, | 4709 Handle<Code> Builtins::CallFunction(ConvertReceiverMode mode, |
4758 TailCallMode tail_call_mode) { | 4710 TailCallMode tail_call_mode) { |
4759 switch (tail_call_mode) { | 4711 switch (tail_call_mode) { |
4760 case TailCallMode::kDisallow: | 4712 case TailCallMode::kDisallow: |
4761 switch (mode) { | 4713 switch (mode) { |
4762 case ConvertReceiverMode::kNullOrUndefined: | 4714 case ConvertReceiverMode::kNullOrUndefined: |
4763 return CallFunction_ReceiverIsNullOrUndefined(); | 4715 return CallFunction_ReceiverIsNullOrUndefined(); |
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5580 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 5532 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
5581 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 5533 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
5582 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 5534 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
5583 #undef DEFINE_BUILTIN_ACCESSOR_C | 5535 #undef DEFINE_BUILTIN_ACCESSOR_C |
5584 #undef DEFINE_BUILTIN_ACCESSOR_A | 5536 #undef DEFINE_BUILTIN_ACCESSOR_A |
5585 #undef DEFINE_BUILTIN_ACCESSOR_T | 5537 #undef DEFINE_BUILTIN_ACCESSOR_T |
5586 #undef DEFINE_BUILTIN_ACCESSOR_H | 5538 #undef DEFINE_BUILTIN_ACCESSOR_H |
5587 | 5539 |
5588 } // namespace internal | 5540 } // namespace internal |
5589 } // namespace v8 | 5541 } // namespace v8 |
OLD | NEW |