Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.8.3"
version: "0.8.5"
flutter_lints:
dependency: "direct dev"
description:
Expand Down
41 changes: 41 additions & 0 deletions example/test/flutter_js_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// ignore_for_file: constant_identifier_names, unused_local_variable

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart' show PlatformException;
import 'package:flutter_js/flutter_js.dart';
import 'package:flutter_test/flutter_test.dart';

String one = '1' * 514;
String two = '2' * 515;
String three = '3' * 516;

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

Expand All @@ -17,6 +24,40 @@ void main() {
} on Error catch (_) {}
});

Future<dynamic> longString() async {
final code = '''// js
(async function() {
let ret = '$one' + '$two' + '$three'
return ret
})()
''';

const int PROMISE_TIMEOUT = 120;
try {
var res = await jsRuntime.evaluateAsync(code, sourceUrl: '<test eval>');
jsRuntime.executePendingJob();
final prom = await jsRuntime.handlePromise(res,
timeout: const Duration(seconds: PROMISE_TIMEOUT));
var result = await prom.rawResult;
if (result is JSError || prom.isError) {
throw Exception('JSError: $result');
}
return result;
} on PlatformException catch (e) {
debugPrint('Platform exception [runJsCodeAsync]: ${e.details}');
rethrow;
} catch (e) {
debugPrint('Exception [runJsCodeAsync]: rethrow');
rethrow;
}
}

test('string concat with > 512 chars', () async {
final result = await longString();
String match = one + two + three;
expect(result, equals(match));
});

test('evaluate javascript', () {
final result = jsRuntime.evaluate('Math.pow(5,3)');
if (kDebugMode) {
Expand Down
11 changes: 0 additions & 11 deletions lib/flutter_js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import './extensions/handle_promises.dart';
import './quickjs/quickjs_runtime2.dart';

export './extensions/handle_promises.dart';
//import 'package:flutter_js/quickjs-sync-server/quickjs_oasis_jsbridge.dart';
//import 'package:flutter_js/quickjs/quickjs_runtime.dart';

export './quickjs/quickjs_runtime.dart';
export './quickjs/quickjs_runtime2.dart';
export 'javascript_runtime.dart';
export 'js_eval_result.dart';
export 'quickjs-sync-server/quickjs_oasis_jsbridge.dart';

// import condicional to not import ffi libraries when using web as target
// import "something.dart" if (dart.library.io) "other.dart";
Expand All @@ -34,7 +32,6 @@ JavascriptRuntime getJavascriptRuntime({
int stackSize = extraArgs?['stackSize'] ?? 1024 * 1024;
runtime = QuickJsRuntime2(stackSize: stackSize);
// FlutterJs engine = FlutterJs();
// runtime = QuickJsService(engine);
} else if (Platform.isWindows) {
runtime = QuickJsRuntime2();
} else if (Platform.isLinux) {
Expand All @@ -49,14 +46,6 @@ JavascriptRuntime getJavascriptRuntime({
return runtime;
}

// JavascriptRuntime getJavascriptRuntime({bool xhr = true}) {
// JavascriptRuntime runtime = JavascriptCoreRuntime();
// // setFetchDebug(true);
// if (xhr) runtime.enableFetch();
// runtime.enableHandlePromises();
// return runtime;
// }

final Map<int?, FlutterJs> _engineMap = {};

MethodChannel _methodChannel = const MethodChannel('io.abner.flutter_js')
Expand Down
251 changes: 0 additions & 251 deletions lib/quickjs-sync-server/quickjs_oasis_jsbridge.dart

This file was deleted.

1 change: 1 addition & 0 deletions lib/quickjs/ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class JSTag {
static const BIG_FLOAT = -9;
static const SYMBOL = -8;
static const STRING = -7;
static const STRING_ROPE = -6;
static const MODULE = -3; /* used internally */
static const FUNCTION_BYTECODE = -2; /* used internally */
static const OBJECT = -1;
Expand Down
2 changes: 1 addition & 1 deletion lib/quickjs/quickjs_runtime2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class QuickJsRuntime2 extends JavascriptRuntime {
final jsval = jsEval(
ctx,
command,
name ?? '<eval>',
sourceUrl ?? name ?? '<eval>',
evalFlags ?? JSEvalFlag.GLOBAL,
);

Expand Down
3 changes: 3 additions & 0 deletions lib/quickjs/wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ dynamic _jsToDart(Pointer<JSContext> ctx, Pointer<JSValue> val,
return jsToInt64(ctx, val);
case JSTag.STRING:
return jsToCString(ctx, val);
case JSTag.STRING_ROPE:
return jsToCString(ctx, val);
case JSTag.OBJECT:
final rt = jsGetRuntime(ctx);
final dartObjectClassId = runtimeOpaques[rt]?.dartObjectClassId;
Expand Down Expand Up @@ -244,6 +246,7 @@ dynamic _jsToDart(Pointer<JSContext> ctx, Pointer<JSValue> val,
return ret;
}
default:
// print('--- Undefined tag ---');
}
return null;
}
Binary file modified linux/shared/libquickjs_c_bridge_plugin.so
Binary file not shown.