| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 int length() const { return length_; } | 76 int length() const { return length_; } |
| 77 | 77 |
| 78 Object** arguments() { return arguments_; } | 78 Object** arguments() { return arguments_; } |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 int length_; | 81 int length_; |
| 82 Object** arguments_; | 82 Object** arguments_; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 | 85 |
| 86 // mappings from old property callbacks to new ones | 86 // For each type of callback, we have a list of arguments |
| 87 // F(old name, new name, return value, parameters...) | 87 // They are used to generate the Call() functions below |
| 88 // | |
| 89 // These aren't included in the list as they have duplicate signatures | 88 // These aren't included in the list as they have duplicate signatures |
| 90 // F(NamedPropertyEnumerator, NamedPropertyEnumeratorCallback, ...) | 89 // F(NamedPropertyEnumeratorCallback, ...) |
| 91 // F(NamedPropertyGetter, NamedPropertyGetterCallback, ...) | 90 // F(NamedPropertyGetterCallback, ...) |
| 92 | 91 |
| 93 #define FOR_EACH_CALLBACK_TABLE_MAPPING_0(F) \ | 92 #define FOR_EACH_CALLBACK_TABLE_MAPPING_0(F) \ |
| 94 F(IndexedPropertyEnumerator, IndexedPropertyEnumeratorCallback, v8::Array) \ | 93 F(IndexedPropertyEnumeratorCallback, v8::Array) \ |
| 95 | 94 |
| 96 #define FOR_EACH_CALLBACK_TABLE_MAPPING_1(F) \ | 95 #define FOR_EACH_CALLBACK_TABLE_MAPPING_1(F) \ |
| 97 F(AccessorGetter, AccessorGetterCallback, v8::Value, v8::Local<v8::String>) \ | 96 F(AccessorGetterCallback, v8::Value, v8::Local<v8::String>) \ |
| 98 F(NamedPropertyQuery, \ | 97 F(NamedPropertyQueryCallback, \ |
| 99 NamedPropertyQueryCallback, \ | |
| 100 v8::Integer, \ | 98 v8::Integer, \ |
| 101 v8::Local<v8::String>) \ | 99 v8::Local<v8::String>) \ |
| 102 F(NamedPropertyDeleter, \ | 100 F(NamedPropertyDeleterCallback, \ |
| 103 NamedPropertyDeleterCallback, \ | |
| 104 v8::Boolean, \ | 101 v8::Boolean, \ |
| 105 v8::Local<v8::String>) \ | 102 v8::Local<v8::String>) \ |
| 106 F(IndexedPropertyGetter, \ | 103 F(IndexedPropertyGetterCallback, \ |
| 107 IndexedPropertyGetterCallback, \ | |
| 108 v8::Value, \ | 104 v8::Value, \ |
| 109 uint32_t) \ | 105 uint32_t) \ |
| 110 F(IndexedPropertyQuery, \ | 106 F(IndexedPropertyQueryCallback, \ |
| 111 IndexedPropertyQueryCallback, \ | |
| 112 v8::Integer, \ | 107 v8::Integer, \ |
| 113 uint32_t) \ | 108 uint32_t) \ |
| 114 F(IndexedPropertyDeleter, \ | 109 F(IndexedPropertyDeleterCallback, \ |
| 115 IndexedPropertyDeleterCallback, \ | |
| 116 v8::Boolean, \ | 110 v8::Boolean, \ |
| 117 uint32_t) \ | 111 uint32_t) \ |
| 118 | 112 |
| 119 #define FOR_EACH_CALLBACK_TABLE_MAPPING_2(F) \ | 113 #define FOR_EACH_CALLBACK_TABLE_MAPPING_2(F) \ |
| 120 F(NamedPropertySetter, \ | 114 F(NamedPropertySetterCallback, \ |
| 121 NamedPropertySetterCallback, \ | |
| 122 v8::Value, \ | 115 v8::Value, \ |
| 123 v8::Local<v8::String>, \ | 116 v8::Local<v8::String>, \ |
| 124 v8::Local<v8::Value>) \ | 117 v8::Local<v8::Value>) \ |
| 125 F(IndexedPropertySetter, \ | 118 F(IndexedPropertySetterCallback, \ |
| 126 IndexedPropertySetterCallback, \ | |
| 127 v8::Value, \ | 119 v8::Value, \ |
| 128 uint32_t, \ | 120 uint32_t, \ |
| 129 v8::Local<v8::Value>) \ | 121 v8::Local<v8::Value>) \ |
| 130 | 122 |
| 131 #define FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(F) \ | 123 #define FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(F) \ |
| 132 F(AccessorSetter, \ | 124 F(AccessorSetterCallback, \ |
| 133 AccessorSetterCallback, \ | |
| 134 void, \ | 125 void, \ |
| 135 v8::Local<v8::String>, \ | 126 v8::Local<v8::String>, \ |
| 136 v8::Local<v8::Value>) \ | 127 v8::Local<v8::Value>) \ |
| 137 | 128 |
| 138 // All property callbacks as well as invocation callbacks | |
| 139 #define FOR_EACH_CALLBACK_TABLE_MAPPING(F) \ | |
| 140 F(InvocationCallback, FunctionCallback) \ | |
| 141 F(AccessorGetter, AccessorGetterCallback) \ | |
| 142 F(AccessorSetter, AccessorSetterCallback) \ | |
| 143 F(NamedPropertySetter, NamedPropertySetterCallback) \ | |
| 144 F(NamedPropertyQuery, NamedPropertyQueryCallback) \ | |
| 145 F(NamedPropertyDeleter, NamedPropertyDeleterCallback) \ | |
| 146 F(IndexedPropertyGetter, IndexedPropertyGetterCallback) \ | |
| 147 F(IndexedPropertySetter, IndexedPropertySetterCallback) \ | |
| 148 F(IndexedPropertyQuery, IndexedPropertyQueryCallback) \ | |
| 149 F(IndexedPropertyDeleter, IndexedPropertyDeleterCallback) \ | |
| 150 F(IndexedPropertyEnumerator, IndexedPropertyEnumeratorCallback) \ | |
| 151 | |
| 152 | |
| 153 // TODO(dcarney): Remove this class when old callbacks are gone. | |
| 154 class CallbackTable { | |
| 155 public: | |
| 156 static const bool kStoreVoidFunctions = false; | |
| 157 static inline bool ReturnsVoid(Isolate* isolate, void* function) { | |
| 158 CallbackTable* table = isolate->callback_table(); | |
| 159 bool contains = | |
| 160 table != NULL && | |
| 161 table->map_.occupancy() != 0 && | |
| 162 table->Contains(function); | |
| 163 return contains == kStoreVoidFunctions; | |
| 164 } | |
| 165 | |
| 166 STATIC_ASSERT(sizeof(intptr_t) == sizeof(AccessorGetterCallback)); | |
| 167 | |
| 168 template<typename F> | |
| 169 static inline void* FunctionToVoidPtr(F function) { | |
| 170 return reinterpret_cast<void*>(reinterpret_cast<intptr_t>(function)); | |
| 171 } | |
| 172 | |
| 173 #define WRITE_REGISTER(OldFunction, NewFunction) \ | |
| 174 static NewFunction Register(Isolate* isolate, OldFunction f) { \ | |
| 175 InsertCallback(isolate, FunctionToVoidPtr(f), false); \ | |
| 176 return reinterpret_cast<NewFunction>(f); \ | |
| 177 } \ | |
| 178 \ | |
| 179 static NewFunction Register(Isolate* isolate, NewFunction f) { \ | |
| 180 InsertCallback(isolate, FunctionToVoidPtr(f), true); \ | |
| 181 return f; \ | |
| 182 } | |
| 183 FOR_EACH_CALLBACK_TABLE_MAPPING(WRITE_REGISTER) | |
| 184 #undef WRITE_REGISTER | |
| 185 | |
| 186 private: | |
| 187 CallbackTable(); | |
| 188 bool Contains(void* function); | |
| 189 static void InsertCallback(Isolate* isolate, | |
| 190 void* function, | |
| 191 bool returns_void); | |
| 192 HashMap map_; | |
| 193 DISALLOW_COPY_AND_ASSIGN(CallbackTable); | |
| 194 }; | |
| 195 | |
| 196 | 129 |
| 197 // Custom arguments replicate a small segment of stack that can be | 130 // Custom arguments replicate a small segment of stack that can be |
| 198 // accessed through an Arguments object the same way the actual stack | 131 // accessed through an Arguments object the same way the actual stack |
| 199 // can. | 132 // can. |
| 200 template<int kArrayLength> | 133 template<int kArrayLength> |
| 201 class CustomArgumentsBase : public Relocatable { | 134 class CustomArgumentsBase : public Relocatable { |
| 202 public: | 135 public: |
| 203 virtual inline void IterateInstance(ObjectVisitor* v) { | 136 virtual inline void IterateInstance(ObjectVisitor* v) { |
| 204 v->VisitPointers(values_, values_ + kArrayLength); | 137 v->VisitPointers(values_, values_ + kArrayLength); |
| 205 } | 138 } |
| 206 protected: | 139 protected: |
| 207 inline Object** end() { return values_ + kArrayLength - 1; } | 140 inline Object** end() { return values_ + kArrayLength - 1; } |
| 208 explicit inline CustomArgumentsBase(Isolate* isolate) | 141 explicit inline CustomArgumentsBase(Isolate* isolate) |
| 209 : Relocatable(isolate) {} | 142 : Relocatable(isolate) {} |
| 210 Object* values_[kArrayLength]; | 143 Object* values_[kArrayLength]; |
| 211 }; | 144 }; |
| 212 | 145 |
| 213 | 146 |
| 214 template<typename T> | 147 template<typename T> |
| 215 class CustomArguments : public CustomArgumentsBase<T::kArgsLength> { | 148 class CustomArguments : public CustomArgumentsBase<T::kArgsLength> { |
| 216 public: | 149 public: |
| 217 static const int kReturnValueOffset = T::kReturnValueIndex; | 150 static const int kReturnValueOffset = T::kReturnValueIndex; |
| 218 | 151 |
| 219 typedef CustomArgumentsBase<T::kArgsLength> Super; | 152 typedef CustomArgumentsBase<T::kArgsLength> Super; |
| 220 ~CustomArguments() { | 153 ~CustomArguments() { |
| 221 // TODO(dcarney): create a new zap value for this. | |
| 222 this->end()[kReturnValueOffset] = | 154 this->end()[kReturnValueOffset] = |
| 223 reinterpret_cast<Object*>(kHandleZapValue); | 155 reinterpret_cast<Object*>(kHandleZapValue); |
| 224 } | 156 } |
| 225 | 157 |
| 226 protected: | 158 protected: |
| 227 explicit inline CustomArguments(Isolate* isolate) : Super(isolate) {} | 159 explicit inline CustomArguments(Isolate* isolate) : Super(isolate) {} |
| 228 | 160 |
| 229 template<typename V> | 161 template<typename V> |
| 230 v8::Handle<V> GetReturnValue(Isolate* isolate); | 162 v8::Handle<V> GetReturnValue(Isolate* isolate); |
| 231 | 163 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 196 } |
| 265 | 197 |
| 266 /* | 198 /* |
| 267 * The following Call functions wrap the calling of all callbacks to handle | 199 * The following Call functions wrap the calling of all callbacks to handle |
| 268 * calling either the old or the new style callbacks depending on which one | 200 * calling either the old or the new style callbacks depending on which one |
| 269 * has been registered. | 201 * has been registered. |
| 270 * For old callbacks which return an empty handle, the ReturnValue is checked | 202 * For old callbacks which return an empty handle, the ReturnValue is checked |
| 271 * and used if it's been set to anything inside the callback. | 203 * and used if it's been set to anything inside the callback. |
| 272 * New style callbacks always use the return value. | 204 * New style callbacks always use the return value. |
| 273 */ | 205 */ |
| 274 #define WRITE_CALL_0(OldFunction, NewFunction, ReturnValue) \ | 206 #define WRITE_CALL_0(Function, ReturnValue) \ |
| 275 v8::Handle<ReturnValue> Call(OldFunction f); \ | 207 v8::Handle<ReturnValue> Call(Function f); \ |
| 276 | 208 |
| 277 #define WRITE_CALL_1(OldFunction, NewFunction, ReturnValue, Arg1) \ | 209 #define WRITE_CALL_1(Function, ReturnValue, Arg1) \ |
| 278 v8::Handle<ReturnValue> Call(OldFunction f, Arg1 arg1); \ | 210 v8::Handle<ReturnValue> Call(Function f, Arg1 arg1); \ |
| 279 | 211 |
| 280 #define WRITE_CALL_2(OldFunction, NewFunction, ReturnValue, Arg1, Arg2) \ | 212 #define WRITE_CALL_2(Function, ReturnValue, Arg1, Arg2) \ |
| 281 v8::Handle<ReturnValue> Call(OldFunction f, Arg1 arg1, Arg2 arg2); \ | 213 v8::Handle<ReturnValue> Call(Function f, Arg1 arg1, Arg2 arg2); \ |
| 282 | 214 |
| 283 #define WRITE_CALL_2_VOID(OldFunction, NewFunction, ReturnValue, Arg1, Arg2) \ | 215 #define WRITE_CALL_2_VOID(Function, ReturnValue, Arg1, Arg2) \ |
| 284 void Call(OldFunction f, Arg1 arg1, Arg2 arg2); \ | 216 void Call(Function f, Arg1 arg1, Arg2 arg2); \ |
| 285 | 217 |
| 286 FOR_EACH_CALLBACK_TABLE_MAPPING_0(WRITE_CALL_0) | 218 FOR_EACH_CALLBACK_TABLE_MAPPING_0(WRITE_CALL_0) |
| 287 FOR_EACH_CALLBACK_TABLE_MAPPING_1(WRITE_CALL_1) | 219 FOR_EACH_CALLBACK_TABLE_MAPPING_1(WRITE_CALL_1) |
| 288 FOR_EACH_CALLBACK_TABLE_MAPPING_2(WRITE_CALL_2) | 220 FOR_EACH_CALLBACK_TABLE_MAPPING_2(WRITE_CALL_2) |
| 289 FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(WRITE_CALL_2_VOID) | 221 FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(WRITE_CALL_2_VOID) |
| 290 | 222 |
| 291 #undef WRITE_CALL_0 | 223 #undef WRITE_CALL_0 |
| 292 #undef WRITE_CALL_1 | 224 #undef WRITE_CALL_1 |
| 293 #undef WRITE_CALL_2 | 225 #undef WRITE_CALL_2 |
| 294 #undef WRITE_CALL_2_VOID | 226 #undef WRITE_CALL_2_VOID |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 } | 261 } |
| 330 | 262 |
| 331 /* | 263 /* |
| 332 * The following Call function wraps the calling of all callbacks to handle | 264 * The following Call function wraps the calling of all callbacks to handle |
| 333 * calling either the old or the new style callbacks depending on which one | 265 * calling either the old or the new style callbacks depending on which one |
| 334 * has been registered. | 266 * has been registered. |
| 335 * For old callbacks which return an empty handle, the ReturnValue is checked | 267 * For old callbacks which return an empty handle, the ReturnValue is checked |
| 336 * and used if it's been set to anything inside the callback. | 268 * and used if it's been set to anything inside the callback. |
| 337 * New style callbacks always use the return value. | 269 * New style callbacks always use the return value. |
| 338 */ | 270 */ |
| 339 v8::Handle<v8::Value> Call(InvocationCallback f); | 271 v8::Handle<v8::Value> Call(FunctionCallback f); |
| 340 | 272 |
| 341 private: | 273 private: |
| 342 internal::Object** argv_; | 274 internal::Object** argv_; |
| 343 int argc_; | 275 int argc_; |
| 344 bool is_construct_call_; | 276 bool is_construct_call_; |
| 345 }; | 277 }; |
| 346 | 278 |
| 347 | 279 |
| 348 #define DECLARE_RUNTIME_FUNCTION(Type, Name) \ | 280 #define DECLARE_RUNTIME_FUNCTION(Type, Name) \ |
| 349 Type Name(int args_length, Object** args_object, Isolate* isolate) | 281 Type Name(int args_length, Object** args_object, Isolate* isolate) |
| 350 | 282 |
| 351 #define RUNTIME_FUNCTION(Type, Name) \ | 283 #define RUNTIME_FUNCTION(Type, Name) \ |
| 352 static Type __RT_impl_##Name(Arguments args, Isolate* isolate); \ | 284 static Type __RT_impl_##Name(Arguments args, Isolate* isolate); \ |
| 353 Type Name(int args_length, Object** args_object, Isolate* isolate) { \ | 285 Type Name(int args_length, Object** args_object, Isolate* isolate) { \ |
| 354 Arguments args(args_length, args_object); \ | 286 Arguments args(args_length, args_object); \ |
| 355 return __RT_impl_##Name(args, isolate); \ | 287 return __RT_impl_##Name(args, isolate); \ |
| 356 } \ | 288 } \ |
| 357 static Type __RT_impl_##Name(Arguments args, Isolate* isolate) | 289 static Type __RT_impl_##Name(Arguments args, Isolate* isolate) |
| 358 | 290 |
| 359 #define RUNTIME_ARGUMENTS(isolate, args) \ | 291 #define RUNTIME_ARGUMENTS(isolate, args) \ |
| 360 args.length(), args.arguments(), isolate | 292 args.length(), args.arguments(), isolate |
| 361 | 293 |
| 362 } } // namespace v8::internal | 294 } } // namespace v8::internal |
| 363 | 295 |
| 364 #endif // V8_ARGUMENTS_H_ | 296 #endif // V8_ARGUMENTS_H_ |
| OLD | NEW |