From c6a152558de78f06cac958d477d1c125022a656c Mon Sep 17 00:00:00 2001 From: jugglinmike Date: Thu, 19 May 2016 13:01:07 -0400 Subject: [PATCH] Add tests for Annex B extn: __proto__ in obj init (#633) --- .../expressions/object/__proto__-duplicate.js | 19 ++++ .../object/__proto__-value-non-object.js | 90 +++++++++++++++++++ .../object/__proto__-value-null.js | 24 +++++ .../{__proto__.js => __proto__-value-obj.js} | 9 +- .../destructuring/obj-prop-__proto__dup.js | 32 +++++++ .../object/__proto__-permitted-dup.js | 34 +++++++ 6 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 test/annexB/language/expressions/object/__proto__-duplicate.js create mode 100644 test/annexB/language/expressions/object/__proto__-value-non-object.js create mode 100644 test/annexB/language/expressions/object/__proto__-value-null.js rename test/annexB/language/expressions/object/{__proto__.js => __proto__-value-obj.js} (68%) create mode 100644 test/language/expressions/assignment/destructuring/obj-prop-__proto__dup.js create mode 100644 test/language/expressions/object/__proto__-permitted-dup.js diff --git a/test/annexB/language/expressions/object/__proto__-duplicate.js b/test/annexB/language/expressions/object/__proto__-duplicate.js new file mode 100644 index 0000000000..1d93e263a3 --- /dev/null +++ b/test/annexB/language/expressions/object/__proto__-duplicate.js @@ -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 +}); diff --git a/test/annexB/language/expressions/object/__proto__-value-non-object.js b/test/annexB/language/expressions/object/__proto__-value-non-object.js new file mode 100644 index 0000000000..cfa9587053 --- /dev/null +++ b/test/annexB/language/expressions/object/__proto__-value-non-object.js @@ -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)' +); diff --git a/test/annexB/language/expressions/object/__proto__-value-null.js b/test/annexB/language/expressions/object/__proto__-value-null.js new file mode 100644 index 0000000000..29b1a09e43 --- /dev/null +++ b/test/annexB/language/expressions/object/__proto__-value-null.js @@ -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 +); diff --git a/test/annexB/language/expressions/object/__proto__.js b/test/annexB/language/expressions/object/__proto__-value-obj.js similarity index 68% rename from test/annexB/language/expressions/object/__proto__.js rename to test/annexB/language/expressions/object/__proto__-value-obj.js index a6228f3887..732d80085f 100755 --- a/test/annexB/language/expressions/object/__proto__.js +++ b/test/annexB/language/expressions/object/__proto__-value-obj.js @@ -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 +); diff --git a/test/language/expressions/assignment/destructuring/obj-prop-__proto__dup.js b/test/language/expressions/assignment/destructuring/obj-prop-__proto__dup.js new file mode 100644 index 0000000000..33513bc973 --- /dev/null +++ b/test/language/expressions/assignment/destructuring/obj-prop-__proto__dup.js @@ -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)'); diff --git a/test/language/expressions/object/__proto__-permitted-dup.js b/test/language/expressions/object/__proto__-permitted-dup.js new file mode 100644 index 0000000000..7049eb3272 --- /dev/null +++ b/test/language/expressions/object/__proto__-permitted-dup.js @@ -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);