1402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Copyright 2010 the V8 project authors. All rights reserved. 2402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Redistribution and use in source and binary forms, with or without 3402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// modification, are permitted provided that the following conditions are 4402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// met: 5402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// 6402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// * Redistributions of source code must retain the above copyright 7402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// notice, this list of conditions and the following disclaimer. 8402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// * Redistributions in binary form must reproduce the above 9402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// copyright notice, this list of conditions and the following 10402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// disclaimer in the documentation and/or other materials provided 11402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// with the distribution. 12402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// * Neither the name of Google Inc. nor the names of its 13402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// contributors may be used to endorse or promote products derived 14402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// from this software without specific prior written permission. 15402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// 16402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 28402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Tests the Object.defineProperties method - ES 15.2.3.7 29589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch// Note that the internal DefineOwnProperty method is tested through 30402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// object-define-property.js, this file only contains tests specific for 31402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Object.defineProperties. Also note that object-create.js contains 32402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// a range of indirect tests on this method since Object.create uses 33402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Object.defineProperties as a step in setting up the object. 34402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 35402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Try defining with null as descriptor: 36402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescutry { 37402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu Object.defineProperties({}, null); 38402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu} catch(e) { 39402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu assertTrue(/null to object/.test(e)); 40402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu} 41402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 42402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Try defining with null as object 43402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescutry { 44402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu Object.defineProperties(null, {}); 45402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu} catch(e) { 46402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu assertTrue(/called on non-object/.test(e)); 47402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu} 48402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 49402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 50402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescuvar desc = {foo: {value: 10}, bar: {get: function() {return 42; }}}; 51402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescuvar obj = {}; 52402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Check that we actually get the object back as returnvalue 53402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescuvar x = Object.defineProperties(obj, desc); 54402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 55402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals(x.foo, 10); 56402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals(x.bar, 42); 573ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 583ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 593ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Make sure that all property descriptors are calculated before any 603ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// modifications are done. 613ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 623ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochvar object = {}; 633ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 643ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertThrows(function() { 653ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch Object.defineProperties(object, { 663ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch foo: { value: 1 }, 673ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch bar: { value: 2, get: function() { return 3; } } 683ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch }); 693ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch }, TypeError); 703ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 713ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertEquals(undefined, object.foo); 723ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertEquals(undefined, object.bar); 73