Diff
Modified: branches/safari-601.1.46-branch/LayoutTests/ChangeLog (198634 => 198635)
--- branches/safari-601.1.46-branch/LayoutTests/ChangeLog 2016-03-24 18:14:23 UTC (rev 198634)
+++ branches/safari-601.1.46-branch/LayoutTests/ChangeLog 2016-03-24 18:14:28 UTC (rev 198635)
@@ -1,5 +1,24 @@
2016-03-24 Matthew Hanson <[email protected]>
+ Merge r198592. rdar://problem/25271136
+
+ 2016-03-23 Michael Saboff <[email protected]>
+
+ _javascript_Core ArrayPrototype::join shouldn't cache butterfly when it makes effectful calls
+ https://bugs.webkit.org/show_bug.cgi?id=155776
+
+ Reviewed by Saam Barati.
+
+ New test.
+
+ * js/regress-155776-expected.txt: Added.
+ * js/regress-155776.html: Added.
+ * js/script-tests/regress-155776.js: Added.
+ (fillBigArrayViaToString):
+ (Function.prototype.toString):
+
+2016-03-24 Matthew Hanson <[email protected]>
+
Merge r195614. rdar://problem/24850429
2016-01-26 Philip Rogers <[email protected]>
Added: branches/safari-601.1.46-branch/LayoutTests/js/regress-155776-expected.txt (0 => 198635)
--- branches/safari-601.1.46-branch/LayoutTests/js/regress-155776-expected.txt (rev 0)
+++ branches/safari-601.1.46-branch/LayoutTests/js/regress-155776-expected.txt 2016-03-24 18:14:28 UTC (rev 198635)
@@ -0,0 +1,10 @@
+Regresion test for 155776. This test should pass and not crash.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS stringResult is expectedString
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: branches/safari-601.1.46-branch/LayoutTests/js/regress-155776.html (0 => 198635)
--- branches/safari-601.1.46-branch/LayoutTests/js/regress-155776.html (rev 0)
+++ branches/safari-601.1.46-branch/LayoutTests/js/regress-155776.html 2016-03-24 18:14:28 UTC (rev 198635)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>
Added: branches/safari-601.1.46-branch/LayoutTests/js/script-tests/regress-155776.js (0 => 198635)
--- branches/safari-601.1.46-branch/LayoutTests/js/script-tests/regress-155776.js (rev 0)
+++ branches/safari-601.1.46-branch/LayoutTests/js/script-tests/regress-155776.js 2016-03-24 18:14:28 UTC (rev 198635)
@@ -0,0 +1,50 @@
+description("Regresion test for 155776. This test should pass and not crash.");
+
+var bigArray = [];
+var bigNum = 123456789;
+var smallNum = 123;
+var toStringCount = 0;
+
+function fillBigArrayViaToString(n) {
+ var results = [];
+
+ for (var i = 0; i < n; i++)
+ fillBigArrayViaToString.toString();
+
+ return results;
+}
+
+Function.prototype.toString = function(x) {
+ toStringCount++;
+ bigArray.push(smallNum);
+
+ if (toStringCount == 2000) {
+ var newArray = new Uint32Array(8000);
+ for (var i = 0; i < newArray.length; i++)
+ newArray[i] = 0x10000000;
+ }
+
+ bigArray.push(fillBigArrayViaToString);
+ bigArray.push(fillBigArrayViaToString);
+ bigArray.push(fillBigArrayViaToString);
+ return bigNum;
+};
+
+fillBigArrayViaToString(4000).join();
+
+bigArray.length = 4000;
+
+var stringResult = bigArray.join(":");
+
+var expectedArray = [];
+
+for (var i = 0; i < 1000; i++) {
+ expectedArray.push(smallNum);
+ expectedArray.push(bigNum);
+ expectedArray.push(bigNum);
+ expectedArray.push(bigNum);
+}
+
+var expectedString = expectedArray.join(":");
+
+shouldBe('stringResult', 'expectedString');
Modified: branches/safari-601.1.46-branch/Source/_javascript_Core/ChangeLog (198634 => 198635)
--- branches/safari-601.1.46-branch/Source/_javascript_Core/ChangeLog 2016-03-24 18:14:23 UTC (rev 198634)
+++ branches/safari-601.1.46-branch/Source/_javascript_Core/ChangeLog 2016-03-24 18:14:28 UTC (rev 198635)
@@ -1,3 +1,26 @@
+2016-03-24 Matthew Hanson <[email protected]>
+
+ Merge r198592. rdar://problem/25271136
+
+ 2016-03-23 Michael Saboff <[email protected]>
+
+ _javascript_Core ArrayPrototype::join shouldn't cache butterfly when it makes effectful calls
+ https://bugs.webkit.org/show_bug.cgi?id=155776
+
+ Reviewed by Saam Barati.
+
+ Array.join ends up calling toString, possibly on some object. Since these calls
+ could be effectful and could change the array itself, we can't hold the butterfly
+ pointer while making effectful calls. Changed the code to fall back to the general
+ case when an effectful toString() call might be made.
+
+ * runtime/ArrayPrototype.cpp:
+ (JSC::join):
+ * runtime/JSStringJoiner.h:
+ (JSC::JSStringJoiner::appendWithoutSideEffects): New helper that doesn't make effectful
+ toString() calls.
+ (JSC::JSStringJoiner::append): Built upon appendWithoutSideEffects.
+
2016-02-09 Babak Shafiei <[email protected]>
Merge r196179.
Modified: branches/safari-601.1.46-branch/Source/_javascript_Core/runtime/ArrayPrototype.cpp (198634 => 198635)
--- branches/safari-601.1.46-branch/Source/_javascript_Core/runtime/ArrayPrototype.cpp 2016-03-24 18:14:23 UTC (rev 198634)
+++ branches/safari-601.1.46-branch/Source/_javascript_Core/runtime/ArrayPrototype.cpp 2016-03-24 18:14:28 UTC (rev 198635)
@@ -404,9 +404,8 @@
bool holesKnownToBeOK = false;
for (unsigned i = 0; i < length; ++i) {
if (JSValue value = data[i].get()) {
- joiner.append(state, value);
- if (state.hadException())
- return jsUndefined();
+ if (!joiner.appendWithoutSideEffects(state, value))
+ goto generalCase;
} else {
if (!holesKnownToBeOK) {
if (holesMustForwardToPrototype(state, thisObject))
@@ -454,9 +453,8 @@
auto data = ""
for (unsigned i = 0; i < length; ++i) {
if (JSValue value = data[i].get()) {
- joiner.append(state, value);
- if (state.hadException())
- return jsUndefined();
+ if (!joiner.appendWithoutSideEffects(state, value))
+ goto generalCase;
} else
joiner.appendEmptyString();
}
Modified: branches/safari-601.1.46-branch/Source/_javascript_Core/runtime/JSStringJoiner.h (198634 => 198635)
--- branches/safari-601.1.46-branch/Source/_javascript_Core/runtime/JSStringJoiner.h 2016-03-24 18:14:23 UTC (rev 198634)
+++ branches/safari-601.1.46-branch/Source/_javascript_Core/runtime/JSStringJoiner.h 2016-03-24 18:14:28 UTC (rev 198635)
@@ -37,6 +37,7 @@
JSStringJoiner(ExecState&, StringView separator, unsigned stringCount);
void append(ExecState&, JSValue);
+ bool appendWithoutSideEffects(ExecState&, JSValue);
void appendEmptyString();
JSValue join(ExecState&);
@@ -96,7 +97,7 @@
m_strings.uncheckedAppend({ { }, { } });
}
-ALWAYS_INLINE void JSStringJoiner::append(ExecState& state, JSValue value)
+ALWAYS_INLINE bool JSStringJoiner::appendWithoutSideEffects(ExecState& state, JSValue value)
{
// The following code differs from using the result of JSValue::toString in the following ways:
// 1) It's inlined more than JSValue::toString is.
@@ -104,36 +105,46 @@
// 3) It doesn't create a JSString for numbers, true, or false.
// 4) It turns undefined and null into the empty string instead of "undefined" and "null".
// 5) It uses optimized code paths for all the cases known to be 8-bit and for the empty string.
+ // If we might make an effectful calls, return false. Otherwise return true.
if (value.isCell()) {
- if (value.asCell()->isString()) {
- append(asString(value)->viewWithUnderlyingString(state));
- return;
- }
+ JSString* jsString;
+ if (!value.asCell()->isString())
+ return false;
+ jsString = asString(value);
append(value.toString(&state)->viewWithUnderlyingString(state));
- return;
+ return true;
}
if (value.isInt32()) {
append8Bit(state.vm().numericStrings.add(value.asInt32()));
- return;
+ return true;
}
if (value.isDouble()) {
append8Bit(state.vm().numericStrings.add(value.asDouble()));
- return;
+ return true;
}
if (value.isTrue()) {
append8Bit(state.vm().propertyNames->trueKeyword.string());
- return;
+ return true;
}
if (value.isFalse()) {
append8Bit(state.vm().propertyNames->falseKeyword.string());
- return;
+ return true;
}
ASSERT(value.isUndefinedOrNull());
appendEmptyString();
+ return true;
}
+ALWAYS_INLINE void JSStringJoiner::append(ExecState& state, JSValue value)
+{
+ if (!appendWithoutSideEffects(state, value)) {
+ JSString* jsString = value.toString(&state);
+ append(jsString->viewWithUnderlyingString(state));
+ }
}
+}
+
#endif