Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit a018c34

Browse files
committed
Add Object::GetPropertyAttributes
1 parent dd7b049 commit a018c34

5 files changed

Lines changed: 34 additions & 1 deletion

File tree

ext/v8/enum.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ namespace rr {
1616
operator T() {
1717
return RTEST(value) ? (T)NUM2INT(value) : defaultValue;
1818
}
19+
20+
class Maybe : public rr::Maybe {
21+
public:
22+
Maybe(v8::Maybe<T> maybe) {
23+
if (maybe.IsJust()) {
24+
just(INT2FIX((int)maybe.FromJust()));
25+
}
26+
}
27+
};
1928
};
2029

2130
inline void DefineEnums() {

ext/v8/object.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace rr {
1313
defineMethod("SetAccessor", &SetAccessor).
1414
defineMethod("CreateDataProperty", &CreateDataProperty).
1515
defineMethod("DefineOwnProperty", &DefineOwnProperty).
16+
defineMethod("GetPropertyAttributes", &GetPropertyAttributes).
1617

1718
store(&Class);
1819
}
@@ -126,6 +127,16 @@ namespace rr {
126127
));
127128
}
128129

130+
VALUE Object::GetPropertyAttributes(VALUE self, VALUE r_context, VALUE key) {
131+
Object object(self);
132+
Locker lock(object);
133+
134+
return Enum<v8::PropertyAttribute>::Maybe(object->GetPropertyAttributes(
135+
Context(r_context),
136+
*Name(key)
137+
));
138+
}
139+
129140
Object::operator VALUE() {
130141
Isolate isolate(getIsolate());
131142
Locker lock(isolate);

ext/v8/object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace rr {
1717

1818
static VALUE CreateDataProperty(VALUE self, VALUE r_context, VALUE key, VALUE value);
1919
static VALUE DefineOwnProperty(int argc, VALUE* argv, VALUE self);
20+
static VALUE GetPropertyAttributes(VALUE self, VALUE r_context, VALUE key);
2021

2122
inline Object(VALUE value) : Ref<v8::Object>(value) {}
2223
inline Object(v8::Isolate* isolate, v8::Handle<v8::Object> object) : Ref<v8::Object>(isolate, object) {}

ext/v8/rr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ inline VALUE not_implemented(const char* message) {
1717
}
1818

1919
#include "class_builder.h"
20-
#include "enum.h"
2120

2221
#include "maybe.h"
22+
#include "enum.h"
23+
2324
#include "equiv.h"
2425
#include "bool.h"
2526
#include "uint32_t.h"

spec/c/object_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@
103103
end
104104
end
105105

106+
describe '#GetPropertyAttributes' do
107+
it 'can get the set attributes' do
108+
o = V8::C::Object.New(@isolate)
109+
key = V8::C::String.NewFromUtf8(@isolate, 'foo')
110+
data = V8::C::String.NewFromUtf8(@isolate, 'data')
111+
112+
expect(o.DefineOwnProperty(@ctx, key, data, V8::C::PropertyAttribute::DontEnum)).to be_successful
113+
expect(o.GetPropertyAttributes(@ctx, key)).to eq_just V8::C::PropertyAttribute::DontEnum
114+
end
115+
end
116+
106117
# TODO: Enable this when the methods are implemented in the extension
107118
# it 'can retrieve all property names' do
108119
# o = V8::C::Object.New

0 commit comments

Comments
 (0)