2012-05-04 01:23:41 -04:00
|
|
|
#include "rr.h"
|
|
|
|
|
|
|
|
namespace rr {
|
|
|
|
|
|
|
|
void Object::Init() {
|
2012-05-17 11:30:37 -04:00
|
|
|
ClassBuilder("Object", Value::Class).
|
2012-05-08 12:45:06 -04:00
|
|
|
defineSingletonMethod("New", &New).
|
|
|
|
defineMethod("Set", &Set).
|
|
|
|
defineMethod("ForceSet", &ForceSet).
|
|
|
|
defineMethod("Get", &Get).
|
|
|
|
defineMethod("GetPropertyAttributes", &GetPropertyAttributes).
|
|
|
|
defineMethod("Has", &Has).
|
|
|
|
defineMethod("Delete", &Delete).
|
2012-05-08 13:08:58 -04:00
|
|
|
defineMethod("ForceDelete", &ForceDelete).
|
2012-05-08 17:17:25 -04:00
|
|
|
defineMethod("SetAccessor", &SetAccessor).
|
2012-05-17 11:30:37 -04:00
|
|
|
defineMethod("GetPropertyNames", &GetPropertyNames).
|
|
|
|
defineMethod("GetOwnPropertyNames", &GetOwnPropertyNames).
|
|
|
|
defineMethod("GetPrototype", &GetPrototype).
|
|
|
|
defineMethod("SetPrototype", &SetPrototype).
|
|
|
|
defineMethod("FindInstanceInPrototypeChain", &FindInstanceInPrototypeChain).
|
|
|
|
defineMethod("ObjectProtoToString", &ObjectProtoToString).
|
|
|
|
defineMethod("GetConstructorName", &GetConstructorName).
|
|
|
|
defineMethod("InternalFieldCount", &InternalFieldCount).
|
|
|
|
defineMethod("GetInternalField", &GetInternalField).
|
|
|
|
defineMethod("SetInternalField", &SetInternalField).
|
|
|
|
defineMethod("HasOwnProperty", &HasOwnProperty).
|
|
|
|
defineMethod("HasRealNamedProperty", &HasRealNamedProperty).
|
|
|
|
defineMethod("HasRealIndexedProperty", &HasRealIndexedProperty).
|
|
|
|
defineMethod("HasRealNamedCallbackProperty", &HasRealNamedCallbackProperty).
|
|
|
|
defineMethod("GetRealNamedPropertyInPrototypeChain", &GetRealNamedPropertyInPrototypeChain).
|
|
|
|
defineMethod("GetRealNamedProperty", &GetRealNamedProperty).
|
|
|
|
defineMethod("HasNamedLookupInterceptor", &HasNamedLookupInterceptor).
|
|
|
|
defineMethod("HasIndexedLookupInterceptor", &HasIndexedLookupInterceptor).
|
|
|
|
defineMethod("TurnOnAccessCheck", &TurnOnAccessCheck).
|
|
|
|
defineMethod("GetIdentityHash", &GetIdentityHash).
|
|
|
|
defineMethod("SetHiddenValue", &SetHiddenValue).
|
|
|
|
defineMethod("GetHiddenValue", &GetHiddenValue).
|
|
|
|
defineMethod("DeleteHiddenValue", &DeleteHiddenValue).
|
|
|
|
defineMethod("IsDirty", &IsDirty).
|
|
|
|
defineMethod("Clone", &Clone).
|
|
|
|
defineMethod("CreationContext", &CreationContext).
|
|
|
|
defineMethod("SetIndexedPropertiesToPixelData", &SetIndexedPropertiesToPixelData).
|
|
|
|
defineMethod("GetIndexedPropertiesPixelData", &GetIndexedPropertiesPixelData).
|
|
|
|
defineMethod("HasIndexedPropertiesToPixelData", &HasIndexedPropertiesInPixelData).
|
|
|
|
defineMethod("GetIndexedPropertiesPixelDataLength", &GetIndexedPropertiesPixelDataLength).
|
|
|
|
defineMethod("SetIndexedPropertiesToExternalArrayData", &SetIndexedPropertiesToExternalArrayData).
|
|
|
|
defineMethod("HasIndexedPropertiesInExternalArrayData", &HasIndexedPropertiesInExternalArrayData).
|
|
|
|
defineMethod("GetIndexedPropertiesExternalArrayData", &GetIndexedPropertiesExternalArrayData).
|
|
|
|
defineMethod("GetIndexedPropertiesExternalArrayDataType", &GetIndexedPropertiesExternalArrayDataType).
|
|
|
|
defineMethod("GetIndexedPropertiesExternalArrayDataLength", &GetIndexedPropertiesExternalArrayDataLength).
|
|
|
|
defineMethod("IsCallable", &IsCallable).
|
|
|
|
defineMethod("CallAsFunction", &CallAsFunction).
|
|
|
|
defineMethod("CallAsConstructor", &CallAsConstructor).
|
2012-05-08 17:17:25 -04:00
|
|
|
store(&Class);
|
2012-05-08 12:45:06 -04:00
|
|
|
ClassBuilder("PropertyAttribute").
|
|
|
|
defineEnumConst("None", v8::None).
|
|
|
|
defineEnumConst("ReadOnly", v8::ReadOnly).
|
|
|
|
defineEnumConst("DontEnum", v8::DontEnum).
|
|
|
|
defineEnumConst("DontDelete", v8::DontDelete);
|
2012-05-08 12:56:31 -04:00
|
|
|
ClassBuilder("AccessControl").
|
|
|
|
defineEnumConst("DEFAULT", v8::DEFAULT).
|
|
|
|
defineEnumConst("ALL_CAN_READ", v8::ALL_CAN_READ).
|
|
|
|
defineEnumConst("ALL_CAN_WRITE", v8::ALL_CAN_WRITE).
|
|
|
|
defineEnumConst("PROHIBITS_OVERWRITING", v8::PROHIBITS_OVERWRITING);
|
2012-05-04 01:23:41 -04:00
|
|
|
}
|
|
|
|
|
2012-05-08 17:17:25 -04:00
|
|
|
|
2012-05-04 01:23:41 -04:00
|
|
|
VALUE Object::New(VALUE self) {
|
2012-05-15 13:23:06 -04:00
|
|
|
return Object(v8::Object::New());
|
2012-05-04 01:23:41 -04:00
|
|
|
}
|
|
|
|
|
2012-05-08 12:45:06 -04:00
|
|
|
//TODO: Allow setting of property attributes
|
|
|
|
VALUE Object::Set(VALUE self, VALUE key, VALUE value) {
|
|
|
|
if (rb_obj_is_kind_of(key, rb_cNumeric)) {
|
2012-05-16 23:25:31 -04:00
|
|
|
return Bool(Object(self)->Set(UInt32(key), Value(value)));
|
2012-05-08 12:45:06 -04:00
|
|
|
} else {
|
2012-05-16 23:25:31 -04:00
|
|
|
return Bool(Object(self)->Set(*Value(key), Value(value)));
|
2012-05-08 12:45:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::ForceSet(VALUE self, VALUE key, VALUE value) {
|
2012-05-15 17:49:01 -04:00
|
|
|
return Bool(Object(self)->ForceSet(Value(key), Value(value)));
|
2012-05-08 12:45:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::Get(VALUE self, VALUE key) {
|
|
|
|
if (rb_obj_is_kind_of(key, rb_cNumeric)) {
|
2012-05-16 23:25:31 -04:00
|
|
|
return Value(Object(self)->Get(UInt32(key)));
|
2012-05-08 12:45:06 -04:00
|
|
|
} else {
|
2012-05-16 23:25:31 -04:00
|
|
|
return Value(Object(self)->Get(*Value(key)));
|
2012-05-08 12:45:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetPropertyAttributes(VALUE self, VALUE key) {
|
2012-05-15 17:49:01 -04:00
|
|
|
return PropertyAttribute(Object(self)->GetPropertyAttributes(Value(key)));
|
2012-05-08 12:45:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::Has(VALUE self, VALUE key) {
|
|
|
|
Object obj(self);
|
|
|
|
if (rb_obj_is_kind_of(key, rb_cNumeric)) {
|
2012-05-16 23:25:31 -04:00
|
|
|
return Bool(obj->Has(UInt32(key)));
|
2012-05-08 12:45:06 -04:00
|
|
|
} else {
|
2012-05-17 11:30:37 -04:00
|
|
|
return Bool(obj->Has(*String(key)));
|
2012-05-08 12:45:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::Delete(VALUE self, VALUE key) {
|
|
|
|
Object obj(self);
|
|
|
|
if (rb_obj_is_kind_of(key, rb_cNumeric)) {
|
2012-05-16 23:25:31 -04:00
|
|
|
return Bool(obj->Delete(UInt32(key)));
|
2012-05-08 12:45:06 -04:00
|
|
|
} else {
|
2012-05-16 23:25:31 -04:00
|
|
|
return Bool(obj->Delete(*String(key)));
|
2012-05-08 12:45:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::ForceDelete(VALUE self, VALUE key) {
|
2012-05-15 17:49:01 -04:00
|
|
|
return Bool(Object(self)->ForceDelete(Value(key)));
|
2012-05-08 12:45:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-08 16:11:50 -04:00
|
|
|
VALUE Object::SetAccessor(int argc, VALUE* argv, VALUE self) {
|
2012-05-09 14:12:44 -04:00
|
|
|
VALUE name; VALUE get; VALUE set; VALUE data; VALUE settings; VALUE attribs;
|
|
|
|
rb_scan_args(argc, argv, "24", &name, &get, &set, &data, &settings, &attribs);
|
|
|
|
Accessor::Info accessor(get, set, data);
|
2012-05-17 00:11:23 -04:00
|
|
|
return Bool(Object(self)->SetAccessor(String(name),
|
|
|
|
accessor.Getter(),
|
|
|
|
accessor.Setter(),
|
|
|
|
accessor,
|
|
|
|
AccessControl(settings),
|
|
|
|
PropertyAttribute(attribs)));
|
2012-05-08 16:11:50 -04:00
|
|
|
}
|
2012-05-08 12:45:06 -04:00
|
|
|
|
2012-05-15 17:37:22 -04:00
|
|
|
Object::operator VALUE() {
|
|
|
|
if (handle->IsFunction()) {
|
|
|
|
// return Function(handle);
|
|
|
|
}
|
|
|
|
if (handle->IsArray()) {
|
2012-05-17 23:05:41 -04:00
|
|
|
return Array(handle);
|
2012-05-15 17:37:22 -04:00
|
|
|
}
|
|
|
|
if (handle->IsDate()) {
|
|
|
|
// return Date(handle);
|
|
|
|
}
|
|
|
|
if (handle->IsBooleanObject()) {
|
|
|
|
// return BooleanObject(handle);
|
|
|
|
}
|
|
|
|
if (handle->IsNumberObject()) {
|
|
|
|
// return NumberObject(handle);
|
|
|
|
}
|
|
|
|
if (handle->IsStringObject()) {
|
|
|
|
// return StringObject(handle);
|
|
|
|
}
|
|
|
|
if (handle->IsRegExp()) {
|
|
|
|
// return RegExp(handle);
|
|
|
|
}
|
|
|
|
return Ref<v8::Object>::operator VALUE();
|
|
|
|
}
|
2012-05-17 11:30:37 -04:00
|
|
|
|
|
|
|
VALUE Object::GetPropertyNames(VALUE self) {
|
|
|
|
return Array(Object(self)->GetPropertyNames());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetOwnPropertyNames(VALUE self) {
|
|
|
|
return Array(Object(self)->GetOwnPropertyNames());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetPrototype(VALUE self) {
|
|
|
|
return Value(Object(self)->GetPrototype());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::SetPrototype(VALUE self, VALUE prototype) {
|
|
|
|
return Bool(Object(self)->SetPrototype(Value(prototype)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::FindInstanceInPrototypeChain(VALUE self, VALUE impl) {
|
|
|
|
return Object(Object(self)->FindInstanceInPrototypeChain(FunctionTemplate(impl)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::ObjectProtoToString(VALUE self) {
|
|
|
|
return String(Object(self)->ObjectProtoToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetConstructorName(VALUE self) {
|
|
|
|
return String(Object(self)->GetConstructorName());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::InternalFieldCount(VALUE self) {
|
|
|
|
return Int(Object(self)->InternalFieldCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetInternalField(VALUE self, VALUE idx) {
|
|
|
|
return Value(Object(self)->GetInternalField(Int(idx)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::SetInternalField(VALUE self, VALUE idx, VALUE value) {
|
|
|
|
Void(Object(self)->SetInternalField(Int(idx), Value(value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::HasOwnProperty(VALUE self, VALUE key) {
|
|
|
|
return Bool(Object(self)->HasOwnProperty(String(key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::HasRealNamedProperty(VALUE self, VALUE key) {
|
|
|
|
return Bool(Object(self)->HasRealNamedProperty(String(key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::HasRealIndexedProperty(VALUE self, VALUE idx) {
|
|
|
|
return Bool(Object(self)->HasRealIndexedProperty(UInt32(idx)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::HasRealNamedCallbackProperty(VALUE self, VALUE key) {
|
|
|
|
return Bool(Object(self)->HasRealNamedCallbackProperty(String(key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetRealNamedPropertyInPrototypeChain(VALUE self, VALUE key) {
|
|
|
|
return Value(Object(self)->GetRealNamedPropertyInPrototypeChain(String(key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetRealNamedProperty(VALUE self, VALUE key) {
|
|
|
|
return Value(Object(self)->GetRealNamedProperty(String(key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::HasNamedLookupInterceptor(VALUE self) {
|
|
|
|
return Bool(Object(self)->HasNamedLookupInterceptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::HasIndexedLookupInterceptor(VALUE self) {
|
|
|
|
return Bool(Object(self)->HasIndexedLookupInterceptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::TurnOnAccessCheck(VALUE self) {
|
|
|
|
Void(Object(self)->TurnOnAccessCheck());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetIdentityHash(VALUE self) {
|
|
|
|
return Int(Object(self)->GetIdentityHash());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::SetHiddenValue(VALUE self, VALUE key, VALUE value) {
|
|
|
|
return Bool(Object(self)->SetHiddenValue(String(key), Value(value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetHiddenValue(VALUE self, VALUE key) {
|
|
|
|
return Value(Object(self)->GetHiddenValue(String(key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::DeleteHiddenValue(VALUE self, VALUE key) {
|
|
|
|
return Bool(Object(self)->DeleteHiddenValue(String(key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::IsDirty(VALUE self) {
|
|
|
|
return Bool(Object(self)->IsDirty());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::Clone(VALUE self) {
|
|
|
|
return Object(Object(self)->Clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::CreationContext(VALUE self) {
|
|
|
|
return Context(Object(self)->CreationContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::SetIndexedPropertiesToPixelData(VALUE self, VALUE data, VALUE length) {
|
|
|
|
return not_implemented("SetIndexedPropertiesToPixelData");
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetIndexedPropertiesPixelData(VALUE self) {
|
|
|
|
return not_implemented("GetIndexedPropertiesPixelData");
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::HasIndexedPropertiesInPixelData(VALUE self) {
|
|
|
|
return Bool(Object(self)->HasIndexedPropertiesInPixelData());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetIndexedPropertiesPixelDataLength(VALUE self) {
|
|
|
|
return Int(Object(self)->GetIndexedPropertiesPixelDataLength());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::SetIndexedPropertiesToExternalArrayData(VALUE self) {
|
|
|
|
return not_implemented("SetIndexedPropertiesToExternalArrayData");
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::HasIndexedPropertiesInExternalArrayData(VALUE self) {
|
|
|
|
return Bool(Object(self)->HasIndexedPropertiesInExternalArrayData());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetIndexedPropertiesExternalArrayData(VALUE self) {
|
|
|
|
return not_implemented("GetIndexedPropertiesExternalArrayData");
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetIndexedPropertiesExternalArrayDataType(VALUE self) {
|
|
|
|
return not_implemented("GetIndexedPropertiesExternalArrayDataType");
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::GetIndexedPropertiesExternalArrayDataLength(VALUE self) {
|
|
|
|
return Int(Object(self)->GetIndexedPropertiesExternalArrayDataLength());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::IsCallable(VALUE self) {
|
|
|
|
return Bool(Object(self)->IsCallable());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::CallAsFunction(VALUE self, VALUE recv, VALUE argc, VALUE argv) {
|
|
|
|
std::vector< v8::Handle<v8::Value> > v(NUM2INT(argc));
|
|
|
|
return Value(Object(self)->CallAsFunction(Object(recv), Int(argc), Value::array(argv, v)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Object::CallAsConstructor(VALUE self, VALUE argc, VALUE argv) {
|
|
|
|
std::vector< v8::Handle<v8::Value> > v(NUM2INT(argc));
|
|
|
|
return Value(Object(self)->CallAsConstructor(Int(argc), Value::array(argv, v)));
|
|
|
|
}
|
|
|
|
|
2012-05-04 01:23:41 -04:00
|
|
|
}
|