Add tests for Reflect.enumerate

This commit is contained in:
Leonardo Balter 2015-07-28 17:52:16 -04:00
parent ed233ccb2d
commit 6326408215
8 changed files with 224 additions and 0 deletions

View File

@ -0,0 +1,37 @@
// Copyright (C) 2015 Leonardo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.5
description: >
Returned iterator does not iterate over symbol properties.
info: >
26.1.5 Reflect.enumerate ( target )
...
2. Return target.[[Enumerate]]().
features: [Symbol]
---*/
var iter, step;
var s = Symbol('1');
var o = {
'a': 1,
'b': 1
};
o[s] = 1;
iter = Reflect.enumerate(o);
step = iter.next();
assert.sameValue(step.value, 'a');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, 'b');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, undefined);
assert.sameValue(step.done, true);

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

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.5
description: >
Reflect.enumerate.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.enumerate.length, 1,
'The value of `Reflect.enumerate.length` is `1`'
);
verifyNotEnumerable(Reflect.enumerate, 'length');
verifyNotWritable(Reflect.enumerate, 'length');
verifyConfigurable(Reflect.enumerate, '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.5
description: >
Reflect.enumerate.name value and property descriptor
info: >
26.1.5 Reflect.enumerate ( target )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.enumerate.name, 'enumerate',
'The value of `Reflect.enumerate.name` is `"enumerate"`'
);
verifyNotEnumerable(Reflect.enumerate, 'name');
verifyNotWritable(Reflect.enumerate, 'name');
verifyConfigurable(Reflect.enumerate, '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.5
description: >
Return abrupt result.
info: >
26.1.5 Reflect.enumerate ( target )
...
2. Return target.[[Enumerate]]().
features: [Proxy]
---*/
var o = {};
var p = new Proxy(o, {
enumerate: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.enumerate(p);
});

View File

@ -0,0 +1,62 @@
// 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.5
description: >
Return an iterator.
info: >
26.1.5 Reflect.enumerate ( target )
...
2. Return target.[[Enumerate]]().
---*/
var iter, step;
var arr = ['a', 'b', 'c'];
iter = Reflect.enumerate(arr);
step = iter.next();
assert.sameValue(step.value, '0');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, '1');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, '2');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, undefined);
assert.sameValue(step.done, true);
var o = {
'a': 42,
'b': 43,
'c': 44
};
Object.defineProperty(o, 'd', {
enumerable: false,
value: 45
});
iter = Reflect.enumerate(o);
step = iter.next();
assert.sameValue(step.value, 'a');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, 'b');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, 'c');
assert.sameValue(step.done, false);
step = iter.next();
assert.sameValue(step.value, undefined);
assert.sameValue(step.done, 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.5
description: >
Throws a TypeError if target is not an Object.
info: >
26.1.5 Reflect.enumerate ( target )
1. If Type(target) is not Object, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.enumerate(1);
});
assert.throws(TypeError, function() {
Reflect.enumerate(null);
});
assert.throws(TypeError, function() {
Reflect.enumerate(undefined);
});
assert.throws(TypeError, function() {
Reflect.enumerate('');
});

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