Skip to content

Commit

Permalink
Define length on CoW array should properly convert to writable
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=185927

Reviewed by Yusuke Suzuki.

JSTests:

* stress/cow-define-length-as-value.js: Added.
(test):

Source/JavaScriptCore:

* runtime/JSArray.cpp:
(JSC::JSArray::setLength):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@232138 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
[email protected] committed May 24, 2018
1 parent 6a31919 commit 4789553
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions JSTests/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2018-05-23 Keith Miller <[email protected]>

Define length on CoW array should properly convert to writable
https://bugs.webkit.org/show_bug.cgi?id=185927

Reviewed by Yusuke Suzuki.

* stress/cow-define-length-as-value.js: Added.
(test):

2018-05-23 Michael Saboff <[email protected]>

Date.parse() doesn't properly handle input outside of ES Spec limits
Expand Down
19 changes: 19 additions & 0 deletions JSTests/stress/cow-define-length-as-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function test(create) {
// Set length to be smaller.
Object.defineProperty(create(), "length", { value: 1 });

// Set length to be bigger.
Object.defineProperty(create(), "length", { value: 4 });

// Set length to be the same size
Object.defineProperty(create(), "length", { value: 3 });
}

// Test Int32.
test(() => [1, 2]);
// Test double
test(() => [1.123, 2.50934]);
// Test contiguous via NaN
test(() => [NaN, 2.50934]);
// Test contiguous via string
test(() => ["test", "42"]);
10 changes: 10 additions & 0 deletions Source/JavaScriptCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2018-05-23 Keith Miller <[email protected]>

Define length on CoW array should properly convert to writable
https://bugs.webkit.org/show_bug.cgi?id=185927

Reviewed by Yusuke Suzuki.

* runtime/JSArray.cpp:
(JSC::JSArray::setLength):

2018-05-23 Keith Miller <[email protected]>

InPlaceAbstractState should filter variables at the tail from a GetLocal by their flush format
Expand Down
11 changes: 10 additions & 1 deletion Source/JavaScriptCore/runtime/JSArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ bool JSArray::setLength(ExecState* exec, unsigned newLength, bool throwException
auto scope = DECLARE_THROW_SCOPE(vm);

Butterfly* butterfly = this->butterfly();
switch (indexingType()) {
switch (indexingMode()) {
case ArrayClass:
if (!newLength)
return true;
Expand All @@ -581,6 +581,15 @@ bool JSArray::setLength(ExecState* exec, unsigned newLength, bool throwException
createInitialUndecided(vm, newLength);
return true;

case CopyOnWriteArrayWithInt32:
case CopyOnWriteArrayWithDouble:
case CopyOnWriteArrayWithContiguous:
if (newLength == butterfly->publicLength())
return true;
convertFromCopyOnWrite(vm);
butterfly = this->butterfly();
FALLTHROUGH;

case ArrayWithUndecided:
case ArrayWithInt32:
case ArrayWithDouble:
Expand Down

0 comments on commit 4789553

Please sign in to comment.