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" |
11 #include "src/factory.h" | 11 #include "src/factory.h" |
12 #include "src/isolate.h" | 12 #include "src/isolate.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 namespace compiler { | |
18 class CodeAssemblerState; | |
19 } | |
20 | |
21 // Arguments object passed to C++ builtins. | 17 // Arguments object passed to C++ builtins. |
22 class BuiltinArguments : public Arguments { | 18 class BuiltinArguments : public Arguments { |
23 public: | 19 public: |
24 BuiltinArguments(int length, Object** arguments) | 20 BuiltinArguments(int length, Object** arguments) |
25 : Arguments(length, arguments) { | 21 : Arguments(length, arguments) { |
26 // Check we have at least the receiver. | 22 // Check we have at least the receiver. |
27 DCHECK_LE(1, this->length()); | 23 DCHECK_LE(1, this->length()); |
28 } | 24 } |
29 | 25 |
30 Object*& operator[](int index) { | 26 Object*& operator[](int index) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 return Builtin_Impl_Stats_##name(args_length, args_object, isolate); \ | 96 return Builtin_Impl_Stats_##name(args_length, args_object, isolate); \ |
101 } \ | 97 } \ |
102 BuiltinArguments args(args_length, args_object); \ | 98 BuiltinArguments args(args_length, args_object); \ |
103 return Builtin_Impl_##name(args, isolate); \ | 99 return Builtin_Impl_##name(args, isolate); \ |
104 } \ | 100 } \ |
105 \ | 101 \ |
106 MUST_USE_RESULT static Object* Builtin_Impl_##name(BuiltinArguments args, \ | 102 MUST_USE_RESULT static Object* Builtin_Impl_##name(BuiltinArguments args, \ |
107 Isolate* isolate) | 103 Isolate* isolate) |
108 | 104 |
109 // ---------------------------------------------------------------------------- | 105 // ---------------------------------------------------------------------------- |
110 // Support macro for defining builtins with Turbofan. | |
111 // ---------------------------------------------------------------------------- | |
112 // | |
113 // A builtin function is defined by writing: | |
114 // | |
115 // TF_BUILTIN(name, code_assember_base_class) { | |
116 // ... | |
117 // } | |
118 // | |
119 // In the body of the builtin function the arguments can be accessed | |
120 // as "Parameter(n)". | |
121 #define TF_BUILTIN(Name, AssemblerBase) \ | |
122 class Name##Assembler : public AssemblerBase { \ | |
123 public: \ | |
124 explicit Name##Assembler(compiler::CodeAssemblerState* state) \ | |
125 : AssemblerBase(state) {} \ | |
126 void Generate##Name##Impl(); \ | |
127 }; \ | |
128 void Builtins::Generate_##Name(compiler::CodeAssemblerState* state) { \ | |
129 Name##Assembler assembler(state); \ | |
130 assembler.Generate##Name##Impl(); \ | |
131 } \ | |
132 void Name##Assembler::Generate##Name##Impl() | |
133 | |
134 // ---------------------------------------------------------------------------- | |
135 | 106 |
136 #define CHECK_RECEIVER(Type, name, method) \ | 107 #define CHECK_RECEIVER(Type, name, method) \ |
137 if (!args.receiver()->Is##Type()) { \ | 108 if (!args.receiver()->Is##Type()) { \ |
138 THROW_NEW_ERROR_RETURN_FAILURE( \ | 109 THROW_NEW_ERROR_RETURN_FAILURE( \ |
139 isolate, \ | 110 isolate, \ |
140 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \ | 111 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \ |
141 isolate->factory()->NewStringFromAsciiChecked(method), \ | 112 isolate->factory()->NewStringFromAsciiChecked(method), \ |
142 args.receiver())); \ | 113 args.receiver())); \ |
143 } \ | 114 } \ |
144 Handle<Type> name = Handle<Type>::cast(args.receiver()) | 115 Handle<Type> name = Handle<Type>::cast(args.receiver()) |
145 | 116 |
146 // Throws a TypeError for {method} if the receiver is not coercible to Object, | 117 // Throws a TypeError for {method} if the receiver is not coercible to Object, |
147 // or converts the receiver to a String otherwise and assigns it to a new var | 118 // or converts the receiver to a String otherwise and assigns it to a new var |
148 // with the given {name}. | 119 // with the given {name}. |
149 #define TO_THIS_STRING(name, method) \ | 120 #define TO_THIS_STRING(name, method) \ |
150 if (args.receiver()->IsNullOrUndefined(isolate)) { \ | 121 if (args.receiver()->IsNullOrUndefined(isolate)) { \ |
151 THROW_NEW_ERROR_RETURN_FAILURE( \ | 122 THROW_NEW_ERROR_RETURN_FAILURE( \ |
152 isolate, \ | 123 isolate, \ |
153 NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, \ | 124 NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, \ |
154 isolate->factory()->NewStringFromAsciiChecked(method))); \ | 125 isolate->factory()->NewStringFromAsciiChecked(method))); \ |
155 } \ | 126 } \ |
156 Handle<String> name; \ | 127 Handle<String> name; \ |
157 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ | 128 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ |
158 isolate, name, Object::ToString(isolate, args.receiver())) | 129 isolate, name, Object::ToString(isolate, args.receiver())) |
159 | 130 |
160 } // namespace internal | 131 } // namespace internal |
161 } // namespace v8 | 132 } // namespace v8 |
162 | 133 |
163 #endif // V8_BUILTINS_BUILTINS_UTILS_H_ | 134 #endif // V8_BUILTINS_BUILTINS_UTILS_H_ |
OLD | NEW |