mirror of https://github.com/tc39/test262.git
Add tests for Reflect.get
This commit is contained in:
parent
6326408215
commit
efac2336c2
|
@ -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.6
|
||||
description: >
|
||||
Reflect.get is configurable, writable and not enumerable.
|
||||
info: >
|
||||
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
verifyNotEnumerable(Reflect, 'get');
|
||||
verifyWritable(Reflect, 'get');
|
||||
verifyConfigurable(Reflect, 'get');
|
|
@ -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.6
|
||||
description: >
|
||||
Reflect.get.length value and property descriptor
|
||||
info: >
|
||||
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
|
||||
|
||||
The length property of the get function is 2.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Reflect.get.length, 2,
|
||||
'The value of `Reflect.get.length` is `2`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Reflect.get, 'length');
|
||||
verifyNotWritable(Reflect.get, 'length');
|
||||
verifyConfigurable(Reflect.get, '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.6
|
||||
description: >
|
||||
Reflect.get.name value and property descriptor
|
||||
info: >
|
||||
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Reflect.get.name, 'get',
|
||||
'The value of `Reflect.get.name` is `"get"`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Reflect.get, 'name');
|
||||
verifyNotWritable(Reflect.get, 'name');
|
||||
verifyConfigurable(Reflect.get, '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.6
|
||||
description: >
|
||||
Return abrupt from ToPropertyKey(propertyKey)
|
||||
info: >
|
||||
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
|
||||
|
||||
...
|
||||
2. Let key be ToPropertyKey(propertyKey).
|
||||
3. ReturnIfAbrupt(key).
|
||||
...
|
||||
---*/
|
||||
|
||||
var p = {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Reflect.get({}, p);
|
||||
});
|
|
@ -0,0 +1,29 @@
|
|||
// 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.6
|
||||
description: >
|
||||
Return abrupt result from get a property value.
|
||||
info: >
|
||||
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
|
||||
|
||||
...
|
||||
5. Return target.[[Get]](key, receiver).
|
||||
---*/
|
||||
|
||||
var o1 = {};
|
||||
Object.defineProperty(o1, 'p1', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Reflect.get(o1, 'p1');
|
||||
});
|
||||
|
||||
// Abrupt from the prototype property
|
||||
var o2 = Object.create(o1);
|
||||
assert.throws(Test262Error, function() {
|
||||
Reflect.get(o2, 'p1');
|
||||
});
|
|
@ -0,0 +1,51 @@
|
|||
// 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.6
|
||||
description: >
|
||||
Return value from a receiver.
|
||||
info: >
|
||||
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
|
||||
|
||||
...
|
||||
4. If receiver is not present, then
|
||||
a. Let receiver be target.
|
||||
5. Return target.[[Get]](key, receiver).
|
||||
|
||||
9.1.8 [[Get]] (P, Receiver)
|
||||
|
||||
...
|
||||
2. Let desc be O.[[GetOwnProperty]](P).
|
||||
3. ReturnIfAbrupt(desc).
|
||||
4. If desc is undefined, then
|
||||
a. Let parent be O.[[GetPrototypeOf]]().
|
||||
b. ReturnIfAbrupt(parent).
|
||||
c. If parent is null, return undefined.
|
||||
d. Return parent.[[Get]](P, Receiver).
|
||||
5. If IsDataDescriptor(desc) is true, return desc.[[Value]].
|
||||
6. Otherwise, IsAccessorDescriptor(desc) must be true so, let getter be
|
||||
desc.[[Get]].
|
||||
7. If getter is undefined, return undefined.
|
||||
8. Return Call(getter, Receiver).
|
||||
---*/
|
||||
|
||||
var o1 = {};
|
||||
var receiver = {
|
||||
y: 42
|
||||
};
|
||||
|
||||
Object.defineProperty(o1, 'x', {
|
||||
get: function() {
|
||||
return this.y;
|
||||
}
|
||||
});
|
||||
assert.sameValue(
|
||||
Reflect.get(o1, 'x', receiver), 42,
|
||||
'Return own property value using a receiver'
|
||||
);
|
||||
|
||||
var o2 = Object.create(o1);
|
||||
assert.sameValue(
|
||||
Reflect.get(o2, 'x', receiver), 42,
|
||||
'Return prototype property value using a receiver'
|
||||
);
|
|
@ -0,0 +1,27 @@
|
|||
// 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.6
|
||||
description: >
|
||||
Return value where property key is a symbol.
|
||||
info: >
|
||||
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
|
||||
|
||||
...
|
||||
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 s = Symbol('1');
|
||||
o[s] = 42;
|
||||
|
||||
assert.sameValue(Reflect.get(o, s), 42);
|
|
@ -0,0 +1,67 @@
|
|||
// 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.6
|
||||
description: >
|
||||
Return value.
|
||||
info: >
|
||||
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
|
||||
|
||||
...
|
||||
4. If receiver is not present, then
|
||||
a. Let receiver be target.
|
||||
5. Return target.[[Get]](key, receiver).
|
||||
|
||||
9.1.8 [[Get]] (P, Receiver)
|
||||
|
||||
...
|
||||
2. Let desc be O.[[GetOwnProperty]](P).
|
||||
3. ReturnIfAbrupt(desc).
|
||||
4. If desc is undefined, then
|
||||
a. Let parent be O.[[GetPrototypeOf]]().
|
||||
b. ReturnIfAbrupt(parent).
|
||||
c. If parent is null, return undefined.
|
||||
d. Return parent.[[Get]](P, Receiver).
|
||||
5. If IsDataDescriptor(desc) is true, return desc.[[Value]].
|
||||
6. Otherwise, IsAccessorDescriptor(desc) must be true so, let getter be
|
||||
desc.[[Get]].
|
||||
7. If getter is undefined, return undefined.
|
||||
8. Return Call(getter, Receiver).
|
||||
---*/
|
||||
|
||||
var o = {};
|
||||
|
||||
o.p1 = 'value 1';
|
||||
assert.sameValue(
|
||||
Reflect.get(o, 'p1'), 'value 1',
|
||||
'Return value from data descriptor'
|
||||
);
|
||||
|
||||
Object.defineProperty(o, 'p2', {
|
||||
get: undefined
|
||||
});
|
||||
assert.sameValue(
|
||||
Reflect.get(o, 'p2'), undefined,
|
||||
'Return undefined if getter is undefined'
|
||||
);
|
||||
|
||||
Object.defineProperty(o, 'p3', {
|
||||
get: function() {
|
||||
return 'foo';
|
||||
}
|
||||
});
|
||||
assert.sameValue(
|
||||
Reflect.get(o, 'p3'), 'foo',
|
||||
'Return Call(getter, Receiver)'
|
||||
);
|
||||
|
||||
var o2 = Object.create({p: 42});
|
||||
assert.sameValue(
|
||||
Reflect.get(o2, 'p'), 42,
|
||||
'Return value from prototype without own property.'
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
Reflect.get(o2, 'u'), undefined,
|
||||
'Return undefined without property on the object and its prototype'
|
||||
);
|
|
@ -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.6
|
||||
description: >
|
||||
Throws a TypeError if target is not an Object.
|
||||
info: >
|
||||
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
|
||||
|
||||
1. If Type(target) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.get(1, 'p');
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.get(null, 'p');
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.get(undefined, 'p');
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.get('', '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.6
|
||||
description: >
|
||||
Throws a TypeError if target is a Symbol
|
||||
info: >
|
||||
26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
|
||||
|
||||
1. If Type(target) is not Object, throw a TypeError exception.
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.get(Symbol(1), 'p');
|
||||
});
|
Loading…
Reference in New Issue