| 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 #ifdef DEBUG | |
| 15 | |
| 16 #define RUNTIME_ASSERT(value) \ | |
| 17 do { \ | |
| 18 if (!(value)) { \ | |
| 19 V8_RuntimeError(__FILE__, __LINE__, #value); \ | |
| 20 return isolate->ThrowIllegalOperation(); \ | |
| 21 } \ | |
| 22 } while (0) | |
| 23 | |
| 24 #else | |
| 25 | |
| 26 #define RUNTIME_ASSERT(value) \ | |
| 27 do { \ | |
| 28 if (!(value)) { \ | |
| 29 return isolate->ThrowIllegalOperation(); \ | |
| 30 } \ | |
| 31 } while (0) | |
| 32 | |
| 33 #endif | |
| 34 | |
| 35 // 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 |
| 36 // 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 |
| 37 // expected type call IllegalOperation and return. | 16 // expected type we crash safely. |
| 38 #define CONVERT_ARG_CHECKED(Type, name, index) \ | 17 #define CONVERT_ARG_CHECKED(Type, name, index) \ |
| 39 RUNTIME_ASSERT(args[index]->Is##Type()); \ | 18 CHECK(args[index]->Is##Type()); \ |
| 40 Type* name = Type::cast(args[index]); | 19 Type* name = Type::cast(args[index]); |
| 41 | 20 |
| 42 #define CONVERT_ARG_HANDLE_CHECKED(Type, name, index) \ | 21 #define CONVERT_ARG_HANDLE_CHECKED(Type, name, index) \ |
| 43 RUNTIME_ASSERT(args[index]->Is##Type()); \ | 22 CHECK(args[index]->Is##Type()); \ |
| 44 Handle<Type> name = args.at<Type>(index); | 23 Handle<Type> name = args.at<Type>(index); |
| 45 | 24 |
| 46 #define CONVERT_NUMBER_ARG_HANDLE_CHECKED(name, index) \ | 25 #define CONVERT_NUMBER_ARG_HANDLE_CHECKED(name, index) \ |
| 47 RUNTIME_ASSERT(args[index]->IsNumber()); \ | 26 CHECK(args[index]->IsNumber()); \ |
| 48 Handle<Object> name = args.at<Object>(index); | 27 Handle<Object> name = args.at<Object>(index); |
| 49 | 28 |
| 50 // 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 |
| 51 // the given name. If the object is not a boolean call IllegalOperation | 30 // the given name. If the object is not a boolean we crash safely. |
| 52 // and return. | |
| 53 #define CONVERT_BOOLEAN_ARG_CHECKED(name, index) \ | 31 #define CONVERT_BOOLEAN_ARG_CHECKED(name, index) \ |
| 54 RUNTIME_ASSERT(args[index]->IsBoolean()); \ | 32 CHECK(args[index]->IsBoolean()); \ |
| 55 bool name = args[index]->IsTrue(isolate); | 33 bool name = args[index]->IsTrue(isolate); |
| 56 | 34 |
| 57 // 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 |
| 58 // with the given name. If the argument is not a Smi call IllegalOperation | 36 // with the given name. If the argument is not a Smi we crash safely. |
| 59 // and return. | |
| 60 #define CONVERT_SMI_ARG_CHECKED(name, index) \ | 37 #define CONVERT_SMI_ARG_CHECKED(name, index) \ |
| 61 RUNTIME_ASSERT(args[index]->IsSmi()); \ | 38 CHECK(args[index]->IsSmi()); \ |
| 62 int name = args.smi_at(index); | 39 int name = args.smi_at(index); |
| 63 | 40 |
| 64 // 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 |
| 65 // 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 |
| 66 // the number not-a-number) call IllegalOperation and return. | 43 // the number not-a-number) we crash safely. |
| 67 #define CONVERT_DOUBLE_ARG_CHECKED(name, index) \ | 44 #define CONVERT_DOUBLE_ARG_CHECKED(name, index) \ |
| 68 RUNTIME_ASSERT(args[index]->IsNumber()); \ | 45 CHECK(args[index]->IsNumber()); \ |
| 69 double name = args.number_at(index); | 46 double name = args.number_at(index); |
| 70 | 47 |
| 71 | |
| 72 // 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 |
| 73 // the given name. If the argument is not a size_t call IllegalOperation and | 49 // the given name. If the argument is not a size_t we crash safely. |
| 74 // return. | |
| 75 #define CONVERT_SIZE_ARG_CHECKED(name, index) \ | 50 #define CONVERT_SIZE_ARG_CHECKED(name, index) \ |
| 76 RUNTIME_ASSERT(args[index]->IsNumber()); \ | 51 CHECK(args[index]->IsNumber()); \ |
| 77 Handle<Object> name##_object = args.at<Object>(index); \ | 52 Handle<Object> name##_object = args.at<Object>(index); \ |
| 78 size_t name = 0; \ | 53 size_t name = 0; \ |
| 79 RUNTIME_ASSERT(TryNumberToSize(isolate, *name##_object, &name)); | 54 CHECK(TryNumberToSize(isolate, *name##_object, &name)); |
| 80 | |
| 81 | 55 |
| 82 // 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 |
| 83 // 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 |
| 84 // object is not a Number call IllegalOperation and return. | 58 // object is not a Number we crash safely. |
| 85 #define CONVERT_NUMBER_CHECKED(type, name, Type, obj) \ | 59 #define CONVERT_NUMBER_CHECKED(type, name, Type, obj) \ |
| 86 RUNTIME_ASSERT(obj->IsNumber()); \ | 60 CHECK(obj->IsNumber()); \ |
| 87 type name = NumberTo##Type(obj); | 61 type name = NumberTo##Type(obj); |
| 88 | 62 |
| 89 | |
| 90 // 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 |
| 91 // variable with the given name. If the argument is not a Smi call | 64 // variable with the given name. If the argument is not a Smi we crash safely. |
| 92 // IllegalOperation and return. | |
| 93 #define CONVERT_PROPERTY_DETAILS_CHECKED(name, index) \ | 65 #define CONVERT_PROPERTY_DETAILS_CHECKED(name, index) \ |
| 94 RUNTIME_ASSERT(args[index]->IsSmi()); \ | 66 CHECK(args[index]->IsSmi()); \ |
| 95 PropertyDetails name = PropertyDetails(Smi::cast(args[index])); | 67 PropertyDetails name = PropertyDetails(Smi::cast(args[index])); |
| 96 | 68 |
| 97 | |
| 98 // Assert that the given argument has a valid value for a LanguageMode | 69 // Assert that the given argument has a valid value for a LanguageMode |
| 99 // and store it in a LanguageMode variable with the given name. | 70 // and store it in a LanguageMode variable with the given name. |
| 100 #define CONVERT_LANGUAGE_MODE_ARG_CHECKED(name, index) \ | 71 #define CONVERT_LANGUAGE_MODE_ARG_CHECKED(name, index) \ |
| 101 RUNTIME_ASSERT(args[index]->IsSmi()); \ | 72 CHECK(args[index]->IsSmi()); \ |
| 102 RUNTIME_ASSERT(is_valid_language_mode(args.smi_at(index))); \ | 73 CHECK(is_valid_language_mode(args.smi_at(index))); \ |
| 103 LanguageMode name = static_cast<LanguageMode>(args.smi_at(index)); | 74 LanguageMode name = static_cast<LanguageMode>(args.smi_at(index)); |
| 104 | 75 |
| 105 | |
| 106 // Assert that the given argument is a number within the Int32 range | 76 // Assert that the given argument is a number within the Int32 range |
| 107 // and convert it to int32_t. If the argument is not an Int32 call | 77 // and convert it to int32_t. If the argument is not an Int32 we crash safely. |
| 108 // IllegalOperation and return. | |
| 109 #define CONVERT_INT32_ARG_CHECKED(name, index) \ | 78 #define CONVERT_INT32_ARG_CHECKED(name, index) \ |
| 110 RUNTIME_ASSERT(args[index]->IsNumber()); \ | 79 CHECK(args[index]->IsNumber()); \ |
| 111 int32_t name = 0; \ | 80 int32_t name = 0; \ |
| 112 RUNTIME_ASSERT(args[index]->ToInt32(&name)); | 81 CHECK(args[index]->ToInt32(&name)); |
| 113 | |
| 114 | 82 |
| 115 // Cast the given argument to PropertyAttributes and store its value in a | 83 // Cast the given argument to PropertyAttributes and store its value in a |
| 116 // variable with the given name. If the argument is not a Smi call or the | 84 // variable with the given name. If the argument is not a Smi or the |
| 117 // enum value is out of range, call IllegalOperation and return. | 85 // enum value is out of range, we crash safely. |
| 118 #define CONVERT_PROPERTY_ATTRIBUTES_CHECKED(name, index) \ | 86 #define CONVERT_PROPERTY_ATTRIBUTES_CHECKED(name, index) \ |
| 119 RUNTIME_ASSERT(args[index]->IsSmi()); \ | 87 CHECK(args[index]->IsSmi()); \ |
| 120 RUNTIME_ASSERT( \ | 88 CHECK((args.smi_at(index) & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); \ |
| 121 (args.smi_at(index) & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); \ | |
| 122 PropertyAttributes name = static_cast<PropertyAttributes>(args.smi_at(index)); | 89 PropertyAttributes name = static_cast<PropertyAttributes>(args.smi_at(index)); |
| 123 | 90 |
| 124 | |
| 125 // A mechanism to return a pair of Object pointers in registers (if possible). | 91 // A mechanism to return a pair of Object pointers in registers (if possible). |
| 126 // How this is achieved is calling convention-dependent. | 92 // How this is achieved is calling convention-dependent. |
| 127 // All currently supported x86 compiles uses calling conventions that are cdecl | 93 // All currently supported x86 compiles uses calling conventions that are cdecl |
| 128 // variants where a 64-bit value is returned in two 32-bit registers | 94 // variants where a 64-bit value is returned in two 32-bit registers |
| 129 // (edx:eax on ia32, r1:r0 on ARM). | 95 // (edx:eax on ia32, r1:r0 on ARM). |
| 130 // In AMD-64 calling convention a struct of two pointers is returned in rdx:rax. | 96 // In AMD-64 calling convention a struct of two pointers is returned in rdx:rax. |
| 131 // In Win64 calling convention, a struct of two pointers is returned in memory, | 97 // In Win64 calling convention, a struct of two pointers is returned in memory, |
| 132 // allocated by the caller, and passed as a pointer in a hidden first parameter. | 98 // allocated by the caller, and passed as a pointer in a hidden first parameter. |
| 133 #ifdef V8_HOST_ARCH_64_BIT | 99 #ifdef V8_HOST_ARCH_64_BIT |
| 134 struct ObjectPair { | 100 struct ObjectPair { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 static inline ObjectTriple MakeTriple(Object* x, Object* y, Object* z) { | 154 static inline ObjectTriple MakeTriple(Object* x, Object* y, Object* z) { |
| 189 ObjectTriple result = {x, y, z}; | 155 ObjectTriple result = {x, y, z}; |
| 190 // ObjectTriple is assigned to a hidden first argument. | 156 // ObjectTriple is assigned to a hidden first argument. |
| 191 return result; | 157 return result; |
| 192 } | 158 } |
| 193 | 159 |
| 194 } // namespace internal | 160 } // namespace internal |
| 195 } // namespace v8 | 161 } // namespace v8 |
| 196 | 162 |
| 197 #endif // V8_RUNTIME_RUNTIME_UTILS_H_ | 163 #endif // V8_RUNTIME_RUNTIME_UTILS_H_ |
| OLD | NEW |