Merge autoland to mozilla-central. a=merge
[gecko.git] / js / src / tests / test262 / built-ins / String / prototype / matchAll / toString-this-val.js
blob6652e29f064fd34435c0d217241e763aec226fb9
1 // Copyright (C) 2018 Peter Wong. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: pending
5 description: |
6   Verify ToString is called when regexp[@@matchAll] is undefined or null
7 info: |
8   String.prototype.matchAll ( regexp )
9     1. Let O be ? RequireObjectCoercible(this value).
10     2. If regexp is neither undefined nor null, then
11       a. Let matcher be ? GetMethod(regexp, @@matchAll).
12       b. If matcher is not undefined, then
13         [...]
14     3. Let S be ? ToString(O).
15     4. Let rx be ? RegExpCreate(R, "g").
16     5. Return ? Invoke(rx, @@matchAll, « S »).
17 features: [Symbol.matchAll, String.prototype.matchAll]
18 ---*/
20 var regexp = /./;
21 var callCount = 0;
22 var arg;
23 var obj = {};
24 var toStringResult = 'abc';
25 var receiver = {
26   [Symbol.toPrimitive]: function() {
27     callCount++;
28     return toStringResult;
29   }
31 RegExp.prototype[Symbol.matchAll] = function(string) {
32   arg = string;
35 String.prototype.matchAll.call(receiver, null);
36 assert.sameValue(callCount, 1);
37 assert.sameValue(arg, toStringResult);
39 String.prototype.matchAll.call(receiver, undefined);
40 assert.sameValue(callCount, 2);
41 assert.sameValue(arg, toStringResult);
43 reportCompare(0, 0);