mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
parent
2f11b4d806
commit
e45b2ae532
@ -0,0 +1,54 @@
|
|||||||
|
// 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.hasOwnProperty.call(obj, '__proto__'),
|
||||||
|
'has own property __proto__'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
obj.__proto__,
|
||||||
|
ownProp,
|
||||||
|
'own property value'
|
||||||
|
);
|
177
test/language/expressions/object/computed-__proto__.js
Normal file
177
test/language/expressions/object/computed-__proto__.js
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-PropertyDefinition
|
||||||
|
description: >
|
||||||
|
computed __proto__ property key is assigned to an own property
|
||||||
|
info: |
|
||||||
|
12.2.6 Object Initializer
|
||||||
|
|
||||||
|
PropertyDefinition[Yield, Await] :
|
||||||
|
PropertyName[?Yield, ?Await] : AssignmentExpression[+In, ?Yield, ?Await]
|
||||||
|
|
||||||
|
PropertyName[Yield, Await] :
|
||||||
|
LiteralPropertyName
|
||||||
|
ComputedPropertyName[?Yield, ?Await]
|
||||||
|
|
||||||
|
ComputedPropertyName[Yield, Await] :
|
||||||
|
[ AssignmentExpression[+In, ?Yield, ?Await] ]
|
||||||
|
|
||||||
|
B.3.1__proto__ Property Names in Object Initializers
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If propKey is the String value "__proto__" and if IsComputedPropertyKey(propKey)
|
||||||
|
is false, then
|
||||||
|
a. If Type(propValue) is either Object or Null, then
|
||||||
|
i. Return object.[[SetPrototypeOf]](propValue).
|
||||||
|
b. Return NormalCompletion(empty).
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj;
|
||||||
|
var sample = {};
|
||||||
|
|
||||||
|
obj = {
|
||||||
|
['__proto__']: sample
|
||||||
|
};
|
||||||
|
assert.sameValue(
|
||||||
|
Object.getPrototypeOf(obj),
|
||||||
|
Object.prototype,
|
||||||
|
'does not change the object prototype (ordinary object)'
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
obj.hasOwnProperty('__proto__'),
|
||||||
|
'computed __proto__ property is set as an own property (ordinary object)'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
obj.__proto__,
|
||||||
|
sample,
|
||||||
|
'value is properly defined (ordinary object)'
|
||||||
|
);
|
||||||
|
|
||||||
|
obj = {
|
||||||
|
['__proto__']: null
|
||||||
|
};
|
||||||
|
assert.sameValue(
|
||||||
|
Object.getPrototypeOf(obj),
|
||||||
|
Object.prototype,
|
||||||
|
'does not change the object prototype (null)'
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
obj.hasOwnProperty('__proto__'),
|
||||||
|
'computed __proto__ property is set as an own property (null)'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
obj.__proto__,
|
||||||
|
null,
|
||||||
|
'value is properly defined (null)'
|
||||||
|
);
|
||||||
|
|
||||||
|
obj = {
|
||||||
|
['__proto__']: undefined
|
||||||
|
};
|
||||||
|
assert.sameValue(
|
||||||
|
Object.getPrototypeOf(obj),
|
||||||
|
Object.prototype,
|
||||||
|
'does not change the object prototype (undefined)'
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
obj.hasOwnProperty('__proto__'),
|
||||||
|
'computed __proto__ property is set as an own property (undefined)'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
obj.__proto__,
|
||||||
|
undefined,
|
||||||
|
'value is properly defined (undefined)'
|
||||||
|
);
|
||||||
|
|
||||||
|
var func = function() {};
|
||||||
|
obj = {
|
||||||
|
['__proto__']: func
|
||||||
|
};
|
||||||
|
assert.sameValue(
|
||||||
|
Object.getPrototypeOf(obj),
|
||||||
|
Object.prototype,
|
||||||
|
'does not change the object prototype (func)'
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
obj.hasOwnProperty('__proto__'),
|
||||||
|
'computed __proto__ property is set as an own property (func)'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
obj.__proto__,
|
||||||
|
func,
|
||||||
|
'value is properly defined (func)'
|
||||||
|
);
|
||||||
|
|
||||||
|
var symbol = Symbol('Leo');
|
||||||
|
obj = {
|
||||||
|
['__proto__']: symbol
|
||||||
|
};
|
||||||
|
assert.sameValue(
|
||||||
|
Object.getPrototypeOf(obj),
|
||||||
|
Object.prototype,
|
||||||
|
'does not change the object prototype (symbol)'
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
obj.hasOwnProperty('__proto__'),
|
||||||
|
'computed __proto__ property is set as an own property (symbol)'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
obj.__proto__,
|
||||||
|
symbol,
|
||||||
|
'value is properly defined (symbol)'
|
||||||
|
);
|
||||||
|
|
||||||
|
obj = {
|
||||||
|
['__proto__']: 42
|
||||||
|
};
|
||||||
|
assert.sameValue(
|
||||||
|
Object.getPrototypeOf(obj),
|
||||||
|
Object.prototype,
|
||||||
|
'does not change the object prototype (number)'
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
obj.hasOwnProperty('__proto__'),
|
||||||
|
'computed __proto__ property is set as an own property (number)'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
obj.__proto__,
|
||||||
|
42,
|
||||||
|
'value is properly defined (number)'
|
||||||
|
);
|
||||||
|
|
||||||
|
obj = {
|
||||||
|
['__proto__']: ''
|
||||||
|
};
|
||||||
|
assert.sameValue(
|
||||||
|
Object.getPrototypeOf(obj),
|
||||||
|
Object.prototype,
|
||||||
|
'does not change the object prototype (string)'
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
obj.hasOwnProperty('__proto__'),
|
||||||
|
'computed __proto__ property is set as an own property (string)'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
obj.__proto__,
|
||||||
|
'',
|
||||||
|
'value is properly defined (string)'
|
||||||
|
);
|
||||||
|
|
||||||
|
obj = {
|
||||||
|
['__proto__']: false
|
||||||
|
};
|
||||||
|
assert.sameValue(
|
||||||
|
Object.getPrototypeOf(obj),
|
||||||
|
Object.prototype,
|
||||||
|
'does not change the object prototype (boolean)'
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
obj.hasOwnProperty('__proto__'),
|
||||||
|
'computed __proto__ property is set as an own property (boolean)'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
obj.__proto__,
|
||||||
|
false,
|
||||||
|
'value is properly defined (boolean)'
|
||||||
|
);
|
Loading…
x
Reference in New Issue
Block a user