@@ -641,13 +641,22 @@ namespace Js
641
641
}
642
642
}
643
643
644
- ArrayBuffer::ArrayBuffer (byte* buffer, uint32 length, DynamicType * type) :
644
+ ArrayBuffer::ArrayBuffer (byte* buffer, uint32 length, DynamicType * type, bool isExternal ) :
645
645
buffer (buffer), bufferLength(length), ArrayBufferBase(type)
646
646
{
647
647
if (length > MaxArrayBufferLength)
648
648
{
649
649
JavascriptError::ThrowTypeError (GetScriptContext (), JSERR_FunctionArgument_Invalid);
650
650
}
651
+
652
+ if (!isExternal)
653
+ {
654
+ // we take the ownership of the buffer and will have to free it so charge it to our quota.
655
+ if (!this ->GetRecycler ()->RequestExternalMemoryAllocation (length))
656
+ {
657
+ JavascriptError::ThrowOutOfMemoryError (this ->GetScriptContext ());
658
+ }
659
+ }
651
660
}
652
661
653
662
BOOL ArrayBuffer::GetDiagTypeString (StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext)
@@ -701,13 +710,6 @@ namespace Js
701
710
Recycler* recycler = type->GetScriptContext ()->GetRecycler ();
702
711
JavascriptArrayBuffer* result = RecyclerNewFinalized (recycler, JavascriptArrayBuffer, buffer, length, type);
703
712
Assert (result);
704
-
705
- // we take the ownership of the buffer and will have to free it so charge it to our quota.
706
- if (!recycler->RequestExternalMemoryAllocation (length))
707
- {
708
- JavascriptError::ThrowOutOfMemoryError (result->GetScriptContext ());
709
- }
710
-
711
713
recycler->AddExternalMemoryUsage (length);
712
714
return result;
713
715
}
@@ -890,12 +892,6 @@ namespace Js
890
892
if (buffer)
891
893
{
892
894
result = RecyclerNewFinalized (recycler, WebAssemblyArrayBuffer, buffer, length, type);
893
-
894
- // we take the ownership of the buffer and will have to free it so charge it to our quota.
895
- if (!recycler->RequestExternalMemoryAllocation (length))
896
- {
897
- JavascriptError::ThrowOutOfMemoryError (result->GetScriptContext ());
898
- }
899
895
}
900
896
else
901
897
{
@@ -1039,13 +1035,6 @@ namespace Js
1039
1035
{
1040
1036
Recycler* recycler = type->GetScriptContext ()->GetRecycler ();
1041
1037
ProjectionArrayBuffer* result = RecyclerNewFinalized (recycler, ProjectionArrayBuffer, buffer, length, type);
1042
-
1043
- // we take the ownership of the buffer and will have to free it so charge it to our quota.
1044
- if (!recycler->RequestExternalMemoryAllocation (length))
1045
- {
1046
- JavascriptError::ThrowOutOfMemoryError (result->GetScriptContext ());
1047
- }
1048
-
1049
1038
// This is user passed [in] buffer, user should AddExternalMemoryUsage before calling jscript, but
1050
1039
// I don't see we ask everyone to do this. Let's add the memory pressure here as well.
1051
1040
recycler->AddExternalMemoryUsage (length);
@@ -1072,7 +1061,7 @@ namespace Js
1072
1061
}
1073
1062
1074
1063
ExternalArrayBuffer::ExternalArrayBuffer (byte *buffer, uint32 length, DynamicType *type)
1075
- : ArrayBuffer(buffer, length, type)
1064
+ : ArrayBuffer(buffer, length, type, true )
1076
1065
{
1077
1066
}
1078
1067
0 commit comments