diff --git a/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp b/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp index f06cd62bec9..eba396012d9 100644 --- a/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp +++ b/lib/Runtime/Library/IntlEngineInterfaceExtensionObject.cpp @@ -297,35 +297,46 @@ namespace Js void IntlEngineInterfaceExtensionObject::deletePrototypePropertyHelper(ScriptContext* scriptContext, DynamicObject* intlObject, Js::PropertyId objectPropertyId, Js::PropertyId getterFunctionId) { - DynamicObject *prototypeVal = nullptr; + DynamicObject *prototypeObject = nullptr; DynamicObject *functionObj = nullptr; - Var propertyValue; - Var getter; - Var setter; + Var propertyValue = nullptr; + Var prototypeValue = nullptr; + Var resolvedOptionsValue = nullptr; + Var getter = nullptr; + Var setter = nullptr; - if (!Js::JavascriptOperators::GetProperty(intlObject, objectPropertyId, &propertyValue, scriptContext)) + if (!JavascriptOperators::GetProperty(intlObject, objectPropertyId, &propertyValue, scriptContext) || + !JavascriptOperators::IsObject(propertyValue)) { - AssertMsg(false, "Error."); return; } - if (!Js::JavascriptOperators::GetProperty(DynamicObject::FromVar(propertyValue), Js::PropertyIds::prototype, &propertyValue, scriptContext)) + if (!JavascriptOperators::GetProperty(DynamicObject::FromVar(propertyValue), Js::PropertyIds::prototype, &prototypeValue, scriptContext) || + !JavascriptOperators::IsObject(prototypeValue)) { - AssertMsg(false, "Can't be null, otherwise Intl library wasn't initialized correctly"); return; } - if (!Js::JavascriptOperators::GetProperty(prototypeVal = DynamicObject::FromVar(propertyValue), Js::PropertyIds::resolvedOptions, &propertyValue, scriptContext)) + prototypeObject = DynamicObject::FromVar(prototypeValue); + + if (!JavascriptOperators::GetProperty(prototypeObject, Js::PropertyIds::resolvedOptions, &resolvedOptionsValue, scriptContext) || + !JavascriptOperators::IsObject(resolvedOptionsValue)) { - AssertMsg(false, "If these operations result in false, Intl tests will detect them"); return; } - (functionObj = DynamicObject::FromVar(propertyValue))->SetConfigurable(Js::PropertyIds::prototype, true); + functionObj = DynamicObject::FromVar(resolvedOptionsValue); + functionObj->SetConfigurable(Js::PropertyIds::prototype, true); functionObj->DeleteProperty(Js::PropertyIds::prototype, Js::PropertyOperationFlags::PropertyOperation_None); - JavascriptOperators::GetOwnAccessors(prototypeVal, getterFunctionId, &getter, &setter, scriptContext); - (functionObj = DynamicObject::FromVar(getter))->SetConfigurable(Js::PropertyIds::prototype, true); + if (!JavascriptOperators::GetOwnAccessors(prototypeObject, getterFunctionId, &getter, &setter, scriptContext) || + !JavascriptOperators::IsObject(getter)) + { + return; + } + + functionObj = DynamicObject::FromVar(getter); + functionObj->SetConfigurable(Js::PropertyIds::prototype, true); functionObj->DeleteProperty(Js::PropertyIds::prototype, Js::PropertyOperationFlags::PropertyOperation_None); } diff --git a/lib/Runtime/Library/JavascriptFunction.cpp b/lib/Runtime/Library/JavascriptFunction.cpp index 5ed7da25916..ce524e59c72 100644 --- a/lib/Runtime/Library/JavascriptFunction.cpp +++ b/lib/Runtime/Library/JavascriptFunction.cpp @@ -1027,15 +1027,16 @@ namespace Js if (arr != nullptr && !arr->IsCrossSiteObject()) { + uint32 length = arr->GetLength(); // CONSIDER: Optimize by creating a JavascriptArray routine which allows // memcpy-like semantics in optimal situations (no gaps, etc.) - if (argsIndex + arr->GetLength() > destArgs.Info.Count) + if (argsIndex + length > destArgs.Info.Count) { AssertMsg(false, "The array length has changed since we allocated the destArgs buffer?"); Throw::FatalInternalError(); } - for (uint32 j = 0; j < arr->GetLength(); j++) + for (uint32 j = 0; j < length; j++) { Var element; if (!arr->DirectGetItemAtFull(j, &element)) diff --git a/lib/Runtime/Library/JavascriptSimdObject.cpp b/lib/Runtime/Library/JavascriptSimdObject.cpp index efed36511ac..0f4dd44e918 100644 --- a/lib/Runtime/Library/JavascriptSimdObject.cpp +++ b/lib/Runtime/Library/JavascriptSimdObject.cpp @@ -147,7 +147,7 @@ namespace Js } template - Var JavascriptSIMDObject::ToLocaleString(const Var* args, uint numArgs, const char16 *typeString, const T (&laneValues)[N], + Var JavascriptSIMDObject::ToLocaleString(const Var* args, uint numArgs, const char16 *typeString, const T(&laneValues)[N], CallInfo* callInfo, ScriptContext* scriptContext) const { Assert(args); @@ -159,23 +159,26 @@ namespace Js return ToString(scriptContext); //Boolean types does not have toLocaleString. } + // Clamp to the first 3 arguments - we'll ignore more. + if (numArgs > 3) + { + numArgs = 3; + } + // Creating a new arguments list for the JavascriptNumber generated from each lane.The optional SIMDToLocaleString Args are //added to this argument list. - Var* newArgs = HeapNewArray(Var, numArgs); - switch (numArgs) + Var newArgs[3] = { nullptr, nullptr, nullptr }; + CallInfo newCallInfo((ushort)numArgs); + + if (numArgs > 1) { - case 1: - break; - case 2: - newArgs[1] = args[1]; - break; - case 3: newArgs[1] = args[1]; + } + if (numArgs > 2) + { newArgs[2] = args[2]; - break; - default: - Assert(UNREACHED); } + //Locale specifc seperator?? JavascriptString *seperator = JavascriptString::NewWithSz(_u(", "), scriptContext); uint idx = 0; @@ -184,7 +187,7 @@ namespace Js char16* stringBuffer = AnewArray(tempAllocator, char16, SIMD_STRING_BUFFER_MAX); JavascriptString *result = nullptr; - swprintf_s(stringBuffer, 1024, typeString); + swprintf_s(stringBuffer, SIMD_STRING_BUFFER_MAX, typeString); result = JavascriptString::NewCopySzFromArena(stringBuffer, scriptContext, scriptContext->GeneralAllocator()); if (typeDescriptor == TypeIds_SIMDFloat32x4) @@ -193,44 +196,43 @@ namespace Js { laneVar = JavascriptNumber::ToVarWithCheck(laneValues[idx], scriptContext); newArgs[0] = laneVar; - JavascriptString *laneValue = JavascriptNumber::ToLocaleStringIntl(newArgs, *callInfo, scriptContext); + JavascriptString *laneValue = JavascriptNumber::ToLocaleStringIntl(newArgs, newCallInfo, scriptContext); result = JavascriptString::Concat(result, laneValue); result = JavascriptString::Concat(result, seperator); } laneVar = JavascriptNumber::ToVarWithCheck(laneValues[idx], scriptContext); newArgs[0] = laneVar; - result = JavascriptString::Concat(result, JavascriptNumber::ToLocaleStringIntl(newArgs, *callInfo, scriptContext)); + result = JavascriptString::Concat(result, JavascriptNumber::ToLocaleStringIntl(newArgs, newCallInfo, scriptContext)); } else if (typeDescriptor == TypeIds_SIMDInt8x16 || typeDescriptor == TypeIds_SIMDInt16x8 || typeDescriptor == TypeIds_SIMDInt32x4) { for (; idx < numLanes - 1; ++idx) { - laneVar = JavascriptNumber::ToVar(static_cast(laneValues[idx]), scriptContext); + laneVar = JavascriptNumber::ToVar(static_cast(laneValues[idx]), scriptContext); newArgs[0] = laneVar; - JavascriptString *laneValue = JavascriptNumber::ToLocaleStringIntl(newArgs, *callInfo, scriptContext); + JavascriptString *laneValue = JavascriptNumber::ToLocaleStringIntl(newArgs, newCallInfo, scriptContext); result = JavascriptString::Concat(result, laneValue); result = JavascriptString::Concat(result, seperator); } laneVar = JavascriptNumber::ToVar(static_cast(laneValues[idx]), scriptContext); newArgs[0] = laneVar; - result = JavascriptString::Concat(result, JavascriptNumber::ToLocaleStringIntl(newArgs, *callInfo, scriptContext)); + result = JavascriptString::Concat(result, JavascriptNumber::ToLocaleStringIntl(newArgs, newCallInfo, scriptContext)); } else { Assert((typeDescriptor == TypeIds_SIMDUint8x16 || typeDescriptor == TypeIds_SIMDUint16x8 || typeDescriptor == TypeIds_SIMDUint32x4)); for (; idx < numLanes - 1; ++idx) { - laneVar = JavascriptNumber::ToVar(static_cast(laneValues[idx]), scriptContext); + laneVar = JavascriptNumber::ToVar(static_cast(laneValues[idx]), scriptContext); newArgs[0] = laneVar; - JavascriptString *laneValue = JavascriptNumber::ToLocaleStringIntl(newArgs, *callInfo, scriptContext); + JavascriptString *laneValue = JavascriptNumber::ToLocaleStringIntl(newArgs, newCallInfo, scriptContext); result = JavascriptString::Concat(result, laneValue); result = JavascriptString::Concat(result, seperator); } laneVar = JavascriptNumber::ToVar(static_cast(laneValues[idx]), scriptContext); newArgs[0] = laneVar; - result = JavascriptString::Concat(result, JavascriptNumber::ToLocaleStringIntl(newArgs, *callInfo, scriptContext)); + result = JavascriptString::Concat(result, JavascriptNumber::ToLocaleStringIntl(newArgs, newCallInfo, scriptContext)); } - HeapDeleteArray(numArgs, newArgs); END_TEMP_ALLOCATOR(tempAllocator, scriptContext); return JavascriptString::Concat(result, JavascriptString::NewWithSz(_u(")"), scriptContext)); } diff --git a/lib/Runtime/Library/SimdFloat32x4Lib.cpp b/lib/Runtime/Library/SimdFloat32x4Lib.cpp index 337c9144730..b442234b87c 100644 --- a/lib/Runtime/Library/SimdFloat32x4Lib.cpp +++ b/lib/Runtime/Library/SimdFloat32x4Lib.cpp @@ -1035,8 +1035,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 4 * FLOAT32_SIZE, scriptContext); + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 4 * FLOAT32_SIZE, scriptContext); } Var SIMDFloat32x4Lib::EntryLoad1(RecyclableObject* function, CallInfo callInfo, ...) @@ -1049,7 +1067,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 1 * FLOAT32_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 1 * FLOAT32_SIZE, scriptContext); } Var SIMDFloat32x4Lib::EntryLoad2(RecyclableObject* function, CallInfo callInfo, ...) @@ -1062,7 +1099,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 2 * FLOAT32_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 2 * FLOAT32_SIZE, scriptContext); } Var SIMDFloat32x4Lib::EntryLoad3(RecyclableObject* function, CallInfo callInfo, ...) @@ -1075,7 +1131,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 3 * FLOAT32_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 3 * FLOAT32_SIZE, scriptContext); } Var SIMDFloat32x4Lib::EntryStore(RecyclableObject* function, CallInfo callInfo, ...) diff --git a/lib/Runtime/Library/SimdFloat64x2Lib.cpp b/lib/Runtime/Library/SimdFloat64x2Lib.cpp index a9e8a520861..a3a253c1a5a 100644 --- a/lib/Runtime/Library/SimdFloat64x2Lib.cpp +++ b/lib/Runtime/Library/SimdFloat64x2Lib.cpp @@ -875,7 +875,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 2 * FLOAT64_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 2 * FLOAT64_SIZE, scriptContext); } Var SIMDFloat64x2Lib::EntryLoad1(RecyclableObject* function, CallInfo callInfo, ...) @@ -888,7 +907,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 1 * FLOAT64_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 1 * FLOAT64_SIZE, scriptContext); } Var SIMDFloat64x2Lib::EntryStore(RecyclableObject* function, CallInfo callInfo, ...) diff --git a/lib/Runtime/Library/SimdInt16x8Lib.cpp b/lib/Runtime/Library/SimdInt16x8Lib.cpp index a1808a86585..4221357d08e 100644 --- a/lib/Runtime/Library/SimdInt16x8Lib.cpp +++ b/lib/Runtime/Library/SimdInt16x8Lib.cpp @@ -703,8 +703,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 8 * INT16_SIZE, scriptContext); + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 8 * INT16_SIZE, scriptContext); } Var SIMDInt16x8Lib::EntryStore(RecyclableObject* function, CallInfo callInfo, ...) diff --git a/lib/Runtime/Library/SimdInt32x4Lib.cpp b/lib/Runtime/Library/SimdInt32x4Lib.cpp index 55d7a1e3976..7dcc8fe28be 100644 --- a/lib/Runtime/Library/SimdInt32x4Lib.cpp +++ b/lib/Runtime/Library/SimdInt32x4Lib.cpp @@ -947,7 +947,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 4 * INT32_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 4 * INT32_SIZE, scriptContext); } Var SIMDInt32x4Lib::EntryLoad1(RecyclableObject* function, CallInfo callInfo, ...) @@ -960,7 +979,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 1 * INT32_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 1 * INT32_SIZE, scriptContext); } Var SIMDInt32x4Lib::EntryLoad2(RecyclableObject* function, CallInfo callInfo, ...) @@ -973,7 +1011,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 2 * INT32_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 2 * INT32_SIZE, scriptContext); } Var SIMDInt32x4Lib::EntryLoad3(RecyclableObject* function, CallInfo callInfo, ...) @@ -986,7 +1043,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 3 * INT32_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 3 * INT32_SIZE, scriptContext); } Var SIMDInt32x4Lib::EntryStore(RecyclableObject* function, CallInfo callInfo, ...) diff --git a/lib/Runtime/Library/SimdInt8x16Lib.cpp b/lib/Runtime/Library/SimdInt8x16Lib.cpp index 69c28be173a..c9f58476601 100644 --- a/lib/Runtime/Library/SimdInt8x16Lib.cpp +++ b/lib/Runtime/Library/SimdInt8x16Lib.cpp @@ -792,8 +792,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 16 * INT8_SIZE, scriptContext); + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 16 * INT8_SIZE, scriptContext); } Var SIMDInt8x16Lib::EntryStore(RecyclableObject* function, CallInfo callInfo, ...) diff --git a/lib/Runtime/Library/SimdUint16x8Lib.cpp b/lib/Runtime/Library/SimdUint16x8Lib.cpp index 539cab31d9c..be3cfb38d4c 100644 --- a/lib/Runtime/Library/SimdUint16x8Lib.cpp +++ b/lib/Runtime/Library/SimdUint16x8Lib.cpp @@ -238,7 +238,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 8 * INT16_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 8 * INT16_SIZE, scriptContext); } Var SIMDUint16x8Lib::EntryStore(RecyclableObject* function, CallInfo callInfo, ...) diff --git a/lib/Runtime/Library/SimdUint32x4Lib.cpp b/lib/Runtime/Library/SimdUint32x4Lib.cpp index 3f385e98538..320ad4df033 100644 --- a/lib/Runtime/Library/SimdUint32x4Lib.cpp +++ b/lib/Runtime/Library/SimdUint32x4Lib.cpp @@ -893,7 +893,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 4 * INT32_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 4 * INT32_SIZE, scriptContext); } Var SIMDUint32x4Lib::EntryLoad1(RecyclableObject* function, CallInfo callInfo, ...) @@ -906,7 +925,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 1 * INT32_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 1 * INT32_SIZE, scriptContext); } Var SIMDUint32x4Lib::EntryLoad2(RecyclableObject* function, CallInfo callInfo, ...) @@ -919,7 +957,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 2 * INT32_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 2 * INT32_SIZE, scriptContext); } Var SIMDUint32x4Lib::EntryLoad3(RecyclableObject* function, CallInfo callInfo, ...) @@ -932,7 +989,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 3 * INT32_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 3 * INT32_SIZE, scriptContext); } Var SIMDUint32x4Lib::EntryStore(RecyclableObject* function, CallInfo callInfo, ...) diff --git a/lib/Runtime/Library/SimdUint8x16Lib.cpp b/lib/Runtime/Library/SimdUint8x16Lib.cpp index a6a25473e2e..7a6baee35fc 100644 --- a/lib/Runtime/Library/SimdUint8x16Lib.cpp +++ b/lib/Runtime/Library/SimdUint8x16Lib.cpp @@ -238,7 +238,26 @@ namespace Js AssertMsg(args.Info.Count > 0, "Should always have implicit 'this'"); Assert(!(callInfo.Flags & CallFlags_New)); - return SIMDUtils::SIMD128TypedArrayLoad(args[1], args[2], 16 * INT8_SIZE, scriptContext); + Var tarray; + Var index; + if (args.Info.Count > 1) + { + tarray = args[1]; + } + else + { + tarray = scriptContext->GetLibrary()->GetUndefined(); + } + if (args.Info.Count > 2) + { + index = args[2]; + } + else + { + index = scriptContext->GetLibrary()->GetUndefined(); + } + + return SIMDUtils::SIMD128TypedArrayLoad(tarray, index, 16 * INT8_SIZE, scriptContext); } Var SIMDUint8x16Lib::EntryStore(RecyclableObject* function, CallInfo callInfo, ...) diff --git a/lib/Runtime/Library/TypedArray.cpp b/lib/Runtime/Library/TypedArray.cpp index ede567433d7..c60600b87dd 100644 --- a/lib/Runtime/Library/TypedArray.cpp +++ b/lib/Runtime/Library/TypedArray.cpp @@ -2235,6 +2235,12 @@ namespace Js dblResult = JavascriptConversion::ToNumber_Full(retVal, scriptContext); } + // ToNumber may execute user-code which can cause the array to become detached + if (TypedArrayBase::IsDetachedTypedArray(contextArray[0])) + { + JavascriptError::ThrowTypeError(scriptContext, JSERR_DetachedTypedArray, _u("[TypedArray].prototype.sort")); + } + if (dblResult < 0) { return -1;