Add tests for Reflect.getOwnPropertyDescriptor

This commit is contained in:
Leonardo Balter 2015-07-29 17:00:49 -04:00
parent efac2336c2
commit ec82bff120
12 changed files with 322 additions and 0 deletions

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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);
});

View File

@ -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');
});

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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');
});

View File

@ -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');
});

View File

@ -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);

View File

@ -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);