OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_RUNTIME_RUNTIME_UTILS_H_ | 5 #ifndef V8_RUNTIME_RUNTIME_UTILS_H_ |
6 #define V8_RUNTIME_RUNTIME_UTILS_H_ | 6 #define V8_RUNTIME_RUNTIME_UTILS_H_ |
7 | 7 |
8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
9 #include "src/runtime/runtime.h" | 9 #include "src/runtime/runtime.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 // Cast the given object to a value of the specified type and store | 14 // Cast the given object to a value of the specified type and store |
15 // it in a variable with the given name. If the object is not of the | 15 // it in a variable with the given name. If the object is not of the |
16 // expected type we crash safely. | 16 // expected type we crash safely. |
17 #define CONVERT_ARG_CHECKED(Type, name, index) \ | 17 #define CONVERT_ARG_CHECKED(Type, name, index) \ |
18 CHECK(args[index]->Is##Type()); \ | 18 CHECK(args[index]->Is##Type()); \ |
19 Type* name = Type::cast(args[index]); | 19 Type* name = Type::cast(args[index]); |
20 | 20 |
21 #define CONVERT_ARG_HANDLE_CHECKED(Type, name, index) \ | 21 #define CONVERT_ARG_HANDLE_CHECKED(Type, name, index) \ |
22 CHECK(args[index]->Is##Type()); \ | 22 CHECK(args[index]->Is##Type()); \ |
23 Handle<Type> name = args.at<Type>(index); | 23 Handle<Type> name = args.at<Type>(index); |
24 | 24 |
25 #define CONVERT_NUMBER_ARG_HANDLE_CHECKED(name, index) \ | 25 #define CONVERT_NUMBER_ARG_HANDLE_CHECKED(name, index) \ |
26 CHECK(args[index]->IsNumber()); \ | 26 CHECK(args[index]->IsNumber()); \ |
27 Handle<Object> name = args.at<Object>(index); | 27 Handle<Object> name = args.at(index); |
28 | 28 |
29 // Cast the given object to a boolean and store it in a variable with | 29 // Cast the given object to a boolean and store it in a variable with |
30 // the given name. If the object is not a boolean we crash safely. | 30 // the given name. If the object is not a boolean we crash safely. |
31 #define CONVERT_BOOLEAN_ARG_CHECKED(name, index) \ | 31 #define CONVERT_BOOLEAN_ARG_CHECKED(name, index) \ |
32 CHECK(args[index]->IsBoolean()); \ | 32 CHECK(args[index]->IsBoolean()); \ |
33 bool name = args[index]->IsTrue(isolate); | 33 bool name = args[index]->IsTrue(isolate); |
34 | 34 |
35 // Cast the given argument to a Smi and store its value in an int variable | 35 // Cast the given argument to a Smi and store its value in an int variable |
36 // with the given name. If the argument is not a Smi we crash safely. | 36 // with the given name. If the argument is not a Smi we crash safely. |
37 #define CONVERT_SMI_ARG_CHECKED(name, index) \ | 37 #define CONVERT_SMI_ARG_CHECKED(name, index) \ |
38 CHECK(args[index]->IsSmi()); \ | 38 CHECK(args[index]->IsSmi()); \ |
39 int name = args.smi_at(index); | 39 int name = args.smi_at(index); |
40 | 40 |
41 // Cast the given argument to a double and store it in a variable with | 41 // Cast the given argument to a double and store it in a variable with |
42 // the given name. If the argument is not a number (as opposed to | 42 // the given name. If the argument is not a number (as opposed to |
43 // the number not-a-number) we crash safely. | 43 // the number not-a-number) we crash safely. |
44 #define CONVERT_DOUBLE_ARG_CHECKED(name, index) \ | 44 #define CONVERT_DOUBLE_ARG_CHECKED(name, index) \ |
45 CHECK(args[index]->IsNumber()); \ | 45 CHECK(args[index]->IsNumber()); \ |
46 double name = args.number_at(index); | 46 double name = args.number_at(index); |
47 | 47 |
48 // Cast the given argument to a size_t and store its value in a variable with | 48 // Cast the given argument to a size_t and store its value in a variable with |
49 // the given name. If the argument is not a size_t we crash safely. | 49 // the given name. If the argument is not a size_t we crash safely. |
50 #define CONVERT_SIZE_ARG_CHECKED(name, index) \ | 50 #define CONVERT_SIZE_ARG_CHECKED(name, index) \ |
51 CHECK(args[index]->IsNumber()); \ | 51 CHECK(args[index]->IsNumber()); \ |
52 Handle<Object> name##_object = args.at<Object>(index); \ | 52 Handle<Object> name##_object = args.at(index); \ |
53 size_t name = 0; \ | 53 size_t name = 0; \ |
54 CHECK(TryNumberToSize(*name##_object, &name)); | 54 CHECK(TryNumberToSize(*name##_object, &name)); |
55 | 55 |
56 // Call the specified converter on the object *comand store the result in | 56 // Call the specified converter on the object *comand store the result in |
57 // a variable of the specified type with the given name. If the | 57 // a variable of the specified type with the given name. If the |
58 // object is not a Number we crash safely. | 58 // object is not a Number we crash safely. |
59 #define CONVERT_NUMBER_CHECKED(type, name, Type, obj) \ | 59 #define CONVERT_NUMBER_CHECKED(type, name, Type, obj) \ |
60 CHECK(obj->IsNumber()); \ | 60 CHECK(obj->IsNumber()); \ |
61 type name = NumberTo##Type(obj); | 61 type name = NumberTo##Type(obj); |
62 | 62 |
63 // Cast the given argument to PropertyDetails and store its value in a | 63 // Cast the given argument to PropertyDetails and store its value in a |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 static inline ObjectTriple MakeTriple(Object* x, Object* y, Object* z) { | 164 static inline ObjectTriple MakeTriple(Object* x, Object* y, Object* z) { |
165 ObjectTriple result = {x, y, z}; | 165 ObjectTriple result = {x, y, z}; |
166 // ObjectTriple is assigned to a hidden first argument. | 166 // ObjectTriple is assigned to a hidden first argument. |
167 return result; | 167 return result; |
168 } | 168 } |
169 | 169 |
170 } // namespace internal | 170 } // namespace internal |
171 } // namespace v8 | 171 } // namespace v8 |
172 | 172 |
173 #endif // V8_RUNTIME_RUNTIME_UTILS_H_ | 173 #endif // V8_RUNTIME_RUNTIME_UTILS_H_ |
OLD | NEW |