Add tests for Reflect.ownKeys

This commit is contained in:
Leonardo Balter 2015-07-29 20:58:17 -04:00
parent a66ae7cbce
commit bc51cfa0e0
10 changed files with 267 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.11
description: >
Reflect.ownKeys.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.ownKeys.length, 1,
'The value of `Reflect.ownKeys.length` is `1`'
);
verifyNotEnumerable(Reflect.ownKeys, 'length');
verifyNotWritable(Reflect.ownKeys, 'length');
verifyConfigurable(Reflect.ownKeys, '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.11
description: >
Reflect.ownKeys.name value and property descriptor
info: >
26.1.11 Reflect.ownKeys ( target )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.ownKeys.name, 'ownKeys',
'The value of `Reflect.ownKeys.name` is `"ownKeys"`'
);
verifyNotEnumerable(Reflect.ownKeys, 'name');
verifyNotWritable(Reflect.ownKeys, 'name');
verifyConfigurable(Reflect.ownKeys, 'name');

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.11
description: >
Reflect.ownKeys is configurable, writable and not enumerable.
info: >
26.1.11 Reflect.ownKeys ( target )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'ownKeys');
verifyWritable(Reflect, 'ownKeys');
verifyConfigurable(Reflect, 'ownKeys');

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.11
description: >
Return abrupt result from target.[[OwnPropertyKeys]]()
info: >
26.1.11 Reflect.ownKeys ( target )
...
2. Let keys be target.[[OwnPropertyKeys]]().
3. ReturnIfAbrupt(keys).
...
features: [Proxy]
---*/
var o = {};
var p = new Proxy(o, {
ownKeys: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.ownKeys(p);
});

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.11
description: >
Returns target's own property keys only, ignore prototype keys.
info: >
26.1.11 Reflect.ownKeys ( target )
...
2. Let keys be target.[[OwnPropertyKeys]]().
3. ReturnIfAbrupt(keys).
4. Return CreateArrayFromList(keys).
includes: [compareArray.js]
---*/
var proto = {
foo: 1
};
var o = Object.create(proto);
o.p1 = 42;
o.p2 = 43;
o.p3 = 44;
assert(
compareArray(Reflect.ownKeys(o), ['p1', 'p2', 'p3']),
'return object own keys'
);

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.11
description: >
Returns empty array when target has now own properties.
info: >
26.1.11 Reflect.ownKeys ( target )
...
2. Let keys be target.[[OwnPropertyKeys]]().
3. ReturnIfAbrupt(keys).
4. Return CreateArrayFromList(keys).
includes: [compareArray.js]
---*/
assert(compareArray(Reflect.ownKeys({}), []));
var o = {d: 42};
delete o.d;
assert(compareArray(Reflect.ownKeys(o), []));

View File

@ -0,0 +1,37 @@
// 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.11
description: >
Returns target's own non enumerable property keys.
info: >
26.1.11 Reflect.ownKeys ( target )
...
2. Let keys be target.[[OwnPropertyKeys]]().
3. ReturnIfAbrupt(keys).
4. Return CreateArrayFromList(keys).
includes: [compareArray.js]
---*/
assert(
compareArray(Reflect.ownKeys([]), ['length']),
'return non enumerable `length` from empty array'
);
assert(
compareArray(Reflect.ownKeys([,,2]), ['2', 'length']),
'return array keys'
);
var o = {};
Object.defineProperty(o, 'p1', {
value: 42,
enumerable: false
});
Object.defineProperty(o, 'p2', {
get: function() {},
enumerable: false
});
assert(compareArray(Reflect.ownKeys(o), ['p1', 'p2']));

View File

@ -0,0 +1,54 @@
// 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.11
description: >
Returns keys in their corresponding order.
info: >
26.1.11 Reflect.ownKeys ( target )
...
2. Let keys be target.[[OwnPropertyKeys]]().
3. ReturnIfAbrupt(keys).
4. Return CreateArrayFromList(keys).
9.1.12 [[OwnPropertyKeys]] ( )
1. Let keys be a new empty List.
2. For each own property key P of O that is an integer index, in ascending
numeric index order
a. Add P as the last element of keys.
3. For each own property key P of O that is a String but is not an integer
index, in property creation order
a. Add P as the last element of keys.
4. For each own property key P of O that is a Symbol, in property creation
order
a. Add P as the last element of keys.
5. Return keys.
features: [Symbol]
---*/
var o = {};
o.p1 = 42;
o.p2 = 43;
var s1 = Symbol('1');
var s2 = Symbol('a');
o[s1] = 44;
o[s2] = 45;
o[2] = 46;
o[0] = 47;
o[1] = 48;
var result = Reflect.ownKeys(o);
assert.sameValue(result.length, 7);
assert.sameValue(result[0], '0');
assert.sameValue(result[1], '1');
assert.sameValue(result[2], '2');
assert.sameValue(result[3], 'p1');
assert.sameValue(result[4], 'p2');
assert.sameValue(result[5], s1);
assert.sameValue(result[6], s2);

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.11
description: >
Throws a TypeError if target is not an Object.
info: >
26.1.11 Reflect.ownKeys ( target )
1. If Type(target) is not Object, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.ownKeys(1);
});
assert.throws(TypeError, function() {
Reflect.ownKeys(null);
});
assert.throws(TypeError, function() {
Reflect.ownKeys(undefined);
});
assert.throws(TypeError, function() {
Reflect.ownKeys('');
});

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.11
description: >
Throws a TypeError if target is a Symbol
info: >
26.1.11 Reflect.ownKeys ( target )
1. If Type(target) is not Object, throw a TypeError exception.
...
features: [Symbol]
---*/
assert.throws(TypeError, function() {
Reflect.ownKeys(Symbol(1));
});