src/third_party/mozjs/extract/js/src/builtin/String.js
/**
 * A helper function implementing the logic for both String.prototype.padStart
 * and String.prototype.padEnd as described in ES7 Draft March 29, 2016
 */
A helper function implementing the logic for both String.prototype.padStart
and String.prototype.padEnd as described in ES7 Draft March 29, 2016
A helper function implementing the logic for both String . prototype . padStart and String . prototype . padEnd as described in ES7 Draft March 29 2016
function String_pad(maxLength, fillString, padEnd) {
    if (this === undefined || this === null)
        ThrowIncompatibleMethod(padEnd ? "padEnd" : "padStart", this);
    let str = ToString(this);
    let intMaxLength = ToLength(maxLength);
    let strLen = str.length;
    if (intMaxLength <= strLen)
        return str;
    assert(fillString !== undefined, "never called when fillString is undefined");
    let filler = ToString(fillString);
    if (filler === "")
        return str;
    if (intMaxLength > MAX_STRING_LENGTH)
        ThrowRangeError(JSMSG_RESULTING_STRING_TOO_LARGE);
    let fillLen = intMaxLength - strLen;
    let truncatedStringFiller = callFunction(String_repeat, filler,
                                             (fillLen / filler.length) | 0);
    truncatedStringFiller += Substring(filler, 0, fillLen % filler.length);
    if (padEnd === true)
        return str + truncatedStringFiller;
    return truncatedStringFiller + str;
}
function String_pad ( maxLength , fillString , padEnd ) { if ( this === undefined || this === null ) ThrowIncompatibleMethod ( padEnd ? "padEnd" : "padStart" , this ) ; let str = ToString ( this ) ; let intMaxLength = ToLength ( maxLength ) ; let strLen = str . length ; if ( intMaxLength <= strLen ) return str ; assert ( fillString !== undefined , "never called when fillString is undefined" ) ; let filler = ToString ( fillString ) ; if ( filler === "" ) return str ; if ( intMaxLength > MAX_STRING_LENGTH ) ThrowRangeError ( JSMSG_RESULTING_STRING_TOO_LARGE ) ; let fillLen = intMaxLength - strLen ; let truncatedStringFiller = callFunction ( String_repeat , filler , ( fillLen / filler . length ) | 0 ) ; truncatedStringFiller += Substring ( filler , 0 , fillLen % filler . length ) ; if ( padEnd === true ) return str + truncatedStringFiller ; return truncatedStringFiller + str ; }
A helper function implementing the logic for both String.prototype.padStart
 and String.prototype.padEnd as described in ES7 Draft March 29, 2016
A helper function implementing the logic for both String . prototype . padStart and String . prototype . padEnd as described in ES7 Draft March 29 2016
// Step 1. // Step 2. // Steps 3-4. // Step 5. // Steps 6-7. // Step 8. // Throw an error if the final string length exceeds the maximum string // length. Perform this check early so we can use int32 operations below. // Step 9. // Step 10. // Perform an int32 division to ensure String_repeat is not called with a // double to avoid repeated bailouts in ToInteger. // Step 11.