Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index 5d4911bb5ade1070e44ca83fc47a700fd45cce98..47b1a2eb09a98e2c75e87e7035a9bed3d2f99464 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -1098,20 +1098,12 @@ void FunctionTemplate::SetCallHandler(InvocationCallback callback, |
} |
-static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
- v8::Handle<String> name, |
- AccessorGetter getter, |
- AccessorSetter setter, |
- v8::Handle<Value> data, |
- v8::AccessControl settings, |
- v8::PropertyAttribute attributes, |
- v8::Handle<AccessorSignature> signature) { |
- i::Handle<i::ExecutableAccessorInfo> obj = |
- FACTORY->NewExecutableAccessorInfo(); |
- SET_FIELD_WRAPPED(obj, set_getter, getter); |
- SET_FIELD_WRAPPED(obj, set_setter, setter); |
- if (data.IsEmpty()) data = v8::Undefined(); |
- obj->set_data(*Utils::OpenHandle(*data)); |
+static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( |
+ i::Handle<i::AccessorInfo> obj, |
+ v8::Handle<String> name, |
+ v8::AccessControl settings, |
+ v8::PropertyAttribute attributes, |
+ v8::Handle<AccessorSignature> signature) { |
obj->set_name(*Utils::OpenHandle(*name)); |
if (settings & ALL_CAN_READ) obj->set_all_can_read(true); |
if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); |
@@ -1124,7 +1116,7 @@ static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
} |
-void FunctionTemplate::AddInstancePropertyAccessor( |
+static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
v8::Handle<String> name, |
AccessorGetter getter, |
AccessorSetter setter, |
@@ -1132,24 +1124,32 @@ void FunctionTemplate::AddInstancePropertyAccessor( |
v8::AccessControl settings, |
v8::PropertyAttribute attributes, |
v8::Handle<AccessorSignature> signature) { |
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
- if (IsDeadCheck(isolate, |
- "v8::FunctionTemplate::AddInstancePropertyAccessor()")) { |
- return; |
- } |
- ENTER_V8(isolate); |
- i::HandleScope scope(isolate); |
+ i::Handle<i::ExecutableAccessorInfo> obj = |
+ FACTORY->NewExecutableAccessorInfo(); |
Sven Panne
2013/02/19 08:41:16
Don't use FACTORY, get the Isolate via e.g. the na
|
+ SET_FIELD_WRAPPED(obj, set_getter, getter); |
+ SET_FIELD_WRAPPED(obj, set_setter, setter); |
+ if (data.IsEmpty()) data = v8::Undefined(); |
+ obj->set_data(*Utils::OpenHandle(*data)); |
+ return SetAccessorInfoProperties(obj, name, settings, attributes, signature); |
+} |
- i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(name, getter, setter, data, |
- settings, attributes, |
- signature); |
- i::Handle<i::Object> list(Utils::OpenHandle(this)->property_accessors()); |
- if (list->IsUndefined()) { |
- list = NeanderArray().value(); |
- Utils::OpenHandle(this)->set_property_accessors(*list); |
+ |
+static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
+ v8::Handle<String> name, |
+ const AccessorDescriptor* descriptor, |
+ v8::AccessControl settings, |
+ v8::PropertyAttribute attributes, |
+ v8::Handle<AccessorSignature> signature, |
+ i::Isolate* isolate) { |
Sven Panne
2013/02/19 08:41:16
You don't need an explicit Isolate, just retrieve
|
+ i::Handle<i::DeclaredAccessorDescriptor> descriptor_internal = |
+ i::DeclaredAccessorDescriptor::Create(descriptor, isolate); |
+ if (descriptor_internal.is_null()) { |
+ return i::Handle<i::DeclaredAccessorInfo>(); |
} |
- NeanderArray array(list); |
- array.add(obj); |
+ i::Handle<i::DeclaredAccessorInfo> obj = |
+ FACTORY->NewDeclaredAccessorInfo(); |
Sven Panne
2013/02/19 08:41:16
Use isolate->factory() here.
|
+ obj->set_descriptor(*descriptor_internal); |
+ return SetAccessorInfoProperties(obj, name, settings, attributes, signature); |
} |
@@ -1330,12 +1330,25 @@ static void EnsureConstructor(ObjectTemplate* object_template) { |
} |
+static inline void AddPropertyToFunctionTemplate( |
+ i::Handle<i::FunctionTemplateInfo> cons, |
+ i::Handle<i::AccessorInfo> obj) { |
+ i::Handle<i::Object> list(cons->property_accessors()); |
+ if (list->IsUndefined()) { |
+ list = NeanderArray().value(); |
+ cons->set_property_accessors(*list); |
+ } |
+ NeanderArray array(list); |
+ array.add(obj); |
+} |
+ |
+ |
void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
AccessorGetter getter, |
AccessorSetter setter, |
v8::Handle<Value> data, |
AccessControl settings, |
- PropertyAttribute attribute, |
+ PropertyAttribute attributes, |
v8::Handle<AccessorSignature> signature) { |
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return; |
@@ -1345,13 +1358,31 @@ void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
i::FunctionTemplateInfo* constructor = |
i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
i::Handle<i::FunctionTemplateInfo> cons(constructor); |
- Utils::ToLocal(cons)->AddInstancePropertyAccessor(name, |
- getter, |
- setter, |
- data, |
- settings, |
- attribute, |
- signature); |
+ i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(name, getter, setter, data, |
+ settings, attributes, |
+ signature); |
+ AddPropertyToFunctionTemplate(cons, obj); |
+} |
+ |
+ |
+bool ObjectTemplate::SetAccessor(Handle<String> name, |
+ const AccessorDescriptor* descriptor, |
+ AccessControl settings, |
+ PropertyAttribute attributes, |
+ Handle<AccessorSignature> signature) { |
+ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
+ if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return false; |
+ ENTER_V8(isolate); |
+ i::HandleScope scope(isolate); |
+ EnsureConstructor(this); |
+ i::FunctionTemplateInfo* constructor = |
+ i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
+ i::Handle<i::FunctionTemplateInfo> cons(constructor); |
+ i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( |
+ name, descriptor, settings, attributes, signature, isolate); |
+ if (obj.is_null()) return false; |
+ AddPropertyToFunctionTemplate(cons, obj); |
+ return true; |
} |
@@ -3149,6 +3180,16 @@ bool v8::Object::Has(uint32_t index) { |
} |
+static inline bool SetAccessor(Object* obj, i::Handle<i::AccessorInfo> info) { |
+ if (info.is_null()) return false; |
+ bool fast = Utils::OpenHandle(obj)->HasFastProperties(); |
+ i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(obj), info); |
+ if (result.is_null() || result->IsUndefined()) return false; |
+ if (fast) i::JSObject::TransformToFastProperties(Utils::OpenHandle(obj), 0); |
+ return true; |
+} |
+ |
+ |
bool Object::SetAccessor(Handle<String> name, |
AccessorGetter getter, |
AccessorSetter setter, |
@@ -3163,11 +3204,22 @@ bool Object::SetAccessor(Handle<String> name, |
i::Handle<i::AccessorInfo> info = MakeAccessorInfo(name, getter, setter, data, |
settings, attributes, |
signature); |
- bool fast = Utils::OpenHandle(this)->HasFastProperties(); |
- i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(this), info); |
- if (result.is_null() || result->IsUndefined()) return false; |
- if (fast) i::JSObject::TransformToFastProperties(Utils::OpenHandle(this), 0); |
- return true; |
+ return v8::SetAccessor(this, info); |
+} |
+ |
+ |
+bool Object::SetAccessor(Handle<String> name, |
+ const AccessorDescriptor* descriptor, |
+ AccessControl settings, |
+ PropertyAttribute attributes) { |
+ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
+ ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false); |
+ ENTER_V8(isolate); |
+ i::HandleScope scope(isolate); |
+ v8::Handle<AccessorSignature> signature; |
+ i::Handle<i::AccessorInfo> info = MakeAccessorInfo( |
+ name, descriptor, settings, attributes, signature, isolate); |
+ return v8::SetAccessor(this, info); |
} |