-EncodedJSValue JSCallbackFunction::call(ExecState* exec)
-{
- JSContextRef execRef = toRef(exec);
- JSObjectRef functionRef = toRef(exec->callee());
- JSObjectRef thisObjRef = toRef(exec->hostThisValue().toThisObject(exec));
-
- size_t argumentCount = exec->argumentCount();
- Vector<JSValueRef, 16> arguments;
- arguments.reserveInitialCapacity(argumentCount);
- for (size_t i = 0; i < argumentCount; ++i)
- arguments.uncheckedAppend(toRef(exec, exec->argument(i)));
-
- JSValueRef exception = 0;
- JSValueRef result;
- {
- APICallbackShim callbackShim(exec);
- result = jsCast<JSCallbackFunction*>(toJS(functionRef))->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception);
- }
- if (exception)
- throwError(exec, toJS(exec, exception));
-
- // result must be a valid JSValue.
- if (!result)
- return JSValue::encode(jsUndefined());
-
- return JSValue::encode(toJS(exec, result));
-}
-