Loading js/src/builtin/intl/NumberFormat.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ #include "vm/WellKnownAtom.h" // js_*_str #include "vm/JSObject-inl.h" #include "vm/NativeObject-inl.h" using namespace js; Loading Loading @@ -1203,11 +1204,14 @@ static bool FormattedNumberToParts(JSContext* cx, HandleString str, RootedObject singlePart(cx); RootedValue propVal(cx); RootedArrayObject partsArray(cx, NewDenseEmptyArray(cx)); RootedArrayObject partsArray(cx, NewDenseFullyAllocatedArray(cx, parts.length())); if (!partsArray) { return false; } partsArray->ensureDenseInitializedLength(0, parts.length()); size_t index = 0; for (const auto& part : parts) { FieldType type = GetFieldTypeForNumberPartType(part.first); size_t endIndex = part.second; Loading Loading @@ -1235,13 +1239,12 @@ static bool FormattedNumberToParts(JSContext* cx, HandleString str, return false; } if (!NewbornArrayPush(cx, partsArray, ObjectValue(*singlePart))) { return false; } partsArray->initDenseElement(index++, ObjectValue(*singlePart)); lastEndIndex = endIndex; } MOZ_ASSERT(index == parts.length()); MOZ_ASSERT(lastEndIndex == str->length(), "result array must partition the entire string"); Loading js/src/builtin/intl/PluralRules.cpp +9 −7 Original line number Diff line number Diff line Loading @@ -327,25 +327,27 @@ bool js::intl_GetPluralCategories(JSContext* cx, unsigned argc, Value* vp) { PluralRulesObject::UPluralRulesEstimatedMemoryUse); } auto categories = pr->Categories(); if (categories.isErr()) { auto categoriesResult = pr->Categories(); if (categoriesResult.isErr()) { intl::ReportInternalError(cx); return false; } auto categories = categoriesResult.unwrap(); RootedObject res(cx, NewDenseEmptyArray(cx)); ArrayObject* res = NewDenseFullyAllocatedArray(cx, categories.size()); if (!res) { return false; } res->setDenseInitializedLength(categories.size()); for (PluralRules::Keyword keyword : categories.unwrap()) { size_t index = 0; for (PluralRules::Keyword keyword : categories) { JSString* str = KeywordToString(keyword, cx); MOZ_ASSERT(str); if (!NewbornArrayPush(cx, res, StringValue(str))) { return false; } res->initDenseElement(index++, StringValue(str)); } MOZ_ASSERT(index == categories.size()); args.rval().setObject(*res); return true; Loading Loading
js/src/builtin/intl/NumberFormat.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ #include "vm/WellKnownAtom.h" // js_*_str #include "vm/JSObject-inl.h" #include "vm/NativeObject-inl.h" using namespace js; Loading Loading @@ -1203,11 +1204,14 @@ static bool FormattedNumberToParts(JSContext* cx, HandleString str, RootedObject singlePart(cx); RootedValue propVal(cx); RootedArrayObject partsArray(cx, NewDenseEmptyArray(cx)); RootedArrayObject partsArray(cx, NewDenseFullyAllocatedArray(cx, parts.length())); if (!partsArray) { return false; } partsArray->ensureDenseInitializedLength(0, parts.length()); size_t index = 0; for (const auto& part : parts) { FieldType type = GetFieldTypeForNumberPartType(part.first); size_t endIndex = part.second; Loading Loading @@ -1235,13 +1239,12 @@ static bool FormattedNumberToParts(JSContext* cx, HandleString str, return false; } if (!NewbornArrayPush(cx, partsArray, ObjectValue(*singlePart))) { return false; } partsArray->initDenseElement(index++, ObjectValue(*singlePart)); lastEndIndex = endIndex; } MOZ_ASSERT(index == parts.length()); MOZ_ASSERT(lastEndIndex == str->length(), "result array must partition the entire string"); Loading
js/src/builtin/intl/PluralRules.cpp +9 −7 Original line number Diff line number Diff line Loading @@ -327,25 +327,27 @@ bool js::intl_GetPluralCategories(JSContext* cx, unsigned argc, Value* vp) { PluralRulesObject::UPluralRulesEstimatedMemoryUse); } auto categories = pr->Categories(); if (categories.isErr()) { auto categoriesResult = pr->Categories(); if (categoriesResult.isErr()) { intl::ReportInternalError(cx); return false; } auto categories = categoriesResult.unwrap(); RootedObject res(cx, NewDenseEmptyArray(cx)); ArrayObject* res = NewDenseFullyAllocatedArray(cx, categories.size()); if (!res) { return false; } res->setDenseInitializedLength(categories.size()); for (PluralRules::Keyword keyword : categories.unwrap()) { size_t index = 0; for (PluralRules::Keyword keyword : categories) { JSString* str = KeywordToString(keyword, cx); MOZ_ASSERT(str); if (!NewbornArrayPush(cx, res, StringValue(str))) { return false; } res->initDenseElement(index++, StringValue(str)); } MOZ_ASSERT(index == categories.size()); args.rval().setObject(*res); return true; Loading