⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 202966 in webkit


Ignore:
Timestamp:
Jul 7, 2016, 11:25:34 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

padStart/padEnd with Infinity produces unexpected result
https://bugs.webkit.org/show_bug.cgi?id=159543

Patch by Joseph Pecoraro <Joseph Pecoraro> on 2016-07-07
Reviewed by Benjamin Poulain.

Source/JavaScriptCore:

  • builtins/GlobalOperations.js:

(globalPrivate.toLength):
Fix style.

  • builtins/StringPrototype.js:

(padStart):
(padEnd):
After all observable operations, and after empty string has been handled,
throw an out of memory error if the resulting string would be greater
than the maximum string size.

  • tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors-proxy.js:

(shouldThrow): Deleted.

  • tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors.js:

(shouldThrow):
(testMeta):

  • tests/es6/String.prototype_methods_String.prototype.padEnd.js:

(shouldThrow):
(TestToLength):
(TestMemoryLimits):
(TestMeta): Deleted.

  • tests/es6/String.prototype_methods_String.prototype.padStart.js:

(shouldThrow):
(TestToLength):
(TestMemoryLimits):
Replace incorrect shouldThrow(..., errorType) with explicit shouldThrow(..., errorMessage).
The old shouldThrow would incorrectly succeed if the expected error type was just "Error".
Now we explicitly check the error message.

LayoutTests:

  • js/script-tests/string-padend.js: Added.

(thisObject.toString):
(lengthObject.valueOf):
(fillObject.toString):

  • js/script-tests/string-padstart.js: Added.

(thisObject.toString):
(lengthObject.valueOf):
(fillObject.toString):

  • js/string-padend-expected.txt: Added.
  • js/string-padend.html: Added.
  • js/string-padstart-expected.txt: Added.
  • js/string-padstart.html: Added.

Add some basic String.prototype.padStart/padEnd test coverage
that is not just in the JavaScriptCore/tests/es6 directory.

