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>
This commit is contained in:
Jamie Kyle 2021-06-16 14:35:06 -07:00 committed by GitHub
parent 1b16396c88
commit bad7c0487e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
63 changed files with 1363 additions and 0 deletions

View File

@ -205,6 +205,10 @@ arbitrary-module-namespace-names
# https://github.com/tc39/ecma262/pull/2164
align-detached-buffer-semantics-with-web-reality
# Object.hasOwn
# https://github.com/tc39/proposal-accessible-object-hasownproperty
Object.hasOwn
## Standard language features
#
# Language features that have been included in a published version of the

View File

@ -0,0 +1,15 @@
// 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: Testing descriptor property of Object.hasOwn
includes:
- propertyHelper.js
author: Jamie Kyle
features: [Object.hasOwn]
---*/
verifyWritable(Object, "hasOwn");
verifyNotEnumerable(Object, "hasOwn");
verifyConfigurable(Object, "hasOwn");

View File

@ -0,0 +1,19 @@
// Copyright 2021 Jamie Kyle. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object.hasown
info: |
Object.hasOwn ( _O_, _P_ )
1. Let _obj_ be ? ToObject(_O_).
2. Let _key_ be ? ToPropertyKey(_P_).
3. Return ? HasOwnProperty(_obj_, _key_).
description: >
Checking type of the Object.hasOwn and the returned result
author: Jamie Kyle
features: [Object.hasOwn]
---*/
assert.sameValue(typeof Object.hasOwn, 'function');
assert(Object.hasOwn(Object, 'hasOwn'));

View File

