Method: Mustang::V8::Function#call_on

Defined in:
ext/v8/v8_function.cpp

#call_on(recv, *args) ⇒ Object

Executes function with given arguments on specified receiver. When function code is broken then proper JavaScript error will be returned.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'ext/v8/v8_function.cpp', line 95

static VALUE rb_v8_function_call_on(int argc, VALUE *argv, VALUE self)
{
  HandleScope scope;
  TryCatch try_catch;

  if (argc < 1) {
    rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", FIX2INT(argc));
    return Qnil;
  }
  
  VALUE recv = argv[0];
  
  Handle<Object> this_obj =
    NIL_P(recv) ? Context::GetEntered()->Global() :
    unwrap(recv)->ToObject();
  
  Handle<Value> args[argc-1];
  
  for (int i = 1; i < argc; i++) {
    args[i-1] = to_v8(argv[i]);
  }
  
  Handle<Value> result = unwrap(self)->Call(this_obj, argc-1, args);

  if (try_catch.HasCaught()) {
    return rb_v8_error_new3(try_catch);
  } else {
    return to_ruby(result);
  }
}