diff --git a/ecmascript/builtins/builtins_arraybuffer.cpp b/ecmascript/builtins/builtins_arraybuffer.cpp index 44ca29e3d4b3ba83e8b458bf64dc285303dd7da0..a4bf0f7a5257c61d0ef245dabdd72a27f3debb26 100644 --- a/ecmascript/builtins/builtins_arraybuffer.cpp +++ b/ecmascript/builtins/builtins_arraybuffer.cpp @@ -229,10 +229,6 @@ JSTaggedValue BuiltinsArrayBuffer::AllocateArrayBuffer(JSThread *thread, const J if (byteLength > INT_MAX) { THROW_RANGE_ERROR_AND_RETURN(thread, "Out of range", JSTaggedValue::Exception()); } - uint64_t totalNativeSize = static_cast(thread->GetNativeAreaAllocator()->GetArrayBufferNativeSize()); - if (UNLIKELY(totalNativeSize > MAX_NATIVE_SIZE_LIMIT)) { - THROW_RANGE_ERROR_AND_RETURN(thread, NATIVE_SIZE_OUT_OF_LIMIT_MESSAGE, JSTaggedValue::Exception()); - } uint32_t arrayByteLength = static_cast(byteLength); JSHandle arrayBuffer(obj); // 6. Set obj’s [[ArrayBufferData]] internal slot to block. diff --git a/ecmascript/builtins/builtins_arraybuffer.h b/ecmascript/builtins/builtins_arraybuffer.h index 1a0f5ff025e6a995e0e7373728522e37080ff1ae..2fdc5d43697e5b82f4fe22dac45727e07fef8b0c 100644 --- a/ecmascript/builtins/builtins_arraybuffer.h +++ b/ecmascript/builtins/builtins_arraybuffer.h @@ -113,10 +113,6 @@ public: DataViewType type, bool littleEndian); static void *GetDataPointFromBuffer(JSTaggedValue arrBuf, uint32_t byteOffset = 0); -protected: - static constexpr uint64_t MAX_NATIVE_SIZE_LIMIT = 4_GB; - static constexpr char const *NATIVE_SIZE_OUT_OF_LIMIT_MESSAGE = "total array buffer size out of limit(4_GB)"; - private: #define BUILTIN_ARRAY_BUFFER_ENTRY(name, func, length, id) \ base::BuiltinFunctionEntry::Create((name), (BuiltinsArrayBuffer::func), (length), (BUILTINS_STUB_ID(id))), diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 322720e8f1ea75d759cafc0948554a1f7546ea9e..54fd09c757d3ca546d2d5683e20cdba58fd16ab0 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -2370,6 +2370,10 @@ Local StringRef::EncodeIntoUint8Array(const EcmaVM *vm) JSHandle obj = TypedArrayHelper::FastCreateTypedArray(thread, thread->GlobalConstants()->GetHandledUint8ArrayString(), length - 1, DataViewType::UINT8); + if (JSNApi::HasPendingException(vm)) { + LOG_ECMA(ERROR) << "JSNapi EncodeIntoUint8Array: Create TypedArray failed"; + return Undefined(vm); + } JSHandle arrayBuffer(thread, JSTypedArray::Cast(*obj)->GetViewedArrayBufferOrByteArray()); JSTaggedValue bufferData = JSHandle::Cast(arrayBuffer)->GetArrayBufferData(); void *buffer = JSNativePointer::Cast(bufferData.GetTaggedObject())->GetExternalPointer(); diff --git a/test/moduletest/allocatearraybuffer/allocatearraybuffer.js b/test/moduletest/allocatearraybuffer/allocatearraybuffer.js index 9475338d24f294f0852b924207effe4c936f1a77..0e5a07d549ce9fda4da7b6abe50b040f9b620123 100644 --- a/test/moduletest/allocatearraybuffer/allocatearraybuffer.js +++ b/test/moduletest/allocatearraybuffer/allocatearraybuffer.js @@ -40,23 +40,6 @@ for (let i = 0; i < v32.length; i++) { const v36 = this.Atomics; print(v36.and(v32, this, v36)); -function f() { - let a1 = new ArrayBuffer(1025*1025*1025); - let a2 = new ArrayBuffer(1025*1025*1025); - let a3 = new ArrayBuffer(1025*1025*1025); - let a4 = new ArrayBuffer(1025*1025*1025); - try { - let arr = new ArrayBuffer(10); - print(a1.byteLength + a2.byteLength + a3.byteLength + a4.byteLength + arr.byteLength); - } catch (error) { - print(error); - } -} -f(); -ArkTools.forceFullGC(); -f(); -ArkTools.forceFullGC(); - function SendableArrayBufferTest() { try { const o1 = {}; diff --git a/test/moduletest/allocatearraybuffer/expect_output.txt b/test/moduletest/allocatearraybuffer/expect_output.txt index 6b6c6971a7e0e21c984f342e5f787df86f4c9cf6..5fd9e962a359b02511ec76f82633c98d8d966fb4 100644 --- a/test/moduletest/allocatearraybuffer/expect_output.txt +++ b/test/moduletest/allocatearraybuffer/expect_output.txt @@ -14,6 +14,4 @@ undefined NaN 1 -RangeError: total array buffer size out of limit(4_GB) -RangeError: total array buffer size out of limit(4_GB) TypeError: shared ctor cannot assign unshared newTarget \ No newline at end of file