Skip to content

Commit 2e25af0

Browse files
committed
Merge branch 'master' of github.com:abner/flutter_js
2 parents f5f0cf5 + 08486ae commit 2e25af0

File tree

6 files changed

+34
-17
lines changed

6 files changed

+34
-17
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
# 0.5.0+1
2+
3+
- Fix the handle_promises when the promise result is not a string
14
# 0.5.0+0
25

36
- Fixes issue relative to build on Dart 2.13 (issues #41 and #42)
7+
# 0.4.0+6
8+
9+
- Fix executePendingJobs (wasn't dispatching in the most current version)
10+
# 0.4.0+5
11+
12+
- Removed console.log from fetch.js
413

514
# 0.4.0+4
615

7-
- Small README.md fix
16+
- Fixed issue on xhr requests - wasn't passing headers to the requests
817

918
# 0.4.0+3
1019

assets/js/fetch.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ function fetch(url, options) {
1515
json: () => {
1616
// TODO: review this handle because it may discard \n from json attributes
1717
try {
18-
console.log('RESPONSE TEXT IN FETCH: ' + request.responseText);
18+
// console.log('RESPONSE TEXT IN FETCH: ' + request.responseText);
1919
return Promise.resolve(JSON.parse(request.responseText));
2020
} catch (e) {
21-
console.log('ERROR on fetch parsing JSON: ' + e.message);
21+
// console.log('ERROR on fetch parsing JSON: ' + e.message);
2222
return Promise.resolve(request.responseText);
2323
}
2424
},
@@ -47,8 +47,16 @@ function fetch(url, options) {
4747

4848
request.withCredentials = options.credentials=='include';
4949

50-
for (const i in options.headers) {
51-
request.setRequestHeader(i, options.headers[i]);
50+
if (options.headers) {
51+
if (options.headers.constructor.name == 'Object') {
52+
for (const i in options.headers) {
53+
request.setRequestHeader(i, options.headers[i]);
54+
}
55+
} else { // if it is some Headers pollyfill, the way to iterate is through for of
56+
for (const header of options.headers) {
57+
request.setRequestHeader(header[0], header[1]);
58+
}
59+
}
5260
}
5361

5462
request.send(options.body || null);

lib/extensions/handle_promises.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ extension HandlePromises on JavascriptRuntime {
127127
// this.executePendingJob();
128128
// });
129129
return await (value.rawResult as Future<dynamic>).then((dynamic res) {
130-
final resEval = JsEvalResult(res, value.rawResult);
130+
final resEval = JsEvalResult("$res", value.rawResult);
131131
completer.complete(resEval);
132132
completed = true;
133133
return resEval;

lib/extensions/xhr.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,21 +366,21 @@ extension JavascriptRuntimeXhrExtension on JavascriptRuntime {
366366
try {
367367
String? method = arguments[0];
368368
String? url = arguments[1];
369-
List<String> headersList =
370-
(arguments[2] as List<dynamic>).cast<String>();
369+
dynamic headersList = arguments[2];
371370
String? body = arguments[3];
372371
int? idRequest = arguments[4];
373372

374373
Map<String, String> headers = {};
375-
headersList.forEach((value) {
376-
final headerMatch = regexpHeader.allMatches(value).first;
377-
String? headerName = headerMatch.group(0);
378-
String? headerValue = headerMatch.group(1);
379-
if (headerName != null) {
380-
headers[headerName] = headerValue ?? '';
381-
}
374+
headersList.forEach((header) {
375+
// final headerMatch = regexpHeader.allMatches(value).first;
376+
// String? headerName = headerMatch.group(0);
377+
// String? headerValue = headerMatch.group(1);
378+
// if (headerName != null) {
379+
// headers[headerName] = headerValue ?? '';
380+
// }
381+
String headerKey = header[0];
382+
headers[headerKey] = header[1];
382383
});
383-
384384
(dartContext[XHR_PENDING_CALLS_KEY] as List<dynamic>).add(
385385
XhrPendingCall(
386386
idRequest: idRequest,

lib/quickjs/quickjs_runtime2.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class QuickJsRuntime2 extends JavascriptRuntime {
214214

215215
@override
216216
int executePendingJob() {
217-
_executePendingJob();
217+
this.dispatch();
218218
return 0;
219219
}
220220

-16.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)