Location:
trunk
Files:
6 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r202962 r202966  
     12016-07-07  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        padStart/padEnd with Infinity produces unexpected result
     4        https://bugs.webkit.org/show_bug.cgi?id=159543
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * js/script-tests/string-padend.js: Added.
     9        (thisObject.toString):
     10        (lengthObject.valueOf):
     11        (fillObject.toString):
     12        * js/script-tests/string-padstart.js: Added.
     13        (thisObject.toString):
     14        (lengthObject.valueOf):
     15        (fillObject.toString):
     16        * js/string-padend-expected.txt: Added.
     17        * js/string-padend.html: Added.
     18        * js/string-padstart-expected.txt: Added.
     19        * js/string-padstart.html: Added.
     20        Add some basic String.prototype.padStart/padEnd test coverage
     21        that is not just in the JavaScriptCore/tests/es6 directory.
     22
    1232016-07-07  Frederic Wang  <fwang@igalia.com>
    224
  • trunk/Source/JavaScriptCore/ChangeLog

    r202956 r202966  
     12016-07-07  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        padStart/padEnd with Infinity produces unexpected result
     4        https://bugs.webkit.org/show_bug.cgi?id=159543
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * builtins/GlobalOperations.js:
     9        (globalPrivate.toLength):
     10        Fix style.
     11
     12        * builtins/StringPrototype.js:
     13        (padStart):
     14        (padEnd):
     15        After all observable operations, and after empty string has been handled,
     16        throw an out of memory error if the resulting string would be greater
     17        than the maximum string size.
     18
     19        * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors-proxy.js:
     20        (shouldThrow): Deleted.
     21        * tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors.js:
     22        (shouldThrow):
     23        (testMeta):
     24        * tests/es6/String.prototype_methods_String.prototype.padEnd.js:
     25        (shouldThrow):
     26        (TestToLength):
     27        (TestMemoryLimits):
     28        (TestMeta): Deleted.
     29        * tests/es6/String.prototype_methods_String.prototype.padStart.js:
     30        (shouldThrow):
     31        (TestToLength):
     32        (TestMemoryLimits):
     33        Replace incorrect shouldThrow(..., errorType) with explicit shouldThrow(..., errorMessage).
     34        The old shouldThrow would incorrectly succeed if the expected error type was just "Error".
     35        Now we explicitly check the error message.
     36
    1372016-07-07  Benjamin Poulain  <benjamin@webkit.org>
    238
  • trunk/Source/JavaScriptCore/builtins/GlobalOperations.js

    r202680 r202966  
    4646    var length = @toInteger(target);
    4747    // originally Math.min(Math.max(length, 0), maxSafeInteger));
    48     return length > 0 ? (length < @MAX_SAFE_INTEGER? length : @MAX_SAFE_INTEGER) : 0;
    49 
     48    return length > 0 ? (length < @MAX_SAFE_INTEGER ? length : @MAX_SAFE_INTEGER) : 0;
    5049}
    5150
  • trunk/Source/JavaScriptCore/builtins/StringPrototype.js

    r202954 r202966  
    139139    var string = @toString(this);
    140140    maxLength = @toLength(maxLength);
    141     var fillString = arguments[1];
    142141
    143142    var stringLength = string.length;
     
    146145
    147146    var filler;
    148     if (arguments[1] === @undefined)
     147    var fillString = arguments[1];
     148    if (fillString === @undefined)
    149149        filler = " ";
    150150    else {
    151         filler = @toString(arguments[1]);
     151        filler = @toString(fillString);
    152152        if (filler === "")
    153153            return string;
    154154    }
     155
     156    if (maxLength > @MAX_STRING_LENGTH)
     157        throw new @Error("Out of memory");
    155158
    156159    var fillLength = maxLength - stringLength;
     
    182185
    183186    var filler;
    184     if (arguments[1] === @undefined)
     187    var fillString = arguments[1];
     188    if (fillString === @undefined)
    185189        filler = " ";
    186190    else {
    187         filler = @toString(arguments[1]);
     191        filler = @toString(fillString);
    188192        if (filler === "")
    189193            return string;
    190194    }
     195
     196    if (maxLength > @MAX_STRING_LENGTH)
     197        throw new @Error("Out of memory");
    191198
    192199    var fillLength = maxLength - stringLength;
  • trunk/Source/JavaScriptCore/tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors-proxy.js

    r196040 r202966  
    66    if (actual !== expected)
    77        throw new Error('bad value' + msg + ': ' + actual + '. Expected ' + expected);
    8 }
    9 
    10 function shouldThrow(func, errorType) {
    11     try {
    12         func();
    13         throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but did not throw.');
    14     } catch (e) {
    15         if (e instanceof errorType) return;
    16         throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but threw ' + e);
    17     }
    188}
    199
  • trunk/Source/JavaScriptCore/tests/es6/Object_static_methods_Object.getOwnPropertyDescriptors.js

    r198572 r202966  
    88}
    99
    10 function shouldThrow(func, errorType) {
     10function shouldThrow(func, errorMessage) {
     11    var errorThrown = false;
     12    var error = null;
    1113    try {
    1214        func();
    13         throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but did not throw.');
    1415    } catch (e) {
    15         if (e instanceof errorType) return;
    16         throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but threw ' + e);
     16        errorThrown = true;
     17        error = e;
    1718    }
     19    if (!errorThrown)
     20        throw new Error('not thrown');
     21    if (String(error) !== errorMessage)
     22        throw new Error(`bad error: ${String(error)}`);
    1823}
    1924
     
    3944    shouldBe(true, propertyDescriptor.configurable);
    4045
    41     shouldThrow(() => new Object.getOwnPropertyDescriptors({}), TypeError);
     46    shouldThrow(() => new Object.getOwnPropertyDescriptors({}), "TypeError: function is not a constructor (evaluating 'new Object.getOwnPropertyDescriptors({})')");
    4247})();
    4348
    4449(function testToObject() {
    45     shouldThrow(() => Object.getOwnPropertyDescriptors(null), TypeError);
    46     shouldThrow(() => Object.getOwnPropertyDescriptors(undefined), TypeError);
    47     shouldThrow(() => Object.getOwnPropertyDescriptors(), TypeError);
     50    shouldThrow(() => Object.getOwnPropertyDescriptors(null), "TypeError: null is not an object (evaluating 'Object.getOwnPropertyDescriptors(null)')");
     51    shouldThrow(() => Object.getOwnPropertyDescriptors(undefined), "TypeError: undefined is not an object (evaluating 'Object.getOwnPropertyDescriptors(undefined)')");
     52    shouldThrow(() => Object.getOwnPropertyDescriptors(), "TypeError: undefined is not an object (evaluating 'Object.getOwnPropertyDescriptors()')");
    4853})();
    4954
  • trunk/Source/JavaScriptCore/tests/es6/String.prototype_methods_String.prototype.padEnd.js

    r200194 r202966  
    88}
    99
    10 function shouldThrow(func, errorType) {
     10function shouldThrow(func, errorMessage) {
     11    var errorThrown = false;
     12    var error = null;
    1113    try {
    1214        func();
    13         throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but did not throw.');
    1415    } catch (e) {
    15         if (e instanceof errorType) return;
    16         throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but threw ' + e);
     16        errorThrown = true;
     17        error = e;
    1718    }
     19    if (!errorThrown)
     20        throw new Error('not thrown');
     21    if (String(error) !== errorMessage)
     22        throw new Error(`bad error: ${String(error)}`);
    1823}
    1924
     
    3237    shouldBe(String.prototype.padEnd, descriptor.value);
    3338
    34     shouldThrow(() => new Function(`${String.prototype.padEnd}`), SyntaxError);
     39    shouldThrow(() => new Function(`${String.prototype.padEnd}`), "SyntaxError: Unexpected identifier 'code'. Expected either a closing ']' or a ',' following an array element.");
    3540})();
    3641
    3742(function TestRequireObjectCoercible() {
    3843    var padEnd = String.prototype.padEnd;
    39     shouldThrow(() => padEnd.call(null, 4, "test"), TypeError);
    40     shouldThrow(() => padEnd.call(undefined, 4, "test"), TypeError);
     44    shouldThrow(() => padEnd.call(null, 4, "test"), "TypeError: String.prototype.padEnd requires that |this| not be null");
     45    shouldThrow(() => padEnd.call(undefined, 4, "test"), "TypeError: String.prototype.padEnd requires that |this| not be undefined");
    4146    shouldBe("123   ", padEnd.call({
    4247        __proto__: null,
     
    6469
    6570(function TestToLength() {
    66     shouldThrow(() => "123".padEnd(Symbol("16")), TypeError);
     71    shouldThrow(() => "123".padEnd(Symbol("16")), "TypeError: Cannot convert a symbol to a number");
    6772    shouldBe("123", "123".padEnd(-1));
    6873    shouldBe("123", "123".padEnd({ toString() { return -1; } }));
     
    97102
    98103(function TestMemoryLimits() {
    99     shouldThrow(() => ".".padEnd(0x80000000, "o"), Error);
    100     shouldThrow(() => ".".padEnd({ valueOf() { return 0x80000000; } }, "o"), Error);
    101     shouldThrow(() => ".".padEnd("0x80000000", "o"), Error);
     104    shouldThrow(() => ".".padEnd(0x80000000, "o"), "Error: Out of memory");
     105    shouldThrow(() => ".".padEnd({ valueOf() { return 0x80000000; } }, "o"), "Error: Out of memory");
     106    shouldThrow(() => ".".padEnd("0x80000000", "o"), "Error: Out of memory");
    102107})();
    103108
  • trunk/Source/JavaScriptCore/tests/es6/String.prototype_methods_String.prototype.padStart.js

    r200194 r202966  
    88}
    99
    10 function shouldThrow(func, errorType) {
     10function shouldThrow(func, errorMessage) {
     11    var errorThrown = false;
     12    var error = null;
    1113    try {
    1214        func();
    13         throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but did not throw.');
    1415    } catch (e) {
    15         if (e instanceof errorType) return;
    16         throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but threw ' + e);
     16        errorThrown = true;
     17        error = e;
    1718    }
     19    if (!errorThrown)
     20        throw new Error('not thrown');
     21    if (String(error) !== errorMessage)
     22        throw new Error(`bad error: ${String(error)}`);
    1823}
    1924
     
    3237    shouldBe(String.prototype.padStart, descriptor.value);
    3338
    34     shouldThrow(() => new Function(`${String.prototype.padStart}`), SyntaxError);
     39    shouldThrow(() => new Function(`${String.prototype.padStart}`), "SyntaxError: Unexpected identifier 'code'. Expected either a closing ']' or a ',' following an array element.");
    3540})();
    3641
    3742(function TestRequireObjectCoercible() {
    3843    var padStart = String.prototype.padStart;
    39     shouldThrow(() => padStart.call(null, 4, "test"), TypeError);
    40     shouldThrow(() => padStart.call(undefined, 4, "test"), TypeError);
     44    shouldThrow(() => padStart.call(null, 4, "test"), "TypeError: String.prototype.padStart requires that |this| not be null");
     45    shouldThrow(() => padStart.call(undefined, 4, "test"), "TypeError: String.prototype.padStart requires that |this| not be undefined");
    4146    shouldBe("   123", padStart.call({
    4247        __proto__: null,
     
    6469
    6570(function TestToLength() {
    66     shouldThrow(() => "123".padStart(Symbol("16")), TypeError);
     71    shouldThrow(() => "123".padStart(Symbol("16")), "TypeError: Cannot convert a symbol to a number");
    6772    shouldBe("123", "123".padStart(-1));
    6873    shouldBe("123", "123".padStart({ toString() { return -1; } }));
     
    97102
    98103(function TestMemoryLimits() {
    99     shouldThrow(() => ".".padStart(0x80000000, "o"), Error);
    100     shouldThrow(() => ".".padStart({ valueOf() { return 0x80000000; } }, "o"), Error);
    101     shouldThrow(() => ".".padStart("0x80000000", "o"), Error);
     104    shouldThrow(() => ".".padStart(0x80000000, "o"), "Error: Out of memory");
     105    shouldThrow(() => ".".padStart({ valueOf() { return 0x80000000; } }, "o"), "Error: Out of memory");
     106    shouldThrow(() => ".".padStart("0x80000000", "o"), "Error: Out of memory");
    102107})();
    103108
Note: See TracChangeset for help on using the changeset viewer.