2006-11-06 Mark Rowe <bdash@webkit.org>
authorbdash <bdash@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Nov 2006 08:30:01 +0000 (08:30 +0000)
committerbdash <bdash@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Nov 2006 08:30:01 +0000 (08:30 +0000)
        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: https://svn.webkit.org/repository/webkit/trunk@17610 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/array_object.cpp
LayoutTests/ChangeLog
LayoutTests/fast/js/array-join-bug-11524-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/array-join-bug-11524.html [new file with mode: 0644]
LayoutTests/fast/js/resources/array-join-bug-11524.js [new file with mode: 0644]

index 2dcb62501a121215ca258435f9cf7361d88100a5..e1ac701f07a2b7ed23c0101b9a671894cd3de070 100644 (file)
@@ -1,3 +1,13 @@
+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
index fcdf1df81c32a080f8d41c2c17b405b8884a9b06..9892a76617aaa0d2e892f486bb5865d399a354ed 100644 (file)
@@ -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);
index bcab8285aa794d38b28c15829e052ede308846bf..849f6ffd35d166e3a82b38b058752f4b70b21159 100644 (file)
@@ -1,3 +1,14 @@
+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.
diff --git a/LayoutTests/fast/js/array-join-bug-11524-expected.txt b/LayoutTests/fast/js/array-join-bug-11524-expected.txt
new file mode 100644 (file)
index 0000000..a45fc67
--- /dev/null
@@ -0,0 +1,10 @@
+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
+
diff --git a/LayoutTests/fast/js/array-join-bug-11524.html b/LayoutTests/fast/js/array-join-bug-11524.html
new file mode 100644 (file)
index 0000000..4891125
--- /dev/null
@@ -0,0 +1,13 @@
+<!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>
diff --git a/LayoutTests/fast/js/resources/array-join-bug-11524.js b/LayoutTests/fast/js/resources/array-join-bug-11524.js
new file mode 100644 (file)
index 0000000..5de1501
--- /dev/null
@@ -0,0 +1,9 @@
+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;