5 #ifndef V8_BUILTINS_BUILTINS_UTILS_H_ 6 #define V8_BUILTINS_BUILTINS_UTILS_H_ 8 #include "src/arguments.h" 9 #include "src/base/logging.h" 10 #include "src/builtins/builtins.h" 11 #include "src/heap/factory.h" 12 #include "src/isolate.h" 23 DCHECK_LE(1, this->length());
27 DCHECK_LT(index, length());
28 return Arguments::operator[](index);
31 template <
class S = Object>
33 DCHECK_LT(index, length());
34 return Arguments::at<S>(index);
37 static constexpr
int kNewTargetOffset = 0;
38 static constexpr
int kTargetOffset = 1;
39 static constexpr
int kArgcOffset = 2;
40 static constexpr
int kPaddingOffset = 3;
42 static constexpr
int kNumExtraArgs = 4;
43 static constexpr
int kNumExtraArgsWithReceiver = 5;
52 int length()
const {
return Arguments::length() - kNumExtraArgs; }
69 #define BUILTIN(name) \ 70 V8_WARN_UNUSED_RESULT static Object* Builtin_Impl_##name( \ 71 BuiltinArguments args, Isolate* isolate); \ 73 V8_NOINLINE static Object* Builtin_Impl_Stats_##name( \ 74 int args_length, Address* args_object, Isolate* isolate) { \ 75 BuiltinArguments args(args_length, args_object); \ 76 RuntimeCallTimerScope timer(isolate, \ 77 RuntimeCallCounterId::kBuiltin_##name); \ 78 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"), \ 79 "V8.Builtin_" #name); \ 80 return Builtin_Impl_##name(args, isolate); \ 83 V8_WARN_UNUSED_RESULT Object* Builtin_##name( \ 84 int args_length, Address* args_object, Isolate* isolate) { \ 85 DCHECK(isolate->context().is_null() || isolate->context()->IsContext()); \ 86 if (V8_UNLIKELY(FLAG_runtime_stats)) { \ 87 return Builtin_Impl_Stats_##name(args_length, args_object, isolate); \ 89 BuiltinArguments args(args_length, args_object); \ 90 return Builtin_Impl_##name(args, isolate); \ 93 V8_WARN_UNUSED_RESULT static Object* Builtin_Impl_##name( \ 94 BuiltinArguments args, Isolate* isolate) 98 #define CHECK_RECEIVER(Type, name, method) \ 99 if (!args.receiver()->Is##Type()) { \ 100 THROW_NEW_ERROR_RETURN_FAILURE( \ 102 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \ 103 isolate->factory()->NewStringFromAsciiChecked(method), \ 106 Handle<Type> name = Handle<Type>::cast(args.receiver()) 111 #define TO_THIS_STRING(name, method) \ 112 if (args.receiver()->IsNullOrUndefined(isolate)) { \ 113 THROW_NEW_ERROR_RETURN_FAILURE( \ 115 NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, \ 116 isolate->factory()->NewStringFromAsciiChecked(method))); \ 118 Handle<String> name; \ 119 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ 120 isolate, name, Object::ToString(isolate, args.receiver())) 125 #endif // V8_BUILTINS_BUILTINS_UTILS_H_