Skip to content

Commit

Permalink
fixed all lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
abner committed Jul 8, 2023
1 parent bb57df5 commit 6c1541e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 114 deletions.
74 changes: 2 additions & 72 deletions lib/extensions/xhr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:http/http.dart' as http;
* limitations under the License.
*/

// ignore: non_constant_identifier_names
var _XHR_DEBUG = false;

setXhrDebug(bool value) => _XHR_DEBUG = value;
Expand Down Expand Up @@ -337,7 +338,7 @@ extension JavascriptRuntimeXhrExtension on JavascriptRuntime {
final error = xhrResult.error;
// send back to the javascript environment the
// response for the http pending callback
final xhrEvalCallback = this.evaluate(
this.evaluate(
"globalThis.xhrRequests[${pendingCall.idRequest}].callback($responseInfo, `$responseText`, $error);",
);
});
Expand Down Expand Up @@ -405,51 +406,6 @@ extension JavascriptRuntimeXhrExtension on JavascriptRuntime {
});
return this;
}

void responseCallback(int idRequest, http.Response response) {
// String body = response.body.replaceAll("\n", "").replaceAll("\r", "");
// print('Here 1: $body');
//XmlHttpRequestResponse xhrResult;
// try {
// print('Here 1.1');
// xhrResult = XmlHttpRequestResponse(
// responseText: jsonEncode(body),
// responseInfo: XhtmlHttpResponseInfo(statusCode: 200, statusText: "OK"),
// );
// print('Here 2');
// } on Error catch (e) {
// print('Here 3: $e');
// xhrResult = XmlHttpRequestResponse(
// responseText: e.toString(),
// responseInfo: XhtmlHttpResponseInfo(statusCode: 200, statusText: "OK"),
// );
// } on Exception catch (e) {
// print('Here 4: $e');
// xhrResult = XmlHttpRequestResponse(
// responseText: e.toString(),
// responseInfo: XhtmlHttpResponseInfo(statusCode: 200, statusText: "OK"),
// );
// }

// final responseInfo = jsonEncode(xhrResult.responseInfo);
// print('Here 3');
// final responseText = xhrResult.responseText;
// final error = xhrResult.error;

// String responseText =
// '{"ok": true, "time": "${DateTime.now().toIso8601String()}" }'; //"{\"userId\": 1, \"id\": 1, \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\", \"body\": \"quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto\"}";
// String responseInfo =
// """{"statusCode":200,"statusText":"{}","responseHeaders":"[]"}""";
// String error = "null";
// print('HERE 11111');
// final xhrEvalCallback = this.eval(
// "globalThis.xhrRequests[$idRequest].callback($responseInfo, $responseText, $error);",
// );
// print('HERE 22222');

// // if (_XHR_DEBUG) print('xhrcallback call result: $xhrEvalCallback');
// print('Here 5');
}
}

class XhtmlHttpResponseInfo {
Expand Down Expand Up @@ -490,29 +446,3 @@ class XmlHttpRequestResponse {
};
}
}

