From d3743c3ba794b8e66bbe234c09c2e910120c9d35 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Wed, 29 Jul 2015 23:01:24 -0400 Subject: [PATCH] Add tests for Reflect.set --- .../set/call-prototype-property-set.js | 45 +++++++++++ .../Reflect/set/creates-a-data-descriptor.js | 78 +++++++++++++++++++ .../set/different-property-descriptors.js | 65 ++++++++++++++++ test/built-ins/Reflect/set/length.js | 21 +++++ test/built-ins/Reflect/set/name.js | 22 ++++++ .../Reflect/set/receiver-is-not-object.js | 41 ++++++++++ .../set/return-abrupt-from-property-key.js | 24 ++++++ .../Reflect/set/return-abrupt-from-result.js | 29 +++++++ ...eturn-false-if-receiver-is-not-writable.js | 31 ++++++++ .../return-false-if-target-is-not-writable.js | 41 ++++++++++ ...ue-on-accessor-descriptor-with-receiver.js | 51 ++++++++++++ .../set/set-value-on-accessor-descriptor.js | 45 +++++++++++ .../set/set-value-on-data-descriptor.js | 46 +++++++++++ test/built-ins/Reflect/set/set.js | 17 ++++ test/built-ins/Reflect/set/symbol-property.js | 36 +++++++++ .../set/target-is-not-object-throws.js | 28 +++++++ .../Reflect/set/target-is-symbol-throws.js | 17 ++++ 17 files changed, 637 insertions(+) create mode 100644 test/built-ins/Reflect/set/call-prototype-property-set.js create mode 100644 test/built-ins/Reflect/set/creates-a-data-descriptor.js create mode 100644 test/built-ins/Reflect/set/different-property-descriptors.js create mode 100644 test/built-ins/Reflect/set/length.js create mode 100644 test/built-ins/Reflect/set/name.js create mode 100644 test/built-ins/Reflect/set/receiver-is-not-object.js create mode 100644 test/built-ins/Reflect/set/return-abrupt-from-property-key.js create mode 100644 test/built-ins/Reflect/set/return-abrupt-from-result.js create mode 100644 test/built-ins/Reflect/set/return-false-if-receiver-is-not-writable.js create mode 100644 test/built-ins/Reflect/set/return-false-if-target-is-not-writable.js create mode 100644 test/built-ins/Reflect/set/set-value-on-accessor-descriptor-with-receiver.js create mode 100644 test/built-ins/Reflect/set/set-value-on-accessor-descriptor.js create mode 100644 test/built-ins/Reflect/set/set-value-on-data-descriptor.js create mode 100644 test/built-ins/Reflect/set/set.js create mode 100644 test/built-ins/Reflect/set/symbol-property.js create mode 100644 test/built-ins/Reflect/set/target-is-not-object-throws.js create mode 100644 test/built-ins/Reflect/set/target-is-symbol-throws.js diff --git a/test/built-ins/Reflect/set/call-prototype-property-set.js b/test/built-ins/Reflect/set/call-prototype-property-set.js new file mode 100644 index 0000000000..3adef66307 --- /dev/null +++ b/test/built-ins/Reflect/set/call-prototype-property-set.js @@ -0,0 +1,45 @@ +// 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.13 +description: > + Call accessor's set from target's prototype. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 4. If ownDesc is undefined, then + a. Let parent be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(parent). + c. If parent is not null, then + i. Return parent.[[Set]](P, V, Receiver). + ... + 11. Return true. +---*/ + +var args; +var count = 0; +var _this; +var proto = {}; +Object.defineProperty(proto, 'p', { + set: function() { + _this = this; + args = arguments; + count++; + } +}); + +var target = Object.create(proto); +var result = Reflect.set(target, 'p', 42); +assert.sameValue(result, true, 'returns true'); +assert.sameValue(args.length, 1, 'prototype `set` called with 1 argument'); +assert.sameValue(args[0], 42, 'prototype `set` called with 42'); +assert.sameValue(_this, target, 'prototype `set` called with target as `this`'); +assert.sameValue(count, 1, 'prototype `set` called once'); diff --git a/test/built-ins/Reflect/set/creates-a-data-descriptor.js b/test/built-ins/Reflect/set/creates-a-data-descriptor.js new file mode 100644 index 0000000000..6e6daa9607 --- /dev/null +++ b/test/built-ins/Reflect/set/creates-a-data-descriptor.js @@ -0,0 +1,78 @@ +// 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.13 +description: > + Creates a property data descriptor. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 4. If ownDesc is undefined, then + a. Let parent be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(parent). + c. If parent is not null, then + i. Return parent.[[Set]](P, V, Receiver). + d. Else, + ii. Let ownDesc be the PropertyDescriptor{[[Value]]: undefined, + [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true}. + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + b. If Type(Receiver) is not Object, return false. + c. Let existingDescriptor be Receiver.[[GetOwnProperty]](P). + d. ReturnIfAbrupt(existingDescriptor). + e. If existingDescriptor is not undefined, then + i. If IsAccessorDescriptor(existingDescriptor) is true, return false. + ii. If existingDescriptor.[[Writable]] is false, return false. + iii. Let valueDesc be the PropertyDescriptor{[[Value]]: V}. + iv. Return Receiver.[[DefineOwnProperty]](P, valueDesc). + f. Else Receiver does not currently have a property P, + i. Return CreateDataProperty(Receiver, P, V). + 6. Assert: IsAccessorDescriptor(ownDesc) is true. + 7. Let setter be ownDesc.[[Set]]. + 8. If setter is undefined, return false. + ... + 11. Return true. +includes: [propertyHelper.js] +---*/ + +var o1 = {}; +var result = Reflect.set(o1, 'p', 42); +assert.sameValue(result, true, 'returns true on a successful setting'); +var desc = Object.getOwnPropertyDescriptor(o1, 'p'); +assert.sameValue( + desc.value, 42, + 'sets a data descriptor to set a new property' +); +verifyWritable(o1, 'p'); +verifyEnumerable(o1, 'p'); +verifyConfigurable(o1, 'p'); + +var o2 = {}; +var receiver = {}; +result = Reflect.set(o2, 'p', 43, receiver); +assert.sameValue( + result, true, + 'returns true on a successful setting with a receiver' +); +desc = Object.getOwnPropertyDescriptor(o2, 'p'); +assert.sameValue( + desc, undefined, + 'does not set a data descriptor on target if receiver is given' +); +desc = Object.getOwnPropertyDescriptor(receiver, 'p'); +assert.sameValue( + desc.value, 43, + 'sets a data descriptor on the receiver object to set a new property' +); +verifyWritable(receiver, 'p'); +verifyEnumerable(receiver, 'p'); +verifyConfigurable(receiver, 'p'); + diff --git a/test/built-ins/Reflect/set/different-property-descriptors.js b/test/built-ins/Reflect/set/different-property-descriptors.js new file mode 100644 index 0000000000..3c51b72d1f --- /dev/null +++ b/test/built-ins/Reflect/set/different-property-descriptors.js @@ -0,0 +1,65 @@ +// 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.13 +description: > + Return false if target property turns to a data descriptor and receiver + property is an accessor descriptor. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 4. If ownDesc is undefined, then + a. Let parent be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(parent). + c. If parent is not null, then + i. Return parent.[[Set]](P, V, Receiver). + d. Else, + ii. Let ownDesc be the PropertyDescriptor{[[Value]]: undefined, + [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true}. + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + b. If Type(Receiver) is not Object, return false. + c. Let existingDescriptor be Receiver.[[GetOwnProperty]](P). + d. ReturnIfAbrupt(existingDescriptor). + e. If existingDescriptor is not undefined, then + i. If IsAccessorDescriptor(existingDescriptor) is true, return false. + ... +---*/ + +var receiver = {}; +var fn = function() {}; +Object.defineProperty(receiver, 'p', { + set: fn +}); + +var o1 = {}; +var result = Reflect.set(o1, 'p', 42, receiver); +assert.sameValue( + result, false, + 'target has no own `p` and receiver.p has an accessor descriptor' +); +assert.sameValue( + Object.getOwnPropertyDescriptor(receiver, 'p').set, fn, + 'receiver.p is not changed' +); +assert.sameValue(o1.hasOwnProperty('p'), false, 'target.p is not set'); + +var o2 = {p: 43}; +result = Reflect.set(o2, 'p', 42, receiver); +assert.sameValue( + result, false, + 'target.p has a data descriptor and receiver.p has an accessor descriptor' +); +assert.sameValue( + Object.getOwnPropertyDescriptor(receiver, 'p').set, fn, + 'receiver.p is not changed' +); +assert.sameValue(o2.p, 43, 'target.p is not changed'); diff --git a/test/built-ins/Reflect/set/length.js b/test/built-ins/Reflect/set/length.js new file mode 100644 index 0000000000..ff223f36cd --- /dev/null +++ b/test/built-ins/Reflect/set/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.13 +description: > + Reflect.set.length value and property descriptor +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + The length property of the set function is 3. +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Reflect.set.length, 3, + 'The value of `Reflect.set.length` is `3`' +); + +verifyNotEnumerable(Reflect.set, 'length'); +verifyNotWritable(Reflect.set, 'length'); +verifyConfigurable(Reflect.set, 'length'); diff --git a/test/built-ins/Reflect/set/name.js b/test/built-ins/Reflect/set/name.js new file mode 100644 index 0000000000..5dd7b46fe9 --- /dev/null +++ b/test/built-ins/Reflect/set/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.13 +description: > + Reflect.set.name value and property descriptor +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Reflect.set.name, 'set', + 'The value of `Reflect.set.name` is `"set"`' +); + +verifyNotEnumerable(Reflect.set, 'name'); +verifyNotWritable(Reflect.set, 'name'); +verifyConfigurable(Reflect.set, 'name'); diff --git a/test/built-ins/Reflect/set/receiver-is-not-object.js b/test/built-ins/Reflect/set/receiver-is-not-object.js new file mode 100644 index 0000000000..a8fbc95a44 --- /dev/null +++ b/test/built-ins/Reflect/set/receiver-is-not-object.js @@ -0,0 +1,41 @@ +// 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.13 +description: > + Return false if receiver is not an object. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 4. If ownDesc is undefined, then + a. Let parent be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(parent). + c. If parent is not null, then + i. Return parent.[[Set]](P, V, Receiver). + d. Else, + ii. Let ownDesc be the PropertyDescriptor{[[Value]]: undefined, + [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true}. + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + b. If Type(Receiver) is not Object, return false. + ... +---*/ + +var o1 = {p: 42}; +var receiver = 'receiver is a string'; +var result = Reflect.set(o1, 'p', 43, receiver); + +assert.sameValue(result, false, 'returns false'); +assert.sameValue(o1.p, 42, 'does not set a value'); +assert.sameValue( + receiver.hasOwnProperty('p'), false, + 'does not set a new property on receiver if it is not an object' +); diff --git a/test/built-ins/Reflect/set/return-abrupt-from-property-key.js b/test/built-ins/Reflect/set/return-abrupt-from-property-key.js new file mode 100644 index 0000000000..b11c29c034 --- /dev/null +++ b/test/built-ins/Reflect/set/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.13 +description: > + Return abrupt from ToPropertyKey(propertyKey) +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + 3. ReturnIfAbrupt(key). + ... +---*/ + +var p = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + Reflect.set({}, p); +}); diff --git a/test/built-ins/Reflect/set/return-abrupt-from-result.js b/test/built-ins/Reflect/set/return-abrupt-from-result.js new file mode 100644 index 0000000000..739c5ab5b3 --- /dev/null +++ b/test/built-ins/Reflect/set/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.13 +description: > + Return abrupt result from get a property value. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 5. Return target.[[Set]](key, V, receiver). +---*/ + +var o1 = {}; +Object.defineProperty(o1, 'p1', { + set: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.set(o1, 'p1', 42); +}); + +// Abrupt from the prototype property +var o2 = Object.create(o1); +assert.throws(Test262Error, function() { + Reflect.set(o2, 'p1', 42); +}); diff --git a/test/built-ins/Reflect/set/return-false-if-receiver-is-not-writable.js b/test/built-ins/Reflect/set/return-false-if-receiver-is-not-writable.js new file mode 100644 index 0000000000..e0c9a47036 --- /dev/null +++ b/test/built-ins/Reflect/set/return-false-if-receiver-is-not-writable.js @@ -0,0 +1,31 @@ +// 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.13 +description: > + Return false if receiver is not writable. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + ... +---*/ + +var o1 = {}; + +Object.defineProperty(o1, 'p', { + writable: false, + value: 42 +}); +var result = Reflect.set(o1, 'p', 43); +assert.sameValue(result, false, 'returns false'); +assert.sameValue(o1.p, 42, 'does not set a new value'); diff --git a/test/built-ins/Reflect/set/return-false-if-target-is-not-writable.js b/test/built-ins/Reflect/set/return-false-if-target-is-not-writable.js new file mode 100644 index 0000000000..aec90ec215 --- /dev/null +++ b/test/built-ins/Reflect/set/return-false-if-target-is-not-writable.js @@ -0,0 +1,41 @@ +// 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.13 +description: > + Return false if target is not writable. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + b. If Type(Receiver) is not Object, return false. + c. Let existingDescriptor be Receiver.[[GetOwnProperty]](P). + d. ReturnIfAbrupt(existingDescriptor). + e. If existingDescriptor is not undefined, then + i. If IsAccessorDescriptor(existingDescriptor) is true, return false. + ii. If existingDescriptor.[[Writable]] is false, return false. + ... +---*/ + +var o1 = {}; +var receiver = {}; +Object.defineProperty(receiver, 'p', { + writable: false, + value: 42 +}); +var result = Reflect.set(o1, 'p', 43, receiver); +assert.sameValue(result, false, 'returns false'); +assert.sameValue(receiver.p, 42, 'does not set a new value on receiver'); +assert.sameValue( + o1.hasOwnProperty('p'), false, + 'does not set a new value on target' +); diff --git a/test/built-ins/Reflect/set/set-value-on-accessor-descriptor-with-receiver.js b/test/built-ins/Reflect/set/set-value-on-accessor-descriptor-with-receiver.js new file mode 100644 index 0000000000..3d2cd7b0ab --- /dev/null +++ b/test/built-ins/Reflect/set/set-value-on-accessor-descriptor-with-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.13 +description: > + Set value on an accessor descriptor property with receiver as `this`. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 6. Assert: IsAccessorDescriptor(ownDesc) is true. + 7. Let setter be ownDesc.[[Set]]. + 8. If setter is undefined, return false. + 9. Let setterResult be Call(setter, Receiver, «V»). + 10. ReturnIfAbrupt(setterResult). + 11. Return true. +---*/ + +var args; +var count = 0 +var o1 = {}; +var receiver = {}; +var _receiver; +Object.defineProperty(o1, 'p', { + set: function(a) { + count++; + args = arguments; + _receiver = this; + return false; + } +}); + +var result = Reflect.set(o1, 'p', 42, receiver); +assert.sameValue( + result, true, + 'returns true if target.p has an accessor descriptor' +); +assert.sameValue(args.length, 1, 'target.p set is called with 1 argument'); +assert.sameValue(args[0], 42, 'target.p set is called with V'); +assert.sameValue(count, 1, 'target.p set is called once'); +assert.sameValue( + _receiver, receiver, + 'target.p set is called with receiver as `this`' +); diff --git a/test/built-ins/Reflect/set/set-value-on-accessor-descriptor.js b/test/built-ins/Reflect/set/set-value-on-accessor-descriptor.js new file mode 100644 index 0000000000..dff846d1e5 --- /dev/null +++ b/test/built-ins/Reflect/set/set-value-on-accessor-descriptor.js @@ -0,0 +1,45 @@ +// 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.13 +description: > + Set value on an accessor descriptor property. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 6. Assert: IsAccessorDescriptor(ownDesc) is true. + 7. Let setter be ownDesc.[[Set]]. + 8. If setter is undefined, return false. + 9. Let setterResult be Call(setter, Receiver, «V»). + 10. ReturnIfAbrupt(setterResult). + 11. Return true. +---*/ + +var args; +var count = 0 +var o1 = {}; +Object.defineProperty(o1, 'p', { + set: function(a) { + count++; + args = arguments; + return false; + } +}); + +var result = Reflect.set(o1, 'p', 42); +assert.sameValue( + result, true, + 'returns true if target.p has an accessor descriptor' +); +assert.sameValue(args.length, 1, 'target.p set is called with 1 argument'); +assert.sameValue(args[0], 42, 'target.p set is called with V'); +assert.sameValue(count, 1, 'target.p set is called once'); + diff --git a/test/built-ins/Reflect/set/set-value-on-data-descriptor.js b/test/built-ins/Reflect/set/set-value-on-data-descriptor.js new file mode 100644 index 0000000000..0a472a9efa --- /dev/null +++ b/test/built-ins/Reflect/set/set-value-on-data-descriptor.js @@ -0,0 +1,46 @@ +// 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.13 +description: > + Sets the new value. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + ... + 4. If receiver is not present, then + a. Let receiver be target. + 5. Return target.[[Set]](key, V, receiver). + + 9.1.9 [[Set]] ( P, V, Receiver) + + ... + 5. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + b. If Type(Receiver) is not Object, return false. + c. Let existingDescriptor be Receiver.[[GetOwnProperty]](P). + d. ReturnIfAbrupt(existingDescriptor). + e. If existingDescriptor is not undefined, then + i. If IsAccessorDescriptor(existingDescriptor) is true, return false. + ii. If existingDescriptor.[[Writable]] is false, return false. + iii. Let valueDesc be the PropertyDescriptor{[[Value]]: V}. + iv. Return Receiver.[[DefineOwnProperty]](P, valueDesc). + f. Else Receiver does not currently have a property P, + i. Return CreateDataProperty(Receiver, P, V). + ... +---*/ + +var o1 = {p: 43}; +var result = Reflect.set(o1, 'p', 42); +assert.sameValue(result, true, 'returns true on a successful setting'); +assert.sameValue( + o1.p, 42, + 'sets the new value' +); + +var o2 = {p: 43}; +var receiver = {p: 44}; +var result = Reflect.set(o2, 'p', 42, receiver); +assert.sameValue(result, true, 'returns true on a successful setting'); +assert.sameValue(o2.p, 43, 'with a receiver, does not set a value on target'); +assert.sameValue(receiver.p, 42, 'sets the new value on the receiver'); diff --git a/test/built-ins/Reflect/set/set.js b/test/built-ins/Reflect/set/set.js new file mode 100644 index 0000000000..8a267ae721 --- /dev/null +++ b/test/built-ins/Reflect/set/set.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.13 +description: > + Reflect.set is configurable, writable and not enumerable. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Reflect, 'set'); +verifyWritable(Reflect, 'set'); +verifyConfigurable(Reflect, 'set'); diff --git a/test/built-ins/Reflect/set/symbol-property.js b/test/built-ins/Reflect/set/symbol-property.js new file mode 100644 index 0000000000..f0f0bada79 --- /dev/null +++ b/test/built-ins/Reflect/set/symbol-property.js @@ -0,0 +1,36 @@ +// 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.13 +description: > + Sets the new value. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , 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 o1 = {}; +var s = Symbol('1'); +var result = Reflect.set(o1, s, 42); +assert.sameValue(result, true, 'returns true on a successful setting'); +assert.sameValue(o1[s], 42, 'sets the new value'); + +var o2 = {}; +o2[s] = 43; +var receiver = {}; +receiver[s] = 44; +var result = Reflect.set(o2, s, 42, receiver); +assert.sameValue(result, true, 'returns true on a successful setting'); +assert.sameValue(o2[s], 43, 'with a receiver, does not set a value on target'); +assert.sameValue(receiver[s], 42, 'sets the new value on the receiver'); diff --git a/test/built-ins/Reflect/set/target-is-not-object-throws.js b/test/built-ins/Reflect/set/target-is-not-object-throws.js new file mode 100644 index 0000000000..cf1be9a438 --- /dev/null +++ b/test/built-ins/Reflect/set/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.13 +description: > + Throws a TypeError if target is not an Object. +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + Reflect.set(1, 'p', 42); +}); + +assert.throws(TypeError, function() { + Reflect.set(null, 'p', 42); +}); + +assert.throws(TypeError, function() { + Reflect.set(undefined, 'p', 42); +}); + +assert.throws(TypeError, function() { + Reflect.set('', 'p', 42); +}); diff --git a/test/built-ins/Reflect/set/target-is-symbol-throws.js b/test/built-ins/Reflect/set/target-is-symbol-throws.js new file mode 100644 index 0000000000..aa03763854 --- /dev/null +++ b/test/built-ins/Reflect/set/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.13 +description: > + Throws a TypeError if target is a Symbol +info: > + 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.set(Symbol(1), 'p', 42); +});