Skip to content

Commit

Permalink
fix(android): fix nested sub-tag serialization issue
Browse files Browse the repository at this point in the history
  • Loading branch information
medns authored and zoomchan-cxj committed Mar 29, 2022
1 parent 249f9e4 commit 7fe73ca
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ protected SerializationTag peekTag() {
}

protected ArrayBufferViewTag readArrayBufferViewTag() {
return ArrayBufferViewTag.fromTag(reader.getByte());
return ArrayBufferViewTag.fromTag((byte) reader.getVarint());
}

protected ErrorTag readErrorTag() {
return ErrorTag.fromTag(reader.getByte());
return ErrorTag.fromTag((byte) reader.getVarint());
}

protected int readZigZag() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ protected void writeTag(SerializationTag tag) {
}

protected void writeTag(ArrayBufferViewTag tag) {
writer.putByte(tag.getTag());
writer.putVarint(tag.getTag());
}

protected void writeTag(ErrorTag tag) {
writer.putByte(tag.getTag());
writer.putVarint(tag.getTag());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import androidx.annotation.NonNull;

import com.tencent.mtt.hippy.serialization.ArrayBufferViewTag;
import com.tencent.mtt.hippy.serialization.exception.DataCloneOutOfRangeException;
import com.tencent.mtt.hippy.serialization.exception.DataCloneOutOfValueException;
import com.tencent.mtt.hippy.exception.UnexpectedException;
Expand Down Expand Up @@ -323,16 +324,13 @@ private JSDataView<JSArrayBuffer> readJSArrayBufferView(JSArrayBuffer arrayBuffe
if (arrayBufferViewTag != SerializationTag.ARRAY_BUFFER_VIEW) {
throw new AssertionError("ArrayBufferViewTag: " + arrayBufferViewTag);
}
int offset = (int) reader.getVarint();
if (offset < 0) {
throw new DataCloneOutOfValueException(offset);
}
int byteLength = (int) reader.getVarint();
if (byteLength < 0) {
throw new DataCloneOutOfValueException(byteLength);
}

ArrayBufferViewTag tag = readArrayBufferViewTag();
JSDataView.DataViewKind kind;
switch (readArrayBufferViewTag()) {
if (tag == null) {
tag = ArrayBufferViewTag.INT8_ARRAY;
}
switch (tag) {
case DATA_VIEW: {
kind = JSDataView.DataViewKind.DATA_VIEW;
break;
Expand Down Expand Up @@ -377,6 +375,16 @@ private JSDataView<JSArrayBuffer> readJSArrayBufferView(JSArrayBuffer arrayBuffe
throw new UnreachableCodeException();
}
}

int offset = (int) reader.getVarint();
if (offset < 0) {
throw new DataCloneOutOfValueException(offset);
}
int byteLength = (int) reader.getVarint();
if (byteLength < 0) {
throw new DataCloneOutOfValueException(byteLength);
}

JSDataView<JSArrayBuffer> view = new JSDataView<>(arrayBuffer, kind, offset, byteLength);
assignId(view);
return view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,30 +425,37 @@ private void writeErrorTypeTag(@NonNull JSError error) {
JSError.ErrorType errorType = error.getType();
ErrorTag tag;
switch (errorType) {
case EvalError:
case EvalError: {
tag = ErrorTag.EVAL_ERROR;
break;
case RangeError:
}
case RangeError: {
tag = ErrorTag.RANGE_ERROR;
break;
case ReferenceError:
}
case ReferenceError: {
tag = ErrorTag.REFERENCE_ERROR;
break;
case SyntaxError:
}
case SyntaxError: {
tag = ErrorTag.SYNTAX_ERROR;
break;
case TypeError:
}
case TypeError: {
tag = ErrorTag.TYPE_ERROR;
break;
case URIError:
}
case URIError: {
tag = ErrorTag.URI_ERROR;
break;
default:
}
default: {
tag = null;
if (errorType != JSError.ErrorType.Error && errorType != JSError.ErrorType.AggregateError) {
throw new UnreachableCodeException();
}
break;
}
}
if (tag != null) {
writeTag(tag);
Expand Down

0 comments on commit 7fe73ca

Please sign in to comment.