@ -0,0 +1,16 @@
// 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: Properties - [[HasOwnProperty]] (old style inherited property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {
foo: 42
};
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,18 @@
// 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: Properties - [[HasOwnProperty]] (literal inherited getter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {
get foo() {
return 42;
}
};
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,22 @@
// 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: >
Properties - [[HasOwnProperty]] (literal inherited getter/setter
property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {
get foo() {
return 42;
},
set foo(x) {
}
};
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,25 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, enumerable
inherited getter/setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
get: function() {
return 42;
},
set: function() {;
},
enumerable: true,
configurable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,24 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, non-enumerable
inherited getter/setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
get: function() {
return 42;
},
set: function() {;
},
configurable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,24 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, enumerable
inherited getter/setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
get: function() {
return 42;
},
set: function() {;
},
enumerable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,23 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, non-enumerable
inherited getter/setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
get: function() {
return 42;
},
set: function() {;
}
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,23 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, enumerable
inherited getter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
get: function() {
return 42;
},
enumerable: true,
configurable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,22 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, non-enumerable
inherited getter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
get: function() {
return 42;
},
configurable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,22 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, enumerable
inherited getter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
get: function() {
return 42;
},
enumerable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,21 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, non-enumerable
inherited getter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
get: function() {
return 42;
}
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,21 @@
// 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: >
Properties - [[HasOwnProperty]] (non-writable, configurable,
enumerable inherited value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
value: 42,
configurable: true,
enumerable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,20 @@
// 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: >
Properties - [[HasOwnProperty]] (non-writable, configurable,
non-enumerable inherited value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
value: 42,
configurable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,20 @@
// 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: >
Properties - [[HasOwnProperty]] (non-writable, non-configurable,
enumerable inherited value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
value: 42,
enumerable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,19 @@
// 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: >
Properties - [[HasOwnProperty]] (non-writable, non-configurable,
non-enumerable inherited value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
value: 42
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,17 @@
// 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: Properties - [[HasOwnProperty]] (literal inherited setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {
set foo(x) {
}
};
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,22 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, enumerable
inherited setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
set: function() {;
},
enumerable: true,
configurable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,21 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, non-enumerable
inherited setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
set: function() {;
},
configurable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,21 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, enumerable
inherited setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
set: function() {;
},
enumerable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,20 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, non-enumerable
inherited setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
set: function() {;
}
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,22 @@
// 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: >
Properties - [[HasOwnProperty]] (writable, configurable,
enumerable inherited value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
value: 42,
writable: true,
enumerable: true,
configurable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,21 @@
// 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: >
Properties - [[HasOwnProperty]] (writable, configurable,
non-enumerable inherited value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
value: 42,
writable: true,
configurable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,21 @@
// 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: >
Properties - [[HasOwnProperty]] (writable, non-configurable,
enumerable inherited value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
value: 42,
writable: true,
enumerable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,20 @@
// 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: >
Properties - [[HasOwnProperty]] (writable, non-configurable,
non-enumerable inherited value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var base = {};
Object.defineProperty(base, "foo", {
value: 42,
writable: true
});
var o = Object.create(base);
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,13 @@
// 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: Properties - [[HasOwnProperty]] (property does not exist)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
assert.sameValue(Object.hasOwn(o, "foo"), false, 'Object.hasOwn(o, "foo")');

View File

@ -0,0 +1,17 @@
// 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: Properties - [[HasOwnProperty]] (literal own getter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {
get foo() {
return 42;
}
};
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,21 @@
// 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: >
Properties - [[HasOwnProperty]] (literal own getter/setter
property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {
get foo() {
return 42;
},
set foo(x) {
}
};
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,24 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, enumerable own
getter/setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
get: function() {
return 42;
},
set: function() {;
},
enumerable: true,
configurable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,23 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, non-enumerable own
getter/setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
get: function() {
return 42;
},
set: function() {;
},
configurable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,23 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, enumerable own
getter/setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
get: function() {
return 42;
},
set: function() {;
},
enumerable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,22 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, non-enumerable
own getter/setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
get: function() {
return 42;
},
set: function() {;
}
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,22 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, enumerable own
getter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
get: function() {
return 42;
},
enumerable: true,
configurable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,21 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, non-enumerable own
getter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
get: function() {
return 42;
},
configurable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,21 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, enumerable own
getter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
get: function() {
return 42;
},
enumerable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,20 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, non-enumerable
own getter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
get: function() {
return 42;
}
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,20 @@
// 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: >
Properties - [[HasOwnProperty]] (non-writable, configurable,
enumerable own value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
value: 42,
configurable: true,
enumerable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,19 @@
// 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: >
Properties - [[HasOwnProperty]] (non-writable, non-configurable,
enumerable own value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
value: 42,
enumerable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,19 @@
// 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: >
Properties - [[HasOwnProperty]] (non-writable, configurable,
non-enumerable own value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
value: 42,
configurable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,18 @@
// 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: >
Properties - [[HasOwnProperty]] (non-writable, non-configurable,
non-enumerable own value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
value: 42
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,15 @@
// 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: Properties - [[HasOwnProperty]] (old style own property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {
foo: 42
};
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,16 @@
// 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: Properties - [[HasOwnProperty]] (literal own setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {
set foo(x) {
}
};
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,21 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, enumerable own
setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
set: function() {;
},
enumerable: true,
configurable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,20 @@
// 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: >
Properties - [[HasOwnProperty]] (configurable, non-enumerable own
setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
set: function() {;
},
configurable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,20 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, enumerable own
setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
set: function() {;
},
enumerable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,19 @@
// 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: >
Properties - [[HasOwnProperty]] (non-configurable, non-enumerable
own setter property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
set: function() {;
}
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,21 @@
// 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: >
Properties - [[HasOwnProperty]] (writable, configurable,
enumerable own value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
value: 42,
writable: true,
enumerable: true,
configurable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,20 @@
// 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: >
Properties - [[HasOwnProperty]] (writable, configurable,
non-enumerable own value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
value: 42,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,20 @@
// 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: >
Properties - [[HasOwnProperty]] (writable, non-configurable,
enumerable own value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
value: 42,
writable: true,
enumerable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,19 @@
// 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: >
Properties - [[HasOwnProperty]] (writable, non-configurable,
non-enumerable own value property)
author: Jamie Kyle
features: [Object.hasOwn]
---*/
var o = {};
Object.defineProperty(o, "foo", {
value: 42,
writable: true
});
assert.sameValue(Object.hasOwn(o, "foo"), true, 'Object.hasOwn(o, "foo") !== true');

View File

@ -0,0 +1,31 @@
// 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: >
Object.hasOwn.length is 2.
info: |
Object.hasOwn ( _O_, _P_ )
ECMAScript Standard Built-in Objects
Every built-in function object, including constructors, has a "length"
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description.
Unless otherwise specified, the "length" property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
author: Jamie Kyle
features: [Object.hasOwn]
---*/
verifyProperty(Object.hasOwn, "length", {
value: 2,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,28 @@
// 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: >
Object.hasOwn.name is "hasOwn".
info: |
Object.hasOwn ( _O_, _P_ )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value
is a String.
Unless otherwise specified, the name property of a built-in Function
object, if it exists, has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
author: Jamie Kyle
features: [Object.hasOwn]
---*/
assert.sameValue(Object.hasOwn.name, "hasOwn");
verifyNotEnumerable(Object.hasOwn, "name");
verifyNotWritable(Object.hasOwn, "name");
verifyConfigurable(Object.hasOwn, "name");

View File

@ -0,0 +1,33 @@
// Copyright (C) 2021 Jamie Kyle. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-ecmascript-standard-built-in-objects
description: >
Object.hasOwn does not implement [[Construct]], is not new-able
info: |
ECMAScript Function Objects
Built-in function objects that are not identified as constructors do not
implement the [[Construct]] internal method unless otherwise specified in
the description of a particular function.
sec-evaluatenew
...
7. If IsConstructor(constructor) is false, throw a TypeError exception.
...
includes: [isConstructor.js]
author: Jamie Kyle
features: [Reflect.construct, arrow-function, Object.hasOwn]
---*/
assert.sameValue(
isConstructor(Object.hasOwn),
false,
'isConstructor(Object.hasOwn) must return false'
);
assert.throws(TypeError, () => {
new Object.hasOwn('');
}, '`new Object.hasOwn(\'\')` throws TypeError');

View File

@ -0,0 +1,13 @@
// Copyright 2021 Jamie Kyle. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object.hasown
info: Object.hasOwn has not prototype property
description: >
Checking if obtaining the prototype property of Object.hasOwn fails
author: Jamie Kyle
features: [Object.hasOwn]
---*/
assert.sameValue(Object.hasOwn.prototype, undefined);

View File

@ -0,0 +1,32 @@
// 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: Object.hasOwn called with symbol property key
info: |
Object.hasOwn ( _O_, _P_ )
1. Let _obj_ be ? ToObject(_O_).
1. Let _key_ be ? ToPropertyKey(_P_).
...
author: Jamie Kyle
features: [Symbol, Object.hasOwn]
---*/
var obj = {};
var sym = Symbol();
assert.sameValue(
Object.hasOwn(obj, sym),
false,
"Returns false if symbol own property not found"
);
obj[sym] = 0;
assert.sameValue(
Object.hasOwn(obj, sym),
true,
"Returns true if symbol own property found"
);

View File

@ -0,0 +1,35 @@
// 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: Object.hasOwn with symbol and @@toPrimitive conversion
info: |
Object.hasOwn ( _O_, _P_ )
1. Let _obj_ be ? ToObject(_O_).
1. Let _key_ be ? ToPropertyKey(_P_).
...
author: Jamie Kyle
features: [Symbol.toPrimitive, Object.hasOwn]
---*/
var obj = {};
var sym = Symbol();
var callCount = 0;
var wrapper = {};
wrapper[Symbol.toPrimitive] = function() {
callCount += 1;
return sym;
};
obj[sym] = 0;
assert.sameValue(
Object.hasOwn(obj, wrapper),
true,
"Returns true if symbol own property found"
);
assert.sameValue(callCount, 1, "toPrimitive method called exactly once");

View File

@ -0,0 +1,39 @@
// 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: Object.hasOwn with symbol and toString conversion
info: |
Object.hasOwn ( _O_, _P_ )
1. Let _obj_ be ? ToObject(_O_).
1. Let _key_ be ? ToPropertyKey(_P_).
...
author: Jamie Kyle
features: [Symbol, Object.hasOwn]
---*/
var obj = {};
var sym = Symbol();
var callCount = 0;
var wrapper = {
toString: function() {
callCount += 1;
return sym;
},
valueOf: function () {
throw new Test262Error("valueOf() called")
}
};
obj[sym] = 0;
assert.sameValue(
Object.hasOwn(obj, wrapper),
true,
"Returns true if symbol own property found"
);
assert.sameValue(callCount, 1, "toString method called exactly once");

View File

@ -0,0 +1,37 @@
// 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: Object.hasOwn with symbol and valueOf conversion
info: |
Object.hasOwn ( _O_, _P_ )
1. Let _obj_ be ? ToObject(_O_).
2. Let _key_ be ? ToPropertyKey(_P_).
...
author: Jamie Kyle
features: [Symbol, Object.hasOwn]
---*/
var obj = {};
var sym = Symbol();
var callCount = 0;
var wrapper = {
valueOf: function() {
callCount += 1;
return sym;
},
toString: null
};
obj[sym] = 0;
assert.sameValue(
Object.hasOwn(obj, wrapper),
true,
"Returns true if symbol own property found"
);
assert.sameValue(callCount, 1, "valueOf method called exactly once");

View File

@ -0,0 +1,48 @@
// 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");

View File

@ -0,0 +1,15 @@
// Copyright 2021 Jamie Kyle. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object.hasown
description: >
Let O be the result of calling ToObject passing the this value as
the argument.
author: Jamie Kyle
features: [Object.hasOwn]
---*/
assert.throws(TypeError, function() {
Object.hasOwn(null, 'foo');
});

View File

@ -0,0 +1,15 @@
// Copyright 2021 Jamie Kyle. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object.hasown
description: >
Let O be the result of calling ToObject passing the this value as
the argument.
author: Jamie Kyle
features: [Object.hasOwn]
---*/
assert.throws(TypeError, function() {
Object.hasOwn(undefined, 'foo');
});