1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

Let enums accept a default value

This commit is contained in:
Charles Lowell 2012-05-16 23:11:23 -05:00
parent 899a64fb8c
commit 72e72ada55
2 changed files with 12 additions and 13 deletions

View file

@ -82,16 +82,13 @@ VALUE Object::ForceDelete(VALUE self, VALUE key) {
VALUE Object::SetAccessor(int argc, VALUE* argv, VALUE self) {
VALUE name; VALUE get; VALUE set; VALUE data; VALUE settings; VALUE attribs;
rb_scan_args(argc, argv, "24", &name, &get, &set, &data, &settings, &attribs);
AccessControl ac = v8::DEFAULT;
PropertyAttribute attrs = v8::None;
if (RTEST(settings)) {
ac = AccessControl(settings);
}
if (RTEST(attribs)) {
attrs = PropertyAttribute(attribs);
}
Accessor::Info accessor(get, set, data);
return Bool(Object(self)->SetAccessor(String(name), accessor.Getter(), accessor.Setter(), accessor, ac, attrs));
return Bool(Object(self)->SetAccessor(String(name),
accessor.Getter(),
accessor.Setter(),
accessor,
AccessControl(settings),
PropertyAttribute(attribs)));
}
//

View file

@ -38,14 +38,16 @@ public:
template <class T> class Enum {
public:
Enum<T>(VALUE value) {
Enum<T>(VALUE value, T defaultValue = 0) {
this->value = value;
this->defaultValue = defaultValue;
}
inline operator T() {
return (T)(RTEST(value) ? NUM2INT(value) : 0);
return (T)(RTEST(value) ? NUM2INT(value) : defaultValue);
}
private:
VALUE value;
T defaultValue;
};
/**
@ -196,11 +198,11 @@ public:
class PropertyAttribute: public Enum<v8::PropertyAttribute> {
public:
inline PropertyAttribute(VALUE value) : Enum<v8::PropertyAttribute>(value) {}
inline PropertyAttribute(VALUE value) : Enum<v8::PropertyAttribute>(value, v8::None) {}
};
class AccessControl: public Enum<v8::AccessControl> {
public:
inline AccessControl(VALUE value) : Enum<v8::AccessControl>(value) {}
inline AccessControl(VALUE value) : Enum<v8::AccessControl>(value, v8::DEFAULT) {}
};
class Accessor {