test262/test/built-ins/Object/hasOwn/toobject_before_topropertykey.js
Jamie Kyle bad7c0487e
Add tests for Object.hasOwn (#2995)
* Add tests for Object.hasOwn

* Update test/built-ins/Object/hasOwn/length.js

Co-authored-by: Jordan Harband <ljharb@gmail.com>

* Update test/built-ins/Object/hasOwn/name.js

Co-authored-by: Jordan Harband <ljharb@gmail.com>

* Fixup comments for Object.hasOwn

* Add Object.hasOwn descriptor test

* use assert.sameValue with true instead of assert()

* remove extra semicolons

* Remove old $ERROR style tests from hasown

* Fix thrown error type in hasown tests

* Fix incorrect test cases

Co-authored-by: Jordan Harband <ljharb@gmail.com>
2021-06-16 17:35:06 -04:00

49 lines
1.1 KiB
JavaScript

// 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");