From ec82bff120b70a55062fb7aad2ad49eb1a294be5 Mon Sep 17 00:00:00 2001
From: Leonardo Balter <leonardo.balter@gmail.com>
Date: Wed, 29 Jul 2015 17:00:49 -0400
Subject: [PATCH] Add tests for Reflect.getOwnPropertyDescriptor

---
 .../getOwnPropertyDescriptor.js               | 17 ++++++
 .../getOwnPropertyDescriptor/length.js        | 17 ++++++
 .../Reflect/getOwnPropertyDescriptor/name.js  | 22 ++++++++
 .../return-abrupt-from-property-key.js        | 24 ++++++++
 .../return-abrupt-from-result.js              | 26 +++++++++
 .../return-from-accessor-descriptor.js        | 56 +++++++++++++++++++
 .../return-from-data-descriptor.js            | 32 +++++++++++
 .../symbol-property.js                        | 39 +++++++++++++
 .../target-is-not-object-throws.js            | 28 ++++++++++
 .../target-is-symbol-throws.js                | 17 ++++++
 .../undefined-own-property.js                 | 23 ++++++++
 .../undefined-property.js                     | 21 +++++++
 12 files changed, 322 insertions(+)
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/getOwnPropertyDescriptor.js
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/length.js
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/name.js
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-property-key.js
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-result.js
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/return-from-accessor-descriptor.js
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/return-from-data-descriptor.js
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/symbol-property.js
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/target-is-not-object-throws.js
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/target-is-symbol-throws.js
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/undefined-own-property.js
 create mode 100644 test/built-ins/Reflect/getOwnPropertyDescriptor/undefined-property.js

diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/getOwnPropertyDescriptor.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/getOwnPropertyDescriptor.js
new file mode 100644
index 0000000000..4d202dbd2c
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/getOwnPropertyDescriptor.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.7
+description: >
+  Reflect.getOwnPropertyDescriptor is configurable, writable and not enumerable.
+info: >
+  26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
+
+  17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+verifyNotEnumerable(Reflect, 'getOwnPropertyDescriptor');
+verifyWritable(Reflect, 'getOwnPropertyDescriptor');
+verifyConfigurable(Reflect, 'getOwnPropertyDescriptor');
diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/length.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/length.js
new file mode 100644
index 0000000000..6335bf455a
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/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.7
+description: >
+  Reflect.getOwnPropertyDescriptor.length value and property descriptor
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+  Reflect.getOwnPropertyDescriptor.length, 2,
+  'The value of `Reflect.getOwnPropertyDescriptor.length` is `2`'
+);
+
+verifyNotEnumerable(Reflect.getOwnPropertyDescriptor, 'length');
+verifyNotWritable(Reflect.getOwnPropertyDescriptor, 'length');
+verifyConfigurable(Reflect.getOwnPropertyDescriptor, 'length');
diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/name.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/name.js
new file mode 100644
index 0000000000..d8806484ca
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/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.7
+description: >
+  Reflect.getOwnPropertyDescriptor.name value and property descriptor
+info: >
+  26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
+
+  17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+  Reflect.getOwnPropertyDescriptor.name, 'getOwnPropertyDescriptor',
+  'The value of `Reflect.getOwnPropertyDescriptor.name` is `"getOwnPropertyDescriptor"`'
+);
+
+verifyNotEnumerable(Reflect.getOwnPropertyDescriptor, 'name');
+verifyNotWritable(Reflect.getOwnPropertyDescriptor, 'name');
+verifyConfigurable(Reflect.getOwnPropertyDescriptor, 'name');
diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-property-key.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-property-key.js
new file mode 100644
index 0000000000..c0a905319f
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-property-key.js
@@ -0,0 +1,24 @@
+// 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.7
+description: >
+  Return abrupt from ToPropertyKey(propertyKey)
+info: >
+  26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
+
+  ...
+  2. Let key be ToPropertyKey(propertyKey).
+  3. ReturnIfAbrupt(key).
+  ...
+---*/
+
+var p = {
+  toString: function() {
+    throw new Test262Error();
+  }
+};
+
+assert.throws(Test262Error, function() {
+  Reflect.getOwnPropertyDescriptor({}, p);
+});
diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-result.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-result.js
new file mode 100644
index 0000000000..b1a7f771ee
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/return-abrupt-from-result.js
@@ -0,0 +1,26 @@
+// 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.7
+description: >
+  Return abrupt result from getting the property descriptor.
+info: >
+  26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
+
+  ...
+  4. Let desc be target.[[GetOwnProperty]](key).
+  5. ReturnIfAbrupt(desc).
+  ...
+features: [Proxy]
+---*/
+
+var o1 = {};
+var p = new Proxy(o1, {
+  getOwnPropertyDescriptor: function() {
+    throw new Test262Error();
+  }
+});
+
+assert.throws(Test262Error, function() {
+  Reflect.getOwnPropertyDescriptor(p, 'p1');
+});
diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/return-from-accessor-descriptor.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/return-from-accessor-descriptor.js
new file mode 100644
index 0000000000..b6f1ed349f
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/return-from-accessor-descriptor.js
@@ -0,0 +1,56 @@
+// 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.7
+description: >
+  Return a property descriptor object as an accessor descriptor.
+info: >
+  26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
+
+  ...
+  4. Let desc be target.[[GetOwnProperty]](key).
+  5. ReturnIfAbrupt(desc).
+  6. Return FromPropertyDescriptor(desc).
+
+  6.2.4.4 FromPropertyDescriptor ( Desc )
+
+  ...
+  2. Let obj be ObjectCreate(%ObjectPrototype%).
+  ...
+  4. If Desc has a [[Value]] field, then
+    a. Perform CreateDataProperty(obj, "value", Desc.[[Value]]).
+  5. If Desc has a [[Writable]] field, then
+    a. Perform CreateDataProperty(obj, "writable", Desc.[[Writable]]).
+  6. If Desc has a [[Get]] field, then
+    a. Perform CreateDataProperty(obj, "get", Desc.[[Get]]).
+  7. If Desc has a [[Set]] field, then
+    a. Perform CreateDataProperty(obj, "set", Desc.[[Set]])
+  8. If Desc has an [[Enumerable]] field, then
+    a. Perform CreateDataProperty(obj, "enumerable", Desc.[[Enumerable]]).
+  9. If Desc has a [[Configurable]] field, then
+    a. Perform CreateDataProperty(obj , "configurable", Desc.[[Configurable]]).
+  ...
+  11. Return obj.
+
+includes: [compareArray.js]
+---*/
+
+var o1 = {};
+var fn = function() {};
+Object.defineProperty(o1, 'p', {
+  get: fn,
+  configurable: true
+});
+
+var result = Reflect.getOwnPropertyDescriptor(o1, 'p');
+
+assert(
+  compareArray(
+    Object.keys(result),
+    ['get', 'set', 'enumerable', 'configurable']
+  )
+);
+assert.sameValue(result.enumerable, false);
+assert.sameValue(result.configurable, true);
+assert.sameValue(result.get, fn);
+assert.sameValue(result.set, undefined);
diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/return-from-data-descriptor.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/return-from-data-descriptor.js
new file mode 100644
index 0000000000..849797fa2b
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/return-from-data-descriptor.js
@@ -0,0 +1,32 @@
+// 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.7
+description: >
+  Return a property descriptor object as a data descriptor.
+info: >
+  26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
+
+  ...
+  4. Let desc be target.[[GetOwnProperty]](key).
+  5. ReturnIfAbrupt(desc).
+  6. Return FromPropertyDescriptor(desc).
+includes: [compareArray.js]
+---*/
+
+var o1 = {
+  p: 'foo'
+};
+
+var result = Reflect.getOwnPropertyDescriptor(o1, 'p');
+
+assert(
+  compareArray(
+    Object.keys(result),
+    ['value', 'writable', 'enumerable', 'configurable']
+  )
+);
+assert.sameValue(result.value, 'foo');
+assert.sameValue(result.enumerable, true);
+assert.sameValue(result.configurable, true);
+assert.sameValue(result.writable, true);
diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/symbol-property.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/symbol-property.js
new file mode 100644
index 0000000000..a1416bccf2
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/symbol-property.js
@@ -0,0 +1,39 @@
+// 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.7
+description: >
+  Use a symbol value on property key.
+info: >
+  26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
+
+  ...
+  2. Let key be ToPropertyKey(propertyKey).
+  ...
+
+  7.1.14 ToPropertyKey ( argument )
+
+  ...
+  3. If Type(key) is Symbol, then
+    a. Return key.
+  ...
+includes: [compareArray.js]
+features: [Symbol]
+---*/
+
+var o = {};
+var s = Symbol('42');
+o[s] = 42;
+
+var result = Reflect.getOwnPropertyDescriptor(o, s);
+
+assert(
+  compareArray(
+    Object.keys(result),
+    ['value', 'writable', 'enumerable', 'configurable']
+  )
+);
+assert.sameValue(result.value, 42);
+assert.sameValue(result.enumerable, true);
+assert.sameValue(result.configurable, true);
+assert.sameValue(result.writable, true);
diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/target-is-not-object-throws.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/target-is-not-object-throws.js
new file mode 100644
index 0000000000..7ab25e723a
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/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.7
+description: >
+  Throws a TypeError if target is not an Object.
+info: >
+  26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
+
+  1. If Type(target) is not Object, throw a TypeError exception.
+  ...
+---*/
+
+assert.throws(TypeError, function() {
+  Reflect.getOwnPropertyDescriptor(1, 'p');
+});
+
+assert.throws(TypeError, function() {
+  Reflect.getOwnPropertyDescriptor(null, 'p');
+});
+
+assert.throws(TypeError, function() {
+  Reflect.getOwnPropertyDescriptor(undefined, 'p');
+});
+
+assert.throws(TypeError, function() {
+  Reflect.getOwnPropertyDescriptor('', 'p');
+});
diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/target-is-symbol-throws.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/target-is-symbol-throws.js
new file mode 100644
index 0000000000..9d1bae34df
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/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.7
+description: >
+  Throws a TypeError if target is a Symbol
+info: >
+  26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
+
+  1. If Type(target) is not Object, throw a TypeError exception.
+  ...
+features: [Symbol]
+---*/
+
+assert.throws(TypeError, function() {
+  Reflect.getOwnPropertyDescriptor(Symbol(1), 'p');
+});
diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/undefined-own-property.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/undefined-own-property.js
new file mode 100644
index 0000000000..3313063ae1
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/undefined-own-property.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2015 Leonardo Balter. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 26.1.7
+description: >
+  Return undefined for an non existing own property.
+info: >
+  26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
+
+  ...
+  4. Let desc be target.[[GetOwnProperty]](key).
+  5. ReturnIfAbrupt(desc).
+  6. Return FromPropertyDescriptor(desc).
+
+  6.2.4.4 FromPropertyDescriptor ( Desc )
+
+  1. If Desc is undefined, return undefined.
+---*/
+
+var o = Object.create({p: 1});
+
+var result = Reflect.getOwnPropertyDescriptor(o, 'p');
+assert.sameValue(result, undefined);
diff --git a/test/built-ins/Reflect/getOwnPropertyDescriptor/undefined-property.js b/test/built-ins/Reflect/getOwnPropertyDescriptor/undefined-property.js
new file mode 100644
index 0000000000..f2fbce7811
--- /dev/null
+++ b/test/built-ins/Reflect/getOwnPropertyDescriptor/undefined-property.js
@@ -0,0 +1,21 @@
+// 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.7
+description: >
+  Return undefined for an undefined property.
+info: >
+  26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
+
+  ...
+  4. Let desc be target.[[GetOwnProperty]](key).
+  5. ReturnIfAbrupt(desc).
+  6. Return FromPropertyDescriptor(desc).
+
+  6.2.4.4 FromPropertyDescriptor ( Desc )
+
+  1. If Desc is undefined, return undefined.
+---*/
+
+var result = Reflect.getOwnPropertyDescriptor({}, undefined);
+assert.sameValue(result, undefined);
-- 
GitLab