mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
add seeds for passing javascript objects back to ruby
This commit is contained in:
parent
68c968e109
commit
c0d8d85b95
3 changed files with 19 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
#define __ruby_data_h__
|
#define __ruby_data_h__
|
||||||
|
|
||||||
#include <ruby.h>
|
#include <ruby.h>
|
||||||
|
#include <v8.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -87,6 +88,10 @@ class RubyDest {
|
||||||
VALUE pushUndefined(const char* name=0) {
|
VALUE pushUndefined(const char* name=0) {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE pushObject(v8::Handle<v8::Value>& value, const char* name = 0) {
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,14 @@ describe "The Ruby Racer" do
|
||||||
eval("true").should be(true)
|
eval("true").should be(true)
|
||||||
eval("false").should be(false)
|
eval("false").should be(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can pass objects back to ruby" do
|
||||||
|
eval("({foo: 'bar', baz: 'bang'})").tap do |object|
|
||||||
|
object.should_not be_nil
|
||||||
|
object['foo'].should == 'bar'
|
||||||
|
object['baz'].should == 'bang'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,12 @@ template<class T, class R> class V8HandleSource {
|
||||||
if(value->IsNumber()) {
|
if(value->IsNumber()) {
|
||||||
return dest.pushDouble(value->NumberValue(), name);
|
return dest.pushDouble(value->NumberValue(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value->IsObject()) {
|
||||||
|
return dest.pushObject(value, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dest.pushNull(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue