1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/ext/v8/v8_func.cpp
2010-04-22 11:46:21 -05:00

28 lines
No EOL
704 B
C++

#include "converters.h"
#include "v8_func.h"
using namespace v8;
VALUE V8_C_Function;
VALUE V8_Wrap_Function(Handle<Function> f) {
return V8_Ref_Create(V8_C_Function, f);
}
VALUE v8_C_Function_Call(int argc, VALUE *argv, VALUE self) {
HandleScope handles;
VALUE recv; VALUE f_argv;
rb_scan_args(argc, argv, "1*", &recv, &f_argv);
Local<Function> function = V8_Ref_Get<Function>(self);
Local<Object> thisObject(Object::Cast(*RB2V8(recv)));
int f_argc = argc - 1;
Local<Value> arguments[f_argc];
for (int i = 0; i < f_argc; i++) {
arguments[i] = RB2V8(rb_ary_entry(f_argv,i));
}
Local<Value> result = function->Call(thisObject, f_argc, arguments);
return V82RB(result);
}