mirror of https://github.com/tc39/test262.git
Add tests for Annex B extn: __proto__ in obj init (#633)
This commit is contained in:
parent
a0ddf7bfe4
commit
c6a152558d
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2016 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: Duplicate `__proto__` property
|
||||
info: |
|
||||
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 .
|
||||
negative: SyntaxError
|
||||
---*/
|
||||
|
||||
({
|
||||
__proto__: null,
|
||||
other: null,
|
||||
'__proto__': null
|
||||
});
|
|
@ -0,0 +1,90 @@
|
|||
// Copyright (C) 2016 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 value of the `__proto__` property key is not assigned to the
|
||||
[[Prototype]] internal slot, nor to a property named "__proto__" (non-Object,
|
||||
non-null value)
|
||||
info: |
|
||||
...
|
||||
6. If propKey is the String value "__proto__" and if
|
||||
IsComputedPropertyKey(propKey) is false, then
|
||||
a. If Type(propValue) is either Object or Null, then
|
||||
[...]
|
||||
b. Return NormalCompletion(empty).
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var object;
|
||||
|
||||
object = {
|
||||
__proto__: undefined
|
||||
};
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(object),
|
||||
Object.prototype,
|
||||
'prototype (undefined)'
|
||||
);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(object, '__proto__'),
|
||||
undefined,
|
||||
'property (undefined)'
|
||||
);
|
||||
|
||||
object = {
|
||||
__proto__: 1
|
||||
};
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(object),
|
||||
Object.prototype,
|
||||
'prototype (numeric primitive)'
|
||||
);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(object, '__proto__'),
|
||||
undefined,
|
||||
'property (numeric primitive)'
|
||||
);
|
||||
|
||||
object = {
|
||||
__proto__: false
|
||||
};
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(object),
|
||||
Object.prototype,
|
||||
'prototype (boolean primitive)'
|
||||
);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(object, '__proto__'),
|
||||
undefined,
|
||||
'property (boolean primitive)'
|
||||
);
|
||||
|
||||
object = {
|
||||
__proto__: 'string literal'
|
||||
};
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(object),
|
||||
Object.prototype,
|
||||
'prototype (string primitive)'
|
||||
);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(object, '__proto__'),
|
||||
undefined,
|
||||
'property (string primitive)'
|
||||
);
|
||||
|
||||
object = {
|
||||
__proto__: Symbol('')
|
||||
};
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(object),
|
||||
Object.prototype,
|
||||
'prototype (symbol)'
|
||||
);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(object, '__proto__'),
|
||||
undefined,
|
||||
'property (symbol)'
|
||||
);
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2016 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 value of the `__proto__` property key is assigned to the [[Prototype]]
|
||||
internal slot (null value)
|
||||
info: |
|
||||
...
|
||||
6. 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).
|
||||
---*/
|
||||
|
||||
var object = {
|
||||
__proto__: null
|
||||
};
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(object), null);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(object, '__proto__'), undefined
|
||||
);
|
|
@ -1,9 +1,11 @@
|
|||
// Copyright (C) 2015 André Bargull. 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 value of the `__proto__` property key is assigned to the [[Prototype]] internal slot.
|
||||
description: >
|
||||
The value of the `__proto__` property key is assigned to the [[Prototype]]
|
||||
internal slot (Object value)
|
||||
info: >
|
||||
__proto__ Property Names in Object Initializers
|
||||
|
||||
|
@ -22,3 +24,6 @@ var object = {
|
|||
};
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(object), proto);
|
||||
assert.sameValue(
|
||||
Object.getOwnPropertyDescriptor(object, '__proto__'), undefined
|
||||
);
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-destructuring-assignment
|
||||
es6id: 12.14.5
|
||||
description: Duplicate __proto__ property names
|
||||
info: >
|
||||
Annex B defines an early error for duplicate PropertyName of `__proto__`,
|
||||
in object initializers, but this does not apply to Object Assignment
|
||||
patterns
|
||||
---*/
|
||||
|
||||
// Explicitly define an "own" property to avoid Annex B "__proto__ Property
|
||||
// Names in Object Initializers" semantics (in environments which implement
|
||||
// that extension)
|
||||
var value = Object.defineProperty({}, '__proto__', { value: 123 });
|
||||
var result, x, y;
|
||||
|
||||
result = { __proto__: x, __proto__: y } = value;
|
||||
|
||||
assert.sameValue(result, value);
|
||||
assert.sameValue(x, 123, 'first AssignmentProperty');
|
||||
assert.sameValue(y, 123, 'second AssignmentProperty');
|
||||
|
||||
result = x = y = null;
|
||||
|
||||
// CoverParenthesizedExpressionAndArrowParameterList
|
||||
result = ({ __proto__: x, __proto__: y } = value);
|
||||
|
||||
assert.sameValue(result, value);
|
||||
assert.sameValue(x, 123, 'first AssignmentProperty (CPEAAPL)');
|
||||
assert.sameValue(y, 123, 'second AssignmentProperty (CPEAAPL)');
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object-initializer
|
||||
es6id: 12.2.6
|
||||
description: Permitted duplicate `__proto__` property
|
||||
info: >
|
||||
Annex B defines an early error for duplicate PropertyName of `__proto__`,
|
||||
but this does not apply to properties created from other productions.
|
||||
|
||||
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 .
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
__proto__: null,
|
||||
__proto_: null,
|
||||
__proto: null,
|
||||
_proto__: null,
|
||||
proto__: null,
|
||||
['__proto__']: null,
|
||||
__proto__() {},
|
||||
get __proto__() { return 33; },
|
||||
set __proto__(_) { return 44; }
|
||||
};
|
||||
|
||||
var desc = Object.getOwnPropertyDescriptor(obj, '__proto__');
|
||||
|
||||
assert.sameValue(desc.get(), 33);
|
||||
assert.sameValue(desc.set(), 44);
|
Loading…
Reference in New Issue