Debian Codegraph @

js/src/tests/test262/built-ins/Object/hasOwn/symbol_property_toString.js

raw
1 // Copyright (C) 2021 Jamie Kyle. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-object.hasown
6 description: Object.hasOwn with symbol and toString conversion
7 info: |
8 Object.hasOwn ( _O_, _P_ )
9
10 1. Let _obj_ be ? ToObject(_O_).
11 1. Let _key_ be ? ToPropertyKey(_P_).
12 ...
13 author: Jamie Kyle
14 features: [Symbol, Object.hasOwn]
15 ---*/
16
17 var obj = {};
18 var sym = Symbol();
19
20 var callCount = 0;
21 var wrapper = {
22 toString: function() {
23 callCount += 1;
24 return sym;
25 },
26 valueOf: function () {
27 throw new Test262Error("valueOf() called")
28 }
29 };
30
31 obj[sym] = 0;
32
33 assert.sameValue(
34 Object.hasOwn(obj, wrapper),
35 true,
36 "Returns true if symbol own property found"
37 );
38
39 assert.sameValue(callCount, 1, "toString method called exactly once");
40
41 reportCompare(0, 0);