From bbad9482e630aaa9d62716c067db29715d8f0cc1 Mon Sep 17 00:00:00 2001 From: peterwmwong Date: Mon, 4 Jun 2018 20:04:30 -0500 Subject: [PATCH] Update tests for String.prototype.matchAll As per spec changes (https://github.com/tc39/proposal-string-matchall/pull/35), removed tests related to the removed IsRegExp call. To prevent older implementations (not observing spec change) from passing, added a new test to verify the reduced number of observable calls to IsRegExp. Also fix a misreference in `features` frontmatter. --- .../internal-regexp-lastindex-not-zero.js | 33 ------------------- ...xp-is-false.js => isregexp-called-once.js} | 27 ++++++++++----- .../isregexp-internal-regexp-throws.js | 29 ---------------- .../regexpcreate-this-throws.js | 3 +- test/built-ins/Symbol/matchAll/prop-desc.js | 2 +- 5 files changed, 22 insertions(+), 72 deletions(-) delete mode 100644 test/built-ins/RegExp/prototype/Symbol.matchAll/internal-regexp-lastindex-not-zero.js rename test/built-ins/RegExp/prototype/Symbol.matchAll/{isregexp-internal-regexp-is-false.js => isregexp-called-once.js} (55%) delete mode 100644 test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-internal-regexp-throws.js diff --git a/test/built-ins/RegExp/prototype/Symbol.matchAll/internal-regexp-lastindex-not-zero.js b/test/built-ins/RegExp/prototype/Symbol.matchAll/internal-regexp-lastindex-not-zero.js deleted file mode 100644 index 944ef30989e..00000000000 --- a/test/built-ins/RegExp/prototype/Symbol.matchAll/internal-regexp-lastindex-not-zero.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2018 Peter Wong. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: pending -description: | - Throws TypeError when internally created RegExp's lastIndex is not 0 -info: | - RegExp.prototype [ @@matchAll ] ( string ) - [...] - 3. Return ? MatchAllIterator(R, string). - - MatchAllIterator ( R, O ) - [...] - 2. If ? IsRegExp(R) is true, then - [...] - 3. Else, - a. Let matcher be RegExpCreate(R, "g"). - b. If ? IsRegExp(matcher) is not true, throw a TypeError exception. - [...] - 3. If Get(matcher, "lastIndex") is not 0, throw a TypeError exception. -features: [Symbol.match, Symbol.matchAll] ----*/ - -Object.defineProperty(RegExp.prototype, Symbol.match, { - get() { - this.lastIndex = 1; - return true; - } -}); - -assert.throws(TypeError, function() { - RegExp.prototype[Symbol.matchAll].call({}, ''); -}); diff --git a/test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-internal-regexp-is-false.js b/test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-called-once.js similarity index 55% rename from test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-internal-regexp-is-false.js rename to test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-called-once.js index 214e9b7efd2..b74b19181c0 100644 --- a/test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-internal-regexp-is-false.js +++ b/test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-called-once.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: pending -description: Throws TypeError when internally created RegExp's @@match is false +description: IsRegExp should only be called once info: | RegExp.prototype [ @@matchAll ] ( string ) [...] @@ -13,17 +13,28 @@ info: | 2. If ? IsRegExp(R) is true, then [...] 3. Else, - a. Let matcher be RegExpCreate(R, "g"). - b. If ? IsRegExp(matcher) is not true, throw a TypeError exception. + a. Let flags be "g". + b. Let matcher be ? RegExpCreate(R, flags). features: [Symbol.match, Symbol.matchAll] ---*/ +var internalCount = 0; Object.defineProperty(RegExp.prototype, Symbol.match, { - get() { - return false; + get: function() { + ++internalCount; + return true; } }); -assert.throws(TypeError, function() { - RegExp.prototype[Symbol.matchAll].call({}, ''); -}); +var count = 0; +var o = { + get [Symbol.match]() { + ++count; + return false; + } +}; + +RegExp.prototype[Symbol.matchAll].call(o, '1'); + +assert.sameValue(0, internalCount); +assert.sameValue(1, count); diff --git a/test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-internal-regexp-throws.js b/test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-internal-regexp-throws.js deleted file mode 100644 index 70b62da39f5..00000000000 --- a/test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-internal-regexp-throws.js +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2018 Peter Wong. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: pending -description: Re-throws errors thrown while accessing @@match property -info: | - RegExp.prototype [ @@matchAll ] ( string ) - [...] - 3. Return ? MatchAllIterator(R, string). - - MatchAllIterator ( R, O ) - [...] - 2. If ? IsRegExp(R) is true, then - [...] - 3. Else, - a. Let matcher be RegExpCreate(R, "g"). - b. If ? IsRegExp(matcher) is not true, throw a TypeError exception. -features: [Symbol.match, Symbol.matchAll] ----*/ - -Object.defineProperty(RegExp.prototype, Symbol.match, { - get() { - throw new Test262Error(); - } -}); - -assert.throws(Test262Error, function() { - RegExp.prototype[Symbol.matchAll].call({}, ''); -}); diff --git a/test/built-ins/RegExp/prototype/Symbol.matchAll/regexpcreate-this-throws.js b/test/built-ins/RegExp/prototype/Symbol.matchAll/regexpcreate-this-throws.js index d34b563c282..e46c074e99e 100644 --- a/test/built-ins/RegExp/prototype/Symbol.matchAll/regexpcreate-this-throws.js +++ b/test/built-ins/RegExp/prototype/Symbol.matchAll/regexpcreate-this-throws.js @@ -13,7 +13,8 @@ info: | 2. If ? IsRegExp(R) is true, then [...] 3. Else, - a. Let R be RegExpCreate(R, "g"). + a. Let flags be "g". + b. Let matcher be ? RegExpCreate(R, flags). features: [Symbol.matchAll] ---*/ diff --git a/test/built-ins/Symbol/matchAll/prop-desc.js b/test/built-ins/Symbol/matchAll/prop-desc.js index 705adfc519c..f111ce0f7d8 100644 --- a/test/built-ins/Symbol/matchAll/prop-desc.js +++ b/test/built-ins/Symbol/matchAll/prop-desc.js @@ -8,7 +8,7 @@ info: | This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. includes: [propertyHelper.js] -features: [Symbol.match] +features: [Symbol.matchAll] ---*/ assert.sameValue(typeof Symbol.matchAll, 'symbol');