mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
set JavaScript function() names from Ruby.
This commit is contained in:
parent
96eb8463c0
commit
67a1cc5c9e
3 changed files with 31 additions and 0 deletions
|
|
@ -39,9 +39,11 @@ namespace {
|
|||
return rr_v8_ref_create(rr_cV8_C_Object, function->NewInstance(argc, argv));
|
||||
}
|
||||
VALUE GetName(VALUE self) {
|
||||
HandleScope scope;
|
||||
return rr_v82rb(unwrap(self)->GetName());
|
||||
}
|
||||
VALUE SetName(VALUE self, VALUE name) {
|
||||
HandleScope scope;
|
||||
Local<String> str = V8_Ref_Get<String>(name);
|
||||
unwrap(self)->SetName(str);
|
||||
return Qnil;
|
||||
|
|
|
|||
|
|
@ -24,5 +24,19 @@ module V8
|
|||
to.rb(@native.NewInstance(to.v8(args)))
|
||||
end
|
||||
end
|
||||
|
||||
def name
|
||||
@portal.open do |to|
|
||||
to.rb(@native.GetName())
|
||||
end
|
||||
end
|
||||
|
||||
def name=(name)
|
||||
name.tap do
|
||||
@portal.open do |to|
|
||||
@native.SetName(to.v8(name))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -46,4 +46,19 @@ describe C::Function do
|
|||
cxt.eval('say("Hello", 3)').should == "HelloHelloHello"
|
||||
end
|
||||
end
|
||||
|
||||
it "has a name" do
|
||||
Context.new do |cxt|
|
||||
f = cxt.eval('(function hi() {return "Hello World"})', '<eval>')
|
||||
f.name.should == "hi"
|
||||
end
|
||||
end
|
||||
|
||||
it "can have its name set" do
|
||||
Context.new do |cxt|
|
||||
f = cxt.eval('(function () {return "Goodbye World"})', '<eval>')
|
||||
f.name = 'bye'
|
||||
f.name.should == 'bye'
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue