mirror of
https://github.com/wgh136/flutter_qjs.git
synced 2025-09-27 13:27:24 +00:00
add call method to JSInvokable;
Convert js object to dart Map<String, dynamic>
This commit is contained in:
@@ -11,6 +11,8 @@ part of '../flutter_qjs.dart';
|
||||
abstract class JSInvokable extends JSRef {
|
||||
dynamic invoke(List args, [dynamic thisVal]);
|
||||
|
||||
dynamic call(List args) => invoke(args);
|
||||
|
||||
static dynamic _wrap(dynamic func) {
|
||||
return func is JSInvokable
|
||||
? func
|
||||
@@ -188,6 +190,9 @@ class _JSFunction extends _JSObject implements JSInvokable, _IsolateEncodable {
|
||||
Map _encode() {
|
||||
return IsolateFunction._new(this)._encode();
|
||||
}
|
||||
|
||||
@override
|
||||
call(List<dynamic> args) => invoke(args);
|
||||
}
|
||||
|
||||
/// Dart function wrapper for isolate
|
||||
|
@@ -197,7 +197,8 @@ dynamic _jsToDart(Pointer<JSContext> ctx, Pointer<JSValue> val,
|
||||
},
|
||||
(e) {
|
||||
JSRef.dupRecursive(e);
|
||||
if (!completer.isCompleted) completer.completeError(e);
|
||||
// `throw null` is allowed in js
|
||||
if (!completer.isCompleted) completer.completeError(e ?? "null");
|
||||
},
|
||||
], jsPromise);
|
||||
jsPromise.free();
|
||||
@@ -227,13 +228,13 @@ dynamic _jsToDart(Pointer<JSContext> ctx, Pointer<JSValue> val,
|
||||
}
|
||||
final len = plen.value;
|
||||
malloc.free(plen);
|
||||
final ret = Map();
|
||||
final ret = Map<String, dynamic>();
|
||||
cache[valptr] = ret;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
final jsAtom = jsPropertyEnumGetAtom(ptab.value, i);
|
||||
final jsAtomValue = jsAtomToValue(ctx, jsAtom);
|
||||
final jsProp = jsGetProperty(ctx, val, jsAtom);
|
||||
ret[_jsToDart(ctx, jsAtomValue, cache: cache)] =
|
||||
ret[_jsToDart(ctx, jsAtomValue, cache: cache).toString()] =
|
||||
_jsToDart(ctx, jsProp, cache: cache);
|
||||
jsFreeValue(ctx, jsAtomValue);
|
||||
jsFreeValue(ctx, jsProp);
|
||||
|
Reference in New Issue
Block a user