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

Side by Side Diff: include/v8.h

Issue 12494012: new style of property/function callbacks (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: make arm look like other architectures Created 7 years, 7 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 class String; 137 class String;
138 class StringObject; 138 class StringObject;
139 class Symbol; 139 class Symbol;
140 class SymbolObject; 140 class SymbolObject;
141 class Uint32; 141 class Uint32;
142 class Utils; 142 class Utils;
143 class Value; 143 class Value;
144 template <class T> class Handle; 144 template <class T> class Handle;
145 template <class T> class Local; 145 template <class T> class Local;
146 template <class T> class Persistent; 146 template <class T> class Persistent;
147 class FunctionTemplate;
148 class ObjectTemplate;
149 class Data;
150 class AccessorInfo;
151 template<typename T> class PropertyCallbackInfo;
152 class StackTrace;
153 class StackFrame;
154 class Isolate;
155 class DeclaredAccessorDescriptor;
156 class ObjectOperationDescriptor;
157 class RawOperationDescriptor;
147 158
148 namespace internal { 159 namespace internal {
149 class Arguments; 160 class Arguments;
150 class Heap; 161 class Heap;
151 class HeapObject; 162 class HeapObject;
152 class Isolate; 163 class Isolate;
153 class Object; 164 class Object;
165 template<typename T>
166 class CustomArguments;
167 class PropertyCallbackArguments;
168 class FunctionCallbackArguments;
154 } 169 }
155 170
156 171
157 /** 172 /**
158 * General purpose unique identifier. 173 * General purpose unique identifier.
159 */ 174 */
160 class UniqueId { 175 class UniqueId {
161 public: 176 public:
162 explicit UniqueId(intptr_t data) 177 explicit UniqueId(intptr_t data)
163 : data_(data) {} 178 : data_(data) {}
(...skipping 1765 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 kExternalPixelArray 1944 kExternalPixelArray
1930 }; 1945 };
1931 1946
1932 /** 1947 /**
1933 * Accessor[Getter|Setter] are used as callback functions when 1948 * Accessor[Getter|Setter] are used as callback functions when
1934 * setting|getting a particular property. See Object and ObjectTemplate's 1949 * setting|getting a particular property. See Object and ObjectTemplate's
1935 * method SetAccessor. 1950 * method SetAccessor.
1936 */ 1951 */
1937 typedef Handle<Value> (*AccessorGetter)(Local<String> property, 1952 typedef Handle<Value> (*AccessorGetter)(Local<String> property,
1938 const AccessorInfo& info); 1953 const AccessorInfo& info);
1954 typedef void (*AccessorGetterCallback)(
1955 Local<String> property,
1956 const PropertyCallbackInfo<Value>& info);
1939 1957
1940 1958
1941 typedef void (*AccessorSetter)(Local<String> property, 1959 typedef void (*AccessorSetter)(Local<String> property,
1942 Local<Value> value, 1960 Local<Value> value,
1943 const AccessorInfo& info); 1961 const AccessorInfo& info);
1962 typedef void (*AccessorSetterCallback)(
1963 Local<String> property,
1964 Local<Value> value,
1965 const PropertyCallbackInfo<void>& info);
1944 1966
1945 1967
1946 /** 1968 /**
1947 * Access control specifications. 1969 * Access control specifications.
1948 * 1970 *
1949 * Some accessors should be accessible across contexts. These 1971 * Some accessors should be accessible across contexts. These
1950 * accessors have an explicit access control parameter which specifies 1972 * accessors have an explicit access control parameter which specifies
1951 * the kind of cross-context access that should be allowed. 1973 * the kind of cross-context access that should be allowed.
1952 * 1974 *
1953 * Additionally, for security, accessors can prohibit overwriting by 1975 * Additionally, for security, accessors can prohibit overwriting by
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2003 bool Delete(Handle<Value> key); 2025 bool Delete(Handle<Value> key);
2004 2026
2005 // Delete a property on this object bypassing interceptors and 2027 // Delete a property on this object bypassing interceptors and
2006 // ignoring dont-delete attributes. 2028 // ignoring dont-delete attributes.
2007 bool ForceDelete(Handle<Value> key); 2029 bool ForceDelete(Handle<Value> key);
2008 2030
2009 bool Has(uint32_t index); 2031 bool Has(uint32_t index);
2010 2032
2011 bool Delete(uint32_t index); 2033 bool Delete(uint32_t index);
2012 2034
2035 // TODO(dcarney): deprecate
2013 bool SetAccessor(Handle<String> name, 2036 bool SetAccessor(Handle<String> name,
2014 AccessorGetter getter, 2037 AccessorGetter getter,
2015 AccessorSetter setter = 0, 2038 AccessorSetter setter = 0,
2016 Handle<Value> data = Handle<Value>(), 2039 Handle<Value> data = Handle<Value>(),
2017 AccessControl settings = DEFAULT, 2040 AccessControl settings = DEFAULT,
2018 PropertyAttribute attribute = None); 2041 PropertyAttribute attribute = None);
2042 bool SetAccessor(Handle<String> name,
2043 AccessorGetterCallback getter,
2044 AccessorSetterCallback setter = 0,
2045 Handle<Value> data = Handle<Value>(),
2046 AccessControl settings = DEFAULT,
2047 PropertyAttribute attribute = None);
2019 2048
2020 // This function is not yet stable and should not be used at this time. 2049 // This function is not yet stable and should not be used at this time.
2021 bool SetAccessor(Handle<String> name, 2050 bool SetAccessor(Handle<String> name,
2022 Handle<DeclaredAccessorDescriptor> descriptor, 2051 Handle<DeclaredAccessorDescriptor> descriptor,
2023 AccessControl settings = DEFAULT, 2052 AccessControl settings = DEFAULT,
2024 PropertyAttribute attribute = None); 2053 PropertyAttribute attribute = None);
2025 2054
2026 /** 2055 /**
2027 * Returns an array containing the names of the enumerable properties 2056 * Returns an array containing the names of the enumerable properties
2028 * of this object, including properties from prototype objects. The 2057 * of this object, including properties from prototype objects. The
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
2697 PropertyAttribute attributes = None); 2726 PropertyAttribute attributes = None);
2698 V8_INLINE(void Set(const char* name, Handle<Data> value)); 2727 V8_INLINE(void Set(const char* name, Handle<Data> value));
2699 private: 2728 private:
2700 Template(); 2729 Template();
2701 2730
2702 friend class ObjectTemplate; 2731 friend class ObjectTemplate;
2703 friend class FunctionTemplate; 2732 friend class FunctionTemplate;
2704 }; 2733 };
2705 2734
2706 2735
2736 template<typename T>
2737 class V8EXPORT ReturnValue {
2738 public:
2739 V8_INLINE(explicit ReturnValue(internal::Object** slot));
2740 // Handle setters
2741 V8_INLINE(void Set(const Persistent<T>& handle));
2742 V8_INLINE(void Set(const Handle<T> handle));
2743 // TODO(dcarney): implement
2744 // Fast primitive setters
2745 // V8_INLINE(void Set(Isolate* isolate, bool));
2746 // V8_INLINE(void Set(Isolate* isolate, float i));
2747 // V8_INLINE(void Set(Isolate* isolate, double i));
2748 // V8_INLINE(void Set(Isolate* isolate, int32_t i));
2749 // V8_INLINE(void Set(Isolate* isolate, uint32_t i));
2750 // Fast JS primitive setters
2751 // V8_INLINE(void SetNull(Isolate* isolate));
2752 // V8_INLINE(void SetUndefined(Isolate* isolate));
2753 private:
2754 internal::Object** value_;
2755 };
2756
2757
2707 /** 2758 /**
2708 * The argument information given to function call callbacks. This 2759 * The argument information given to function call callbacks. This
2709 * class provides access to information about the context of the call, 2760 * class provides access to information about the context of the call,
2710 * including the receiver, the number and values of arguments, and 2761 * including the receiver, the number and values of arguments, and
2711 * the holder of the function. 2762 * the holder of the function.
2712 */ 2763 */
2713 class V8EXPORT Arguments { 2764 template<typename T>
2765 class V8EXPORT FunctionCallbackInfo {
2714 public: 2766 public:
2715 V8_INLINE(int Length() const); 2767 V8_INLINE(int Length() const);
2716 V8_INLINE(Local<Value> operator[](int i) const); 2768 V8_INLINE(Local<Value> operator[](int i) const);
2717 V8_INLINE(Local<Function> Callee() const); 2769 V8_INLINE(Local<Function> Callee() const);
2718 V8_INLINE(Local<Object> This() const); 2770 V8_INLINE(Local<Object> This() const);
2719 V8_INLINE(Local<Object> Holder() const); 2771 V8_INLINE(Local<Object> Holder() const);
2720 V8_INLINE(bool IsConstructCall() const); 2772 V8_INLINE(bool IsConstructCall() const);
2721 V8_INLINE(Local<Value> Data() const); 2773 V8_INLINE(Local<Value> Data() const);
2722 V8_INLINE(Isolate* GetIsolate() const); 2774 V8_INLINE(Isolate* GetIsolate() const);
2775 V8_INLINE(ReturnValue<T> GetReturnValue() const);
2776 // This shouldn't be public, but the arm compiler needs it.
2777 static const int kArgsLength = 5;
2723 2778
2724 private: 2779 protected:
2725 static const int kIsolateIndex = 0; 2780 friend class internal::FunctionCallbackArguments;
2726 static const int kDataIndex = -1; 2781 friend class internal::CustomArguments<FunctionCallbackInfo>;
2727 static const int kCalleeIndex = -2; 2782 static const int kReturnValueIndex = 0;
2728 static const int kHolderIndex = -3; 2783 static const int kIsolateIndex = -1;
2784 static const int kDataIndex = -2;
2785 static const int kCalleeIndex = -3;
2786 static const int kHolderIndex = -4;
2729 2787
2730 friend class ImplementationUtilities; 2788 V8_INLINE(FunctionCallbackInfo(internal::Object** implicit_args,
2731 V8_INLINE(Arguments(internal::Object** implicit_args,
2732 internal::Object** values, 2789 internal::Object** values,
2733 int length, 2790 int length,
2734 bool is_construct_call)); 2791 bool is_construct_call));
2735 internal::Object** implicit_args_; 2792 internal::Object** implicit_args_;
2736 internal::Object** values_; 2793 internal::Object** values_;
2737 int length_; 2794 int length_;
2738 bool is_construct_call_; 2795 bool is_construct_call_;
2739 }; 2796 };
2740 2797
2741 2798
2799 class V8EXPORT Arguments : public FunctionCallbackInfo<Value> {
2800 private:
2801 friend class internal::FunctionCallbackArguments;
2802 V8_INLINE(Arguments(internal::Object** implicit_args,
2803 internal::Object** values,
2804 int length,
2805 bool is_construct_call));
2806 };
2807
2742 /** 2808 /**
2743 * The information passed to an accessor callback about the context 2809 * The information passed to a property callback about the context
2744 * of the property access. 2810 * of the property access.
2745 */ 2811 */
2746 class V8EXPORT AccessorInfo { 2812 template<typename T>
2813 class V8EXPORT PropertyCallbackInfo {
2747 public: 2814 public:
2748 V8_INLINE(AccessorInfo(internal::Object** args))
2749 : args_(args) { }
2750 V8_INLINE(Isolate* GetIsolate() const); 2815 V8_INLINE(Isolate* GetIsolate() const);
2751 V8_INLINE(Local<Value> Data() const); 2816 V8_INLINE(Local<Value> Data() const);
2752 V8_INLINE(Local<Object> This() const); 2817 V8_INLINE(Local<Object> This() const);
2753 V8_INLINE(Local<Object> Holder() const); 2818 V8_INLINE(Local<Object> Holder() const);
2819 V8_INLINE(ReturnValue<T> GetReturnValue() const);
2820 // This shouldn't be public, but the arm compiler needs it.
2821 static const int kArgsLength = 5;
2754 2822
2755 private: 2823 protected:
2824 friend class MacroAssembler;
2825 friend class internal::PropertyCallbackArguments;
2826 friend class internal::CustomArguments<PropertyCallbackInfo>;
2827 static const int kThisIndex = 0;
2828 static const int kHolderIndex = -1;
2829 static const int kDataIndex = -2;
2830 static const int kIsolateIndex = -3;
2831 static const int kReturnValueIndex = -4;
2832
2833 V8_INLINE(PropertyCallbackInfo(internal::Object** args))
2834 : args_(args) { }
2756 internal::Object** args_; 2835 internal::Object** args_;
2757 }; 2836 };
2758 2837
2759 2838
2839 class V8EXPORT AccessorInfo : public PropertyCallbackInfo<Value> {
2840 private:
2841 friend class internal::PropertyCallbackArguments;
2842 V8_INLINE(AccessorInfo(internal::Object** args))
2843 : PropertyCallbackInfo<Value>(args) { }
2844 };
2845
2846
2760 typedef Handle<Value> (*InvocationCallback)(const Arguments& args); 2847 typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
2848 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
2761 2849
2762 /** 2850 /**
2763 * NamedProperty[Getter|Setter] are used as interceptors on object. 2851 * NamedProperty[Getter|Setter] are used as interceptors on object.
2764 * See ObjectTemplate::SetNamedPropertyHandler. 2852 * See ObjectTemplate::SetNamedPropertyHandler.
2765 */ 2853 */
2766 typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, 2854 typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
2767 const AccessorInfo& info); 2855 const AccessorInfo& info);
2856 typedef void (*NamedPropertyGetterCallback)(
2857 Local<String> property,
2858 const PropertyCallbackInfo<Value>& info);
2768 2859
2769 2860
2770 /** 2861 /**
2771 * Returns the value if the setter intercepts the request. 2862 * Returns the value if the setter intercepts the request.
2772 * Otherwise, returns an empty handle. 2863 * Otherwise, returns an empty handle.
2773 */ 2864 */
2774 typedef Handle<Value> (*NamedPropertySetter)(Local<String> property, 2865 typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
2775 Local<Value> value, 2866 Local<Value> value,
2776 const AccessorInfo& info); 2867 const AccessorInfo& info);
2868 typedef void (*NamedPropertySetterCallback)(
2869 Local<String> property,
2870 Local<Value> value,
2871 const PropertyCallbackInfo<Value>& info);
2872
2777 2873
2778 /** 2874 /**
2779 * Returns a non-empty handle if the interceptor intercepts the request. 2875 * Returns a non-empty handle if the interceptor intercepts the request.
2780 * The result is an integer encoding property attributes (like v8::None, 2876 * The result is an integer encoding property attributes (like v8::None,
2781 * v8::DontEnum, etc.) 2877 * v8::DontEnum, etc.)
2782 */ 2878 */
2783 typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, 2879 typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
2784 const AccessorInfo& info); 2880 const AccessorInfo& info);
2881 typedef void (*NamedPropertyQueryCallback)(
2882 Local<String> property,
2883 const PropertyCallbackInfo<Integer>& info);
2785 2884
2786 2885
2787 /** 2886 /**
2788 * Returns a non-empty handle if the deleter intercepts the request. 2887 * Returns a non-empty handle if the deleter intercepts the request.
2789 * The return value is true if the property could be deleted and false 2888 * The return value is true if the property could be deleted and false
2790 * otherwise. 2889 * otherwise.
2791 */ 2890 */
2792 typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, 2891 typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
2793 const AccessorInfo& info); 2892 const AccessorInfo& info);
2893 typedef void (*NamedPropertyDeleterCallback)(
2894 Local<String> property,
2895 const PropertyCallbackInfo<Boolean>& info);
2896
2794 2897
2795 /** 2898 /**
2796 * Returns an array containing the names of the properties the named 2899 * Returns an array containing the names of the properties the named
2797 * property getter intercepts. 2900 * property getter intercepts.
2798 */ 2901 */
2799 typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); 2902 typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
2903 typedef void (*NamedPropertyEnumeratorCallback)(
2904 const PropertyCallbackInfo<Array>& info);
2800 2905
2801 2906
2802 /** 2907 /**
2803 * Returns the value of the property if the getter intercepts the 2908 * Returns the value of the property if the getter intercepts the
2804 * request. Otherwise, returns an empty handle. 2909 * request. Otherwise, returns an empty handle.
2805 */ 2910 */
2806 typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, 2911 typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
2807 const AccessorInfo& info); 2912 const AccessorInfo& info);
2913 typedef void (*IndexedPropertyGetterCallback)(
2914 uint32_t index,
2915 const PropertyCallbackInfo<Value>& info);
2808 2916
2809 2917
2810 /** 2918 /**
2811 * Returns the value if the setter intercepts the request. 2919 * Returns the value if the setter intercepts the request.
2812 * Otherwise, returns an empty handle. 2920 * Otherwise, returns an empty handle.
2813 */ 2921 */
2814 typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, 2922 typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
2815 Local<Value> value, 2923 Local<Value> value,
2816 const AccessorInfo& info); 2924 const AccessorInfo& info);
2925 typedef void (*IndexedPropertySetterCallback)(
2926 uint32_t index,
2927 Local<Value> value,
2928 const PropertyCallbackInfo<Value>& info);
2817 2929
2818 2930
2819 /** 2931 /**
2820 * Returns a non-empty handle if the interceptor intercepts the request. 2932 * Returns a non-empty handle if the interceptor intercepts the request.
2821 * The result is an integer encoding property attributes. 2933 * The result is an integer encoding property attributes.
2822 */ 2934 */
2823 typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index, 2935 typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
2824 const AccessorInfo& info); 2936 const AccessorInfo& info);
2937 typedef void (*IndexedPropertyQueryCallback)(
2938 uint32_t index,
2939 const PropertyCallbackInfo<Integer>& info);
2940
2825 2941
2826 /** 2942 /**
2827 * Returns a non-empty handle if the deleter intercepts the request. 2943 * Returns a non-empty handle if the deleter intercepts the request.
2828 * The return value is true if the property could be deleted and false 2944 * The return value is true if the property could be deleted and false
2829 * otherwise. 2945 * otherwise.
2830 */ 2946 */
2831 typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, 2947 typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
2832 const AccessorInfo& info); 2948 const AccessorInfo& info);
2949 typedef void (*IndexedPropertyDeleterCallback)(
2950 uint32_t index,
2951 const PropertyCallbackInfo<Boolean>& info);
2952
2833 2953
2834 /** 2954 /**
2835 * Returns an array containing the indices of the properties the 2955 * Returns an array containing the indices of the properties the
2836 * indexed property getter intercepts. 2956 * indexed property getter intercepts.
2837 */ 2957 */
2838 typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); 2958 typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
2959 typedef void (*IndexedPropertyEnumeratorCallback)(
2960 const PropertyCallbackInfo<Array>& info);
2839 2961
2840 2962
2841 /** 2963 /**
2842 * Access type specification. 2964 * Access type specification.
2843 */ 2965 */
2844 enum AccessType { 2966 enum AccessType {
2845 ACCESS_GET, 2967 ACCESS_GET,
2846 ACCESS_SET, 2968 ACCESS_SET,
2847 ACCESS_HAS, 2969 ACCESS_HAS,
2848 ACCESS_DELETE, 2970 ACCESS_DELETE,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2958 * 3080 *
2959 * \code 3081 * \code
2960 * child_func.prototype.__proto__ == function.prototype; 3082 * child_func.prototype.__proto__ == function.prototype;
2961 * child_instance.instance_accessor calls 'InstanceAccessorCallback' 3083 * child_instance.instance_accessor calls 'InstanceAccessorCallback'
2962 * child_instance.instance_property == 3; 3084 * child_instance.instance_property == 3;
2963 * \endcode 3085 * \endcode
2964 */ 3086 */
2965 class V8EXPORT FunctionTemplate : public Template { 3087 class V8EXPORT FunctionTemplate : public Template {
2966 public: 3088 public:
2967 /** Creates a function template.*/ 3089 /** Creates a function template.*/
3090 // TODO(dcarney): deprecate
2968 static Local<FunctionTemplate> New( 3091 static Local<FunctionTemplate> New(
2969 InvocationCallback callback = 0, 3092 InvocationCallback callback = 0,
2970 Handle<Value> data = Handle<Value>(), 3093 Handle<Value> data = Handle<Value>(),
2971 Handle<Signature> signature = Handle<Signature>(), 3094 Handle<Signature> signature = Handle<Signature>(),
2972 int length = 0); 3095 int length = 0);
3096 static Local<FunctionTemplate> New(
3097 FunctionCallback callback, // TODO(dcarney): add back default param.
3098 Handle<Value> data = Handle<Value>(),
3099 Handle<Signature> signature = Handle<Signature>(),
3100 int length = 0);
3101
2973 /** Returns the unique function instance in the current execution context.*/ 3102 /** Returns the unique function instance in the current execution context.*/
2974 Local<Function> GetFunction(); 3103 Local<Function> GetFunction();
2975 3104
2976 /** 3105 /**
2977 * Set the call-handler callback for a FunctionTemplate. This 3106 * Set the call-handler callback for a FunctionTemplate. This
2978 * callback is called whenever the function created from this 3107 * callback is called whenever the function created from this
2979 * FunctionTemplate is called. 3108 * FunctionTemplate is called.
2980 */ 3109 */
3110 // TODO(dcarney): deprecate
2981 void SetCallHandler(InvocationCallback callback, 3111 void SetCallHandler(InvocationCallback callback,
2982 Handle<Value> data = Handle<Value>()); 3112 Handle<Value> data = Handle<Value>());
3113 void SetCallHandler(FunctionCallback callback,
3114 Handle<Value> data = Handle<Value>());
2983 3115
2984 /** Set the predefined length property for the FunctionTemplate. */ 3116 /** Set the predefined length property for the FunctionTemplate. */
2985 void SetLength(int length); 3117 void SetLength(int length);
2986 3118
2987 /** Get the InstanceTemplate. */ 3119 /** Get the InstanceTemplate. */
2988 Local<ObjectTemplate> InstanceTemplate(); 3120 Local<ObjectTemplate> InstanceTemplate();
2989 3121
2990 /** Causes the function template to inherit from a parent function template.*/ 3122 /** Causes the function template to inherit from a parent function template.*/
2991 void Inherit(Handle<FunctionTemplate> parent); 3123 void Inherit(Handle<FunctionTemplate> parent);
2992 3124
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 void ReadOnlyPrototype(); 3156 void ReadOnlyPrototype();
3025 3157
3026 /** 3158 /**
3027 * Returns true if the given object is an instance of this function 3159 * Returns true if the given object is an instance of this function
3028 * template. 3160 * template.
3029 */ 3161 */
3030 bool HasInstance(Handle<Value> object); 3162 bool HasInstance(Handle<Value> object);
3031 3163
3032 private: 3164 private:
3033 FunctionTemplate(); 3165 FunctionTemplate();
3034 void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
3035 NamedPropertySetter setter,
3036 NamedPropertyQuery query,
3037 NamedPropertyDeleter remover,
3038 NamedPropertyEnumerator enumerator,
3039 Handle<Value> data);
3040 void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
3041 IndexedPropertySetter setter,
3042 IndexedPropertyQuery query,
3043 IndexedPropertyDeleter remover,
3044 IndexedPropertyEnumerator enumerator,
3045 Handle<Value> data);
3046 void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
3047 Handle<Value> data);
3048
3049 friend class Context; 3166 friend class Context;
3050 friend class ObjectTemplate; 3167 friend class ObjectTemplate;
3051 }; 3168 };
3052 3169
3053 3170
3054 /** 3171 /**
3055 * An ObjectTemplate is used to create objects at runtime. 3172 * An ObjectTemplate is used to create objects at runtime.
3056 * 3173 *
3057 * Properties added to an ObjectTemplate are added to each object 3174 * Properties added to an ObjectTemplate are added to each object
3058 * created from the ObjectTemplate. 3175 * created from the ObjectTemplate.
(...skipping 28 matching lines...) Expand all
3087 * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all 3204 * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
3088 * cross-context access. 3205 * cross-context access.
3089 * \param attribute The attributes of the property for which an accessor 3206 * \param attribute The attributes of the property for which an accessor
3090 * is added. 3207 * is added.
3091 * \param signature The signature describes valid receivers for the accessor 3208 * \param signature The signature describes valid receivers for the accessor
3092 * and is used to perform implicit instance checks against them. If the 3209 * and is used to perform implicit instance checks against them. If the
3093 * receiver is incompatible (i.e. is not an instance of the constructor as 3210 * receiver is incompatible (i.e. is not an instance of the constructor as
3094 * defined by FunctionTemplate::HasInstance()), an implicit TypeError is 3211 * defined by FunctionTemplate::HasInstance()), an implicit TypeError is
3095 * thrown and no callback is invoked. 3212 * thrown and no callback is invoked.
3096 */ 3213 */
3214 // TODO(dcarney): deprecate
3097 void SetAccessor(Handle<String> name, 3215 void SetAccessor(Handle<String> name,
3098 AccessorGetter getter, 3216 AccessorGetter getter,
3099 AccessorSetter setter = 0, 3217 AccessorSetter setter = 0,
3100 Handle<Value> data = Handle<Value>(), 3218 Handle<Value> data = Handle<Value>(),
3101 AccessControl settings = DEFAULT, 3219 AccessControl settings = DEFAULT,
3102 PropertyAttribute attribute = None, 3220 PropertyAttribute attribute = None,
3103 Handle<AccessorSignature> signature = 3221 Handle<AccessorSignature> signature =
3104 Handle<AccessorSignature>()); 3222 Handle<AccessorSignature>());
3223 void SetAccessor(Handle<String> name,
3224 AccessorGetterCallback getter,
3225 AccessorSetterCallback setter = 0,
3226 Handle<Value> data = Handle<Value>(),
3227 AccessControl settings = DEFAULT,
3228 PropertyAttribute attribute = None,
3229 Handle<AccessorSignature> signature =
3230 Handle<AccessorSignature>());
3105 3231
3106 // This function is not yet stable and should not be used at this time. 3232 // This function is not yet stable and should not be used at this time.
3107 bool SetAccessor(Handle<String> name, 3233 bool SetAccessor(Handle<String> name,
3108 Handle<DeclaredAccessorDescriptor> descriptor, 3234 Handle<DeclaredAccessorDescriptor> descriptor,
3109 AccessControl settings = DEFAULT, 3235 AccessControl settings = DEFAULT,
3110 PropertyAttribute attribute = None, 3236 PropertyAttribute attribute = None,
3111 Handle<AccessorSignature> signature = 3237 Handle<AccessorSignature> signature =
3112 Handle<AccessorSignature>()); 3238 Handle<AccessorSignature>());
3113 3239
3114 /** 3240 /**
3115 * Sets a named property handler on the object template. 3241 * Sets a named property handler on the object template.
3116 * 3242 *
3117 * Whenever a named property is accessed on objects created from 3243 * Whenever a named property is accessed on objects created from
3118 * this object template, the provided callback is invoked instead of 3244 * this object template, the provided callback is invoked instead of
3119 * accessing the property directly on the JavaScript object. 3245 * accessing the property directly on the JavaScript object.
3120 * 3246 *
3121 * \param getter The callback to invoke when getting a property. 3247 * \param getter The callback to invoke when getting a property.
3122 * \param setter The callback to invoke when setting a property. 3248 * \param setter The callback to invoke when setting a property.
3123 * \param query The callback to invoke to check if a property is present, 3249 * \param query The callback to invoke to check if a property is present,
3124 * and if present, get its attributes. 3250 * and if present, get its attributes.
3125 * \param deleter The callback to invoke when deleting a property. 3251 * \param deleter The callback to invoke when deleting a property.
3126 * \param enumerator The callback to invoke to enumerate all the named 3252 * \param enumerator The callback to invoke to enumerate all the named
3127 * properties of an object. 3253 * properties of an object.
3128 * \param data A piece of data that will be passed to the callbacks 3254 * \param data A piece of data that will be passed to the callbacks
3129 * whenever they are invoked. 3255 * whenever they are invoked.
3130 */ 3256 */
3257 // TODO(dcarney): deprecate
3131 void SetNamedPropertyHandler(NamedPropertyGetter getter, 3258 void SetNamedPropertyHandler(NamedPropertyGetter getter,
3132 NamedPropertySetter setter = 0, 3259 NamedPropertySetter setter = 0,
3133 NamedPropertyQuery query = 0, 3260 NamedPropertyQuery query = 0,
3134 NamedPropertyDeleter deleter = 0, 3261 NamedPropertyDeleter deleter = 0,
3135 NamedPropertyEnumerator enumerator = 0, 3262 NamedPropertyEnumerator enumerator = 0,
3136 Handle<Value> data = Handle<Value>()); 3263 Handle<Value> data = Handle<Value>());
3264 void SetNamedPropertyHandler(
3265 NamedPropertyGetterCallback getter,
3266 NamedPropertySetterCallback setter = 0,
3267 NamedPropertyQueryCallback query = 0,
3268 NamedPropertyDeleterCallback deleter = 0,
3269 NamedPropertyEnumeratorCallback enumerator = 0,
3270 Handle<Value> data = Handle<Value>());
3137 3271
3138 /** 3272 /**
3139 * Sets an indexed property handler on the object template. 3273 * Sets an indexed property handler on the object template.
3140 * 3274 *
3141 * Whenever an indexed property is accessed on objects created from 3275 * Whenever an indexed property is accessed on objects created from
3142 * this object template, the provided callback is invoked instead of 3276 * this object template, the provided callback is invoked instead of
3143 * accessing the property directly on the JavaScript object. 3277 * accessing the property directly on the JavaScript object.
3144 * 3278 *
3145 * \param getter The callback to invoke when getting a property. 3279 * \param getter The callback to invoke when getting a property.
3146 * \param setter The callback to invoke when setting a property. 3280 * \param setter The callback to invoke when setting a property.
3147 * \param query The callback to invoke to check if an object has a property. 3281 * \param query The callback to invoke to check if an object has a property.
3148 * \param deleter The callback to invoke when deleting a property. 3282 * \param deleter The callback to invoke when deleting a property.
3149 * \param enumerator The callback to invoke to enumerate all the indexed 3283 * \param enumerator The callback to invoke to enumerate all the indexed
3150 * properties of an object. 3284 * properties of an object.
3151 * \param data A piece of data that will be passed to the callbacks 3285 * \param data A piece of data that will be passed to the callbacks
3152 * whenever they are invoked. 3286 * whenever they are invoked.
3153 */ 3287 */
3288 // TODO(dcarney): deprecate
3154 void SetIndexedPropertyHandler(IndexedPropertyGetter getter, 3289 void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
3155 IndexedPropertySetter setter = 0, 3290 IndexedPropertySetter setter = 0,
3156 IndexedPropertyQuery query = 0, 3291 IndexedPropertyQuery query = 0,
3157 IndexedPropertyDeleter deleter = 0, 3292 IndexedPropertyDeleter deleter = 0,
3158 IndexedPropertyEnumerator enumerator = 0, 3293 IndexedPropertyEnumerator enumerator = 0,
3159 Handle<Value> data = Handle<Value>()); 3294 Handle<Value> data = Handle<Value>());
3295 void SetIndexedPropertyHandler(
3296 IndexedPropertyGetterCallback getter,
3297 IndexedPropertySetterCallback setter = 0,
3298 IndexedPropertyQueryCallback query = 0,
3299 IndexedPropertyDeleterCallback deleter = 0,
3300 IndexedPropertyEnumeratorCallback enumerator = 0,
3301 Handle<Value> data = Handle<Value>());
3160 3302
3161 /** 3303 /**
3162 * Sets the callback to be used when calling instances created from 3304 * Sets the callback to be used when calling instances created from
3163 * this template as a function. If no callback is set, instances 3305 * this template as a function. If no callback is set, instances
3164 * behave like normal JavaScript objects that cannot be called as a 3306 * behave like normal JavaScript objects that cannot be called as a
3165 * function. 3307 * function.
3166 */ 3308 */
3309 // TODO(dcarney): deprecate
3167 void SetCallAsFunctionHandler(InvocationCallback callback, 3310 void SetCallAsFunctionHandler(InvocationCallback callback,
3168 Handle<Value> data = Handle<Value>()); 3311 Handle<Value> data = Handle<Value>());
3312 void SetCallAsFunctionHandler(FunctionCallback callback,
3313 Handle<Value> data = Handle<Value>());
3169 3314
3170 /** 3315 /**
3171 * Mark object instances of the template as undetectable. 3316 * Mark object instances of the template as undetectable.
3172 * 3317 *
3173 * In many ways, undetectable objects behave as though they are not 3318 * In many ways, undetectable objects behave as though they are not
3174 * there. They behave like 'undefined' in conditionals and when 3319 * there. They behave like 'undefined' in conditionals and when
3175 * printed. However, properties can be accessed and called as on 3320 * printed. However, properties can be accessed and called as on
3176 * normal objects. 3321 * normal objects.
3177 */ 3322 */
3178 void MarkAsUndetectable(); 3323 void MarkAsUndetectable();
(...skipping 2269 matching lines...) Expand 10 before | Expand all | Expand 10 after
5448 template <class T> 5593 template <class T>
5449 uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { 5594 uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const {
5450 typedef internal::Internals I; 5595 typedef internal::Internals I;
5451 if (this->IsEmpty()) return 0; 5596 if (this->IsEmpty()) return 0;
5452 if (!I::IsInitialized(isolate)) return 0; 5597 if (!I::IsInitialized(isolate)) return 0;
5453 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); 5598 internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
5454 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; 5599 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
5455 return *reinterpret_cast<uint16_t*>(addr); 5600 return *reinterpret_cast<uint16_t*>(addr);
5456 } 5601 }
5457 5602
5458 Arguments::Arguments(internal::Object** implicit_args, 5603 template<typename T>
5459 internal::Object** values, int length, 5604 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
5460 bool is_construct_call) 5605
5606 template<typename T>
5607 void ReturnValue<T>::Set(const Persistent<T>& handle) {
5608 *value_ = *reinterpret_cast<internal::Object**>(*handle);
5609 }
5610
5611 template<typename T>
5612 void ReturnValue<T>::Set(const Handle<T> handle) {
5613 *value_ = *reinterpret_cast<internal::Object**>(*handle);
5614 }
5615
5616 template<typename T>
5617 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
5618 internal::Object** values,
5619 int length,
5620 bool is_construct_call)
5461 : implicit_args_(implicit_args), 5621 : implicit_args_(implicit_args),
5462 values_(values), 5622 values_(values),
5463 length_(length), 5623 length_(length),
5464 is_construct_call_(is_construct_call) { } 5624 is_construct_call_(is_construct_call) { }
5465 5625
5466 5626
5467 Local<Value> Arguments::operator[](int i) const { 5627 Arguments::Arguments(internal::Object** args,
5628 internal::Object** values,
5629 int length,
5630 bool is_construct_call)
5631 : FunctionCallbackInfo<Value>(args, values, length, is_construct_call) { }
5632
5633
5634 template<typename T>
5635 Local<Value> FunctionCallbackInfo<T>::operator[](int i) const {
5468 if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); 5636 if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
5469 return Local<Value>(reinterpret_cast<Value*>(values_ - i)); 5637 return Local<Value>(reinterpret_cast<Value*>(values_ - i));
5470 } 5638 }
5471 5639
5472 5640
5473 Local<Function> Arguments::Callee() const { 5641 template<typename T>
5642 Local<Function> FunctionCallbackInfo<T>::Callee() const {
5474 return Local<Function>(reinterpret_cast<Function*>( 5643 return Local<Function>(reinterpret_cast<Function*>(
5475 &implicit_args_[kCalleeIndex])); 5644 &implicit_args_[kCalleeIndex]));
5476 } 5645 }
5477 5646
5478 5647
5479 Local<Object> Arguments::This() const { 5648 template<typename T>
5649 Local<Object> FunctionCallbackInfo<T>::This() const {
5480 return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); 5650 return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
5481 } 5651 }
5482 5652
5483 5653
5484 Local<Object> Arguments::Holder() const { 5654 template<typename T>
5655 Local<Object> FunctionCallbackInfo<T>::Holder() const {
5485 return Local<Object>(reinterpret_cast<Object*>( 5656 return Local<Object>(reinterpret_cast<Object*>(
5486 &implicit_args_[kHolderIndex])); 5657 &implicit_args_[kHolderIndex]));
5487 } 5658 }
5488 5659
5489 5660
5490 Local<Value> Arguments::Data() const { 5661 template<typename T>
5662 Local<Value> FunctionCallbackInfo<T>::Data() const {
5491 return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex])); 5663 return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
5492 } 5664 }
5493 5665
5494 5666
5495 Isolate* Arguments::GetIsolate() const { 5667 template<typename T>
5668 Isolate* FunctionCallbackInfo<T>::GetIsolate() const {
5496 return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]); 5669 return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
5497 } 5670 }
5498 5671
5499 5672
5500 bool Arguments::IsConstructCall() const { 5673 template<typename T>
5674 ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const {
5675 return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
5676 }
5677
5678
5679 template<typename T>
5680 bool FunctionCallbackInfo<T>::IsConstructCall() const {
5501 return is_construct_call_; 5681 return is_construct_call_;
5502 } 5682 }
5503 5683
5504 5684
5505 int Arguments::Length() const { 5685 template<typename T>
5686 int FunctionCallbackInfo<T>::Length() const {
5506 return length_; 5687 return length_;
5507 } 5688 }
5508 5689
5509 5690
5510 template <class T> 5691 template <class T>
5511 Local<T> HandleScope::Close(Handle<T> value) { 5692 Local<T> HandleScope::Close(Handle<T> value) {
5512 internal::Object** before = reinterpret_cast<internal::Object**>(*value); 5693 internal::Object** before = reinterpret_cast<internal::Object**>(*value);
5513 internal::Object** after = RawClose(before); 5694 internal::Object** after = RawClose(before);
5514 return Local<T>(reinterpret_cast<T*>(after)); 5695 return Local<T>(reinterpret_cast<T*>(after));
5515 } 5696 }
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
5884 6065
5885 6066
5886 External* External::Cast(v8::Value* value) { 6067 External* External::Cast(v8::Value* value) {
5887 #ifdef V8_ENABLE_CHECKS 6068 #ifdef V8_ENABLE_CHECKS
5888 CheckCast(value); 6069 CheckCast(value);
5889 #endif 6070 #endif
5890 return static_cast<External*>(value); 6071 return static_cast<External*>(value);
5891 } 6072 }
5892 6073
5893 6074
5894 Isolate* AccessorInfo::GetIsolate() const { 6075 template<typename T>
5895 return *reinterpret_cast<Isolate**>(&args_[-3]); 6076 Isolate* PropertyCallbackInfo<T>::GetIsolate() const {
6077 return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
5896 } 6078 }
5897 6079
5898 6080
5899 Local<Value> AccessorInfo::Data() const { 6081 template<typename T>
5900 return Local<Value>(reinterpret_cast<Value*>(&args_[-2])); 6082 Local<Value> PropertyCallbackInfo<T>::Data() const {
6083 return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
5901 } 6084 }
5902 6085
5903 6086
5904 Local<Object> AccessorInfo::This() const { 6087 template<typename T>
5905 return Local<Object>(reinterpret_cast<Object*>(&args_[0])); 6088 Local<Object> PropertyCallbackInfo<T>::This() const {
6089 return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
5906 } 6090 }
5907 6091
5908 6092
5909 Local<Object> AccessorInfo::Holder() const { 6093 template<typename T>
5910 return Local<Object>(reinterpret_cast<Object*>(&args_[-1])); 6094 Local<Object> PropertyCallbackInfo<T>::Holder() const {
6095 return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
5911 } 6096 }
5912 6097
5913 6098
6099 template<typename T>
6100 ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const {
6101 return ReturnValue<T>(&args_[kReturnValueIndex]);
6102 }
6103
6104
5914 Handle<Primitive> Undefined(Isolate* isolate) { 6105 Handle<Primitive> Undefined(Isolate* isolate) {
5915 typedef internal::Object* S; 6106 typedef internal::Object* S;
5916 typedef internal::Internals I; 6107 typedef internal::Internals I;
5917 if (!I::IsInitialized(isolate)) return Undefined(); 6108 if (!I::IsInitialized(isolate)) return Undefined();
5918 S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); 6109 S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
5919 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); 6110 return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
5920 } 6111 }
5921 6112
5922 6113
5923 Handle<Primitive> Null(Isolate* isolate) { 6114 Handle<Primitive> Null(Isolate* isolate) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
5994 6185
5995 6186
5996 } // namespace v8 6187 } // namespace v8
5997 6188
5998 6189
5999 #undef V8EXPORT 6190 #undef V8EXPORT
6000 #undef TYPE_CHECK 6191 #undef TYPE_CHECK
6001 6192
6002 6193
6003 #endif // V8_H_ 6194 #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