diff --git a/test/built-ins/Reflect/get/get.js b/test/built-ins/Reflect/get/get.js new file mode 100644 index 0000000000..c786824fd5 --- /dev/null +++ b/test/built-ins/Reflect/get/get.js @@ -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'); diff --git a/test/built-ins/Reflect/get/length.js b/test/built-ins/Reflect/get/length.js new file mode 100644 index 0000000000..133325dd2e --- /dev/null +++ b/test/built-ins/Reflect/get/length.js @@ -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'); diff --git a/test/built-ins/Reflect/get/name.js b/test/built-ins/Reflect/get/name.js new file mode 100644 index 0000000000..28e983404c --- /dev/null +++ b/test/built-ins/Reflect/get/name.js @@ -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'); diff --git a/test/built-ins/Reflect/get/return-abrupt-from-property-key.js b/test/built-ins/Reflect/get/return-abrupt-from-property-key.js new file mode 100644 index 0000000000..f93ea2ce50 --- /dev/null +++ b/test/built-ins/Reflect/get/return-abrupt-from-property-key.js @@ -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); +}); diff --git a/test/built-ins/Reflect/get/return-abrupt-from-result.js b/test/built-ins/Reflect/get/return-abrupt-from-result.js new file mode 100644 index 0000000000..360e6b46c7 --- /dev/null +++ b/test/built-ins/Reflect/get/return-abrupt-from-result.js @@ -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'); +}); diff --git a/test/built-ins/Reflect/get/return-value-from-receiver.js b/test/built-ins/Reflect/get/return-value-from-receiver.js new file mode 100644 index 0000000000..13902f351a --- /dev/null +++ b/test/built-ins/Reflect/get/return-value-from-receiver.js @@ -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' +); diff --git a/test/built-ins/Reflect/get/return-value-from-symbol-key.js b/test/built-ins/Reflect/get/return-value-from-symbol-key.js new file mode 100644 index 0000000000..02ec2e04b4 --- /dev/null +++ b/test/built-ins/Reflect/get/return-value-from-symbol-key.js @@ -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); diff --git a/test/built-ins/Reflect/get/return-value.js b/test/built-ins/Reflect/get/return-value.js new file mode 100644 index 0000000000..daa2125df2 --- /dev/null +++ b/test/built-ins/Reflect/get/return-value.js @@ -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' +); diff --git a/test/built-ins/Reflect/get/target-is-not-object-throws.js b/test/built-ins/Reflect/get/target-is-not-object-throws.js new file mode 100644 index 0000000000..842fdfb73f --- /dev/null +++ b/test/built-ins/Reflect/get/target-is-not-object-throws.js @@ -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'); +}); diff --git a/test/built-ins/Reflect/get/target-is-symbol-throws.js b/test/built-ins/Reflect/get/target-is-symbol-throws.js new file mode 100644 index 0000000000..e78cab4713 --- /dev/null +++ b/test/built-ins/Reflect/get/target-is-symbol-throws.js @@ -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'); +});