test262/src/class-elements/field-declaration.case
Philip Chimento d87a7da6e1 Replace Object.hasOwnProperty.call with Object.prototype.hasOwnProperty.call
While we're at it, use assert() instead of assert.sameValue() for brevity,
if we are not specifically testing that the return value of hasOwnProperty
is the value true or false; and add more informative assertion messages to
help with debugging.

In some cases, the Object.hasOwnProperty.call could be replaced with
verifyProperty(), if the property descriptor was also being verified at
the same time.

This fixes some tests that were faulty to begin with: a common mistake was
Object.hasOwnProperty(obj, prop) which is probably going to return false
when that's not what you want.

The only instances left of `Object.hasOwnProperty` are one regression test
in implementation-contributed which I can't tell if it was intentionally
needed to trigger the regression, and a few instances of
`Object.hasOwnProperty('prototype')` which would defeat the purpose to
convert into `Object.prototype.hasOwnProperty.call(Object, 'prototype')`
form.

Closes: #3524
2022-11-30 16:04:02 -08:00

108 lines
2.1 KiB
Plaintext

// Copyright (C) 2019 Caio Lima (Igalia SL), Adrian Heine. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Fields are defined
info: |
Updated Productions
ClassElement :
...
FieldDefinition ;
FieldDefinition :
ClassElementName Initializer_opt
ClassElementName :
PropertyName
PropertyName :
LiteralPropertyName
ComputedPropertyName
LiteralPropertyName :
IdentifierName
StringLiteral
NumericLiteral
ClassDefinitionEvaluation:
...
26. Let instanceFields be a new empty List.
28. For each ClassElement e in order from elements,
a. If IsStatic of e is false, then
i. Let field be the result of performing ClassElementEvaluation for e with arguments proto and false.
b. ...
c. ...
d. If field is not empty, append field to instanceFields.
...
30. Set F.[[Fields]] to instanceFields.
...
template: default
includes: [propertyHelper.js]
features: [class-fields-public]
---*/
//- setup
var computed = 'h';
//- elements
f = 'test262';
'g';
0 = 'bar';
[computed];
//- assertions
let c = new C();
assert.sameValue(C.f, undefined);
assert.sameValue(C.g, undefined);
assert.sameValue(C.h, undefined);
assert.sameValue(C[0], undefined);
assert(
!Object.prototype.hasOwnProperty.call(C, 'f'),
"f does not appear as an own property on C constructor"
);
assert(
!Object.prototype.hasOwnProperty.call(C, 'g'),
"g does not appear as an own property on C constructor"
);
assert(
!Object.prototype.hasOwnProperty.call(C, 'h'),
"h does not appear as an own property on C constructor"
);
assert(
!Object.prototype.hasOwnProperty.call(C, 0),
"0 does not appear as an own property on C constructor"
);
verifyProperty(c, 'f', {
value: 'test262',
enumerable: true,
writable: true,
configurable: true
});
verifyProperty(c, 'g', {
value: undefined,
enumerable: true,
writable: true,
configurable: true
});
verifyProperty(c, 0, {
value: 'bar',
enumerable: true,
writable: true,
configurable: true
});
verifyProperty(c, 'h', {
value: undefined,
enumerable: true,
writable: true,
configurable: true
});