Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
JSArrayBufferViews of length 0 allocate 0 CopiedSpace bytes, which is…
… invalid https://bugs.webkit.org/show_bug.cgi?id=123746 Reviewed by Geoffrey Garen. Source/JavaScriptCore: This patch disallows clients from allocating 0 bytes in CopiedSpace. We enforce this invariant with an ASSERT in C++ code and a breakpoint in JIT code. Clients who care about 0-byte allocations (like JSArrayBufferViews) must handle that case themselves, but we don't punish anybody else for the rare case that somebody decides to allocate a 0-length typed array. It also makes the allocation and copying cases consistent for CopiedSpace: no 0-byte allocations, no 0-byte copying. Also added a check so that JSArrayBufferViews don't try to copy their m_vector backing store when their length is 0. Also sprinkled several ASSERTs throughout the JSArrayBufferView code to make sure that when length is 0 m_vector is null. * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileNewTypedArray): * dfg/DFGSpeculativeJIT.h: (JSC::DFG::SpeculativeJIT::emitAllocateBasicStorage): * heap/CopiedSpaceInlines.h: (JSC::CopiedSpace::tryAllocate): * runtime/ArrayBuffer.h: (JSC::ArrayBuffer::create): * runtime/JSArrayBufferView.cpp: (JSC::JSArrayBufferView::ConstructionContext::ConstructionContext): * runtime/JSGenericTypedArrayViewInlines.h: (JSC::::visitChildren): (JSC::::copyBackingStore): (JSC::::slowDownAndWasteMemory): LayoutTests: Added a test to make sure that we don't crash when allocating a typed array with 0 length. * js/script-tests/typedarray-zero-size.js: Added. (foo): * js/typedarray-zero-size-expected.txt: Added. * js/typedarray-zero-size.html: Added. Canonical link: https://commits.webkit.org/141936@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@158583 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Mark Hahnenberg
committed
Nov 4, 2013
1 parent
c204a1e
commit 6b0ff88
Showing
11 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
description( | ||
"Tests that creating TypedArrays of length 0 doesn't cause us to crash." | ||
); | ||
|
||
var array = new Uint8Array(0); | ||
|
||
function foo() { | ||
return new Uint16Array(0); | ||
} | ||
|
||
var result = 0; | ||
|
||
for (var i = 1; i < 10001; i++) { | ||
var newArray = foo(); | ||
var otherArray = new Array(i); | ||
for (var j = 0; j < i; ++j) | ||
otherArray[j] = j; | ||
result += otherArray[i - 1]; | ||
} | ||
|
||
if (result != (10000 * 9999) / 2) | ||
throw "Bad result: " + result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Tests that creating TypedArrays of length 0 doesn't cause us to crash. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | ||
<html> | ||
<head> | ||
<script src="../resources/js-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<script src="script-tests/typedarray-zero-size.js"></script> | ||
<script src="../resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters