mirror of https://github.com/tc39/test262.git
Add tests for Reflect.has
This commit is contained in:
parent
b2fd133f88
commit
257bd7b48e
|
@ -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.9
|
||||||
|
description: >
|
||||||
|
Reflect.has is configurable, writable and not enumerable.
|
||||||
|
info: >
|
||||||
|
26.1.9 Reflect.has ( target, propertyKey )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyNotEnumerable(Reflect, 'has');
|
||||||
|
verifyWritable(Reflect, 'has');
|
||||||
|
verifyConfigurable(Reflect, 'has');
|
|
@ -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.9
|
||||||
|
description: >
|
||||||
|
Reflect.has.length value and property descriptor
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Reflect.has.length, 2,
|
||||||
|
'The value of `Reflect.has.length` is `2`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Reflect.has, 'length');
|
||||||
|
verifyNotWritable(Reflect.has, 'length');
|
||||||
|
verifyConfigurable(Reflect.has, 'length');
|
|
@ -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.9
|
||||||
|
description: >
|
||||||
|
Reflect.has.name value and property descriptor
|
||||||
|
info: >
|
||||||
|
26.1.9 Reflect.has ( target, propertyKey )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Reflect.has.name, 'has',
|
||||||
|
'The value of `Reflect.has.name` is `"has"`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Reflect.has, 'name');
|
||||||
|
verifyNotWritable(Reflect.has, 'name');
|
||||||
|
verifyConfigurable(Reflect.has, 'name');
|
|
@ -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.9
|
||||||
|
description: >
|
||||||
|
Return abrupt from ToPropertyKey(propertyKey)
|
||||||
|
info: >
|
||||||
|
26.1.9 Reflect.has ( target, propertyKey )
|
||||||
|
|
||||||
|
...
|
||||||
|
2. Let key be ToPropertyKey(propertyKey).
|
||||||
|
3. ReturnIfAbrupt(key).
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var p = {
|
||||||
|
toString: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
Reflect.has({}, p);
|
||||||
|
});
|
|
@ -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.9
|
||||||
|
description: >
|
||||||
|
Return abrupt result.
|
||||||
|
info: >
|
||||||
|
26.1.9 Reflect.has ( target, propertyKey )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. Return target.[[HasProperty]](key).
|
||||||
|
features: [Proxy]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var o = {};
|
||||||
|
var p = new Proxy(o, {
|
||||||
|
has: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
Reflect.has(p, 'p1');
|
||||||
|
});
|
|
@ -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.9
|
||||||
|
description: >
|
||||||
|
Return boolean value.
|
||||||
|
info: >
|
||||||
|
26.1.9 Reflect.has ( target, propertyKey )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. Return target.[[HasProperty]](key).
|
||||||
|
|
||||||
|
|
||||||
|
9.1.7.1 OrdinaryHasProperty (O, P)
|
||||||
|
|
||||||
|
...
|
||||||
|
2. Let hasOwn be OrdinaryGetOwnProperty(O, P).
|
||||||
|
3. If hasOwn is not undefined, return true.
|
||||||
|
4. Let parent be O.[[GetPrototypeOf]]().
|
||||||
|
5. ReturnIfAbrupt(parent).
|
||||||
|
6. If parent is not null, then
|
||||||
|
a. Return parent.[[HasProperty]](P).
|
||||||
|
7. Return false.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var o1 = {
|
||||||
|
p: 42
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.sameValue(Reflect.has(o1, 'p'), true, 'true from own property');
|
||||||
|
assert.sameValue(
|
||||||
|
Reflect.has(o1, 'z'), false,
|
||||||
|
'false when property is not present'
|
||||||
|
);
|
||||||
|
|
||||||
|
var o2 = Object.create({p: 42});
|
||||||
|
assert.sameValue(Reflect.has(o2, 'p'), true, 'true from a prototype property');
|
|
@ -0,0 +1,34 @@
|
||||||
|
// 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.9
|
||||||
|
description: >
|
||||||
|
Return boolean value from a projectKey as a Symbol
|
||||||
|
info: >
|
||||||
|
26.1.9 Reflect.has ( target, propertyKey )
|
||||||
|
|
||||||
|
...
|
||||||
|
2. Let key be ToPropertyKey(propertyKey).
|
||||||
|
...
|
||||||
|
|
||||||
|
7.1.14 ToPropertyKey ( argument )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If Type(key) is Symbol, then
|
||||||
|
a. Return key.
|
||||||
|
...
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var o = {};
|
||||||
|
var s1 = Symbol('1');
|
||||||
|
o[s1] = 42;
|
||||||
|
|
||||||
|
var s2 = Symbol('1');
|
||||||
|
|
||||||
|
|
||||||
|
assert.sameValue(Reflect.has(o, s1), true, 'true from own property');
|
||||||
|
assert.sameValue(
|
||||||
|
Reflect.has(o, s2), false,
|
||||||
|
'false when property is not present'
|
||||||
|
);
|
|
@ -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.9
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if target is not an Object.
|
||||||
|
info: >
|
||||||
|
26.1.9 Reflect.has ( target, propertyKey )
|
||||||
|
|
||||||
|
1. If Type(target) is not Object, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Reflect.has(1, 'p');
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Reflect.has(null, 'p');
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Reflect.has(undefined, 'p');
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Reflect.has('', 'p');
|
||||||
|
});
|
|
@ -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.9
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if target is a Symbol
|
||||||
|
info: >
|
||||||
|
26.1.9 Reflect.has ( target, propertyKey )
|
||||||
|
|
||||||
|
1. If Type(target) is not Object, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Reflect.has(Symbol(1), 'p');
|
||||||
|
});
|
Loading…
Reference in New Issue