test262/test/language/expressions/object/__proto__-duplicate-computed.js
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

55 lines
1.3 KiB
JavaScript

// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-__proto__-property-names-in-object-initializers
es6id: B.3.1
description: >
The syntax error for duplicate `__proto__` property is not valid if the duplicate is a
ComputedPropertyName
info: |
B.3.1__proto__ Property Names in Object Initializers
It is a Syntax Error if PropertyNameList of PropertyDefinitionList contains any duplicate
entries for "__proto__" and at least two of those entries were obtained from productions of
the form
PropertyDefinition : PropertyName : AssignmentExpression .
12.2.6.6 Static Semantics: PropertyNameList
...
3. Append PropName of PropertyDefinition to the end of list.
...
12.2.6.5 Static Semantics: PropName
ComputedPropertyName : [ AssignmentExpression ]
1. Return empty.
---*/
var obj;
var proto = {};
var ownProp = {};
obj = {
__proto__: proto,
['__proto__']: {},
['__proto__']: ownProp
};
assert.sameValue(
Object.getPrototypeOf(obj),
proto,
'prototype is defined'
);
assert(
Object.prototype.hasOwnProperty.call(obj, '__proto__'),
'has own property __proto__'
);
assert.sameValue(
obj.__proto__,
ownProp,
'own property value'
);