Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: include/v8.h

Issue 15817014: remove most uses of raw handle constructors (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: stupid cast needed Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 class Date; 116 class Date;
117 class DeclaredAccessorDescriptor; 117 class DeclaredAccessorDescriptor;
118 class External; 118 class External;
119 class Function; 119 class Function;
120 class FunctionTemplate; 120 class FunctionTemplate;
121 class HeapProfiler; 121 class HeapProfiler;
122 class ImplementationUtilities; 122 class ImplementationUtilities;
123 class Int32; 123 class Int32;
124 class Integer; 124 class Integer;
125 class Isolate; 125 class Isolate;
126 class LocalContext;
127 class Number; 126 class Number;
128 class NumberObject; 127 class NumberObject;
129 class Object; 128 class Object;
130 class ObjectOperationDescriptor; 129 class ObjectOperationDescriptor;
131 class ObjectTemplate; 130 class ObjectTemplate;
132 class Primitive; 131 class Primitive;
133 class RawOperationDescriptor; 132 class RawOperationDescriptor;
134 class Signature; 133 class Signature;
135 class StackFrame; 134 class StackFrame;
136 class StackTrace; 135 class StackTrace;
(...skipping 18 matching lines...) Expand all
155 class DeclaredAccessorDescriptor; 154 class DeclaredAccessorDescriptor;
156 class ObjectOperationDescriptor; 155 class ObjectOperationDescriptor;
157 class RawOperationDescriptor; 156 class RawOperationDescriptor;
158 157
159 namespace internal { 158 namespace internal {
160 class Arguments; 159 class Arguments;
161 class Heap; 160 class Heap;
162 class HeapObject; 161 class HeapObject;
163 class Isolate; 162 class Isolate;
164 class Object; 163 class Object;
165 template<typename T> 164 template<typename T> class CustomArguments;
166 class CustomArguments;
167 class PropertyCallbackArguments; 165 class PropertyCallbackArguments;
168 class FunctionCallbackArguments; 166 class FunctionCallbackArguments;
169 } 167 }
170 168
171 169
172 /** 170 /**
173 * General purpose unique identifier. 171 * General purpose unique identifier.
174 */ 172 */
175 class UniqueId { 173 class UniqueId {
176 public: 174 public:
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 356
359 private: 357 private:
360 #endif 358 #endif
361 /** 359 /**
362 * Creates a new handle for the specified value. 360 * Creates a new handle for the specified value.
363 */ 361 */
364 V8_INLINE(explicit Handle(T* val)) : val_(val) {} 362 V8_INLINE(explicit Handle(T* val)) : val_(val) {}
365 #endif 363 #endif
366 364
367 private: 365 private:
366 friend class Utils;
368 template<class F> friend class Persistent; 367 template<class F> friend class Persistent;
369 template<class F> friend class Local; 368 template<class F> friend class Local;
370 friend class Arguments; 369 friend class Arguments;
371 template<class F> friend class FunctionCallbackInfo; 370 template<class F> friend class FunctionCallbackInfo;
372 template<class F> friend class PropertyCallbackInfo; 371 template<class F> friend class PropertyCallbackInfo;
373 friend class String; 372 template<class F> friend class CustomArguments;
374 friend class Object;
375 friend class AccessorInfo; 373 friend class AccessorInfo;
376 friend Handle<Primitive> Undefined(Isolate* isolate); 374 friend Handle<Primitive> Undefined(Isolate* isolate);
377 friend Handle<Primitive> Null(Isolate* isolate); 375 friend Handle<Primitive> Null(Isolate* isolate);
378 friend Handle<Boolean> True(Isolate* isolate); 376 friend Handle<Boolean> True(Isolate* isolate);
379 friend Handle<Boolean> False(Isolate* isolate); 377 friend Handle<Boolean> False(Isolate* isolate);
380 friend class Context; 378 friend class Context;
381 friend class InternalHandleHelper;
382 friend class LocalContext;
383 friend class HandleScope; 379 friend class HandleScope;
384 380
385 #ifndef V8_USE_UNSAFE_HANDLES 381 #ifndef V8_USE_UNSAFE_HANDLES
386 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); 382 V8_INLINE(static Handle<T> New(Isolate* isolate, T* that));
387 #endif 383 #endif
388 384
389 T* val_; 385 T* val_;
390 }; 386 };
391 387
392 388
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); 443 V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that));
448 444
449 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR 445 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
450 446
451 private: 447 private:
452 #endif 448 #endif
453 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } 449 template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { }
454 #endif 450 #endif
455 451
456 private: 452 private:
453 friend class Utils;
457 template<class F> friend class Persistent; 454 template<class F> friend class Persistent;
458 template<class F> friend class Handle; 455 template<class F> friend class Handle;
459 friend class Arguments; 456 friend class Arguments;
460 template<class F> friend class FunctionCallbackInfo; 457 template<class F> friend class FunctionCallbackInfo;
461 template<class F> friend class PropertyCallbackInfo; 458 template<class F> friend class PropertyCallbackInfo;
462 friend class String; 459 friend class String;
463 friend class Object; 460 friend class Object;
464 friend class AccessorInfo; 461 friend class AccessorInfo;
465 friend class Context; 462 friend class Context;
466 friend class InternalHandleHelper; 463 template<class F> friend class CustomArguments;
467 friend class LocalContext;
468 friend class HandleScope; 464 friend class HandleScope;
469 465
470 V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); 466 V8_INLINE(static Local<T> New(Isolate* isolate, T* that));
471 }; 467 };
472 468
473 /** 469 /**
474 * An object reference that is independent of any handle scope. Where 470 * An object reference that is independent of any handle scope. Where
475 * a Local handle only lives as long as the HandleScope in which it was 471 * a Local handle only lives as long as the HandleScope in which it was
476 * allocated, a Persistent handle remains valid until it is explicitly 472 * allocated, a Persistent handle remains valid until it is explicitly
477 * disposed. 473 * disposed.
(...skipping 26 matching lines...) Expand all
504 // TODO(dcarney): remove somehow before cutover 500 // TODO(dcarney): remove somehow before cutover
505 // The handle should either be 0, or a pointer to a live cell. 501 // The handle should either be 0, or a pointer to a live cell.
506 V8_INLINE(void Clear()) { val_ = 0; } 502 V8_INLINE(void Clear()) { val_ = 0; }
507 503
508 /** 504 /**
509 * A constructor that creates a new global cell pointing to that. In contrast 505 * A constructor that creates a new global cell pointing to that. In contrast
510 * to the copy constructor, this creates a new persistent handle which needs 506 * to the copy constructor, this creates a new persistent handle which needs
511 * to be separately disposed. 507 * to be separately disposed.
512 */ 508 */
513 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) 509 template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that))
514 : val_(*New(isolate, that)) { } 510 : val_(New(isolate, *that)) { }
515 511
516 template <class S> V8_INLINE(Persistent(Isolate* isolate, 512 template <class S> V8_INLINE(Persistent(Isolate* isolate,
517 Persistent<S>& that)) // NOLINT 513 Persistent<S>& that)) // NOLINT
518 : val_(*New(isolate, that)) { } 514 : val_(New(isolate, *that)) { }
519 515
520 #else 516 #else
521 /** 517 /**
522 * Creates an empty persistent handle that doesn't point to any 518 * Creates an empty persistent handle that doesn't point to any
523 * storage cell. 519 * storage cell.
524 */ 520 */
525 V8_INLINE(Persistent()) : Handle<T>() { } 521 V8_INLINE(Persistent()) : Handle<T>() { }
526 522
527 /** 523 /**
528 * Creates a persistent handle for the same storage cell as the 524 * Creates a persistent handle for the same storage cell as the
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 if (!that.IsEmpty()) T::Cast(*that); 583 if (!that.IsEmpty()) T::Cast(*that);
588 #endif 584 #endif
589 return reinterpret_cast<Persistent<T>&>(that); 585 return reinterpret_cast<Persistent<T>&>(that);
590 } 586 }
591 587
592 template <class S> V8_INLINE(Persistent<S>& As()) { // NOLINT 588 template <class S> V8_INLINE(Persistent<S>& As()) { // NOLINT
593 return Persistent<S>::Cast(*this); 589 return Persistent<S>::Cast(*this);
594 } 590 }
595 #endif 591 #endif
596 592
593 #ifdef V8_USE_UNSAFE_HANDLES
597 V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); 594 V8_DEPRECATED(static Persistent<T> New(Handle<T> that));
598
599 /**
600 * Creates a new persistent handle for an existing local or persistent handle.
601 */
602 // TODO(dcarney): remove before cutover
603 V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); 595 V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that));
604 #ifndef V8_USE_UNSAFE_HANDLES
605 // TODO(dcarney): remove before cutover
606 V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); 596 V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that));
607 #endif 597 #endif
608 598
609 #ifndef V8_USE_UNSAFE_HANDLES 599 #ifndef V8_USE_UNSAFE_HANDLES
610 template <class S> V8_INLINE( 600 template <class S> V8_INLINE(
611 bool operator==(const Persistent<S>& that) const) { 601 bool operator==(const Persistent<S>& that) const) {
612 internal::Object** a = reinterpret_cast<internal::Object**>(**this); 602 internal::Object** a = reinterpret_cast<internal::Object**>(**this);
613 internal::Object** b = reinterpret_cast<internal::Object**>(*that); 603 internal::Object** b = reinterpret_cast<internal::Object**>(*that);
614 if (a == 0) return b == 0; 604 if (a == 0) return b == 0;
615 if (b == 0) return false; 605 if (b == 0) return false;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 return *this; 762 return *this;
773 } 763 }
774 764
775 public: 765 public:
776 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR 766 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
777 767
778 private: 768 private:
779 #endif 769 #endif
780 // TODO(dcarney): remove before cutover 770 // TODO(dcarney): remove before cutover
781 template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } 771 template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { }
782 // TODO(dcarney): remove before cutover 772
783 template <class S> V8_INLINE(Persistent(Persistent<S> that))
784 : val_(*that) {
785 TYPE_CHECK(T, S);
786 }
787 // TODO(dcarney): remove before cutover 773 // TODO(dcarney): remove before cutover
788 V8_INLINE(T* operator*() const) { return val_; } 774 V8_INLINE(T* operator*() const) { return val_; }
789 775
790 private: 776 private:
791 // TODO(dcarney): remove before cutover 777 // TODO(dcarney): remove before cutover
792 V8_INLINE(T* operator->() const) { return val_; } 778 V8_INLINE(T* operator->() const) { return val_; }
793 public: 779 public:
794 #endif 780 #endif
795 781
796 private: 782 private:
783 friend class Utils;
797 template<class F> friend class Handle; 784 template<class F> friend class Handle;
798 template<class F> friend class Local; 785 template<class F> friend class Local;
786 template<class F> friend class Persistent;
799 template<class F> friend class ReturnValue; 787 template<class F> friend class ReturnValue;
800 friend class ImplementationUtilities;
801 friend class ObjectTemplate;
802 friend class Context;
803 friend class InternalHandleHelper;
804 friend class LocalContext;
805 788
806 V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); 789 V8_INLINE(static T* New(Isolate* isolate, T* that));
807 790
808 #ifndef V8_USE_UNSAFE_HANDLES 791 #ifndef V8_USE_UNSAFE_HANDLES
809 T* val_; 792 T* val_;
810 #endif 793 #endif
811 }; 794 };
812 795
813 796
814 /** 797 /**
815 * A stack-allocated class that governs a number of local handles. 798 * A stack-allocated class that governs a number of local handles.
816 * After a handle scope has been created, all local handles will be 799 * After a handle scope has been created, all local handles will be
(...skipping 4686 matching lines...) Expand 10 before | Expand all | Expand 10 after
5503 template <class T> 5486 template <class T>
5504 Local<T> Local<T>::New(Isolate* isolate, T* that) { 5487 Local<T> Local<T>::New(Isolate* isolate, T* that) {
5505 if (that == NULL) return Local<T>(); 5488 if (that == NULL) return Local<T>();
5506 T* that_ptr = that; 5489 T* that_ptr = that;
5507 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); 5490 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
5508 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( 5491 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
5509 reinterpret_cast<internal::Isolate*>(isolate), *p))); 5492 reinterpret_cast<internal::Isolate*>(isolate), *p)));
5510 } 5493 }
5511 5494
5512 5495
5496 #ifdef V8_USE_UNSAFE_HANDLES
5513 template <class T> 5497 template <class T>
5514 Persistent<T> Persistent<T>::New(Handle<T> that) { 5498 Persistent<T> Persistent<T>::New(Handle<T> that) {
5515 return New(Isolate::GetCurrent(), that.val_); 5499 return New(Isolate::GetCurrent(), that.val_);
5516 } 5500 }
5517 5501
5518 5502
5519 template <class T> 5503 template <class T>
5520 Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { 5504 Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) {
5521 return New(Isolate::GetCurrent(), that.val_); 5505 return New(Isolate::GetCurrent(), that.val_);
5522 } 5506 }
5523 5507
5524 #ifndef V8_USE_UNSAFE_HANDLES
5525 template <class T> 5508 template <class T>
5526 Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { 5509 Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) {
5527 return New(Isolate::GetCurrent(), that.val_); 5510 return New(Isolate::GetCurrent(), that.val_);
5528 } 5511 }
5529 #endif 5512 #endif
5530 5513
5514
5531 template <class T> 5515 template <class T>
5532 Persistent<T> Persistent<T>::New(Isolate* isolate, T* that) { 5516 T* Persistent<T>::New(Isolate* isolate, T* that) {
5533 if (that == NULL) return Persistent<T>(); 5517 if (that == NULL) return NULL;
5534 internal::Object** p = reinterpret_cast<internal::Object**>(that); 5518 internal::Object** p = reinterpret_cast<internal::Object**>(that);
5535 return Persistent<T>(reinterpret_cast<T*>( 5519 return reinterpret_cast<T*>(
5536 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), 5520 V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
5537 p))); 5521 p));
5538 } 5522 }
5539 5523
5540 5524
5541 template <class T> 5525 template <class T>
5542 bool Persistent<T>::IsIndependent() const { 5526 bool Persistent<T>::IsIndependent() const {
5543 typedef internal::Internals I; 5527 typedef internal::Internals I;
5544 if (this->IsEmpty()) return false; 5528 if (this->IsEmpty()) return false;
5545 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), 5529 return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
5546 I::kNodeIsIndependentShift); 5530 I::kNodeIsIndependentShift);
5547 } 5531 }
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
6369 6353
6370 6354
6371 } // namespace v8 6355 } // namespace v8
6372 6356
6373 6357
6374 #undef V8EXPORT 6358 #undef V8EXPORT
6375 #undef TYPE_CHECK 6359 #undef TYPE_CHECK
6376 6360
6377 6361
6378 #endif // V8_H_ 6362 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698