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 #ifndef V8_BUILTINS_BUILTINS_UTILS_H_ | 5 #ifndef V8_BUILTINS_BUILTINS_UTILS_H_ |
6 #define V8_BUILTINS_BUILTINS_UTILS_H_ | 6 #define V8_BUILTINS_BUILTINS_UTILS_H_ |
7 | 7 |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/base/logging.h" | 9 #include "src/base/logging.h" |
10 #include "src/builtins/builtins.h" | 10 #include "src/builtins/builtins.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // A builtin function is defined by writing: | 69 // A builtin function is defined by writing: |
70 // | 70 // |
71 // BUILTIN(name) { | 71 // BUILTIN(name) { |
72 // ... | 72 // ... |
73 // } | 73 // } |
74 // | 74 // |
75 // In the body of the builtin function the arguments can be accessed | 75 // In the body of the builtin function the arguments can be accessed |
76 // through the BuiltinArguments object args. | 76 // through the BuiltinArguments object args. |
77 // TODO(cbruni): add global flag to check whether any tracing events have been | 77 // TODO(cbruni): add global flag to check whether any tracing events have been |
78 // enabled. | 78 // enabled. |
79 #define BUILTIN(name) \ | 79 // TODO(cbruni): Convert the IsContext CHECK back to a DCHECK. |
80 MUST_USE_RESULT static Object* Builtin_Impl_##name(BuiltinArguments args, \ | 80 #define BUILTIN(name) \ |
81 Isolate* isolate); \ | 81 MUST_USE_RESULT static Object* Builtin_Impl_##name(BuiltinArguments args, \ |
82 \ | 82 Isolate* isolate); \ |
83 V8_NOINLINE static Object* Builtin_Impl_Stats_##name( \ | 83 \ |
84 int args_length, Object** args_object, Isolate* isolate) { \ | 84 V8_NOINLINE static Object* Builtin_Impl_Stats_##name( \ |
85 BuiltinArguments args(args_length, args_object); \ | 85 int args_length, Object** args_object, Isolate* isolate) { \ |
86 RuntimeCallTimerScope timer(isolate, &RuntimeCallStats::Builtin_##name); \ | 86 BuiltinArguments args(args_length, args_object); \ |
87 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"), \ | 87 RuntimeCallTimerScope timer(isolate, &RuntimeCallStats::Builtin_##name); \ |
88 "V8.Builtin_" #name); \ | 88 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"), \ |
89 return Builtin_Impl_##name(args, isolate); \ | 89 "V8.Builtin_" #name); \ |
90 } \ | 90 return Builtin_Impl_##name(args, isolate); \ |
91 \ | 91 } \ |
92 MUST_USE_RESULT Object* Builtin_##name( \ | 92 \ |
93 int args_length, Object** args_object, Isolate* isolate) { \ | 93 MUST_USE_RESULT Object* Builtin_##name( \ |
94 DCHECK(isolate->context() == nullptr || isolate->context()->IsContext()); \ | 94 int args_length, Object** args_object, Isolate* isolate) { \ |
95 if (FLAG_runtime_call_stats) { \ | 95 CHECK(isolate->context() == nullptr || isolate->context()->IsContext()); \ |
96 return Builtin_Impl_Stats_##name(args_length, args_object, isolate); \ | 96 if (FLAG_runtime_call_stats) { \ |
97 } \ | 97 return Builtin_Impl_Stats_##name(args_length, args_object, isolate); \ |
98 BuiltinArguments args(args_length, args_object); \ | 98 } \ |
99 return Builtin_Impl_##name(args, isolate); \ | 99 BuiltinArguments args(args_length, args_object); \ |
100 } \ | 100 return Builtin_Impl_##name(args, isolate); \ |
101 \ | 101 } \ |
102 MUST_USE_RESULT static Object* Builtin_Impl_##name(BuiltinArguments args, \ | 102 \ |
| 103 MUST_USE_RESULT static Object* Builtin_Impl_##name(BuiltinArguments args, \ |
103 Isolate* isolate) | 104 Isolate* isolate) |
104 | 105 |
105 // ---------------------------------------------------------------------------- | 106 // ---------------------------------------------------------------------------- |
106 | 107 |
107 #define CHECK_RECEIVER(Type, name, method) \ | 108 #define CHECK_RECEIVER(Type, name, method) \ |
108 if (!args.receiver()->Is##Type()) { \ | 109 if (!args.receiver()->Is##Type()) { \ |
109 THROW_NEW_ERROR_RETURN_FAILURE( \ | 110 THROW_NEW_ERROR_RETURN_FAILURE( \ |
110 isolate, \ | 111 isolate, \ |
111 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \ | 112 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \ |
112 isolate->factory()->NewStringFromAsciiChecked(method), \ | 113 isolate->factory()->NewStringFromAsciiChecked(method), \ |
(...skipping 13 matching lines...) Expand all Loading... |
126 isolate->factory()->NewStringFromAsciiChecked(method))); \ | 127 isolate->factory()->NewStringFromAsciiChecked(method))); \ |
127 } \ | 128 } \ |
128 Handle<String> name; \ | 129 Handle<String> name; \ |
129 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ | 130 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ |
130 isolate, name, Object::ToString(isolate, args.receiver())) | 131 isolate, name, Object::ToString(isolate, args.receiver())) |
131 | 132 |
132 } // namespace internal | 133 } // namespace internal |
133 } // namespace v8 | 134 } // namespace v8 |
134 | 135 |
135 #endif // V8_BUILTINS_BUILTINS_UTILS_H_ | 136 #endif // V8_BUILTINS_BUILTINS_UTILS_H_ |
OLD | NEW |