mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 18:20:04 +00:00
五大项整改 :JSDeserializer::ReadJSTypedArray()
Signed-off-by: 杨云飞 <yangyunfei19@h-partners.com>
This commit is contained in:
parent
0ffb69845b
commit
1bd16f7462
@ -1656,62 +1656,16 @@ JSHandle<JSTaggedValue> JSDeserializer::ReadJSRegExp()
|
||||
JSHandle<JSTaggedValue> JSDeserializer::ReadJSTypedArray(SerializationUID uid)
|
||||
{
|
||||
JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
|
||||
JSHandle<JSTaggedValue> target;
|
||||
JSHandle<JSObject> obj;
|
||||
JSHandle<JSTaggedValue> objTag;
|
||||
switch (uid) {
|
||||
case SerializationUID::JS_INT8_ARRAY: {
|
||||
target = env->GetInt8ArrayFunction();
|
||||
break;
|
||||
}
|
||||
case SerializationUID::JS_UINT8_ARRAY: {
|
||||
target = env->GetUint8ArrayFunction();
|
||||
break;
|
||||
}
|
||||
case SerializationUID::JS_UINT8_CLAMPED_ARRAY: {
|
||||
target = env->GetUint8ClampedArrayFunction();
|
||||
break;
|
||||
}
|
||||
case SerializationUID::JS_INT16_ARRAY: {
|
||||
target = env->GetInt16ArrayFunction();
|
||||
break;
|
||||
}
|
||||
case SerializationUID::JS_UINT16_ARRAY: {
|
||||
target = env->GetUint16ArrayFunction();
|
||||
break;
|
||||
}
|
||||
case SerializationUID::JS_INT32_ARRAY: {
|
||||
target = env->GetInt32ArrayFunction();
|
||||
break;
|
||||
}
|
||||
case SerializationUID::JS_UINT32_ARRAY: {
|
||||
target = env->GetUint32ArrayFunction();
|
||||
break;
|
||||
}
|
||||
case SerializationUID::JS_FLOAT32_ARRAY: {
|
||||
target = env->GetFloat32ArrayFunction();
|
||||
break;
|
||||
}
|
||||
case SerializationUID::JS_FLOAT64_ARRAY: {
|
||||
target = env->GetFloat64ArrayFunction();
|
||||
break;
|
||||
}
|
||||
case SerializationUID::JS_BIGINT64_ARRAY: {
|
||||
target = env->GetBigInt64ArrayFunction();
|
||||
break;
|
||||
}
|
||||
case SerializationUID::JS_BIGUINT64_ARRAY: {
|
||||
target = env->GetBigUint64ArrayFunction();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
JSHandle<JSTaggedValue> target = GetTypedArrayFunction(env, uid);
|
||||
if (target.IsEmpty()) {
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
JSHandle<JSTypedArray> typedArray =
|
||||
JSHandle<JSTypedArray>::Cast(factory_->NewJSObjectByConstructor(JSHandle<JSFunction>(target)));
|
||||
obj = JSHandle<JSObject>::Cast(typedArray);
|
||||
objTag = JSHandle<JSTaggedValue>::Cast(obj);
|
||||
JSHandle<JSObject> obj = JSHandle<JSObject>::Cast(typedArray);
|
||||
JSHandle<JSTaggedValue> objTag = JSHandle<JSTaggedValue>::Cast(obj);
|
||||
referenceMap_.emplace(objectId_++, objTag);
|
||||
if (!JudgeType(SerializationUID::JS_PLAIN_OBJECT) || !DefinePropertiesAndElements(objTag)) {
|
||||
return JSHandle<JSTaggedValue>();
|
||||
@ -1721,6 +1675,7 @@ JSHandle<JSTaggedValue> JSDeserializer::ReadJSTypedArray(SerializationUID uid)
|
||||
if (!ReadBoolean(&isViewedArrayBuffer)) {
|
||||
return JSHandle<JSTaggedValue>();
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> viewedArrayBufferOrByteArray;
|
||||
if (isViewedArrayBuffer) {
|
||||
viewedArrayBufferOrByteArray = DeserializeJSTaggedValue();
|
||||
@ -1741,30 +1696,71 @@ JSHandle<JSTaggedValue> JSDeserializer::ReadJSTypedArray(SerializationUID uid)
|
||||
}
|
||||
typedArray->SetTypedArrayName(thread_, typedArrayName);
|
||||
|
||||
if (!SetTypedArrayProperties(typedArray)) {
|
||||
return JSHandle<JSTaggedValue>();
|
||||
}
|
||||
|
||||
return objTag;
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> JSDeserializer::GetTypedArrayFunction(JSHandle<GlobalEnv> &env,
|
||||
SerializationUID &uid)
|
||||
{
|
||||
switch (uid) {
|
||||
case SerializationUID::JS_INT8_ARRAY:
|
||||
return env->GetInt8ArrayFunction();
|
||||
case SerializationUID::JS_UINT8_ARRAY:
|
||||
return env->GetUint8ArrayFunction();
|
||||
case SerializationUID::JS_UINT8_CLAMPED_ARRAY:
|
||||
return env->GetUint8ClampedArrayFunction();
|
||||
case SerializationUID::JS_INT16_ARRAY:
|
||||
return env->GetInt16ArrayFunction();
|
||||
case SerializationUID::JS_UINT16_ARRAY:
|
||||
return env->GetUint16ArrayFunction();
|
||||
case SerializationUID::JS_INT32_ARRAY:
|
||||
return env->GetInt32ArrayFunction();
|
||||
case SerializationUID::JS_UINT32_ARRAY:
|
||||
return env->GetUint32ArrayFunction();
|
||||
case SerializationUID::JS_FLOAT32_ARRAY:
|
||||
return env->GetFloat32ArrayFunction();
|
||||
case SerializationUID::JS_FLOAT64_ARRAY:
|
||||
return env->GetFloat64ArrayFunction();
|
||||
case SerializationUID::JS_BIGINT64_ARRAY:
|
||||
return env->GetBigInt64ArrayFunction();
|
||||
case SerializationUID::JS_BIGUINT64_ARRAY:
|
||||
return env->GetBigUint64ArrayFunction();
|
||||
default:
|
||||
return JSHandle<JSTaggedValue>();
|
||||
}
|
||||
}
|
||||
|
||||
bool JSDeserializer::SetTypedArrayProperties(JSHandle<JSTypedArray> &typedArray)
|
||||
{
|
||||
JSTaggedValue byteLength;
|
||||
if (!ReadJSTaggedValue(&byteLength) || !byteLength.IsNumber()) {
|
||||
return JSHandle<JSTaggedValue>();
|
||||
return false;
|
||||
}
|
||||
typedArray->SetByteLength(byteLength.GetNumber());
|
||||
|
||||
JSTaggedValue byteOffset;
|
||||
if (!ReadJSTaggedValue(&byteOffset) || !byteOffset.IsNumber()) {
|
||||
return JSHandle<JSTaggedValue>();
|
||||
return false;
|
||||
}
|
||||
typedArray->SetByteOffset(byteOffset.GetNumber());
|
||||
|
||||
JSTaggedValue arrayLength;
|
||||
if (!ReadJSTaggedValue(&arrayLength) || !byteOffset.IsNumber()) {
|
||||
return JSHandle<JSTaggedValue>();
|
||||
if (!ReadJSTaggedValue(&arrayLength) || !arrayLength.IsNumber()) {
|
||||
return false;
|
||||
}
|
||||
typedArray->SetArrayLength(arrayLength.GetNumber());
|
||||
|
||||
ContentType *contentType = reinterpret_cast<ContentType*>(GetBuffer(sizeof(ContentType)));
|
||||
if (contentType == nullptr) {
|
||||
return JSHandle<JSTaggedValue>();
|
||||
return false;
|
||||
}
|
||||
typedArray->SetContentType(*contentType);
|
||||
return objTag;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> JSDeserializer::ReadJSNativePointer()
|
||||
|
@ -215,6 +215,8 @@ private:
|
||||
JSHandle<JSTaggedValue> ReadNativeBindingObject();
|
||||
JSHandle<JSTaggedValue> ReadBigInt();
|
||||
JSHandle<JSTaggedValue> DeserializeJSTaggedValue();
|
||||
JSHandle<JSTaggedValue> GetTypedArrayFunction(JSHandle<GlobalEnv> &env, SerializationUID &uid);
|
||||
bool SetTypedArrayProperties(JSHandle<JSTypedArray> &typedArray);
|
||||
bool JudgeType(SerializationUID targetUid);
|
||||
void *GetBuffer(uint32_t bufferSize);
|
||||
bool ReadJSTaggedValue(JSTaggedValue *originalFlags);
|
||||
|
Loading…
Reference in New Issue
Block a user