summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Object/hasOwn/toobject_before_topropertykey.js
blob: 6552617f0399b70d9de40524a4b7d8a6b7611edd (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
48
49
50
// Copyright (C) 2021 Jamie Kyle.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object.hasown
description: >
  ToObject is performed before ToPropertyKey.
info: |
  Object.hasOwn ( _O_, _P_ )

  1. Let _obj_ be ? ToObject(_O_).
  2. Let _key_ be ? ToPropertyKey(_P_).

  ToPropertyKey ( argument )

  1. Let key be ? ToPrimitive(argument, hint String).
author: Jamie Kyle
features: [Symbol.toPrimitive, Object.hasOwn]
---*/

var callCount1 = 0;
var coercibleKey1 = {
  get toString() {
    callCount1++;
    throw new Test262Error();
  },
  get valueOf() {
    callCount1++;
    throw new Test262Error();
  },
};

assert.throws(TypeError, function() {
  Object.hasOwn(null, coercibleKey1);
});
assert.sameValue(callCount1, 0, "toString and valueOf must not be called");


var callCount2 = 0;
var coercibleKey2 = {};
coercibleKey2[Symbol.toPrimitive] = function() {
  callCount2++;
  throw new Test262Error();
};

assert.throws(TypeError, function() {
  Object.hasOwn(undefined, coercibleKey2);
});
assert.sameValue(callCount2, 0, "Symbol.toPrimitive must not be called");

reportCompare(0, 0);