@@ -1361,7 +1361,7 @@ namespace Js
13611361
13621362 Js::Var constructorArgs[] = { constructor, buffer, JavascriptNumber::ToVar (beginByteOffset, scriptContext), JavascriptNumber::ToVar (newLength, scriptContext) };
13631363 Js::CallInfo constructorCallInfo (Js::CallFlags_New, _countof (constructorArgs));
1364- newTypedArray = JavascriptOperators::NewScObject ( constructor, Js::Arguments (constructorCallInfo, constructorArgs), scriptContext);
1364+ newTypedArray = RecyclableObject::FromVar ( TypedArrayBase::TypedArrayCreate ( constructor, & Js::Arguments (constructorCallInfo, constructorArgs), newLength, scriptContext) );
13651365 }
13661366 else
13671367 {
@@ -1447,7 +1447,7 @@ namespace Js
14471447
14481448 Js::Var constructorArgs[] = { constructor, JavascriptNumber::ToVar (len, scriptContext) };
14491449 Js::CallInfo constructorCallInfo (Js::CallFlags_New, _countof (constructorArgs));
1450- newObj = JavascriptOperators::NewScObject (constructor, Js::Arguments (constructorCallInfo, constructorArgs), scriptContext);
1450+ newObj = TypedArrayBase::TypedArrayCreate (constructor, & Js::Arguments (constructorCallInfo, constructorArgs), len , scriptContext);
14511451
14521452 TypedArrayBase* newTypedArrayBase = nullptr ;
14531453 JavascriptArray* newArr = nullptr ;
@@ -1511,7 +1511,7 @@ namespace Js
15111511
15121512 Js::Var constructorArgs[] = { constructor, JavascriptNumber::ToVar (len, scriptContext) };
15131513 Js::CallInfo constructorCallInfo (Js::CallFlags_New, _countof (constructorArgs));
1514- newObj = JavascriptOperators::NewScObject (constructor, Js::Arguments (constructorCallInfo, constructorArgs), scriptContext);
1514+ newObj = TypedArrayBase::TypedArrayCreate (constructor, & Js::Arguments (constructorCallInfo, constructorArgs), len , scriptContext);
15151515
15161516 TypedArrayBase* newTypedArrayBase = nullptr ;
15171517 JavascriptArray* newArr = nullptr ;
@@ -1770,7 +1770,7 @@ namespace Js
17701770
17711771 Js::Var constructorArgs[] = { constructor, JavascriptNumber::ToVar (captured, scriptContext) };
17721772 Js::CallInfo constructorCallInfo (Js::CallFlags_New, _countof (constructorArgs));
1773- newObj = RecyclableObject::FromVar (JavascriptOperators::NewScObject (constructor, Js::Arguments (constructorCallInfo, constructorArgs), scriptContext));
1773+ newObj = RecyclableObject::FromVar (TypedArrayBase::TypedArrayCreate (constructor, & Js::Arguments (constructorCallInfo, constructorArgs), captured , scriptContext));
17741774
17751775 if (TypedArrayBase::Is (newObj))
17761776 {
@@ -2733,6 +2733,40 @@ namespace Js
27332733 return Js::JavascriptNumber::ToVarNoCheck (currentRes, scriptContext);
27342734 }
27352735
2736+ // static
2737+ Var TypedArrayBase::ValidateTypedArray (Var aValue, ScriptContext *scriptContext)
2738+ {
2739+ if (!TypedArrayBase::Is (aValue))
2740+ {
2741+ JavascriptError::ThrowTypeError (scriptContext, JSERR_This_NeedTypedArray);
2742+ }
2743+
2744+ TypedArrayBase *typedArrayBase = TypedArrayBase::FromVar (aValue);
2745+ ArrayBuffer *arrayBuffer = typedArrayBase->GetArrayBuffer ();
2746+ if (arrayBuffer->IsDetached ())
2747+ {
2748+ JavascriptError::ThrowTypeError (scriptContext, JSERR_DetachedTypedArray);
2749+ }
2750+
2751+ return arrayBuffer;
2752+ }
2753+
2754+ // static
2755+ Var TypedArrayBase::TypedArrayCreate (Var constructor, Arguments *args, uint32 length, ScriptContext *scriptContext)
2756+ {
2757+ Var newObj = JavascriptOperators::NewScObject (constructor, *args, scriptContext);
2758+
2759+ TypedArrayBase::ValidateTypedArray (newObj, scriptContext);
2760+
2761+ // ECMA262 22.2.4.6 TypedArrayCreate line 3. "If argumentList is a List of a single Number" (args[0] == constructor)
2762+ if (args->Info .Count == 2 && TypedArrayBase::FromVar (newObj)->GetLength () < length)
2763+ {
2764+ JavascriptError::ThrowTypeError (scriptContext, JSERR_InvalidTypedArrayLength);
2765+ }
2766+
2767+ return newObj;
2768+ }
2769+
27362770 template <> BOOL Uint8ClampedArray::Is (Var aValue)
27372771 {
27382772 return JavascriptOperators::GetTypeId (aValue) == TypeIds_Uint8ClampedArray &&
0 commit comments