jsValue function Null safety

dynamic jsValue(
  1. dynamic value,
  2. WebJsScript script
)

Implementation

jsValue(dynamic value, WebJsScript script) {
  if (value is Future) {
    js.JsObject handler = js.JsObject.jsify({});
    value.then((value) => handler.callMethod("resolve", [jsValue(value, script)]));
    value.catchError((error) => handler.callMethod("reject", [jsValue(error, script)]));
    return script.newPromise(handler);
  } else if (value is WebJsValue) {
    return value._object;
  } else if (value is JsProxy) {
    return (value.value as WebJsValue)._object;
  } else if (value is Function) {
    WebJsValue func = script.function((argv) => Function.apply(value, argv)) as WebJsValue;
    return func._object;
  // } else if (value is Map || value is List) {
  //   WebJsValue obj = script.bind(value, classInfo: value is Map ? mapClass : listClass) as WebJsValue;
  //   obj = script.collectionWrap(obj) as WebJsValue;
  //   return obj._object;
  } else {
    return value;
  }
}