From 53e0b3d2ecf23fa89581760378020f33b728a9c2 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Fri, 22 Apr 2011 09:09:15 -0500 Subject: [PATCH] make Array maintain referential integrity. --- ext/v8/v8_array.cpp | 4 +--- spec/ext/array_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 spec/ext/array_spec.rb diff --git a/ext/v8/v8_array.cpp b/ext/v8/v8_array.cpp index 4a48cef..0895ce0 100644 --- a/ext/v8/v8_array.cpp +++ b/ext/v8/v8_array.cpp @@ -44,7 +44,5 @@ void rr_init_v8_array() { } VALUE rr_reflect_v8_array(Handle value) { - Local array(Array::Cast(*value)); - Local peer = array->GetHiddenValue(String::NewSymbol("TheRubyRacer::RubyObject")); - return peer.IsEmpty() ? rr_v8_handle_new(ArrayClass, value) : (VALUE)External::Unwrap(peer); + return rr_reflect_v8_object_as(value, ArrayClass); } \ No newline at end of file diff --git a/spec/ext/array_spec.rb b/spec/ext/array_spec.rb new file mode 100644 index 0000000..1092bb6 --- /dev/null +++ b/spec/ext/array_spec.rb @@ -0,0 +1,15 @@ +require "spec_helper" + +describe V8::C::Array do + include V8::ExtSpec + + it "can be instantiated" do + a = c::Array::New() + a.Length().should eql(0) + end + + it "maintains referential integrity" do + v8_eval('a = []') + v8_eval('a').should be(v8_eval('a')) + end +end