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

Side by Side Diff: include/v8.h

Issue 24245005: Add EscapableHandleScope to api to fix problems with HandleScope::Close (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 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.cc » ('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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 class ObjectTemplate; 128 class ObjectTemplate;
129 class Data; 129 class Data;
130 template<typename T> class PropertyCallbackInfo; 130 template<typename T> class PropertyCallbackInfo;
131 class StackTrace; 131 class StackTrace;
132 class StackFrame; 132 class StackFrame;
133 class Isolate; 133 class Isolate;
134 class DeclaredAccessorDescriptor; 134 class DeclaredAccessorDescriptor;
135 class ObjectOperationDescriptor; 135 class ObjectOperationDescriptor;
136 class RawOperationDescriptor; 136 class RawOperationDescriptor;
137 class CallHandlerHelper; 137 class CallHandlerHelper;
138 class EscapableHandleScope;
138 139
139 namespace internal { 140 namespace internal {
140 class Arguments; 141 class Arguments;
141 class Heap; 142 class Heap;
142 class HeapObject; 143 class HeapObject;
143 class Isolate; 144 class Isolate;
144 class Object; 145 class Object;
145 template<typename T> class CustomArguments; 146 template<typename T> class CustomArguments;
146 class PropertyCallbackArguments; 147 class PropertyCallbackArguments;
147 class FunctionCallbackArguments; 148 class FunctionCallbackArguments;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 template<class F> friend class Eternal; 395 template<class F> friend class Eternal;
395 template<class F, class M> friend class Persistent; 396 template<class F, class M> friend class Persistent;
396 template<class F> friend class Handle; 397 template<class F> friend class Handle;
397 template<class F> friend class FunctionCallbackInfo; 398 template<class F> friend class FunctionCallbackInfo;
398 template<class F> friend class PropertyCallbackInfo; 399 template<class F> friend class PropertyCallbackInfo;
399 friend class String; 400 friend class String;
400 friend class Object; 401 friend class Object;
401 friend class Context; 402 friend class Context;
402 template<class F> friend class internal::CustomArguments; 403 template<class F> friend class internal::CustomArguments;
403 friend class HandleScope; 404 friend class HandleScope;
405 friend class EscapableHandleScope;
404 406
405 V8_INLINE static Local<T> New(Isolate* isolate, T* that); 407 V8_INLINE static Local<T> New(Isolate* isolate, T* that);
406 }; 408 };
407 409
408 410
409 // Eternal handles are set-once handles that live for the life of the isolate. 411 // Eternal handles are set-once handles that live for the life of the isolate.
410 template <class T> class Eternal { 412 template <class T> class Eternal {
411 public: 413 public:
412 V8_INLINE Eternal() : index_(kInitialValue) { } 414 V8_INLINE Eternal() : index_(kInitialValue) { }
413 template<class S> 415 template<class S>
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 * garbage collector will no longer track the object stored in the 768 * garbage collector will no longer track the object stored in the
767 * handle and may deallocate it. The behavior of accessing a handle 769 * handle and may deallocate it. The behavior of accessing a handle
768 * for which the handle scope has been deleted is undefined. 770 * for which the handle scope has been deleted is undefined.
769 */ 771 */
770 class V8_EXPORT HandleScope { 772 class V8_EXPORT HandleScope {
771 public: 773 public:
772 HandleScope(Isolate* isolate); 774 HandleScope(Isolate* isolate);
773 775
774 ~HandleScope(); 776 ~HandleScope();
775 777
776 /** 778 // TODO(dcarney): deprecated - use EscapableHandleScope::Escape.
777 * Closes the handle scope and returns the value as a handle in the
778 * previous scope, which is the new current scope after the call.
779 */
780 template <class T> Local<T> Close(Handle<T> value); 779 template <class T> Local<T> Close(Handle<T> value);
781 780
782 /** 781 /**
783 * Counts the number of allocated handles. 782 * Counts the number of allocated handles.
784 */ 783 */
785 static int NumberOfHandles(); 784 static int NumberOfHandles();
786 785
787 /** 786 /**
788 * Creates a new handle with the given value. 787 * Creates a new handle with the given value.
789 */ 788 */
790 static internal::Object** CreateHandle(internal::Object* value); 789 static internal::Object** CreateHandle(internal::Object* value);
791 static internal::Object** CreateHandle(internal::Isolate* isolate, 790 static internal::Object** CreateHandle(internal::Isolate* isolate,
792 internal::Object* value); 791 internal::Object* value);
793 // Faster version, uses HeapObject to obtain the current Isolate. 792 // Faster version, uses HeapObject to obtain the current Isolate.
794 static internal::Object** CreateHandle(internal::HeapObject* value); 793 static internal::Object** CreateHandle(internal::HeapObject* value);
795 794
796 private: 795 private:
796 V8_INLINE HandleScope() {}
797 void Initialize(Isolate* isolate);
798
797 // Make it hard to create heap-allocated or illegal handle scopes by 799 // Make it hard to create heap-allocated or illegal handle scopes by
798 // disallowing certain operations. 800 // disallowing certain operations.
799 HandleScope(const HandleScope&); 801 HandleScope(const HandleScope&);
800 void operator=(const HandleScope&); 802 void operator=(const HandleScope&);
801 void* operator new(size_t size); 803 void* operator new(size_t size);
802 void operator delete(void*, size_t); 804 void operator delete(void*, size_t);
803 805
804 // This Data class is accessible internally as HandleScopeData through a 806 // This Data class is accessible internally as HandleScopeData through a
805 // typedef in the ImplementationUtilities class. 807 // typedef in the ImplementationUtilities class.
806 class V8_EXPORT Data { 808 class V8_EXPORT Data {
807 public: 809 public:
808 internal::Object** next; 810 internal::Object** next;
809 internal::Object** limit; 811 internal::Object** limit;
810 int level; 812 int level;
811 V8_INLINE void Initialize() { 813 V8_INLINE void Initialize() {
812 next = limit = NULL; 814 next = limit = NULL;
813 level = 0; 815 level = 0;
814 } 816 }
815 }; 817 };
816 818
817 void Initialize(Isolate* isolate);
818 void Leave(); 819 void Leave();
819 820
820 internal::Isolate* isolate_; 821 internal::Isolate* isolate_;
821 internal::Object** prev_next_; 822 internal::Object** prev_next_;
822 internal::Object** prev_limit_; 823 internal::Object** prev_limit_;
823 824
825 // TODO(dcarney): remove this field
824 // Allow for the active closing of HandleScopes which allows to pass a handle 826 // Allow for the active closing of HandleScopes which allows to pass a handle
825 // from the HandleScope being closed to the next top most HandleScope. 827 // from the HandleScope being closed to the next top most HandleScope.
826 bool is_closed_; 828 bool is_closed_;
827 internal::Object** RawClose(internal::Object** value); 829 internal::Object** RawClose(internal::Object** value);
828 830
829 friend class ImplementationUtilities; 831 friend class ImplementationUtilities;
832 friend class EscapableHandleScope;
830 }; 833 };
831 834
832 835
836 /**
837 * A HandleScope which first allocates a handle in the current scope
838 * which will be later filled with the escape value.
839 */
840 class V8_EXPORT EscapableHandleScope : public HandleScope {
841 public:
842 EscapableHandleScope(Isolate* isolate);
843 V8_INLINE ~EscapableHandleScope() {}
844
845 /**
846 * Pushes the value into the previous scope and returns a handle to it.
847 * Cannot be called twice.
848 */
849 template <class T>
850 V8_INLINE Local<T> Escape(Local<T> value) {
851 internal::Object** slot =
852 Escape(reinterpret_cast<internal::Object**>(*value));
853 return Local<T>(reinterpret_cast<T*>(slot));
854 }
855
856 private:
857 internal::Object** Escape(internal::Object** escape_value);
858
859 internal::Object** escape_slot_;
860 };
861
862
833 /** 863 /**
834 * A simple Maybe type, representing an object which may or may not have a 864 * A simple Maybe type, representing an object which may or may not have a
835 * value. 865 * value.
836 */ 866 */
837 template<class T> 867 template<class T>
838 struct V8_EXPORT Maybe { 868 struct V8_EXPORT Maybe {
839 Maybe() : has_value(false) {} 869 Maybe() : has_value(false) {}
840 explicit Maybe(T t) : has_value(true), value(t) {} 870 explicit Maybe(T t) : has_value(true), value(t) {}
841 Maybe(bool has, T t) : has_value(has), value(t) {} 871 Maybe(bool has, T t) : has_value(has), value(t) {}
842 872
(...skipping 5631 matching lines...) Expand 10 before | Expand all | Expand 10 after
6474 */ 6504 */
6475 6505
6476 6506
6477 } // namespace v8 6507 } // namespace v8
6478 6508
6479 6509
6480 #undef TYPE_CHECK 6510 #undef TYPE_CHECK
6481 6511
6482 6512
6483 #endif // V8_H_ 6513 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698