summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-y.js
blob: 59b44ea327afc914613440b34eb01631cab84d75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
es6id: 21.2.5.11
description: The `y` flag is always used in constructing the "splitter" object
info: |
    [...]
    5. Let C be SpeciesConstructor(rx, %RegExp%).
    [...]
    11. If flags contains "y", let newFlags be flags.
    12. Else, let newFlags be the string that is the concatenation of flags and
        "y".
    13. Let splitter be Construct(C, «rx, newFlags»).
    [...]
features: [Symbol.split, Symbol.species]
---*/

var flagsArg;
var re = {};
re.constructor = function() {};
re.constructor[Symbol.species] = function(_, flags) {
  flagsArg = flags;
  return /./y;
};

re.flags = '';
RegExp.prototype[Symbol.split].call(re, '');
assert.sameValue(flagsArg, 'y');

re.flags = 'abcd';
RegExp.prototype[Symbol.split].call(re, '');
assert.sameValue(flagsArg, 'abcdy');

re.flags = 'Y';
RegExp.prototype[Symbol.split].call(re, '');
assert.sameValue(flagsArg, 'Yy');

re.flags = 'y';
RegExp.prototype[Symbol.split].call(re, '');
assert.sameValue(flagsArg, 'y');

re.flags = 'abycd';
RegExp.prototype[Symbol.split].call(re, '');
assert.sameValue(flagsArg, 'abycd');

reportCompare(0, 0);