From b2fd133f881505110aa0dc582b780a1694820435 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Wed, 29 Jul 2015 17:17:27 -0400 Subject: [PATCH] Add tests for Reflect.getPrototypeOf --- .../Reflect/getPrototypeOf/getPrototypeOf.js | 17 +++++++++++ .../Reflect/getPrototypeOf/length.js | 17 +++++++++++ test/built-ins/Reflect/getPrototypeOf/name.js | 22 +++++++++++++++ .../Reflect/getPrototypeOf/null-prototype.js | 15 ++++++++++ .../return-abrupt-from-result.js | 25 +++++++++++++++++ .../getPrototypeOf/return-prototype.js | 18 ++++++++++++ .../getPrototypeOf/skip-own-properties.js | 22 +++++++++++++++ .../target-is-not-object-throws.js | 28 +++++++++++++++++++ .../getPrototypeOf/target-is-symbol-throws.js | 17 +++++++++++ 9 files changed, 181 insertions(+) create mode 100644 test/built-ins/Reflect/getPrototypeOf/getPrototypeOf.js create mode 100644 test/built-ins/Reflect/getPrototypeOf/length.js create mode 100644 test/built-ins/Reflect/getPrototypeOf/name.js create mode 100644 test/built-ins/Reflect/getPrototypeOf/null-prototype.js create mode 100644 test/built-ins/Reflect/getPrototypeOf/return-abrupt-from-result.js create mode 100644 test/built-ins/Reflect/getPrototypeOf/return-prototype.js create mode 100644 test/built-ins/Reflect/getPrototypeOf/skip-own-properties.js create mode 100644 test/built-ins/Reflect/getPrototypeOf/target-is-not-object-throws.js create mode 100644 test/built-ins/Reflect/getPrototypeOf/target-is-symbol-throws.js diff --git a/test/built-ins/Reflect/getPrototypeOf/getPrototypeOf.js b/test/built-ins/Reflect/getPrototypeOf/getPrototypeOf.js new file mode 100644 index 0000000000..95573c3831 --- /dev/null +++ b/test/built-ins/Reflect/getPrototypeOf/getPrototypeOf.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.8 +description: > + Reflect.getPrototypeOf is configurable, writable and not enumerable. +info: > + 26.1.8 Reflect.getPrototypeOf ( target ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Reflect, 'getPrototypeOf'); +verifyWritable(Reflect, 'getPrototypeOf'); +verifyConfigurable(Reflect, 'getPrototypeOf'); diff --git a/test/built-ins/Reflect/getPrototypeOf/length.js b/test/built-ins/Reflect/getPrototypeOf/length.js new file mode 100644 index 0000000000..e57b7a8932 --- /dev/null +++ b/test/built-ins/Reflect/getPrototypeOf/length.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.8 +description: > + Reflect.getPrototypeOf.length value and property descriptor +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Reflect.getPrototypeOf.length, 1, + 'The value of `Reflect.getPrototypeOf.length` is `1`' +); + +verifyNotEnumerable(Reflect.getPrototypeOf, 'length'); +verifyNotWritable(Reflect.getPrototypeOf, 'length'); +verifyConfigurable(Reflect.getPrototypeOf, 'length'); diff --git a/test/built-ins/Reflect/getPrototypeOf/name.js b/test/built-ins/Reflect/getPrototypeOf/name.js new file mode 100644 index 0000000000..9ad8f77dec --- /dev/null +++ b/test/built-ins/Reflect/getPrototypeOf/name.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.8 +description: > + Reflect.getPrototypeOf.name value and property descriptor +info: > + 26.1.8 Reflect.getPrototypeOf ( target ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Reflect.getPrototypeOf.name, 'getPrototypeOf', + 'The value of `Reflect.getPrototypeOf.name` is `"getPrototypeOf"`' +); + +verifyNotEnumerable(Reflect.getPrototypeOf, 'name'); +verifyNotWritable(Reflect.getPrototypeOf, 'name'); +verifyConfigurable(Reflect.getPrototypeOf, 'name'); diff --git a/test/built-ins/Reflect/getPrototypeOf/null-prototype.js b/test/built-ins/Reflect/getPrototypeOf/null-prototype.js new file mode 100644 index 0000000000..a3a32eadc0 --- /dev/null +++ b/test/built-ins/Reflect/getPrototypeOf/null-prototype.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.8 +description: > + Return null prototype. +info: > + 26.1.8 Reflect.getPrototypeOf ( target ) + + ... + 2. Return target.[[GetPrototypeOf]](). +---*/ + +var o = Object.create(null); +assert.sameValue(Reflect.getPrototypeOf(o), null); diff --git a/test/built-ins/Reflect/getPrototypeOf/return-abrupt-from-result.js b/test/built-ins/Reflect/getPrototypeOf/return-abrupt-from-result.js new file mode 100644 index 0000000000..d1df8086a8 --- /dev/null +++ b/test/built-ins/Reflect/getPrototypeOf/return-abrupt-from-result.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.8 +description: > + Return abrupt result from getting the prototype. +info: > + 26.1.8 Reflect.getPrototypeOf ( target ) + + ... + 2. Return target.[[GetPrototypeOf]](). + ... +features: [Proxy] +---*/ + +var o1 = {}; +var p = new Proxy(o1, { + getPrototypeOf: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.getPrototypeOf(p); +}); diff --git a/test/built-ins/Reflect/getPrototypeOf/return-prototype.js b/test/built-ins/Reflect/getPrototypeOf/return-prototype.js new file mode 100644 index 0000000000..ba29e2fa36 --- /dev/null +++ b/test/built-ins/Reflect/getPrototypeOf/return-prototype.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.8 +description: > + Returns the internal [[Prototype]] object. +info: > + 26.1.8 Reflect.getPrototypeOf ( target ) + + ... + 2. Return target.[[GetPrototypeOf]](). +---*/ + +var o = {}; +assert.sameValue( + Reflect.getPrototypeOf(o), Object.prototype, + 'return default prototypes' +); diff --git a/test/built-ins/Reflect/getPrototypeOf/skip-own-properties.js b/test/built-ins/Reflect/getPrototypeOf/skip-own-properties.js new file mode 100644 index 0000000000..3eee647b7b --- /dev/null +++ b/test/built-ins/Reflect/getPrototypeOf/skip-own-properties.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.8 +description: > + Skip own properties to return the internal [[Prototype]] object. +info: > + 26.1.8 Reflect.getPrototypeOf ( target ) + + ... + 2. Return target.[[GetPrototypeOf]](). +---*/ + +var valid = {}; +var o = Object.create(valid, { + prototype: {value: 'invalid', enumerable: true} +}); + +assert.sameValue( + Reflect.getPrototypeOf(o), valid, + 'skip own properties' +); diff --git a/test/built-ins/Reflect/getPrototypeOf/target-is-not-object-throws.js b/test/built-ins/Reflect/getPrototypeOf/target-is-not-object-throws.js new file mode 100644 index 0000000000..31a4a427e9 --- /dev/null +++ b/test/built-ins/Reflect/getPrototypeOf/target-is-not-object-throws.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.8 +description: > + Throws a TypeError if target is not an Object. +info: > + 26.1.8 Reflect.getPrototypeOf ( target ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + Reflect.getPrototypeOf(1); +}); + +assert.throws(TypeError, function() { + Reflect.getPrototypeOf(null); +}); + +assert.throws(TypeError, function() { + Reflect.getPrototypeOf(undefined); +}); + +assert.throws(TypeError, function() { + Reflect.getPrototypeOf(''); +}); diff --git a/test/built-ins/Reflect/getPrototypeOf/target-is-symbol-throws.js b/test/built-ins/Reflect/getPrototypeOf/target-is-symbol-throws.js new file mode 100644 index 0000000000..495cf40992 --- /dev/null +++ b/test/built-ins/Reflect/getPrototypeOf/target-is-symbol-throws.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.8 +description: > + Throws a TypeError if target is a Symbol +info: > + 26.1.8 Reflect.getPrototypeOf ( target ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.getPrototypeOf(Symbol(1)); +});