Commit c1b7cdcb authored by bdash's avatar bdash

2006-11-06 Mark Rowe <bdash@webkit.org>

        Reviewed by the wonderful Mitz Pettel.

        http://bugs.webkit.org/show_bug.cgi?id=11524
        Bug 11524: REGRESSION(r9842): Array.prototype.join should use ToString operator rather than calling toString on each element

        * kjs/array_object.cpp:
        (ArrayProtoFunc::callAsFunction): Use ToString operator on each element rather than calling their toString method.
2006-11-06  Mark Rowe  <bdash@webkit.org>

        Reviewed by the wonderful Mitz Pettel.

        Test for http://bugs.webkit.org/show_bug.cgi?id=11524
        Bug 11524: REGRESSION(r9842): Array.prototype.join should use ToString operator rather than calling toString on each element

        * fast/js/array-join-bug-11524-expected.txt: Added.
        * fast/js/array-join-bug-11524.html: Added.
        * fast/js/resources/array-join-bug-11524.js: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@17610 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 6de7ecea
2006-11-06 Mark Rowe <bdash@webkit.org>
Reviewed by the wonderful Mitz Pettel.
http://bugs.webkit.org/show_bug.cgi?id=11524
Bug 11524: REGRESSION(r9842): Array.prototype.join should use ToString operator rather than calling toString on each element
* kjs/array_object.cpp:
(ArrayProtoFunc::callAsFunction): Use ToString operator on each element rather than calling their toString method.
2006-11-03 Steve Falkenburg <sfalken@apple.com>
Fix build
......
......@@ -469,50 +469,37 @@ JSValue *ArrayProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, cons
case Join: {
static HashSet<JSObject*> visitedElems;
if (visitedElems.contains(thisObj))
return jsString("");
return jsString("");
UString separator = ",";
UString str = "";
visitedElems.add(thisObj);
if (id == Join && !args[0]->isUndefined())
separator = args[0]->toString(exec);
separator = args[0]->toString(exec);
for (unsigned int k = 0; k < length; k++) {
if (k >= 1)
str += separator;
JSValue *element = thisObj->get(exec, k);
if (element->isUndefinedOrNull())
continue;
bool fallback = false;
if (id == ToLocaleString) {
JSObject *o = element->toObject(exec);
JSValue *conversionFunction = o->get(exec, toLocaleStringPropertyName);
if (conversionFunction->isObject() && static_cast<JSObject *>(conversionFunction)->implementsCall()) {
str += static_cast<JSObject *>(conversionFunction)->call(exec, o, List())->toString(exec);
} else {
// try toString() fallback
fallback = true;
if (k >= 1)
str += separator;
JSValue* element = thisObj->get(exec, k);
if (element->isUndefinedOrNull())
continue;
bool fallback = false;
if (id == ToLocaleString) {
JSObject* o = element->toObject(exec);
JSValue* conversionFunction = o->get(exec, toLocaleStringPropertyName);
if (conversionFunction->isObject() && static_cast<JSObject*>(conversionFunction)->implementsCall())
str += static_cast<JSObject*>(conversionFunction)->call(exec, o, List())->toString(exec);
else
// try toString() fallback
fallback = true;
}
}
if (id == ToString || id == Join || fallback) {
if (element->isObject()) {
JSObject *o = static_cast<JSObject *>(element);
JSValue *conversionFunction = o->get(exec, toStringPropertyName);
if (conversionFunction->isObject() && static_cast<JSObject *>(conversionFunction)->implementsCall()) {
str += static_cast<JSObject *>(conversionFunction)->call(exec, o, List())->toString(exec);
} else {
visitedElems.remove(thisObj);
return throwError(exec, RangeError, "Can't convert " + o->className() + " object to string");
}
} else {
str += element->toString(exec);
}
}
if (id == ToString || id == Join || fallback)
str += element->toString(exec);
if ( exec->hadException() )
break;
if (exec->hadException())
break;
}
visitedElems.remove(thisObj);
result = jsString(str);
......
2006-11-06 Mark Rowe <bdash@webkit.org>
Reviewed by the wonderful Mitz Pettel.
Test for http://bugs.webkit.org/show_bug.cgi?id=11524
Bug 11524: REGRESSION(r9842): Array.prototype.join should use ToString operator rather than calling toString on each element
* fast/js/array-join-bug-11524-expected.txt: Added.
* fast/js/array-join-bug-11524.html: Added.
* fast/js/resources/array-join-bug-11524.js: Added.
2006-11-04 Alexey Proskuryakov <ap@nypop.com>
Reviewed by Maciej.
This test verifies that Array.prototype.join uses the ToString operator rather than calling element.toString(). See bug 11524 for more information.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS [customObject].join() is 'custom object'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="resources/js-test-style.css">
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="resources/array-join-bug-11524.js"></script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
description(
"This test verifies that Array.prototype.join uses the ToString operator rather than calling element.toString(). \
See <a href='http://bugs.webkit.org/show_bug.cgi?id=11524'>bug 11524</a> for more information."
);
var customObject = {toString: 0, valueOf: function() { return "custom object"; } };
shouldBe("[customObject].join()", "'custom object'");
successfullyParsed = true;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment