1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Copyright 2014 the V8 project authors. All rights reserved. 16// Use of this source code is governed by a BSD-style license that can be 17// found in the LICENSE file. 18 19var object = {}; 20Reflect.set (object, 'property', 'batcat'); 21 22assert (object.property === 'batcat'); 23 24var array = ['cat', 'cat', 'cat']; 25Reflect.set (array, 2, 'bat'); 26 27assert (array[2] === 'bat'); 28 29assert (3 === Reflect.set.length); 30 31try { 32 Reflect.set (); 33 assert (false); 34} catch (e) { 35 assert (e instanceof TypeError); 36} 37 38try { 39 Reflect.set (42, 'bat'); 40 assert (false); 41} catch (e) { 42 assert (e instanceof TypeError); 43} 44 45try { 46 Reflect.set (null, 'bat'); 47 assert (false); 48} catch (e) { 49 assert (e instanceof TypeError); 50} 51 52var target = {}; 53var a = { [Symbol.toPrimitive]: function () { return 'bat' } }; 54var b = { [Symbol.toPrimitive]: function () { throw 'cat' } }; 55assert (Reflect.set (target, a, 42) === true); 56assert (42 === target.bat); 57 58try { 59 Reflect.set (null, 'bat'); 60 assert (false); 61} catch (e) { 62 assert (e instanceof TypeError); 63} 64 65var y = []; 66Object.defineProperty (y, 0, {value: 42, configurable: false}); 67assert (Reflect.set (y, 'length', 0) === false); 68assert (Reflect.set (y, 'length', 2) === true); 69