Skip to content

Commit

Permalink
upgraded dependencies to better support to flutter 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Abner Oliveira committed Mar 25, 2021
1 parent fe83d6a commit 40acd4c
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 59 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.2.4+0

- Updated ffi, http dependencies
- Upgraded code for compatibility with ffi 1.0.0
# 0.2.3+0

- Updated QuickJS engine to version 2020-11-08
Expand Down
14 changes: 7 additions & 7 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ packages:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "1.0.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -75,7 +75,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.2.3+0"
version: "0.2.4+0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand All @@ -87,14 +87,14 @@ packages:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.2"
version: "0.13.1"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.4"
version: "4.0.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -122,7 +122,7 @@ packages:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
version: "1.11.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -162,7 +162,7 @@ packages:
name: sync_http
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
version: "0.3.0"
term_glyph:
dependency: transitive
description:
Expand Down Expand Up @@ -192,5 +192,5 @@ packages:
source: hosted
version: "2.1.0"
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.10.0"
12 changes: 6 additions & 6 deletions lib/extensions/xhr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -307,33 +307,33 @@ extension JavascriptRuntimeXhrExtension on JavascriptRuntime {
switch (eMethod) {
case HttpMethod.head:
response = await httpClient.head(
pendingCall.url,
Uri.parse(pendingCall.url),
headers: pendingCall.headers,
);
break;
case HttpMethod.get:
response = await httpClient.get(
pendingCall.url,
Uri.parse(pendingCall.url),
headers: pendingCall.headers,
);
break;
case HttpMethod.post:
response = await httpClient.post(
pendingCall.url,
Uri.parse(pendingCall.url),
body: jsonEncode(pendingCall.body),
headers: pendingCall.headers,
);
break;
case HttpMethod.put:
response = await httpClient.put(
pendingCall.url,
Uri.parse(pendingCall.url),
body: jsonEncode(pendingCall.body),
headers: pendingCall.headers,
);
break;
case HttpMethod.patch:
response = await httpClient.patch(
pendingCall.url,
Uri.parse(pendingCall.url),
body: jsonEncode(pendingCall.body),
headers: pendingCall.headers,
);
Expand Down Expand Up @@ -530,7 +530,7 @@ void executeHttp(String url, String method, Map<String, String> headers) {
};
http
.get(
url,
Uri.parse(url),
headers: headers,
)
.then(callbackResponse);
Expand Down
14 changes: 7 additions & 7 deletions lib/javascriptcore/binding/js_object_ref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ class JSStaticValue extends Struct {
@required Pointer<NativeFunction<JSObjectSetPropertyCallback>> setProperty,
@required int attributes,
}) =>
allocate<JSStaticValue>().ref
calloc<JSStaticValue>().ref
..name = name ?? nullptr
..getProperty = getProperty ?? nullptr
..setProperty = setProperty ?? nullptr
..attributes =
attributes ?? JSPropertyAttributes.kJSPropertyAttributeNone;

factory JSStaticValue.fromStruct(JSStaticValueStruct struct) =>
allocate<JSStaticValue>().ref
calloc<JSStaticValue>().ref
..name = struct.name
..setProperty = struct.setProperty
..getProperty = struct.getProperty
Expand All @@ -308,7 +308,7 @@ class JSStaticValue extends Struct {
return null;
}
var jSStaticValues =
allocate<JSStaticValue>(count: structList.length + 1).ref;
calloc<JSStaticValue>(structList.length + 1).ref;
for (int index = 0; index < structList.length; index++) {
jSStaticValues[index].setValue(structList[index]);
}
Expand Down Expand Up @@ -368,14 +368,14 @@ class JSStaticFunction extends Struct {
Pointer<NativeFunction<JSObjectCallAsFunctionCallback>> callAsFunction,
@required int attributes,
}) =>
allocate<JSStaticFunction>().ref
calloc<JSStaticFunction>().ref
..name = name ?? nullptr
..callAsFunction = callAsFunction ?? nullptr
..attributes =
attributes ?? JSPropertyAttributes.kJSPropertyAttributeNone;

factory JSStaticFunction.fromStruct(JSStaticFunctionStruct struct) =>
allocate<JSStaticFunction>().ref
calloc<JSStaticFunction>().ref
..name = struct.name
..callAsFunction = struct.callAsFunction
..attributes = struct.attributes;
Expand All @@ -386,7 +386,7 @@ class JSStaticFunction extends Struct {
return null;
}
var jSStaticFunctions =
allocate<JSStaticFunction>(count: structList.length + 1).ref;
calloc<JSStaticFunction>(structList.length + 1).ref;
for (int index = 0; index < structList.length; index++) {
jSStaticFunctions[index].setValue(structList[index]);
}
Expand Down Expand Up @@ -513,7 +513,7 @@ class JSClassDefinition extends Struct {
@required
Pointer<NativeFunction<JSObjectConvertToTypeCallback>> convertToType,
}) =>
allocate<JSClassDefinition>().ref
calloc<JSClassDefinition>().ref
..version = version ?? 0
..attributes = attributes ?? JSClassAttributes.kJSClassAttributeNone
..className = className ?? nullptr
Expand Down
14 changes: 7 additions & 7 deletions lib/javascriptcore/jscore/js_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class JSStaticValue {

JSObjectRef.JSStaticValue create() {
return JSObjectRef.JSStaticValue.allocate(
name: Utf8.toUtf8(name),
name: name.toNativeUtf8(),
getProperty: getProperty ?? nullptr,
setProperty: setProperty ?? nullptr,
attributes: jSPropertyAttributesToCEnum(attributes),
Expand All @@ -306,7 +306,7 @@ class JSStaticValue {

JSObjectRef.JSStaticValueStruct toStruct() {
return JSObjectRef.JSStaticValueStruct(
name: Utf8.toUtf8(name),
name: name.toNativeUtf8(),
getProperty: getProperty ?? nullptr,
setProperty: setProperty ?? nullptr,
attributes: jSPropertyAttributesToCEnum(attributes),
Expand Down Expand Up @@ -335,15 +335,15 @@ class JSStaticFunction {

JSObjectRef.JSStaticFunction create() {
return JSObjectRef.JSStaticFunction.allocate(
name: Utf8.toUtf8(name),
name: name.toNativeUtf8(),
callAsFunction: callAsFunction ?? nullptr,
attributes: jSPropertyAttributesToCEnum(attributes),
);
}

JSObjectRef.JSStaticFunctionStruct toStruct() {
return JSObjectRef.JSStaticFunctionStruct(
name: Utf8.toUtf8(name),
name: name.toNativeUtf8(),
callAsFunction: callAsFunction ?? nullptr,
attributes: jSPropertyAttributesToCEnum(attributes),
);
Expand Down Expand Up @@ -455,7 +455,7 @@ class JSClassDefinition {
return JSObjectRef.JSClassDefinition.allocate(
version: version,
attributes: jSClassAttributesToCEnum(attributes),
className: Utf8.toUtf8(className),
className: className.toNativeUtf8(),
parentClass: parentClass == null ? nullptr : parentClass.pointer,
staticValues: staticValues,
staticFunctions: staticFunctions,
Expand Down Expand Up @@ -1024,14 +1024,14 @@ class JSObjectPointer {

JSObjectPointer([Pointer value])
: this.count = 1,
this.pointer = allocate<Pointer>() {
this.pointer = calloc<Pointer>() {
pointer.value = value ?? nullptr;
}

/// JSObjectRef array
JSObjectPointer.array(List<JSObject> array)
: this.count = array.length,
this.pointer = allocate<Pointer>(count: array.length) {
this.pointer = calloc<Pointer>(array.length) {
for (int i = 0; i < array.length; i++) {
this.pointer[i] = array[i].pointer;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/javascriptcore/jscore/js_string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class JSString {
if (string == null) {
_pointer = nullptr;
} else {
var cString = Utf8.toUtf8(string);
var cString = string.toNativeUtf8();
_pointer = JSStringRef.jSStringCreateWithUTF8CString(cString);
free(cString);
calloc.free(cString);
}
}

Expand Down Expand Up @@ -79,14 +79,14 @@ class JSStringPointer {

JSStringPointer([Pointer value])
: this.count = 1,
this.pointer = allocate<Pointer>() {
this.pointer = calloc<Pointer>() {
pointer.value = value ?? nullptr;
}

/// JSStringRef array
JSStringPointer.array(List<String> array)
: this.count = array.length,
this.pointer = allocate<Pointer>(count: array.length) {
this.pointer = calloc.allocate<Pointer>(array.length) {
for (int i = 0; i < array.length; i++) {
this.pointer[i] = JSString.fromString(array[i]).pointer;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/javascriptcore/jscore/js_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,14 @@ class JSValuePointer {

JSValuePointer([Pointer value])
: this.count = 1,
this.pointer = allocate<Pointer>() {
this.pointer = calloc<Pointer>() {
pointer.value = value ?? nullptr;
}

/// JSValueRef array
JSValuePointer.array(List<JSValue> array)
: this.count = array.length,
this.pointer = allocate<Pointer>(count: array.length) {
this.pointer = calloc<Pointer>(array.length) {
for (int i = 0; i < array.length; i++) {
this.pointer[i] = array[i].pointer;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/javascriptcore/jscore_runtime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class JavascriptCoreRuntime extends JavascriptRuntime {

_sendMessageDartFunc = _sendMessage;

Pointer<Utf8> funcNameCString = Utf8.toUtf8('sendMessage');
Pointer<Utf8> funcNameCString = 'sendMessage'.toNativeUtf8();
var functionObject = jSObjectMakeFunctionWithCallback(
_globalContext,
jSStringCreateWithUTF8CString(funcNameCString),
Expand All @@ -48,7 +48,7 @@ class JavascriptCoreRuntime extends JavascriptRuntime {
functionObject,
jsObject.JSPropertyAttributes.kJSPropertyAttributeNone,
nullptr);
free(funcNameCString);
calloc.free(funcNameCString);

init();
}
Expand All @@ -59,7 +59,7 @@ class JavascriptCoreRuntime extends JavascriptRuntime {
}

JsEvalResult evaluate(String js) {
Pointer<Utf8> scriptCString = Utf8.toUtf8(js);
Pointer<Utf8> scriptCString = js.toNativeUtf8();

JSValuePointer exception = JSValuePointer();
var jsValueRef = jSEvaluateScript(
Expand All @@ -69,7 +69,7 @@ class JavascriptCoreRuntime extends JavascriptRuntime {
nullptr,
1,
exception.pointer);
free(scriptCString);
calloc.free(scriptCString);

String result;

Expand Down
26 changes: 13 additions & 13 deletions lib/quickjs/quickjs_runtime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Pointer<JSValueConst> bridgeCallbackGlobalHandler(
print('EXCEPTION ------ $e');
}
if (result == null) {
Pointer<JSValueConst> nullValue = allocate();
Pointer<JSValueConst> nullValue = calloc();
QuickJsRuntime._jsGetNullValue(ctx, nullValue);
return nullValue;
} else {
Expand Down Expand Up @@ -127,8 +127,8 @@ class QuickJsRuntime extends JavascriptRuntime {
Pointer function,
Pointer argument,
) {
Pointer result = allocate<JSValueConst>();
Pointer<Pointer<Utf8NullTerminated>> stringResult = allocate<Pointer<Utf8NullTerminated>>();
Pointer result = calloc<JSValueConst>();
Pointer<Pointer<Utf8NullTerminated>> stringResult = calloc<Pointer<Utf8NullTerminated>>();
int operationResult =
_callJsFunction1Arg(_context, function, argument, result, stringResult);
String resultStr = Utf8NullTerminated.fromUtf8(stringResult.value);
Expand Down Expand Up @@ -170,9 +170,9 @@ class QuickJsRuntime extends JavascriptRuntime {
String js, {
String fileName = 'nofile.js',
}) {
Pointer<JSValueConst> result = allocate<JSValueConst>();
Pointer<Pointer<Utf8NullTerminated>> stringResult = allocate<Pointer<Utf8NullTerminated>>();
Pointer<Int32> errors = allocate<Int32>();
Pointer<JSValueConst> result = calloc<JSValueConst>();
Pointer<Pointer<Utf8NullTerminated>> stringResult = calloc<Pointer<Utf8NullTerminated>>();
Pointer<Int32> errors = calloc<Int32>();
_jsEvalWrapper(ctx, Utf8NullTerminated.toUtf8(js), js.length, Utf8NullTerminated.toUtf8(fileName), 0,
errors, result, stringResult);

Expand All @@ -190,8 +190,8 @@ class QuickJsRuntime extends JavascriptRuntime {
Type type = getTypeForJsValue(evalResult.rawResult);

if (_jsIsArray(context, evalResult.rawResult) == 1) {
Pointer<JSValueConst> stringifiedValue = allocate();
Pointer<Pointer<Utf8NullTerminated>> stringResultPointer = allocate();
Pointer<JSValueConst> stringifiedValue = calloc();
Pointer<Pointer<Utf8NullTerminated>> stringResultPointer = calloc();
int res = _jSJSONStringify(
context,
evalResult.rawResult,
Expand All @@ -211,8 +211,8 @@ class QuickJsRuntime extends JavascriptRuntime {
case Null:
return null;
case Object:
Pointer<JSValueConst> stringifiedValue = allocate<JSValueConst>();
Pointer<Pointer<Utf8NullTerminated>> stringResultPointer = allocate();
Pointer<JSValueConst> stringifiedValue = calloc<JSValueConst>();
Pointer<Pointer<Utf8NullTerminated>> stringResultPointer = calloc();

int res = _jSJSONStringify(
context,
Expand All @@ -233,7 +233,7 @@ class QuickJsRuntime extends JavascriptRuntime {

@override
int executePendingJob() {
Pointer<JSContext> newContext = allocate<JSContext>();
Pointer<JSContext> newContext = calloc<JSContext>();
return _jsExecutePendingJob(_runtime, newContext);
}

Expand All @@ -253,8 +253,8 @@ class QuickJsRuntime extends JavascriptRuntime {

@override
String jsonStringify(JsEvalResult jsValue) {
Pointer<JSValueConst> stringifiedValue = allocate();
Pointer<Pointer<Utf8NullTerminated>> stringResultPointer = allocate();
Pointer<JSValueConst> stringifiedValue = calloc();
Pointer<Pointer<Utf8NullTerminated>> stringResultPointer = calloc();
int res = _jSJSONStringify(
_context,
jsValue.rawResult,
Expand Down
Loading

0 comments on commit 40acd4c

Please sign in to comment.