Bug 677820 - String.prototype.match should define properties for matches on the returned array, not set them. r=pbiggar
authorJeff Walden <jwalden@mit.edu>
Wed, 10 Aug 2011 14:54:36 -0700
changeset 74327 37605826f6fb7b21edbf8665c799de8521029035
parent 74326 f3f7872db0aef93fcd565ee96a25fb8c8f02179f
child 74328 137325e8319cc981438172cdd5bb89f9c7b0ceb8
push id1182
push userjwalden@mit.edu
push dateFri, 12 Aug 2011 19:22:57 +0000
treeherdermozilla-inbound@137325e8319c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbiggar
bugs677820
milestone8.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 677820 - String.prototype.match should define properties for matches on the returned array, not set them. r=pbiggar
js/src/jsstr.cpp
js/src/tests/ecma_5/String/jstests.list
js/src/tests/ecma_5/String/match-defines-match-elements.js
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -1530,21 +1530,18 @@ MatchCallback(JSContext *cx, RegExpStati
     JSObject *&arrayobj = *static_cast<MatchArgType>(p);
     if (!arrayobj) {
         arrayobj = NewDenseEmptyArray(cx);
         if (!arrayobj)
             return false;
     }
 
     Value v;
-    if (!res->createLastMatch(cx, &v))
-        return false;
-
-    JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED | JSRESOLVE_ASSIGNING);
-    return !!arrayobj->setProperty(cx, INT_TO_JSID(count), &v, false);
+    return res->createLastMatch(cx, &v) &&
+           arrayobj->defineProperty(cx, INT_TO_JSID(count), v);
 }
 
 static JSBool
 str_match(JSContext *cx, uintN argc, Value *vp)
 {
     JSString *str = ThisToStringForStringProto(cx, vp);
     if (!str)
         return false;
--- a/js/src/tests/ecma_5/String/jstests.list
+++ b/js/src/tests/ecma_5/String/jstests.list
@@ -1,11 +1,12 @@
 url-prefix ../../jsreftest.html?test=ecma_5/String/
 script 15.5.4.2.js
 script 15.5.4.7.js
 script 15.5.4.11-01.js
 script defaultvalue.js
+script match-defines-match-elements.js
 script split-01.js
 script split-undefined-separator.js
 script split-xregexp.js
 script string-object-length.js
 script string-space-trim.js
 script string-upper-lower-mapping.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/String/match-defines-match-elements.js
@@ -0,0 +1,47 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+var BUGNUMBER = 677820;
+var summary =
+  "String.prototype.match must define matches on the returned array, not set " +
+  "them";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+var called = false;
+function setterFunction(v) { called = true; }
+function getterFunction(v) { return "getter"; }
+
+Object.defineProperty(Array.prototype, 1,
+  { get: getterFunction, set: setterFunction });
+
+assertEq(called, false);
+var matches = "abcdef".match(/./g);
+assertEq(called, false);
+assertEq(matches.length, 6);
+assertEq(matches[0], "a");
+assertEq(matches[1], "b");
+assertEq(matches[2], "c");
+assertEq(matches[3], "d");
+assertEq(matches[4], "e");
+assertEq(matches[5], "f");
+
+var desc = Object.getOwnPropertyDescriptor(Array.prototype, 1);
+assertEq(desc.get, getterFunction);
+assertEq(desc.set, setterFunction);
+assertEq(desc.enumerable, false);
+assertEq(desc.configurable, false);
+assertEq([][1], "getter");
+
+assertEq(called, false);
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");