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

Commit 200d617

Browse files
committed
Add Object::ObjectProtoToString
1 parent d849799 commit 200d617

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

ext/v8/object.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace rr {
2020
defineMethod("GetOwnPropertyNames", &GetOwnPropertyNames).
2121
defineMethod("GetPrototype", &GetPrototype).
2222
defineMethod("SetPrototype", &SetPrototype).
23+
defineMethod("ObjectProtoToString", &ObjectProtoToString).
2324

2425
store(&Class);
2526
}
@@ -202,6 +203,13 @@ namespace rr {
202203
));
203204
}
204205

206+
VALUE Object::ObjectProtoToString(VALUE self, VALUE r_context) {
207+
Object object(self);
208+
Locker lock(object);
209+
210+
return String::Maybe(object.getIsolate(), object->ObjectProtoToString(Context(r_context)));
211+
}
212+
205213
Object::operator VALUE() {
206214
Isolate isolate(getIsolate());
207215
Locker lock(isolate);

ext/v8/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace rr {
2626
static VALUE GetPrototype(VALUE self);
2727
static VALUE SetPrototype(VALUE self, VALUE r_context, VALUE prototype);
2828

29+
static VALUE ObjectProtoToString(VALUE self, VALUE r_context);
30+
2931
inline Object(VALUE value) : Ref<v8::Object>(value) {}
3032
inline Object(v8::Isolate* isolate, v8::Handle<v8::Object> object) : Ref<v8::Object>(isolate, object) {}
3133

ext/v8/rr_string.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace rr {
1515
inline String(v8::Isolate* isolate, v8::Handle<v8::String> string) : Ref<v8::String>(isolate, string) {}
1616

1717
virtual operator v8::Handle<v8::String>() const;
18+
19+
typedef MaybeLocal<rr::String, v8::String> Maybe;
1820
};
1921

2022
}

spec/c/object_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,24 @@
282282
expect(names.FromJust.Get(@ctx, 1)).to v8_eq prototype_key
283283
end
284284
end
285+
286+
describe '#ObjectProtoToString' do
287+
it 'can return a string representation of simple objects' do
288+
o = V8::C::Object.New(@isolate)
289+
str = o.ObjectProtoToString(@ctx)
290+
291+
expect(str).to be_successful
292+
expect(str.FromJust.Utf8Value).to eq '[object Object]'
293+
end
294+
295+
it 'can return a string representation of simple objects' do
296+
a = V8::C::Array.New(@isolate)
297+
a.Set(@ctx, 0, 2)
298+
a.Set(@ctx, 1, 3)
299+
300+
str = a.ObjectProtoToString(@ctx)
301+
expect(str).to be_successful
302+
expect(str.FromJust.Utf8Value).to eq '[object Array]'
303+
end
304+
end
285305
end

0 commit comments

Comments
 (0)