void executeHttp(String url, String method, Map<String, String> headers) {
HttpMethod eMethod = HttpMethod.values
.firstWhere((e) => e.toString() == ("HttpMethod.$method"));
String idRequest = "1";
var callbackResponse = (http.Response response) {
final xhrResult = XmlHttpRequestResponse(
responseText: utf8.decode(response.bodyBytes),
responseInfo: XhtmlHttpResponseInfo(statusCode: 200, statusText: "{}"),
);

final responseInfo = jsonEncode(xhrResult.responseInfo);
final responseText = xhrResult.responseText;
final error = xhrResult.error;

print(
"globalThis.xhrRequests[$idRequest].callback($responseInfo, $responseText, $error);",
);
};
http
.get(
Uri.parse(url),
headers: headers,
)
.then(callbackResponse);
}
1 change: 1 addition & 0 deletions lib/flutter_js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class FlutterJs {

bool isReady() => _ready;

// ignore: non_constant_identifier_names
static bool DEBUG = false;

Future<String> eval(String code) {
Expand Down
2 changes: 1 addition & 1 deletion lib/javascript_runtime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ abstract class JavascriptRuntime {
}

void _setupSetTimeout() {
final setTImeoutResult = evaluate("""
evaluate("""
var __NATIVE_FLUTTER_JS__setTimeoutCount = -1;
var __NATIVE_FLUTTER_JS__setTimeoutCallbacks = {};
function setTimeout(fnTimeout, timeout) {
Expand Down
23 changes: 11 additions & 12 deletions lib/quickjs-sync-server/quickjs_oasis_jsbridge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import 'dart:ui';
import 'package:flutter_js/flutter_js.dart';
import 'package:sync_http/sync_http.dart';

ReceivePort _callDartReceivePort = new ReceivePort();
// ReceivePort _callDartReceivePort = new ReceivePort();

void _setupCallDartPorts() {
IsolateNameServer.registerPortWithName(
_callDartReceivePort.sendPort, 'QuickJsServiceCallDart');
// void _setupCallDartPorts() {
// IsolateNameServer.registerPortWithName(
// _callDartReceivePort.sendPort, 'QuickJsServiceCallDart');

_callDartReceivePort.listen((portMessage) {
final decodedMessage = (portMessage as String).split(':');
int idEngine = int.parse(decodedMessage[0]);
String channel = decodedMessage[1];
String message = utf8.decode(base64.decode(decodedMessage[2]));
});
}
// _callDartReceivePort.listen((portMessage) {
// final decodedMessage = (portMessage as String).split(':');
// int idEngine = int.parse(decodedMessage[0]);
// String channel = decodedMessage[1];
// String message = utf8.decode(base64.decode(decodedMessage[2]));
// });
// }

class QuickJsService extends JavascriptRuntime {
ReceivePort _receivePort = new ReceivePort();
Expand All @@ -34,7 +34,6 @@ class QuickJsService extends JavascriptRuntime {
_startServer();
IsolateNameServer.registerPortWithName(
_receivePort.sendPort, 'QuickJsService');
// TODO: remove from here
initChannelFunctions();
}

Expand Down
3 changes: 3 additions & 0 deletions lib/quickjs/qjs_typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const JS_TAG_FIRST = -11,
JS_TAG_EXCEPTION = 6,
JS_TAG_FLOAT64 = 7;

// ignore: camel_case_types
typedef JS_NewRuntimeDartBridge = Pointer<JSRuntime> Function();

typedef ChannelCallback = Pointer<JSValueConst> Function(
Expand All @@ -54,6 +55,7 @@ typedef ChannelCallback = Pointer<JSValueConst> Function(
Pointer<Utf8NullTerminated>,
);

// ignore: camel_case_types
typedef JS_NewContextFn = Pointer<JSContext> Function(
Pointer<JSRuntime>? jrt,
Pointer<NativeFunction<ChannelCallback>>? fnConsoleLog,
Expand All @@ -71,6 +73,7 @@ typedef JSEvalWrapper = Pointer Function(
Pointer<JSValueConst> result,
Pointer<Pointer<Utf8NullTerminated>> stringResult);

// ignore: camel_case_types
typedef JS_GetNullValue = Pointer Function(
Pointer<JSContext> ctx,
Pointer<JSValueConst> v,
Expand Down
12 changes: 6 additions & 6 deletions lib/quickjs/quickjs_runtime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class QuickJsRuntime extends JavascriptRuntime {
.lookup<
NativeFunction<
Void Function(
Pointer<JSRuntime>,
IntPtr,
)>>('jsSetMaxStackSize')
Pointer<JSRuntime>,
IntPtr,
)>>('jsSetMaxStackSize')
.asFunction();

// NATIVE BRIDGE DECLARATIONS
Expand Down Expand Up @@ -220,7 +220,7 @@ class QuickJsRuntime extends JavascriptRuntime {
if (_jsIsArray(context, evalResult.rawResult) == 1) {
Pointer<JSValueConst>? stringifiedValue = calloc();
Pointer<Pointer<Utf8NullTerminated>> stringResultPointer = calloc();
int res = _jSJSONStringify(
_jSJSONStringify(
context,
evalResult.rawResult,
stringifiedValue,
Expand All @@ -243,7 +243,7 @@ class QuickJsRuntime extends JavascriptRuntime {
Pointer<JSValueConst>? stringifiedValue = calloc<JSValueConst>();
Pointer<Pointer<Utf8NullTerminated>> stringResultPointer = calloc();

int res = _jSJSONStringify(
_jSJSONStringify(
context,
evalResult.rawResult,
stringifiedValue,
Expand Down Expand Up @@ -285,7 +285,7 @@ class QuickJsRuntime extends JavascriptRuntime {
String jsonStringify(JsEvalResult jsValue) {
Pointer<JSValueConst>? stringifiedValue = calloc();
Pointer<Pointer<Utf8NullTerminated>> stringResultPointer = calloc();
int res = _jSJSONStringify(
_jSJSONStringify(
_context,
jsValue.rawResult,
stringifiedValue,
Expand Down
21 changes: 1 addition & 20 deletions lib/quickjs/quickjs_runtime2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class QuickJsRuntime2 extends JavascriptRuntime {
return err;
}
}, timeout ?? 0, port);
final stackSize = this.stackSize ?? 0;
final stackSize = this.stackSize;
if (stackSize > 0) jsSetMaxStackSize(rt, stackSize);
final memoryLimit = this.memoryLimit ?? 0;
if (memoryLimit > 0) jsSetMemoryLimit(rt, memoryLimit);
Expand Down Expand Up @@ -196,23 +196,12 @@ class QuickJsRuntime2 extends JavascriptRuntime {
return JsEvalResult(exception.toString(), exception, isError: true);
}
final result = _jsToDart(ctx, jsval);
// if (result is Future) {
// result.then((e) {
// print('E: $e');
// return e;
// });
// print(
// 'RESULT: ${result.whenComplete(() => print('COMPLETED _-----------------'))}');
// print(
// 'RESULT: ${result.onError((error, stackTrace) => print('ERROR: $error _-----------------'))}');
// }
jsFreeValue(ctx, jsval);
return JsEvalResult(result?.toString() ?? "null", result);
}

@override
JsEvalResult callFunction(Pointer<NativeType> fn, Pointer<NativeType> obj) {
// TODO: implement callFunction
throw UnimplementedError();
}

Expand Down Expand Up @@ -268,18 +257,10 @@ class QuickJsRuntime2 extends JavascriptRuntime {
}
}
]);
// final sendMessageCreateFnResult = evaluate("""
// function sendMessage(channelName, message) {
// return FLUTTER_JS_NATIVE_BRIDGE_sendMessage.apply(globalThis, [channelName, message]);
// }
// sendMessage
// """);
//print('RESULT creating sendMessage function: $sendMessageCreateFnResult');
}

@override
String jsonStringify(JsEvalResult jsValue) {
// TODO: implement jsonStringify
throw UnimplementedError();
}

Expand Down
3 changes: 0 additions & 3 deletions test/flutter_js_test.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import 'package:flutter/services.dart';
import 'package:flutter_js/flutter_js.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
const MethodChannel channel = MethodChannel('flutter_js');

TestWidgetsFlutterBinding.ensureInitialized();

late JavascriptRuntime jsRuntime;
Expand Down

0 comments on commit 6c1541e

Please sign in to comment.