callFunction method
Implementation
@override
JsEvalResult callFunction(Pointer<NativeType>? fn, Pointer<NativeType>? obj) {
JSValue fnValue = JSValuePointer(fn).getValue(context);
JSObject functionObj = fnValue.toObject();
JSValuePointer exception = JSValuePointer();
JSValue result = functionObj.callAsFunction(
functionObj,
JSValuePointer(obj),
exception: exception,
);
JSValue exceptionValue = exception.getValue(context);
bool isPromise = false;
if (exceptionValue.isObject) {
throw Exception(
'ERROR: ${exceptionValue.toObject().getProperty("message").string}');
} else {
isPromise = result.isObject &&
result.toObject().getProperty('then').isObject &&
result.toObject().getProperty('catch').isObject;
}
return JsEvalResult(
_getJsValue(result.pointer),
exceptionValue.isObject
? exceptionValue.toObject().pointer
: result.pointer,
isPromise: isPromise,
);
}