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

Commit 1fa84a0

Browse files
committed
Merge pull request #381 from cowboyd/4.5/finish-array-c-api
finish out the Array C API
2 parents d4c68df + 3d5516a commit 1fa84a0

4 files changed

Lines changed: 20 additions & 7 deletions

File tree

ext/v8/array.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ namespace rr {
2525

2626
VALUE Array::Length(VALUE self) {
2727
Array array(self);
28-
Locker lock(array.getIsolate());
28+
Locker lock(array);
2929

3030
return Uint32_t(array->Length());
3131
}
3232

33-
VALUE Array::CloneElementAt(VALUE self, VALUE index) {
33+
VALUE Array::CloneElementAt(VALUE self, VALUE context, VALUE index) {
3434
Array array(self);
35-
Locker lock(array.getIsolate());
35+
Locker lock(array);
3636

37-
return Object(array.getIsolate(), array->CloneElementAt(Uint32_t(index)));
37+
return Object::Maybe(array.getIsolate(), array->CloneElementAt(Context(context), Uint32_t(index)));
3838
}
3939

4040
}

ext/v8/array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace rr {
99

1010
static VALUE New(int argc, VALUE argv[], VALUE self);
1111
static VALUE Length(VALUE self);
12-
static VALUE CloneElementAt(VALUE self, VALUE index);
12+
static VALUE CloneElementAt(VALUE self, VALUE context, VALUE index);
1313

1414
inline Array(v8::Isolate* isolate, v8::Handle<v8::Array> array) : Ref<v8::Array>(isolate, array) {}
1515
inline Array(VALUE value) : Ref<v8::Array>(value) {}

spec/c/array_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,20 @@
1717

1818
it 'can be initialized with a length' do
1919
a = V8::C::Array::New(@isolate, 5)
20-
2120
expect(a.Length).to eq 5
2221
end
22+
23+
it 'can clone its elements' do
24+
o = V8::C::Object::New(@isolate)
25+
key = V8::C::String::NewFromUtf8(@isolate, "key")
26+
o.Set(@ctx, key, key)
27+
a = V8::C::Array::New(@isolate)
28+
29+
a.Set(@ctx, 0, o)
30+
31+
object = a.CloneElementAt(@ctx, 0)
32+
expect(object).to be_successful
33+
expect(object.FromJust().Get(@ctx, key)).to be_successful
34+
expect(object.FromJust().Get(@ctx, key).FromJust().Utf8Value()).to eql "key"
35+
end
2336
end

spec/v8/context_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@
654654

655655
# end
656656

657-
describe "Calling JavaScript Code From Within Ruby", :compat => '0.1.0' do
657+
describe "Calling JavaScript Code From Within Ruby" do
658658

659659
before(:each) do
660660
@cxt = V8::Context.new

0 commit comments

Comments
 (0)