Skip to content
Snippets Groups Projects
Commit ec82bff1 authored by Leonardo Balter's avatar Leonardo Balter
Browse files

Add tests for Reflect.getOwnPropertyDescriptor

parent efac2336
No related branches found
No related tags found
No related merge requests found
Showing
with 322 additions and 0 deletions
// 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');
// 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');
// 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');
// 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);
});
// 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');
});
// 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);
// 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);
// 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);
// 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');
});
// 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');
});
// 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);
// 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);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment