Eventually indexed property query callbacks will return attributes
(as an integer) or an empty handle if property is not intercepted.
To gradually migrate to this new API, USE_NEW_QUERY_CALLBACK
macro would control if old or new style API is used.
So the migration plan is:
1) introduce new API which should be explictily enabled;
2) switch to new API defining USE_NEW_QUERY_CALLBACK before
include of <v8.h> (that would require changes to client code as well)
3) remove old API from v8
4) remove #define USE_NEW_QUERY_CALLBACK from clients.
BUG=http://code.google.com/p/v8/issues/detail?id=816
Review URL: http://codereview.chromium.org/3101001
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5228
ce2b1a6d-e550-0410-aec6-
3dcde31c8c00
/**
* Returns a non-empty handle if the interceptor intercepts the request.
- * The result is true if the property exists and false otherwise.
+ * The result is true if either a boolean (true if property exists and false
+ * otherwise) or an integer encoding property attributes.
*/
+#ifdef USE_NEW_QUERY_CALLBACKS
+typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
+ const AccessorInfo& info);
+#else
typedef Handle<Boolean> (*IndexedPropertyQuery)(uint32_t index,
const AccessorInfo& info);
+#endif
+
+typedef Handle<Value> (*IndexedPropertyQueryImpl)(uint32_t index,
+ const AccessorInfo& info);
/**
* Returns a non-empty handle if the deleter intercepts the request.
IndexedPropertyQuery query,
IndexedPropertyDeleter remover,
IndexedPropertyEnumerator enumerator,
- Handle<Value> data);
+ Handle<Value> data) {
+ IndexedPropertyQueryImpl casted =
+ reinterpret_cast<IndexedPropertyQueryImpl>(query);
+ SetIndexedInstancePropertyHandlerImpl(getter,
+ setter,
+ casted,
+ remover,
+ enumerator,
+ data);
+ }
+ void SetIndexedInstancePropertyHandlerImpl(
+ IndexedPropertyGetter getter,
+ IndexedPropertySetter setter,
+ IndexedPropertyQueryImpl query,
+ IndexedPropertyDeleter remover,
+ IndexedPropertyEnumerator enumerator,
+ Handle<Value> data);
void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
Handle<Value> data);
IndexedPropertyQuery query = 0,
IndexedPropertyDeleter deleter = 0,
IndexedPropertyEnumerator enumerator = 0,
- Handle<Value> data = Handle<Value>());
+ Handle<Value> data = Handle<Value>()) {
+ IndexedPropertyQueryImpl casted =
+ reinterpret_cast<IndexedPropertyQueryImpl>(query);
+ SetIndexedPropertyHandlerImpl(getter,
+ setter,
+ casted,
+ deleter,
+ enumerator,
+ data);
+ }
+ private:
+ void SetIndexedPropertyHandlerImpl(IndexedPropertyGetter getter,
+ IndexedPropertySetter setter,
+ IndexedPropertyQueryImpl query,
+ IndexedPropertyDeleter deleter,
+ IndexedPropertyEnumerator enumerator,
+ Handle<Value> data);
+ public:
+
/**
* Sets the callback to be used when calling instances created from
* this template as a function. If no callback is set, instances
}
-void FunctionTemplate::SetIndexedInstancePropertyHandler(
+void FunctionTemplate::SetIndexedInstancePropertyHandlerImpl(
IndexedPropertyGetter getter,
IndexedPropertySetter setter,
- IndexedPropertyQuery query,
+ IndexedPropertyQueryImpl query,
IndexedPropertyDeleter remover,
IndexedPropertyEnumerator enumerator,
Handle<Value> data) {
}
-void ObjectTemplate::SetIndexedPropertyHandler(
+void ObjectTemplate::SetIndexedPropertyHandlerImpl(
IndexedPropertyGetter getter,
IndexedPropertySetter setter,
- IndexedPropertyQuery query,
+ IndexedPropertyQueryImpl query,
IndexedPropertyDeleter remover,
IndexedPropertyEnumerator enumerator,
Handle<Value> data) {
i::FunctionTemplateInfo* constructor =
i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
i::Handle<i::FunctionTemplateInfo> cons(constructor);
- Utils::ToLocal(cons)->SetIndexedInstancePropertyHandler(getter,
- setter,
- query,
- remover,
- enumerator,
- data);
+ Utils::ToLocal(cons)->SetIndexedInstancePropertyHandlerImpl(getter,
+ setter,
+ query,
+ remover,
+ enumerator,
+ data);
}
CustomArguments args(interceptor->data(), receiver, this);
v8::AccessorInfo info(args.end());
if (!interceptor->query()->IsUndefined()) {
- v8::IndexedPropertyQuery query =
- v8::ToCData<v8::IndexedPropertyQuery>(interceptor->query());
+ v8::IndexedPropertyQueryImpl query =
+ v8::ToCData<v8::IndexedPropertyQueryImpl>(interceptor->query());
LOG(ApiIndexedPropertyAccess("interceptor-indexed-has", this, index));
- v8::Handle<v8::Boolean> result;
+ v8::Handle<v8::Value> result;
{
// Leaving JavaScript.
VMState state(EXTERNAL);
result = query(index, info);
}
- if (!result.IsEmpty()) return result->IsTrue();
+ if (!result.IsEmpty()) {
+ // IsBoolean check would be removed when transition to new API is over.
+ if (result->IsBoolean()) {
+ return result->IsTrue() ? true : false;
+ } else {
+ ASSERT(result->IsInt32());
+ return true; // absence of property is signaled by empty handle.
+ }
+ }
} else if (!interceptor->getter()->IsUndefined()) {
v8::IndexedPropertyGetter getter =
v8::ToCData<v8::IndexedPropertyGetter>(interceptor->getter());
#include <limits.h>
+#define USE_NEW_QUERY_CALLBACKS
+
#include "v8.h"
#include "api.h"
return v8::Handle<Value>();
}
-v8::Handle<v8::Boolean> CheckThisIndexedPropertyQuery(
+v8::Handle<v8::Integer> CheckThisIndexedPropertyQuery(
uint32_t index,
const AccessorInfo& info) {
ApiTestFuzzer::Fuzz();
CHECK(info.This()->Equals(bottom));
- return v8::Handle<v8::Boolean>();
+ return v8::Handle<v8::Integer>();
}