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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 static inline Local<DeclaredAccessorDescriptor> ToLocal( | 266 static inline Local<DeclaredAccessorDescriptor> ToLocal( |
267 v8::internal::Handle<v8::internal::DeclaredAccessorDescriptor> obj); | 267 v8::internal::Handle<v8::internal::DeclaredAccessorDescriptor> obj); |
268 | 268 |
269 #define DECLARE_OPEN_HANDLE(From, To) \ | 269 #define DECLARE_OPEN_HANDLE(From, To) \ |
270 static inline v8::internal::Handle<v8::internal::To> \ | 270 static inline v8::internal::Handle<v8::internal::To> \ |
271 OpenHandle(const From* that, bool allow_empty_handle = false); | 271 OpenHandle(const From* that, bool allow_empty_handle = false); |
272 | 272 |
273 OPEN_HANDLE_LIST(DECLARE_OPEN_HANDLE) | 273 OPEN_HANDLE_LIST(DECLARE_OPEN_HANDLE) |
274 | 274 |
275 #undef DECLARE_OPEN_HANDLE | 275 #undef DECLARE_OPEN_HANDLE |
| 276 |
| 277 template<class From, class To> |
| 278 static inline Local<To> Convert(v8::internal::Handle<From> obj) { |
| 279 ASSERT(obj.is_null() || !obj->IsTheHole()); |
| 280 return Local<To>(reinterpret_cast<To*>(obj.location())); |
| 281 } |
| 282 |
| 283 template <class T> |
| 284 static inline v8::internal::Handle<v8::internal::Object> OpenPersistent( |
| 285 const v8::Persistent<T>& persistent) { |
| 286 return v8::internal::Handle<v8::internal::Object>( |
| 287 reinterpret_cast<v8::internal::Object**>(persistent.val_)); |
| 288 } |
| 289 |
| 290 template <class T> |
| 291 static inline v8::internal::Handle<v8::internal::Object> OpenPersistent( |
| 292 v8::Persistent<T>* persistent) { |
| 293 return OpenPersistent(*persistent); |
| 294 } |
276 }; | 295 }; |
277 | 296 |
278 | 297 |
279 template <class T> | 298 template <class T> |
280 inline T* ToApi(v8::internal::Handle<v8::internal::Object> obj) { | |
281 return reinterpret_cast<T*>(obj.location()); | |
282 } | |
283 | |
284 | |
285 template <class T> | |
286 v8::internal::Handle<T> v8::internal::Handle<T>::EscapeFrom( | 299 v8::internal::Handle<T> v8::internal::Handle<T>::EscapeFrom( |
287 v8::HandleScope* scope) { | 300 v8::HandleScope* scope) { |
288 v8::internal::Handle<T> handle; | 301 v8::internal::Handle<T> handle; |
289 if (!is_null()) { | 302 if (!is_null()) { |
290 handle = *this; | 303 handle = *this; |
291 } | 304 } |
292 return Utils::OpenHandle(*scope->Close(Utils::ToLocal(handle)), true); | 305 return Utils::OpenHandle(*scope->Close(Utils::ToLocal(handle)), true); |
293 } | 306 } |
294 | 307 |
295 | 308 |
296 class InternalHandleHelper { | 309 template <class T> |
297 public: | 310 inline T* ToApi(v8::internal::Handle<v8::internal::Object> obj) { |
298 template<class From, class To> | 311 return reinterpret_cast<T*>(obj.location()); |
299 static inline Local<To> Convert(v8::internal::Handle<From> obj) { | 312 } |
300 return Local<To>(reinterpret_cast<To*>(obj.location())); | 313 |
301 } | 314 template <class T> |
302 }; | 315 inline v8::Local<T> ToApiHandle( |
| 316 v8::internal::Handle<v8::internal::Object> obj) { |
| 317 return Utils::Convert<v8::internal::Object, T>(obj); |
| 318 } |
303 | 319 |
304 | 320 |
305 // Implementations of ToLocal | 321 // Implementations of ToLocal |
306 | 322 |
307 #define MAKE_TO_LOCAL(Name, From, To) \ | 323 #define MAKE_TO_LOCAL(Name, From, To) \ |
308 Local<v8::To> Utils::Name(v8::internal::Handle<v8::internal::From> obj) { \ | 324 Local<v8::To> Utils::Name(v8::internal::Handle<v8::internal::From> obj) { \ |
309 ASSERT(obj.is_null() || !obj->IsTheHole()); \ | 325 return Convert<v8::internal::From, v8::To>(obj); \ |
310 return InternalHandleHelper::Convert<v8::internal::From, v8::To>(obj); \ | |
311 } | 326 } |
312 | 327 |
313 | 328 |
314 #define MAKE_TO_LOCAL_TYPED_ARRAY(TypedArray, typeConst) \ | 329 #define MAKE_TO_LOCAL_TYPED_ARRAY(TypedArray, typeConst) \ |
315 Local<v8::TypedArray> Utils::ToLocal##TypedArray( \ | 330 Local<v8::TypedArray> Utils::ToLocal##TypedArray( \ |
316 v8::internal::Handle<v8::internal::JSTypedArray> obj) { \ | 331 v8::internal::Handle<v8::internal::JSTypedArray> obj) { \ |
317 ASSERT(obj.is_null() || !obj->IsTheHole()); \ | |
318 ASSERT(obj->type() == typeConst); \ | 332 ASSERT(obj->type() == typeConst); \ |
319 return InternalHandleHelper:: \ | 333 return Convert<v8::internal::JSTypedArray, v8::TypedArray>(obj); \ |
320 Convert<v8::internal::JSTypedArray, v8::TypedArray>(obj); \ | |
321 } | 334 } |
322 | 335 |
323 | 336 |
324 MAKE_TO_LOCAL(ToLocal, Context, Context) | 337 MAKE_TO_LOCAL(ToLocal, Context, Context) |
325 MAKE_TO_LOCAL(ToLocal, Object, Value) | 338 MAKE_TO_LOCAL(ToLocal, Object, Value) |
326 MAKE_TO_LOCAL(ToLocal, JSFunction, Function) | 339 MAKE_TO_LOCAL(ToLocal, JSFunction, Function) |
327 MAKE_TO_LOCAL(ToLocal, String, String) | 340 MAKE_TO_LOCAL(ToLocal, String, String) |
328 MAKE_TO_LOCAL(ToLocal, Symbol, Symbol) | 341 MAKE_TO_LOCAL(ToLocal, Symbol, Symbol) |
329 MAKE_TO_LOCAL(ToLocal, JSRegExp, RegExp) | 342 MAKE_TO_LOCAL(ToLocal, JSRegExp, RegExp) |
330 MAKE_TO_LOCAL(ToLocal, JSObject, Object) | 343 MAKE_TO_LOCAL(ToLocal, JSObject, Object) |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 stress_type_ = stress_type; | 682 stress_type_ = stress_type; |
670 } | 683 } |
671 | 684 |
672 private: | 685 private: |
673 static v8::Testing::StressType stress_type_; | 686 static v8::Testing::StressType stress_type_; |
674 }; | 687 }; |
675 | 688 |
676 } } // namespace v8::internal | 689 } } // namespace v8::internal |
677 | 690 |
678 #endif // V8_API_H_ | 691 #endif // V8_API_H_ |
OLD | NEW |