Bug 369778 - RegExp capturing groups that aren't matched during a match (because of, say, a *?+{n}{n,m} quantifier that means they're never used) should be matched as |undefined|, not as the empty string. r=jwalden
authorAndy Anderson <ae.anderson0@gmail.com>
Fri, 25 Jul 2014 14:34:10 -0700
changeset 196086 22cfcffb5a8b250f27e763d694ea8bf858a60a90
parent 196085 5edaa0a67cb8166df09ff85fcee09f1387c4e211
child 196087 eb01c53fd87978dc635fd38336d126b0e3a03a9c
push id46794
push userjwalden@mit.edu
push dateFri, 25 Jul 2014 22:49:49 +0000
treeherdermozilla-inbound@eb01c53fd879 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs369778
milestone34.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 369778 - RegExp capturing groups that aren't matched during a match (because of, say, a *?+{n}{n,m} quantifier that means they're never used) should be matched as |undefined|, not as the empty string. r=jwalden
js/src/tests/ecma_3/String/15.5.4.11.js
js/src/tests/ecma_3/String/regress-369778.js
js/src/tests/ecma_3/String/regress-392378.js
js/src/tests/ecma_3/extensions/regress-220367-002.js
js/src/vm/RegExpStatics.h
--- a/js/src/tests/ecma_3/String/15.5.4.11.js
+++ b/js/src/tests/ecma_3/String/15.5.4.11.js
@@ -1,9 +1,8 @@
-// |reftest| fails
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var BUGNUMBER = 392378;
 var summary = '15.5.4.11 - String.prototype.replace';
 var rex, f, a, i;
 
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_3/String/regress-369778.js
@@ -0,0 +1,29 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+var BUGNUMBER = 369778;
+var summary =
+  "RegExpStatics::makeMatch should make an undefined value when the last " +
+  "match had an undefined capture.";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+var expected = undefined;
+var actual;
+
+'x'.replace(/x(.)?/g, function(m, group) { actual = group; })
+
+print("expected: " + expected)
+print("actual: " + actual)
+
+assertEq(expected, actual)
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
--- a/js/src/tests/ecma_3/String/regress-392378.js
+++ b/js/src/tests/ecma_3/String/regress-392378.js
@@ -1,9 +1,8 @@
-// |reftest| fails
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //-----------------------------------------------------------------------------
 var BUGNUMBER = 392378;
 var summary = 'Regular Expression Non-participating Capture Groups are inaccurate in edge cases';
--- a/js/src/tests/ecma_3/extensions/regress-220367-002.js
+++ b/js/src/tests/ecma_3/extensions/regress-220367-002.js
@@ -27,23 +27,23 @@ var re = /(a)|(b)/;
 re.test('a');
 status = inSection(1);
 actual = RegExp.$1;
 expect = 'a';
 addThis();
 
 status = inSection(2);
 actual = RegExp.$2;
-expect = '';
+expect = undefined;
 addThis();
 
 re.test('b');
 status = inSection(3);
 actual = RegExp.$1;
-expect = '';
+expect = undefined;
 addThis();
 
 status = inSection(4);
 actual = RegExp.$2;
 expect = 'b';
 addThis();
 
 
--- a/js/src/vm/RegExpStatics.h
+++ b/js/src/vm/RegExpStatics.h
@@ -240,17 +240,17 @@ RegExpStatics::createPendingInput(JSCont
 
 inline bool
 RegExpStatics::makeMatch(JSContext *cx, size_t pairNum, MutableHandleValue out)
 {
     /* Private function: caller must perform lazy evaluation. */
     JS_ASSERT(!pendingLazyEvaluation);
 
     if (matches.empty() || pairNum >= matches.pairCount() || matches[pairNum].isUndefined()) {
-        out.setString(cx->runtime()->emptyString);
+        out.setUndefined();
         return true;
     }
 
     const MatchPair &pair = matches[pairNum];
     return createDependent(cx, pair.start, pair.limit, out);
 }
 
 inline bool