mirror of
https://github.com/wgh136/flutter_qjs.git
synced 2025-09-27 05:27:23 +00:00
multi engine
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
* @Author: ekibun
|
* @Author: ekibun
|
||||||
* @Date: 2020-08-07 13:55:52
|
* @Date: 2020-08-07 13:55:52
|
||||||
* @LastEditors: ekibun
|
* @LastEditors: ekibun
|
||||||
* @LastEditTime: 2020-08-15 14:45:00
|
* @LastEditTime: 2020-08-15 16:28:38
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "quickjspp/quickjspp.hpp"
|
#include "quickjspp/quickjspp.hpp"
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
* @Author: ekibun
|
* @Author: ekibun
|
||||||
* @Date: 2020-08-08 10:30:59
|
* @Date: 2020-08-08 10:30:59
|
||||||
* @LastEditors: ekibun
|
* @LastEditors: ekibun
|
||||||
* @LastEditTime: 2020-08-15 13:13:43
|
* @LastEditTime: 2020-08-15 16:31:14
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@@ -22,15 +22,15 @@ namespace qjs
|
|||||||
struct EngineTask
|
struct EngineTask
|
||||||
{
|
{
|
||||||
std::function<Value(Context&)> invoke;
|
std::function<Value(Context&)> invoke;
|
||||||
std::function<void(std::string)> resolve;
|
std::function<void(Value)> resolve;
|
||||||
std::function<void(std::string)> reject;
|
std::function<void(Value)> reject;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EngineTaskResolver
|
struct EngineTaskResolver
|
||||||
{
|
{
|
||||||
Value result;
|
Value result;
|
||||||
std::function<void(std::string)> resolve;
|
std::function<void(Value)> resolve;
|
||||||
std::function<void(std::string)> reject;
|
std::function<void(Value)> reject;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string getStackTrack(Value exc)
|
std::string getStackTrack(Value exc)
|
||||||
@@ -58,9 +58,11 @@ namespace qjs
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Engine(DartChannel channel) : stoped{false}
|
inline Engine(std::function<std::promise<JSFutureReturn> *(std::string, Value, Engine *)> channel) : stoped{false}
|
||||||
{
|
{
|
||||||
thread = std::thread([this, channel] { // 工作线程函数
|
thread = std::thread([this, channel = [this, channel](std::string method, Value args){
|
||||||
|
return channel(method, args, this);
|
||||||
|
}] {
|
||||||
// 创建运行环境
|
// 创建运行环境
|
||||||
Runtime rt;
|
Runtime rt;
|
||||||
js_init_handlers(rt.rt, channel);
|
js_init_handlers(rt.rt, channel);
|
||||||
@@ -114,7 +116,7 @@ namespace qjs
|
|||||||
}
|
}
|
||||||
catch (exception)
|
catch (exception)
|
||||||
{
|
{
|
||||||
task.reject(getStackTrack(ctx.getException()));
|
task.reject(ctx.getException());
|
||||||
}
|
}
|
||||||
// 执行microtask
|
// 执行microtask
|
||||||
JSContext *pctx;
|
JSContext *pctx;
|
||||||
@@ -134,12 +136,12 @@ namespace qjs
|
|||||||
bool finished = false;
|
bool finished = false;
|
||||||
if (it->result["__resolved"])
|
if (it->result["__resolved"])
|
||||||
{
|
{
|
||||||
it->resolve((std::string)it->result["__value"]);
|
it->resolve(it->result["__value"]);
|
||||||
finished = true;
|
finished = true;
|
||||||
};
|
};
|
||||||
if (it->result["__rejected"])
|
if (it->result["__rejected"])
|
||||||
{
|
{
|
||||||
it->reject(getStackTrack(it->result["__error"]));
|
it->reject(it->result["__error"]);
|
||||||
finished = true;
|
finished = true;
|
||||||
};
|
};
|
||||||
if (finished)
|
if (finished)
|
||||||
@@ -162,7 +164,7 @@ namespace qjs
|
|||||||
{
|
{
|
||||||
for (EngineTaskResolver &_task : unresolvedTask)
|
for (EngineTaskResolver &_task : unresolvedTask)
|
||||||
{
|
{
|
||||||
_task.reject("Promise cannot resolve");
|
_task.reject(ctx.newValue("Promise cannot resolve"));
|
||||||
}
|
}
|
||||||
unresolvedTask.clear();
|
unresolvedTask.clear();
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
* @Author: ekibun
|
* @Author: ekibun
|
||||||
* @Date: 2020-07-18 23:28:55
|
* @Date: 2020-07-18 23:28:55
|
||||||
* @LastEditors: ekibun
|
* @LastEditors: ekibun
|
||||||
* @LastEditTime: 2020-08-15 14:01:09
|
* @LastEditTime: 2020-08-15 16:39:07
|
||||||
*/
|
*/
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -17,9 +17,8 @@ class TestPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _TestPageState extends State<TestPage> {
|
class _TestPageState extends State<TestPage> {
|
||||||
|
|
||||||
String code, resp;
|
String code, resp;
|
||||||
int engine;
|
FlutterJs engine;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -36,42 +35,46 @@ class _TestPageState extends State<TestPage> {
|
|||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
FlatButton(child: Text("初始化引擎"), onPressed: () async {
|
FlatButton(
|
||||||
if ((engine?? 0) != 0) return;
|
child: Text("初始化引擎"),
|
||||||
engine = await FlutterJs.initEngine();
|
onPressed: () async {
|
||||||
// dart 函数回调
|
if (engine != null) return;
|
||||||
FlutterJs.methodHandler = (String method, List arg) async {
|
engine = FlutterJs();
|
||||||
|
engine.setMethodHandler((String method, List arg) async {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "delay":
|
case "delay":
|
||||||
await Future.delayed(Duration(milliseconds: arg[0]));
|
await Future.delayed(Duration(milliseconds: arg[0]));
|
||||||
return;
|
return;
|
||||||
case "http":
|
case "http":
|
||||||
Response response = await Dio().get(arg[0]);
|
Response response = await Dio()
|
||||||
|
.get(arg[0], options: Options(responseType: ResponseType.bytes));
|
||||||
return response.data;
|
return response.data;
|
||||||
case "hello":
|
case "hello":
|
||||||
return await arg[0](["hello: "]);
|
return await arg[0](["hello: "]);
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
}),
|
}),
|
||||||
FlatButton(child: Text("运行"), onPressed: () async {
|
FlatButton(
|
||||||
if ((engine?? 0) == 0) {
|
child: Text("运行"),
|
||||||
|
onPressed: () async {
|
||||||
|
if (engine == null) {
|
||||||
print("请先初始化引擎");
|
print("请先初始化引擎");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
resp = await FlutterJs.evaluate(code ?? '', "<eval>");
|
resp = "${await engine.evaluate(code ?? '', "<eval>")}";
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
resp = e.toString();
|
resp = e.toString();
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {});
|
||||||
code = code;
|
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
FlatButton(child: Text("释放引擎"), onPressed: () async {
|
FlatButton(
|
||||||
if ((engine?? 0) == 0) return;
|
child: Text("释放引擎"),
|
||||||
await FlutterJs.close();
|
onPressed: () async {
|
||||||
engine = 0;
|
if (engine != null) return;
|
||||||
|
await engine.destroy();
|
||||||
|
engine = null;
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@@ -3,27 +3,31 @@
|
|||||||
* @Author: ekibun
|
* @Author: ekibun
|
||||||
* @Date: 2020-08-08 08:29:09
|
* @Date: 2020-08-08 08:29:09
|
||||||
* @LastEditors: ekibun
|
* @LastEditors: ekibun
|
||||||
* @LastEditTime: 2020-08-15 13:58:11
|
* @LastEditTime: 2020-08-15 16:21:56
|
||||||
*/
|
*/
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
class FlutterJs {
|
typedef JsMethodHandler = Future<dynamic> Function(String method, List args);
|
||||||
static const MethodChannel _channel = const MethodChannel('soko.ekibun.flutter_qjs');
|
|
||||||
|
|
||||||
static Future<dynamic> Function(String method, List args) methodHandler;
|
class _FlutterJs {
|
||||||
|
factory _FlutterJs() => _getInstance();
|
||||||
static Future<int> initEngine() async {
|
static _FlutterJs get instance => _getInstance();
|
||||||
final int engineId = await _channel.invokeMethod("initEngine");
|
static _FlutterJs _instance;
|
||||||
|
MethodChannel _channel = const MethodChannel('soko.ekibun.flutter_qjs');
|
||||||
|
Map<dynamic, JsMethodHandler> methodHandlers = Map<dynamic, JsMethodHandler>();
|
||||||
|
_FlutterJs._internal() {
|
||||||
_channel.setMethodCallHandler((call) async {
|
_channel.setMethodCallHandler((call) async {
|
||||||
if (methodHandler == null) return call.noSuchMethod(null);
|
print(call.arguments);
|
||||||
return await methodHandler(call.method, _wrapFunctionArguments(call.arguments));
|
var engine = call.arguments["engine"];
|
||||||
|
var args = call.arguments["args"];
|
||||||
|
print(methodHandlers.entries);
|
||||||
|
print(methodHandlers[engine]);
|
||||||
|
if (methodHandlers[engine] == null) return call.noSuchMethod(null);
|
||||||
|
return await methodHandlers[engine](call.method, _wrapFunctionArguments(args));
|
||||||
});
|
});
|
||||||
return engineId;
|
|
||||||
}
|
}
|
||||||
|
dynamic _wrapFunctionArguments(dynamic val) {
|
||||||
static dynamic _wrapFunctionArguments(dynamic val) {
|
|
||||||
if (val is List) {
|
if (val is List) {
|
||||||
for (var i = 0; i < val.length; ++i) {
|
for (var i = 0; i < val.length; ++i) {
|
||||||
val[i] = _wrapFunctionArguments(val[i]);
|
val[i] = _wrapFunctionArguments(val[i]);
|
||||||
@@ -35,20 +39,47 @@ class FlutterJs {
|
|||||||
var arguments = {"function": functionId, "arguments": args};
|
var arguments = {"function": functionId, "arguments": args};
|
||||||
return await _channel.invokeMethod("call", arguments);
|
return await _channel.invokeMethod("call", arguments);
|
||||||
};
|
};
|
||||||
}else for(var key in val.keys) {
|
} else
|
||||||
|
for (var key in val.keys) {
|
||||||
val[key] = _wrapFunctionArguments(val[key]);
|
val[key] = _wrapFunctionArguments(val[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> evaluate(String command, String name) async {
|
static _FlutterJs _getInstance() {
|
||||||
var arguments = {"script": command, "name": command};
|
if (_instance == null) {
|
||||||
final String jsResult = await _channel.invokeMethod("evaluate", arguments);
|
_instance = new _FlutterJs._internal();
|
||||||
return jsResult ?? "null";
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> close() async {
|
class FlutterJs {
|
||||||
return await _channel.invokeMethod("close");
|
dynamic _engine;
|
||||||
|
|
||||||
|
ensureEngine() async {
|
||||||
|
if(_engine == null){
|
||||||
|
_engine = await _FlutterJs.instance._channel.invokeMethod("createEngine");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setMethodHandler(JsMethodHandler handler) async {
|
||||||
|
await ensureEngine();
|
||||||
|
_FlutterJs.instance.methodHandlers[_engine] = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() async {
|
||||||
|
if (_engine != null){
|
||||||
|
await _FlutterJs.instance._channel.invokeMethod("close", {"engine": _engine});
|
||||||
|
_engine = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<dynamic> evaluate(String command, String name) async {
|
||||||
|
ensureEngine();
|
||||||
|
var arguments = {"engine": _engine, "script": command, "name": command};
|
||||||
|
return _FlutterJs.instance._wrapFunctionArguments(
|
||||||
|
await _FlutterJs.instance._channel.invokeMethod("evaluate", arguments));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
* @Author: ekibun
|
* @Author: ekibun
|
||||||
* @Date: 2020-08-14 21:45:02
|
* @Date: 2020-08-14 21:45:02
|
||||||
* @LastEditors: ekibun
|
* @LastEditors: ekibun
|
||||||
* @LastEditTime: 2020-08-15 14:08:04
|
* @LastEditTime: 2020-08-15 15:42:55
|
||||||
*/
|
*/
|
||||||
#include "../cxx/js_engine.hpp"
|
#include "../cxx/js_engine.hpp"
|
||||||
#include <flutter/standard_method_codec.h>
|
#include <flutter/standard_method_codec.h>
|
||||||
@@ -47,7 +47,7 @@ namespace qjs
|
|||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue dartToJs(JSContext *ctx, flutter::EncodableValue val, std::unordered_map<flutter::EncodableValue, JSValue> cache)
|
JSValue dartToJs(JSContext *ctx, flutter::EncodableValue val, std::unordered_map<flutter::EncodableValue, JSValue> cache = std::unordered_map<flutter::EncodableValue, JSValue>())
|
||||||
{
|
{
|
||||||
if (val.IsNull())
|
if (val.IsNull())
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
@@ -111,7 +111,7 @@ namespace qjs
|
|||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
flutter::EncodableValue jsToDart(Value val, std::unordered_map<Value, flutter::EncodableValue> cache)
|
flutter::EncodableValue jsToDart(Value val, std::unordered_map<Value, flutter::EncodableValue> cache = std::unordered_map<Value, flutter::EncodableValue>())
|
||||||
{
|
{
|
||||||
if (cache.find(val) != cache.end())
|
if (cache.find(val) != cache.end())
|
||||||
return cache[val];
|
return cache[val];
|
||||||
|
@@ -30,17 +30,20 @@ namespace
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel;
|
std::shared_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel;
|
||||||
std::promise<qjs::JSFutureReturn> *invokeChannelMethod(std::string name, qjs::Value args)
|
std::promise<qjs::JSFutureReturn> *invokeChannelMethod(std::string name, qjs::Value args, qjs::Engine *engine)
|
||||||
{
|
{
|
||||||
auto promise = new std::promise<qjs::JSFutureReturn>();
|
auto promise = new std::promise<qjs::JSFutureReturn>();
|
||||||
|
auto map = new flutter::EncodableMap();
|
||||||
|
(*map)[std::string("engine")] = (int64_t)engine;
|
||||||
|
(*map)[std::string("args")] = qjs::jsToDart(args, std::unordered_map<qjs::Value, flutter::EncodableValue>());
|
||||||
channel->InvokeMethod(
|
channel->InvokeMethod(
|
||||||
name,
|
name,
|
||||||
std::make_unique<flutter::EncodableValue>(qjs::jsToDart(args, std::unordered_map<qjs::Value, flutter::EncodableValue>())),
|
std::make_unique<flutter::EncodableValue>(*map),
|
||||||
std::make_unique<flutter::MethodResultFunctions<flutter::EncodableValue>>(
|
std::make_unique<flutter::MethodResultFunctions<flutter::EncodableValue>>(
|
||||||
(flutter::ResultHandlerSuccess<flutter::EncodableValue>)[promise](
|
(flutter::ResultHandlerSuccess<flutter::EncodableValue>)[promise](
|
||||||
const flutter::EncodableValue *result) {
|
const flutter::EncodableValue *result) {
|
||||||
promise->set_value((qjs::JSFutureReturn)[result = result ? *result : flutter::EncodableValue()](qjs::JSContext * ctx) {
|
promise->set_value((qjs::JSFutureReturn)[result = result ? *result : flutter::EncodableValue()](qjs::JSContext * ctx) {
|
||||||
qjs::JSValue *ret = new qjs::JSValue{qjs::dartToJs(ctx, result, std::unordered_map<flutter::EncodableValue, qjs::JSValue>())};
|
qjs::JSValue *ret = new qjs::JSValue{qjs::dartToJs(ctx, result)};
|
||||||
return qjs::JSOSFutureArgv{1, ret};
|
return qjs::JSOSFutureArgv{1, ret};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -96,8 +99,6 @@ namespace
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
qjs::Engine *engine = nullptr;
|
|
||||||
|
|
||||||
void FlutterQjsPlugin::HandleMethodCall(
|
void FlutterQjsPlugin::HandleMethodCall(
|
||||||
const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
||||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result)
|
||||||
@@ -108,15 +109,16 @@ namespace
|
|||||||
// and
|
// and
|
||||||
// https://github.com/flutter/engine/tree/master/shell/platform/glfw/client_wrapper/include/flutter
|
// https://github.com/flutter/engine/tree/master/shell/platform/glfw/client_wrapper/include/flutter
|
||||||
// for the relevant Flutter APIs.
|
// for the relevant Flutter APIs.
|
||||||
if (method_call.method_name().compare("initEngine") == 0)
|
if (method_call.method_name().compare("createEngine") == 0)
|
||||||
{
|
{
|
||||||
engine = new qjs::Engine((qjs::DartChannel)invokeChannelMethod);
|
qjs::Engine *engine = new qjs::Engine(invokeChannelMethod);
|
||||||
flutter::EncodableValue response = (int64_t)engine;
|
flutter::EncodableValue response = (int64_t)engine;
|
||||||
result->Success(&response);
|
result->Success(&response);
|
||||||
}
|
}
|
||||||
else if (method_call.method_name().compare("evaluate") == 0)
|
else if (method_call.method_name().compare("evaluate") == 0)
|
||||||
{
|
{
|
||||||
flutter::EncodableMap args = *std::get_if<flutter::EncodableMap>(method_call.arguments());
|
flutter::EncodableMap args = *std::get_if<flutter::EncodableMap>(method_call.arguments());
|
||||||
|
qjs::Engine *engine = (qjs::Engine *)std::get<int64_t>(ValueOrNull(args, "engine"));
|
||||||
std::string script = std::get<std::string>(ValueOrNull(args, "script"));
|
std::string script = std::get<std::string>(ValueOrNull(args, "script"));
|
||||||
std::string name = std::get<std::string>(ValueOrNull(args, "name"));
|
std::string name = std::get<std::string>(ValueOrNull(args, "name"));
|
||||||
auto presult = result.release();
|
auto presult = result.release();
|
||||||
@@ -124,17 +126,18 @@ namespace
|
|||||||
[script, name](qjs::Context &ctx) {
|
[script, name](qjs::Context &ctx) {
|
||||||
return ctx.eval(script, name.c_str(), JS_EVAL_TYPE_GLOBAL);
|
return ctx.eval(script, name.c_str(), JS_EVAL_TYPE_GLOBAL);
|
||||||
},
|
},
|
||||||
[presult](std::string resolve) {
|
[presult](qjs::Value resolve) {
|
||||||
flutter::EncodableValue response = resolve;
|
flutter::EncodableValue response = qjs::jsToDart(resolve);
|
||||||
presult->Success(&response);
|
presult->Success(&response);
|
||||||
},
|
},
|
||||||
[presult](std::string reject) {
|
[presult](qjs::Value reject) {
|
||||||
presult->Error("FlutterJSException", reject);
|
presult->Error("FlutterJSException", qjs::getStackTrack(reject));
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
else if (method_call.method_name().compare("call") == 0)
|
else if (method_call.method_name().compare("call") == 0)
|
||||||
{
|
{
|
||||||
flutter::EncodableMap args = *std::get_if<flutter::EncodableMap>(method_call.arguments());
|
flutter::EncodableMap args = *std::get_if<flutter::EncodableMap>(method_call.arguments());
|
||||||
|
qjs::Engine *engine = (qjs::Engine *)std::get<int64_t>(ValueOrNull(args, "engine"));
|
||||||
qjs::JSValue *function = (qjs::JSValue *)std::get<int64_t>(ValueOrNull(args, "function"));
|
qjs::JSValue *function = (qjs::JSValue *)std::get<int64_t>(ValueOrNull(args, "function"));
|
||||||
flutter::EncodableList arguments = std::get<flutter::EncodableList>(ValueOrNull(args, "arguments"));
|
flutter::EncodableList arguments = std::get<flutter::EncodableList>(ValueOrNull(args, "arguments"));
|
||||||
auto presult = result.release();
|
auto presult = result.release();
|
||||||
@@ -144,7 +147,7 @@ namespace
|
|||||||
qjs::JSValue *callargs = new qjs::JSValue[argscount];
|
qjs::JSValue *callargs = new qjs::JSValue[argscount];
|
||||||
for (size_t i = 0; i < argscount; i++)
|
for (size_t i = 0; i < argscount; i++)
|
||||||
{
|
{
|
||||||
callargs[i] = qjs::dartToJs(ctx.ctx, arguments[i], std::unordered_map<flutter::EncodableValue, qjs::JSValue>());
|
callargs[i] = qjs::dartToJs(ctx.ctx, arguments[i]);
|
||||||
}
|
}
|
||||||
qjs::JSValue ret = JS_Call(ctx.ctx, *function, qjs::JSValue{qjs::JSValueUnion{0}, qjs::JS_TAG_UNDEFINED}, (int)argscount, callargs);
|
qjs::JSValue ret = JS_Call(ctx.ctx, *function, qjs::JSValue{qjs::JSValueUnion{0}, qjs::JS_TAG_UNDEFINED}, (int)argscount, callargs);
|
||||||
qjs::JS_FreeValue(ctx.ctx, *function);
|
qjs::JS_FreeValue(ctx.ctx, *function);
|
||||||
@@ -152,16 +155,17 @@ namespace
|
|||||||
throw qjs::exception{};
|
throw qjs::exception{};
|
||||||
return qjs::Value{ctx.ctx, ret};
|
return qjs::Value{ctx.ctx, ret};
|
||||||
},
|
},
|
||||||
[presult](std::string resolve) {
|
[presult](qjs::Value resolve) {
|
||||||
flutter::EncodableValue response = resolve;
|
flutter::EncodableValue response = qjs::jsToDart(resolve);
|
||||||
presult->Success(&response);
|
presult->Success(&response);
|
||||||
},
|
},
|
||||||
[presult](std::string reject) {
|
[presult](qjs::Value reject) {
|
||||||
presult->Error("FlutterJSException", reject);
|
presult->Error("FlutterJSException", qjs::getStackTrack(reject));
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
else if (method_call.method_name().compare("close") == 0)
|
else if (method_call.method_name().compare("close") == 0)
|
||||||
{
|
{
|
||||||
|
qjs::Engine *engine = (qjs::Engine *)*std::get_if<int64_t>(method_call.arguments());
|
||||||
delete engine;
|
delete engine;
|
||||||
result->Success();
|
result->Success();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user