summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-sticky.js
blob: 6ebd0cf5e96910fcf392169e30eb491e1f230af3 (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) 2017 Aleksey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-regexp.prototype.flags
description: Boolean coercion of the sticky property
info: |
  get RegExp.prototype.flags

  ...
  14. Let sticky be ToBoolean(? Get(R, "sticky")).
  ...
features: [Symbol]
---*/

var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;

var r = {};

r.sticky = undefined;
assert.sameValue(get.call(r), "", "sticky: undefined");

r.sticky = null;
assert.sameValue(get.call(r), "", "sticky: null");

r.sticky = NaN;
assert.sameValue(get.call(r), "", "sticky: NaN");

r.sticky = "";
assert.sameValue(get.call(r), "", "sticky: the empty string");

r.sticky = "string";
assert.sameValue(get.call(r), "y", "sticky: string");

r.sticky = 86;
assert.sameValue(get.call(r), "y", "sticky: 86");

r.sticky = Symbol();
assert.sameValue(get.call(r), "y", "sticky: Symbol()");

r.sticky = [];
assert.sameValue(get.call(r), "y", "sticky: []");

r.sticky = {};
assert.sameValue(get.call(r), "y", "sticky: {}");

reportCompare(0, 0);