- JSContextRef execRef = toRef(exec);
- JSObjectRef functionRef = toRef(exec->callee());
- JSObjectRef thisObjRef = toRef(exec->hostThisValue().toThisObject(exec));
-
- int argumentCount = static_cast<int>(exec->argumentCount());
- Vector<JSValueRef, 16> arguments(argumentCount);
- for (int i = 0; i < argumentCount; i++)
- arguments[i] = 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));
+ JSCallbackFunction* function = new (NotNull, allocateCell<JSCallbackFunction>(vm.heap)) JSCallbackFunction(vm, globalObject->callbackFunctionStructure(), callback);
+ function->finishCreation(vm, name);
+ return function;