Skip to content

Commit fb0688b

Browse files
charles-chaijianghai33
authored andcommitted
[#628]V8升级到9.3.345.11
1 parent 839910c commit fb0688b

38 files changed

+483
-179
lines changed

core/runtime/android/features/src/main/java/org/hapjs/features/AbstractRequest.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
import android.text.TextUtils;
1111
import android.util.Log;
1212
import android.webkit.MimeTypeMap;
13-
import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;
13+
14+
import com.eclipsesource.v8.V8ArrayBuffer;
15+
import com.eclipsesource.v8.utils.ArrayBuffer;
16+
1417
import java.io.File;
1518
import java.io.FileNotFoundException;
1619
import java.io.IOException;
@@ -32,6 +35,7 @@
3235
import okhttp3.OkHttpClient;
3336
import okhttp3.RequestBody;
3437
import okhttp3.internal.http.HttpMethod;
38+
3539
import org.hapjs.bridge.CallbackHybridFeature;
3640
import org.hapjs.bridge.Request;
3741
import org.hapjs.bridge.Response;
@@ -255,10 +259,11 @@ private RequestBody getSimplePostBody(Headers headers, Object objData, String pk
255259
if (TextUtils.isEmpty(contentType)) {
256260
contentType = RequestHelper.CONTENT_TYPE_OCTET_STREAM;
257261
}
258-
ByteBuffer b = ((ArrayBuffer) objData).getByteBuffer();
259-
// copy memory to heap
260-
byte[] buffer = new byte[b.remaining()];
261-
b.get(buffer);
262+
263+
//copy memory to heap
264+
V8ArrayBuffer v8ArrayBuffer = ((ArrayBuffer) objData).getV8ArrayBuffer();
265+
byte[] buffer = new byte[v8ArrayBuffer.remaining()];
266+
v8ArrayBuffer.get(buffer);
262267
return RequestBody.create(MediaType.parse(contentType), buffer);
263268
}
264269

@@ -434,7 +439,11 @@ private void parseData(Request request, SerializeObject result, okhttp3.Response
434439
throw new IOException("Fail to Parsing Data to Json!");
435440
}
436441
} else if (RESPONSE_TYPE_ARRAYBUFFER.equalsIgnoreCase(responseType)) {
437-
result.put(RESULT_KEY_DATA, new ArrayBuffer(response.body().bytes()));
442+
byte[] bytes = response.body().bytes();
443+
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(bytes.length);
444+
byteBuffer.put(bytes);
445+
byteBuffer.rewind();
446+
result.put(RESULT_KEY_DATA, byteBuffer);
438447
} else if (RESPONSE_TYPE_FILE.equalsIgnoreCase(responseType)) {
439448
result.put(RESULT_KEY_DATA, parseFile(request, response));
440449
} else {

core/runtime/android/features/src/main/java/org/hapjs/features/Decode.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
package org.hapjs.features;
77

88
import android.util.Log;
9-
import com.eclipsesource.v8.utils.typedarrays.TypedArray;
109
import java.nio.ByteBuffer;
1110
import java.nio.CharBuffer;
1211
import java.nio.charset.CharacterCodingException;
1312
import java.nio.charset.Charset;
1413
import java.nio.charset.CharsetDecoder;
14+
1515
import org.hapjs.bridge.FeatureExtension;
1616
import org.hapjs.bridge.Request;
1717
import org.hapjs.bridge.Response;
1818
import org.hapjs.bridge.annotation.ActionAnnotation;
1919
import org.hapjs.bridge.annotation.FeatureExtensionAnnotation;
2020
import org.hapjs.common.json.JSONObject;
2121
import org.hapjs.render.jsruntime.serialize.SerializeObject;
22+
import org.hapjs.render.jsruntime.serialize.TypedArrayProxy;
2223
import org.json.JSONException;
2324

2425
@FeatureExtensionAnnotation(
@@ -67,13 +68,14 @@ private Response decode(Request request) throws JSONException {
6768
String encoding = params.optString(PARAMS_ENCODING, "UTF-8");
6869
boolean fatal = params.optBoolean(PARAMS_FATAL, false);
6970
boolean ignoreBom = params.optBoolean(PARAMS_IGNORE_BOM, false);
70-
TypedArray typedArray = params.optTypedArray(PARAMS_ARRAY_BUFFER);
71-
if (typedArray == null) {
71+
TypedArrayProxy typedArrayProxy = params.optTypedArrayProxy(PARAMS_ARRAY_BUFFER);
72+
if (typedArrayProxy == null) {
7273
jsonObject.put(KEY_ERROR_CODE, ERROR_CODE_TYPE_ERROR);
7374
jsonObject.put(KEY_ERROR_MSG, "The encoded data was not valid.");
7475
return new Response(ERROR_CODE_TYPE_ERROR, jsonObject);
7576
}
76-
return decode(encoding, typedArray.getByteBuffer(), ignoreBom, fatal);
77+
78+
return decode(encoding, typedArrayProxy.getBuffer(), ignoreBom, fatal);
7779
} catch (Exception e) {
7880
Log.e(TAG, "params are not valid.", e);
7981
jsonObject.put(KEY_ERROR_CODE, Response.CODE_ILLEGAL_ARGUMENT);

core/runtime/android/features/src/main/java/org/hapjs/features/Record.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
import android.os.Looper;
1515
import android.util.Log;
1616

17-
import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;
18-
import com.eclipsesource.v8.utils.typedarrays.UInt8Array;
17+
import com.eclipsesource.v8.V8Value;
1918

2019
import java.io.File;
2120
import java.io.FileOutputStream;
2221
import java.io.IOException;
2322

23+
import java.nio.ByteBuffer;
2424
import org.hapjs.bridge.Callback;
2525
import org.hapjs.bridge.CallbackContext;
2626
import org.hapjs.bridge.CallbackHybridFeature;
@@ -36,6 +36,7 @@
3636
import org.hapjs.render.Display;
3737
import org.hapjs.render.jsruntime.serialize.JavaSerializeObject;
3838
import org.hapjs.render.jsruntime.serialize.SerializeObject;
39+
import org.hapjs.render.jsruntime.serialize.TypedArrayProxy;
3940
import org.json.JSONException;
4041
import org.json.JSONObject;
4142

@@ -472,8 +473,10 @@ public void run() {
472473
private SerializeObject makeResult(boolean isLastFrame, byte[] bytes) {
473474
SerializeObject result = new JavaSerializeObject();
474475
result.put(RESULT_IS_LAST_FRAME, isLastFrame);
475-
UInt8Array array = new UInt8Array(new ArrayBuffer(bytes));
476-
result.put(RESULT_FRAME_BUFFER, array);
476+
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(bytes.length);
477+
byteBuffer.put(bytes);
478+
byteBuffer.rewind();
479+
result.put(RESULT_FRAME_BUFFER, new TypedArrayProxy(V8Value.UNSIGNED_INT_8_ARRAY, byteBuffer));
477480
return result;
478481
}
479482

core/runtime/android/features/src/main/java/org/hapjs/features/bluetooth/Bluetooth.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
import android.util.Log;
2727
import android.util.Pair;
2828
import androidx.annotation.NonNull;
29-
import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;
29+
30+
import com.eclipsesource.v8.V8ArrayBuffer;
31+
import com.eclipsesource.v8.utils.ArrayBuffer;
32+
3033
import java.nio.ByteBuffer;
3134
import java.util.ArrayList;
3235
import java.util.Arrays;
@@ -38,6 +41,7 @@
3841
import java.util.Vector;
3942
import java.util.concurrent.ConcurrentSkipListSet;
4043
import java.util.concurrent.Semaphore;
44+
4145
import org.hapjs.bridge.CallbackContext;
4246
import org.hapjs.bridge.CallbackHybridFeature;
4347
import org.hapjs.bridge.FeatureExtension;
@@ -632,10 +636,10 @@ private void writeCharacteristic(final Request request) throws SerializeExceptio
632636
String serviceUUID = params.getString(PARAM_SERVICE_UUID);
633637
String charaUUID = params.getString(PARAM_CHARACTERISTIC_UUID);
634638
ArrayBuffer value = (ArrayBuffer) params.get(PARAM_VALUE);
635-
ByteBuffer b = value.getByteBuffer();
636639
// copy memory to heap
637-
byte[] buffer = new byte[b.remaining()];
638-
b.get(buffer);
640+
V8ArrayBuffer v8ArrayBuffer = value.getV8ArrayBuffer();
641+
byte[] buffer = new byte[v8ArrayBuffer.remaining()];
642+
v8ArrayBuffer.get(buffer);
639643
BleManager.getInstance()
640644
.writeCharacteristic(
641645
address, serviceUUID, charaUUID, buffer, getOperationCallback(request));
@@ -863,7 +867,10 @@ public void onCharacteristicChanged(
863867
serviceUUID.toUpperCase());
864868
result.put(RESULT_CHARACTERISTIC_UUID,
865869
characteristicUUID.toUpperCase());
866-
result.put(RESULT_VALUE, new ArrayBuffer(data));
870+
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(data.length);
871+
byteBuffer.put(data);
872+
byteBuffer.rewind();
873+
result.put(RESULT_VALUE, byteBuffer);
867874
runCallbackContext(
868875
EVENT_ON_CHARACTERISTIC_VALUE_CHANGE,
869876
CODE_ON_CHARACTERISTIC_VALUE_CHANGE,
@@ -972,10 +979,17 @@ private JavaSerializeObject toJavaSerializeObject() {
972979
new JavaSerializeArray(new JSONArray(mAdvertisServiceUUIDs)));
973980
JavaSerializeObject serviceData = new JavaSerializeObject();
974981
for (Pair<String, byte[]> d : mServiceData) {
975-
serviceData.put(d.first, new ArrayBuffer(d.second));
982+
byte[] bytes = d.second;
983+
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(bytes.length);
984+
byteBuffer.put(bytes);
985+
byteBuffer.rewind();
986+
serviceData.put(d.first, byteBuffer);
976987
}
977988
result.put(RESULT_SERVICE_DATA, serviceData);
978-
result.put(RESULT_ADVERTIS_DATA, new ArrayBuffer(mAdvertisData));
989+
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(mAdvertisData.length);
990+
byteBuffer.put(mAdvertisData);
991+
byteBuffer.rewind();
992+
result.put(RESULT_ADVERTIS_DATA, byteBuffer);
979993
return result;
980994
}
981995

core/runtime/android/features/src/main/java/org/hapjs/features/net/task/RequestTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@FeatureExtensionAnnotation(
2626
name = RequestTask.FEATURE_NAME,
2727
actions = {
28-
@ActionAnnotation(name = RequestTask.ACTION_REQUEST, mode = FeatureExtension.Mode.SYNC_CALLBACK),
28+
@ActionAnnotation(name = RequestTask.ACTION_REQUEST, mode = FeatureExtension.Mode.SYNC_CALLBACK, normalize = Extension.Normalize.RAW),
2929
@ActionAnnotation(name = RequestTask.ACTION_ON_HEADERS_RECEIVED, mode = FeatureExtension.Mode.CALLBACK, multiple = Extension.Multiple.MULTI),
3030
@ActionAnnotation(name = RequestTask.ACTION_OFF_HEADERS_RECEIVED, mode = FeatureExtension.Mode.SYNC, multiple = Extension.Multiple.MULTI),
3131
@ActionAnnotation(name = RequestTask.ACTION_ABORT, mode = FeatureExtension.Mode.ASYNC)

core/runtime/android/features/src/main/java/org/hapjs/features/net/task/RequestTaskImpl.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import android.text.TextUtils;
1212
import android.util.Log;
1313

14-
import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;
14+
import com.eclipsesource.v8.V8Value;
1515

1616
import org.hapjs.bridge.ExtensionManager;
1717
import org.hapjs.bridge.InstanceManager;
@@ -27,6 +27,7 @@
2727
import org.hapjs.render.jsruntime.serialize.SerializeException;
2828
import org.hapjs.render.jsruntime.serialize.SerializeHelper;
2929
import org.hapjs.render.jsruntime.serialize.SerializeObject;
30+
import org.hapjs.render.jsruntime.serialize.TypedArrayProxy;
3031
import org.json.JSONArray;
3132
import org.json.JSONException;
3233
import org.json.JSONObject;
@@ -101,7 +102,7 @@ public void execute() {
101102
String pkg = mRequest.getApplicationContext().getPackage();
102103
SerializeObject reader = mRequest.getSerializeParams();
103104
String url = reader.getString(RequestTask.PARAMS_KEY_URL);
104-
String responseType = reader.optString(RequestTask.PARAMS_KEY_RESPOSNE_TYPE, RequestTask.RESPONSE_TYPE_TEXT);
105+
String responseType = reader.optString(RequestTask.PARAMS_KEY_RESPOSNE_TYPE, RequestTask.RESPONSE_TYPE_TEXT).toLowerCase();
105106
String dataType = reader.optString(RequestTask.PARAMS_KEY_DATA_TYPE, RequestTask.DATA_TYPE_JSON);
106107
Object dataObj = reader.opt(RequestTask.PARAMS_KEY_DATA);
107108
SerializeObject jsonHeader = reader.optSerializeObject(RequestTask.PARAMS_KEY_HEADER);
@@ -252,16 +253,20 @@ private RequestBody getSimplePostBody(Headers headers, Object objData)
252253
return RequestBody.create(
253254
MediaType.parse(CONTENT_TYPE_FORM_URLENCODED),
254255
textParams);
255-
} else if (objData instanceof ArrayBuffer) {
256+
} else if (objData instanceof ByteBuffer) {
256257
Log.d(TAG, "getSimplePost objData is ArrayBuffer, contentType=" + contentType);
257258
if (TextUtils.isEmpty(contentType)) {
258259
contentType = CONTENT_TYPE_JSON;
259260
}
260-
ByteBuffer b = ((ArrayBuffer) objData).getByteBuffer();
261261
//copy memory to heap
262-
byte[] buffer = new byte[b.remaining()];
263-
b.get(buffer);
264-
return RequestBody.create(MediaType.parse(contentType), buffer);
262+
ByteBuffer byteBuffer = (ByteBuffer) objData;
263+
byte[] buffer = new byte[byteBuffer.remaining()];
264+
byteBuffer.get(buffer);
265+
try {
266+
return RequestBody.create(MediaType.parse(contentType), new JSONArray(buffer).toString());
267+
} catch (JSONException e) {
268+
throw new RuntimeException(e);
269+
}
265270
}
266271

267272
contentType = TextUtils.isEmpty(contentType) ? CONTENT_TYPE_TEXT_PLAIN : contentType;
@@ -319,7 +324,12 @@ public void onResponse(Call call, okhttp3.Response response) throws IOException
319324
result.put(RequestTask.RESULT_KEY_STATUS_CODE, response.code());
320325
result.put(RequestTask.RESULT_KEY_HEADER, parseHeaders(response));
321326
if (response.body() != null) {
322-
result.put(RequestTask.RESULT_KEY_DATA, new ArrayBuffer(response.body().bytes()));
327+
byte[] bytes = response.body().bytes();
328+
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(bytes.length);
329+
byteBuffer.put(bytes);
330+
byteBuffer.rewind();
331+
332+
result.put(RequestTask.RESULT_KEY_DATA, new TypedArrayProxy(V8Value.UNSIGNED_INT_8_ARRAY, byteBuffer));
323333
} else {
324334
Log.w(TAG, "response body is invalid");
325335
}

core/runtime/android/features/src/main/java/org/hapjs/features/net/task/UploadCallbackImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import android.util.Log;
99
import android.webkit.URLUtil;
1010

11-
import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;
12-
1311
import org.hapjs.bridge.Request;
1412
import org.hapjs.bridge.Response;
1513
import org.hapjs.common.utils.FileHelper;
@@ -23,6 +21,7 @@
2321

2422
import java.io.File;
2523
import java.io.IOException;
24+
import java.nio.ByteBuffer;
2625
import java.util.Locale;
2726

2827
import okhttp3.Call;
@@ -97,7 +96,11 @@ private void parseData(SerializeObject result, okhttp3.Response response, String
9796
throw new IOException("Fail to Parsing Data to Json!");
9897
}
9998
} else if (RESPONSE_TYPE_ARRAYBUFFER.equalsIgnoreCase(responseType)) {
100-
result.put(RESULT_KEY_DATA, new ArrayBuffer(response.body().bytes()));
99+
byte[] bytes = response.body().bytes();
100+
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(bytes.length);
101+
byteBuffer.put(bytes);
102+
byteBuffer.rewind();
103+
result.put(RESULT_KEY_DATA, byteBuffer);
101104
} else if (RESPONSE_TYPE_FILE.equalsIgnoreCase(responseType)) {
102105
result.put(RESULT_KEY_DATA, parseFile(response));
103106
} else {

core/runtime/android/features/src/main/java/org/hapjs/features/nfc/IsoDepInstance.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
import android.nfc.NfcAdapter;
99
import android.nfc.tech.IsoDep;
1010

11-
import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;
12-
1311
import org.hapjs.bridge.Request;
1412
import org.hapjs.bridge.Response;
1513
import org.hapjs.features.nfc.base.BaseTagTechInstance;
1614
import org.hapjs.render.jsruntime.serialize.JavaSerializeObject;
1715

1816
import java.io.IOException;
17+
import java.nio.ByteBuffer;
1918

2019
public class IsoDepInstance extends BaseTagTechInstance {
2120

@@ -44,7 +43,10 @@ public byte[] transceive(byte[] buffer) throws IOException {
4443
public void getHistoricalBytes(Request request) {
4544
byte[] historicalBytes = mIsoDep.getHistoricalBytes();
4645
JavaSerializeObject result = new JavaSerializeObject();
47-
result.put(NFC.RESULT_HISTORICAL_BYTES, new ArrayBuffer(historicalBytes));
46+
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(historicalBytes.length);
47+
byteBuffer.put(historicalBytes);
48+
byteBuffer.rewind();
49+
result.put(NFC.RESULT_HISTORICAL_BYTES, byteBuffer);
4850
request.getCallback().callback(new Response(result));
4951
}
5052

core/runtime/android/features/src/main/java/org/hapjs/features/nfc/NFC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
@ActionAnnotation(name = NFC.ACTION_SET_TIMEOUT, mode = FeatureExtension.Mode.ASYNC, permissions = {Manifest.permission.NFC}),
5252
@ActionAnnotation(name = NFC.ACTION_TRANSCEIVE, mode = FeatureExtension.Mode.ASYNC, normalize = FeatureExtension.Normalize.RAW, permissions = {Manifest.permission.NFC}),
5353
// Ndef
54-
@ActionAnnotation(name = NFC.ACTION_WRITE_NDEF_MESSAGE, mode = FeatureExtension.Mode.CALLBACK, permissions = {Manifest.permission.NFC}),
54+
@ActionAnnotation(name = NFC.ACTION_WRITE_NDEF_MESSAGE, mode = FeatureExtension.Mode.CALLBACK, permissions = {Manifest.permission.NFC}, normalize = FeatureExtension.Normalize.RAW),
5555
// IsoDep
5656
@ActionAnnotation(name = NFC.ACTION_GET_HISTORICAL_BYTES, mode = FeatureExtension.Mode.ASYNC, normalize = FeatureExtension.Normalize.RAW),
5757
}

core/runtime/android/features/src/main/java/org/hapjs/features/nfc/NFCAdapterInstance.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import android.text.TextUtils;
2525
import android.util.Log;
2626

27-
import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;
28-
2927
import org.hapjs.bridge.HybridManager;
3028
import org.hapjs.bridge.InstanceManager;
3129
import org.hapjs.bridge.LifecycleListener;
@@ -37,6 +35,7 @@
3735
import org.hapjs.render.jsruntime.serialize.SerializeArray;
3836
import org.hapjs.render.jsruntime.serialize.SerializeObject;
3937

38+
import java.nio.ByteBuffer;
4039
import java.util.Arrays;
4140

4241
public class NFCAdapterInstance extends BaseInstance {
@@ -212,7 +211,10 @@ private void onTagDiscovered(Intent intent) {
212211

213212
byte[] id = mDiscoveredTag.getId();
214213
Log.d(TAG, "id: " + Arrays.toString(id));
215-
resultObj.put(RESULT_ID, new ArrayBuffer(id));
214+
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(id.length);
215+
byteBuffer.put(id);
216+
byteBuffer.rewind();
217+
resultObj.put(RESULT_ID, byteBuffer);
216218
} else {
217219
Log.e(TAG, "null of discovered tag");
218220
}
@@ -264,9 +266,18 @@ private SerializeArray getMessages(Parcelable[] rawMessages) {
264266
SerializeArray arrayRecord = new JavaSerializeArray();
265267
for (NdefRecord record : ndefRecords) {
266268
SerializeObject recordObj = new JavaSerializeObject();
267-
recordObj.put(RESULT_MESSAGES_RECORD_ID, new ArrayBuffer(record.getId()));
268-
recordObj.put(RESULT_MESSAGES_RECORD_PAYLOAD, new ArrayBuffer(record.getPayload()));
269-
recordObj.put(RESULT_MESSAGES_RECORD_TYPE, new ArrayBuffer(record.getType()));
269+
ByteBuffer idByteBuffer = ByteBuffer.allocateDirect(record.getId().length);
270+
idByteBuffer.put(record.getId());
271+
idByteBuffer.rewind();
272+
recordObj.put(RESULT_MESSAGES_RECORD_ID, idByteBuffer);
273+
ByteBuffer payloadByteBuffer = ByteBuffer.allocateDirect(record.getPayload().length);
274+
payloadByteBuffer.put(record.getPayload());
275+
payloadByteBuffer.rewind();
276+
recordObj.put(RESULT_MESSAGES_RECORD_PAYLOAD, payloadByteBuffer);
277+
ByteBuffer typeByteBuffer = ByteBuffer.allocateDirect(record.getType().length);
278+
typeByteBuffer.put(record.getType());
279+
typeByteBuffer.rewind();
280+
recordObj.put(RESULT_MESSAGES_RECORD_TYPE, typeByteBuffer);
270281
recordObj.put(RESULT_MESSAGES_RECORD_TNF, record.getTnf());
271282
arrayRecord.put(recordObj);
272283
}

0 commit comments

Comments
 (0)