Changeset 203952 in webkit


Ignore:
Timestamp:
Jul 30, 2016 6:08:37 PM (8 years ago)
Author:
mark.lam@apple.com
Message:

Assertion failure while setting the length of an ArrayClass array.
https://bugs.webkit.org/show_bug.cgi?id=160381
<rdar://problem/27328703>

Reviewed by Filip Pizlo.

Source/JavaScriptCore:

When setting large length values, we're currently treating ArrayClass as a
ContiguousIndexingType array. This results in an assertion failure. This is
now fixed.

There are currently only 2 places where we create arrays with indexing type
ArrayClass: ArrayPrototype and RuntimeArray. The fix in JSArray:;setLength()
takes care of ArrayPrototype.

RuntimeArray already checks for the setting of its length property, and will
throw a RangeError. Hence, there's no change is needed for the RuntimeArray.
Instead, I added some test cases ensure that the check and throw behavior does
not change without notice.

  • runtime/JSArray.cpp:

(JSC::JSArray::setLength):

  • tests/stress/array-setLength-on-ArrayClass-with-large-length.js: Added.

(toString):
(assertEqual):

  • tests/stress/array-setLength-on-ArrayClass-with-small-length.js: Added.

(toString):
(assertEqual):

LayoutTests:

Test that RuntimeArrays will throw an error if we try to set its length.

  • platform/mac/fast/dom/wrapper-classes-objc.html:
  • platform/mac/fast/dom/wrapper-classes-objc-expected.txt:
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r203950 r203952  
     12016-07-30  Mark Lam  <mark.lam@apple.com>
     2
     3        Assertion failure while setting the length of an ArrayClass array.
     4        https://bugs.webkit.org/show_bug.cgi?id=160381
     5        <rdar://problem/27328703>
     6
     7        Reviewed by Filip Pizlo.
     8
     9        Test that RuntimeArrays will throw an error if we try to set its length.
     10
     11        * platform/mac/fast/dom/wrapper-classes-objc.html:
     12        * platform/mac/fast/dom/wrapper-classes-objc-expected.txt:
     13
    1142016-07-30  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/LayoutTests/platform/mac/fast/dom/wrapper-classes-objc-expected.txt

    r203535 r203952  
    192192PASS objCObjectOfClass('NSArray') instanceof Array is true
    193193PASS concatenateArray(objCArrayOfString()) is 'onetwothree'
     194PASS let arr = objCArrayOfString(); arr.length is 3
     195PASS let arr = objCArrayOfString(); arr.length = 0 threw exception RangeError: Range error.
     196PASS let arr = objCArrayOfString(); arr.length = 5 threw exception RangeError: Range error.
     197PASS let arr = objCArrayOfString(); arr.length = 0x40000000 threw exception RangeError: Range error.
     198PASS let arr = objCArrayOfString(); try { arr.length = 0 } catch(e) { } arr.length is 3
    194199
  • trunk/LayoutTests/platform/mac/fast/dom/wrapper-classes-objc.html

    r203535 r203952  
    291291    shouldBe("concatenateArray(objCArrayOfString())", "'onetwothree'");
    292292
     293    shouldBe("let arr = objCArrayOfString(); arr.length", "3");
     294    shouldThrow("let arr = objCArrayOfString(); arr.length = 0");
     295    shouldThrow("let arr = objCArrayOfString(); arr.length = 5");
     296    shouldThrow("let arr = objCArrayOfString(); arr.length = 0x40000000");
     297    shouldBe("let arr = objCArrayOfString(); try { arr.length = 0 } catch(e) { } arr.length", "3");
     298
    293299    // Not yet tested:
    294300
  • trunk/Source/JavaScriptCore/ChangeLog

    r203937 r203952  
     12016-07-30  Mark Lam  <mark.lam@apple.com>
     2
     3        Assertion failure while setting the length of an ArrayClass array.
     4        https://bugs.webkit.org/show_bug.cgi?id=160381
     5        <rdar://problem/27328703>
     6
     7        Reviewed by Filip Pizlo.
     8
     9        When setting large length values, we're currently treating ArrayClass as a
     10        ContiguousIndexingType array.  This results in an assertion failure.  This is
     11        now fixed.
     12
     13        There are currently only 2 places where we create arrays with indexing type
     14        ArrayClass: ArrayPrototype and RuntimeArray.  The fix in JSArray:;setLength()
     15        takes care of ArrayPrototype.
     16
     17        RuntimeArray already checks for the setting of its length property, and will
     18        throw a RangeError.  Hence, there's no change is needed for the RuntimeArray.
     19        Instead, I added some test cases ensure that the check and throw behavior does
     20        not change without notice.
     21
     22        * runtime/JSArray.cpp:
     23        (JSC::JSArray::setLength):
     24        * tests/stress/array-setLength-on-ArrayClass-with-large-length.js: Added.
     25        (toString):
     26        (assertEqual):
     27        * tests/stress/array-setLength-on-ArrayClass-with-small-length.js: Added.
     28        (toString):
     29        (assertEqual):
     30
    1312016-07-29  Keith Miller  <keith_miller@apple.com>
    232
  • trunk/Source/JavaScriptCore/runtime/JSArray.cpp

    r202844 r203952  
    442442            return setLengthWithArrayStorage(
    443443                exec, newLength, throwException,
    444                 convertContiguousToArrayStorage(exec->vm()));
     444                ensureArrayStorage(exec->vm()));
    445445        }
    446446        createInitialUndecided(exec->vm(), newLength);
Note: See TracChangeset for help on using the changeset viewer.