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

Unified 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: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 1e4d2f927d930158fd832f88b6b3b884a074e2ff..398ee536b60de00da59f12ca37b02757e28eb5e1 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -125,6 +125,7 @@ class FunctionTemplate;
class ObjectTemplate;
class Data;
class AccessorInfo;
+template<typename T> class PropertyCallbackInfo;
class StackTrace;
class StackFrame;
class Isolate;
@@ -1527,11 +1528,18 @@ enum ExternalArrayType {
*/
typedef Handle<Value> (*AccessorGetter)(Local<String> property,
const AccessorInfo& info);
+typedef void (*AccessorGetterCallback)(
+ Local<String> property,
+ const PropertyCallbackInfo<Value>& info);
typedef void (*AccessorSetter)(Local<String> property,
Local<Value> value,
const AccessorInfo& info);
+typedef void (*AccessorSetterCallback)(
+ Local<String> property,
+ Local<Value> value,
+ const PropertyCallbackInfo<void>& info);
/**
@@ -1609,6 +1617,12 @@ class V8EXPORT Object : public Value {
Handle<Value> data = Handle<Value>(),
AccessControl settings = DEFAULT,
PropertyAttribute attribute = None);
+ bool SetAccessor(Handle<String> name,
+ AccessorGetterCallback getter,
+ AccessorSetterCallback setter = 0,
+ Handle<Value> data = Handle<Value>(),
+ AccessControl settings = DEFAULT,
+ PropertyAttribute attribute = None);
// This function is not yet stable and should not be used at this time.
bool SetAccessor(Handle<String> name,
@@ -2060,13 +2074,25 @@ class V8EXPORT Template : public Data {
};
+template<typename T>
+class V8EXPORT ReturnHandler {
Michael Starzinger 2013/03/18 13:57:05 As discussed offline: Let's name this class Return
+ public:
+ V8_INLINE(explicit ReturnHandler(T* slot)) : slot_(slot) {}
+ V8_INLINE(void SetReturnValue(Persistent<T> handle)) { slot_ = *handle; }
Michael Starzinger 2013/03/18 13:57:05 As discussed offline: Let's name these setters jus
+ V8_INLINE(void SetReturnValue(Handle<T> handle)) { slot_ = *handle; }
+ private:
+ T* slot_;
+};
+
+
/**
* The argument information given to function call callbacks. This
* class provides access to information about the context of the call,
* including the receiver, the number and values of arguments, and
* the holder of the function.
*/
-class V8EXPORT Arguments {
+template<typename T>
+class V8EXPORT FunctionCallbackInfo {
public:
V8_INLINE(int Length() const);
V8_INLINE(Local<Value> operator[](int i) const);
@@ -2076,15 +2102,17 @@ class V8EXPORT Arguments {
V8_INLINE(bool IsConstructCall() const);
V8_INLINE(Local<Value> Data() const);
V8_INLINE(Isolate* GetIsolate() const);
+ V8_INLINE(ReturnHandler<T> GetReturnHandler() const);
- private:
+ protected:
static const int kIsolateIndex = 0;
static const int kDataIndex = -1;
static const int kCalleeIndex = -2;
static const int kHolderIndex = -3;
+ static const int kReturnValueIndex = -4;
friend class ImplementationUtilities;
- V8_INLINE(Arguments(internal::Object** implicit_args,
+ V8_INLINE(FunctionCallbackInfo(internal::Object** implicit_args,
internal::Object** values,
int length,
bool is_construct_call));
@@ -2095,25 +2123,52 @@ class V8EXPORT Arguments {
};
+class V8EXPORT Arguments : public FunctionCallbackInfo<Value> {
+ private:
+ friend class ImplementationUtilities;
+ V8_INLINE(Arguments(internal::Object** implicit_args,
+ internal::Object** values,
+ int length,
+ bool is_construct_call));
+};
+
+
/**
- * The information passed to an accessor callback about the context
+ * The information passed to a property callback about the context
* of the property access.
*/
-class V8EXPORT AccessorInfo {
+template<typename T>
+class V8EXPORT PropertyCallbackInfo {
public:
- V8_INLINE(AccessorInfo(internal::Object** args))
+ V8_INLINE(PropertyCallbackInfo(internal::Object** args))
: args_(args) { }
V8_INLINE(Isolate* GetIsolate() const);
V8_INLINE(Local<Value> Data() const);
V8_INLINE(Local<Object> This() const);
V8_INLINE(Local<Object> Holder() const);
+ V8_INLINE(ReturnHandler<T> GetReturnHandler() const);
private:
+ static const int kIsolateIndex = -3;
+ static const int kDataIndex = -2;
+ static const int kThisIndex = 0;
+ static const int kHolderIndex = -1;
+ static const int kReturnValueIndex = -4;
+
internal::Object** args_;
};
+class V8EXPORT AccessorInfo : public PropertyCallbackInfo<Value> {
+ public:
+ V8_INLINE(AccessorInfo(internal::Object** args))
+ : PropertyCallbackInfo<Value>(args) { }
+};
+
+
typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
+typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
+
/**
* NamedProperty[Getter|Setter] are used as interceptors on object.
@@ -2121,6 +2176,9 @@ typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
*/
typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
const AccessorInfo& info);
+typedef void (*NamedPropertyGetterCallback)(
+ Local<String> property,
+ const PropertyCallbackInfo<Value>& info);
/**
@@ -2130,6 +2188,11 @@ typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
Local<Value> value,
const AccessorInfo& info);
+typedef void (*NamedPropertySetterCallback)(
+ Local<String> property,
+ Local<Value> value,
+ const PropertyCallbackInfo<Value>& info);
+
/**
* Returns a non-empty handle if the interceptor intercepts the request.
@@ -2138,6 +2201,9 @@ typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
*/
typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
const AccessorInfo& info);
+typedef void (*NamedPropertyQueryCallback)(
+ Local<String> property,
+ const PropertyCallbackInfo<Integer>& info);
/**
@@ -2147,12 +2213,18 @@ typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
*/
typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
const AccessorInfo& info);
+typedef void (*NamedPropertyDeleterCallback)(
+ Local<String> property,
+ const PropertyCallbackInfo<Boolean>& info);
+
/**
* Returns an array containing the names of the properties the named
* property getter intercepts.
*/
typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
+typedef void (*NamedPropertyEnumeratorCallback)(
+ const PropertyCallbackInfo<Array>& info);
/**
@@ -2161,6 +2233,9 @@ typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
*/
typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
const AccessorInfo& info);
+typedef void (*IndexedPropertyGetterCallback)(
+ uint32_t index,
+ const PropertyCallbackInfo<Value>& info);
/**
@@ -2170,6 +2245,10 @@ typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
Local<Value> value,
const AccessorInfo& info);
+typedef void (*IndexedPropertySetterCallback)(
+ uint32_t index,
+ Local<Value> value,
+ const PropertyCallbackInfo<Value>& info);
/**
@@ -2178,6 +2257,10 @@ typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
*/
typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
const AccessorInfo& info);
+typedef void (*IndexedPropertyQueryCallback)(
+ uint32_t index,
+ const PropertyCallbackInfo<Integer>& info);
+
/**
* Returns a non-empty handle if the deleter intercepts the request.
@@ -2186,12 +2269,18 @@ typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
*/
typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
const AccessorInfo& info);
+typedef void (*IndexedPropertyDeleterCallback)(
+ uint32_t index,
+ const PropertyCallbackInfo<Boolean>& info);
+
/**
* Returns an array containing the indices of the properties the
* indexed property getter intercepts.
*/
typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
+typedef void (*IndexedPropertyEnumeratorCallback)(
+ const PropertyCallbackInfo<Array>& info);
/**
@@ -2326,6 +2415,12 @@ class V8EXPORT FunctionTemplate : public Template {
Handle<Value> data = Handle<Value>(),
Handle<Signature> signature = Handle<Signature>(),
int length = 0);
+ static Local<FunctionTemplate> New(
+ FunctionCallback callback, // TODO(dcarney): add back default param.
+ Handle<Value> data = Handle<Value>(),
+ Handle<Signature> signature = Handle<Signature>(),
+ int length = 0);
+
/** Returns the unique function instance in the current execution context.*/
Local<Function> GetFunction();
@@ -2336,6 +2431,8 @@ class V8EXPORT FunctionTemplate : public Template {
*/
void SetCallHandler(InvocationCallback callback,
Handle<Value> data = Handle<Value>());
+ void SetCallHandler(FunctionCallback callback,
+ Handle<Value> data = Handle<Value>());
/** Set the predefined length property for the FunctionTemplate. */
void SetLength(int length);
@@ -2458,6 +2555,14 @@ class V8EXPORT ObjectTemplate : public Template {
PropertyAttribute attribute = None,
Handle<AccessorSignature> signature =
Handle<AccessorSignature>());
+ void SetAccessor(Handle<String> name,
+ AccessorGetterCallback getter,
+ AccessorSetterCallback setter = 0,
+ Handle<Value> data = Handle<Value>(),
+ AccessControl settings = DEFAULT,
+ PropertyAttribute attribute = None,
+ Handle<AccessorSignature> signature =
+ Handle<AccessorSignature>());
// This function is not yet stable and should not be used at this time.
bool SetAccessor(Handle<String> name,
@@ -2490,6 +2595,13 @@ class V8EXPORT ObjectTemplate : public Template {
NamedPropertyDeleter deleter = 0,
NamedPropertyEnumerator enumerator = 0,
Handle<Value> data = Handle<Value>());
+ void SetNamedPropertyHandler(
+ NamedPropertyGetterCallback getter,
+ NamedPropertySetterCallback setter = 0,
+ NamedPropertyQueryCallback query = 0,
+ NamedPropertyDeleterCallback deleter = 0,
+ NamedPropertyEnumeratorCallback enumerator = 0,
+ Handle<Value> data = Handle<Value>());
/**
* Sets an indexed property handler on the object template.
@@ -2513,6 +2625,13 @@ class V8EXPORT ObjectTemplate : public Template {
IndexedPropertyDeleter deleter = 0,
IndexedPropertyEnumerator enumerator = 0,
Handle<Value> data = Handle<Value>());
+ void SetIndexedPropertyHandler(
+ IndexedPropertyGetterCallback getter,
+ IndexedPropertySetterCallback setter = 0,
+ IndexedPropertyQueryCallback query = 0,
+ IndexedPropertyDeleterCallback deleter = 0,
+ IndexedPropertyEnumeratorCallback enumerator = 0,
+ Handle<Value> data = Handle<Value>());
/**
* Sets the callback to be used when calling instances created from
@@ -2522,6 +2641,8 @@ class V8EXPORT ObjectTemplate : public Template {
*/
void SetCallAsFunctionHandler(InvocationCallback callback,
Handle<Value> data = Handle<Value>());
+ void SetCallAsFunctionHandler(FunctionCallback callback,
+ Handle<Value> data = Handle<Value>());
/**
* Mark object instances of the template as undetectable.
@@ -4608,54 +4729,78 @@ uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const {
return *reinterpret_cast<uint16_t*>(addr);
}
-Arguments::Arguments(internal::Object** implicit_args,
- internal::Object** values, int length,
- bool is_construct_call)
+template<typename T>
+FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
+ internal::Object** values,
+ int length,
+ bool is_construct_call)
: implicit_args_(implicit_args),
values_(values),
length_(length),
is_construct_call_(is_construct_call) { }
-Local<Value> Arguments::operator[](int i) const {
+Arguments::Arguments(internal::Object** args,
+ internal::Object** values,
+ int length,
+ bool is_construct_call)
+ : FunctionCallbackInfo<Value>(args, values, length, is_construct_call) { }
+
+
+template<typename T>
+Local<Value> FunctionCallbackInfo<T>::operator[](int i) const {
if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
return Local<Value>(reinterpret_cast<Value*>(values_ - i));
}
-Local<Function> Arguments::Callee() const {
+template<typename T>
+Local<Function> FunctionCallbackInfo<T>::Callee() const {
return Local<Function>(reinterpret_cast<Function*>(
&implicit_args_[kCalleeIndex]));
}
-Local<Object> Arguments::This() const {
+template<typename T>
+Local<Object> FunctionCallbackInfo<T>::This() const {
return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
}
-Local<Object> Arguments::Holder() const {
+template<typename T>
+Local<Object> FunctionCallbackInfo<T>::Holder() const {
return Local<Object>(reinterpret_cast<Object*>(
&implicit_args_[kHolderIndex]));
}
-Local<Value> Arguments::Data() const {
+template<typename T>
+Local<Value> FunctionCallbackInfo<T>::Data() const {
return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
}
-Isolate* Arguments::GetIsolate() const {
+template<typename T>
+Isolate* FunctionCallbackInfo<T>::GetIsolate() const {
return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
}
-bool Arguments::IsConstructCall() const {
+template<typename T>
+ReturnHandler<T> FunctionCallbackInfo<T>::GetReturnHandler() const {
+ return ReturnHandler<T>(
+ reinterpret_cast<T*>(&implicit_args_[kReturnValueIndex]));
+}
+
+
+template<typename T>
+bool FunctionCallbackInfo<T>::IsConstructCall() const {
return is_construct_call_;
}
-int Arguments::Length() const {
+template<typename T>
+int FunctionCallbackInfo<T>::Length() const {
return length_;
}
@@ -4922,23 +5067,34 @@ External* External::Cast(v8::Value* value) {
}
-Isolate* AccessorInfo::GetIsolate() const {
- return *reinterpret_cast<Isolate**>(&args_[-3]);
+template<typename T>
+Isolate* PropertyCallbackInfo<T>::GetIsolate() const {
+ return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
+}
+
+
+template<typename T>
+Local<Value> PropertyCallbackInfo<T>::Data() const {
+ return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
}
-Local<Value> AccessorInfo::Data() const {
- return Local<Value>(reinterpret_cast<Value*>(&args_[-2]));
+template<typename T>
+Local<Object> PropertyCallbackInfo<T>::This() const {
+ return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
}
-Local<Object> AccessorInfo::This() const {
- return Local<Object>(reinterpret_cast<Object*>(&args_[0]));
+template<typename T>
+Local<Object> PropertyCallbackInfo<T>::Holder() const {
+ return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
}
-Local<Object> AccessorInfo::Holder() const {
- return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
+template<typename T>
+ReturnHandler<T> PropertyCallbackInfo<T>::GetReturnHandler() const {
+ return ReturnHandler<T>(
+ reinterpret_cast<T*>(&args_[kReturnValueIndex]));
}
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698