15c838251403b0be9a882540f1922577abba4c872ager@chromium.org// Copyright 2010 the V8 project authors. All rights reserved.
25c838251403b0be9a882540f1922577abba4c872ager@chromium.org// Redistribution and use in source and binary forms, with or without
35c838251403b0be9a882540f1922577abba4c872ager@chromium.org// modification, are permitted provided that the following conditions are
45c838251403b0be9a882540f1922577abba4c872ager@chromium.org// met:
55c838251403b0be9a882540f1922577abba4c872ager@chromium.org//
65c838251403b0be9a882540f1922577abba4c872ager@chromium.org//     * Redistributions of source code must retain the above copyright
75c838251403b0be9a882540f1922577abba4c872ager@chromium.org//       notice, this list of conditions and the following disclaimer.
85c838251403b0be9a882540f1922577abba4c872ager@chromium.org//     * Redistributions in binary form must reproduce the above
95c838251403b0be9a882540f1922577abba4c872ager@chromium.org//       copyright notice, this list of conditions and the following
105c838251403b0be9a882540f1922577abba4c872ager@chromium.org//       disclaimer in the documentation and/or other materials provided
115c838251403b0be9a882540f1922577abba4c872ager@chromium.org//       with the distribution.
125c838251403b0be9a882540f1922577abba4c872ager@chromium.org//     * Neither the name of Google Inc. nor the names of its
135c838251403b0be9a882540f1922577abba4c872ager@chromium.org//       contributors may be used to endorse or promote products derived
145c838251403b0be9a882540f1922577abba4c872ager@chromium.org//       from this software without specific prior written permission.
155c838251403b0be9a882540f1922577abba4c872ager@chromium.org//
165c838251403b0be9a882540f1922577abba4c872ager@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175c838251403b0be9a882540f1922577abba4c872ager@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185c838251403b0be9a882540f1922577abba4c872ager@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195c838251403b0be9a882540f1922577abba4c872ager@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205c838251403b0be9a882540f1922577abba4c872ager@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215c838251403b0be9a882540f1922577abba4c872ager@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225c838251403b0be9a882540f1922577abba4c872ager@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235c838251403b0be9a882540f1922577abba4c872ager@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245c838251403b0be9a882540f1922577abba4c872ager@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255c838251403b0be9a882540f1922577abba4c872ager@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265c838251403b0be9a882540f1922577abba4c872ager@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275c838251403b0be9a882540f1922577abba4c872ager@chromium.org
285c838251403b0be9a882540f1922577abba4c872ager@chromium.org// Tests the Object.defineProperties method - ES 15.2.3.7
291805e21b0aece8c05f4960a5c0751c4463557891fschneider@chromium.org// Note that the internal DefineOwnProperty method is tested through
305c838251403b0be9a882540f1922577abba4c872ager@chromium.org// object-define-property.js, this file only contains tests specific for
315c838251403b0be9a882540f1922577abba4c872ager@chromium.org// Object.defineProperties. Also note that object-create.js contains
325c838251403b0be9a882540f1922577abba4c872ager@chromium.org// a range of indirect tests on this method since Object.create uses
335c838251403b0be9a882540f1922577abba4c872ager@chromium.org// Object.defineProperties as a step in setting up the object.
345c838251403b0be9a882540f1922577abba4c872ager@chromium.org
355c838251403b0be9a882540f1922577abba4c872ager@chromium.org// Try defining with null as descriptor:
365c838251403b0be9a882540f1922577abba4c872ager@chromium.orgtry {
375c838251403b0be9a882540f1922577abba4c872ager@chromium.org  Object.defineProperties({}, null);
385c838251403b0be9a882540f1922577abba4c872ager@chromium.org} catch(e) {
395c838251403b0be9a882540f1922577abba4c872ager@chromium.org  assertTrue(/null to object/.test(e));
405c838251403b0be9a882540f1922577abba4c872ager@chromium.org}
415c838251403b0be9a882540f1922577abba4c872ager@chromium.org
425c838251403b0be9a882540f1922577abba4c872ager@chromium.org// Try defining with null as object
435c838251403b0be9a882540f1922577abba4c872ager@chromium.orgtry {
445c838251403b0be9a882540f1922577abba4c872ager@chromium.org  Object.defineProperties(null, {});
455c838251403b0be9a882540f1922577abba4c872ager@chromium.org} catch(e) {
465c838251403b0be9a882540f1922577abba4c872ager@chromium.org  assertTrue(/called on non-object/.test(e));
475c838251403b0be9a882540f1922577abba4c872ager@chromium.org}
485c838251403b0be9a882540f1922577abba4c872ager@chromium.org
495c838251403b0be9a882540f1922577abba4c872ager@chromium.org
505c838251403b0be9a882540f1922577abba4c872ager@chromium.orgvar desc = {foo: {value: 10}, bar: {get: function() {return 42; }}};
515c838251403b0be9a882540f1922577abba4c872ager@chromium.orgvar obj = {};
525c838251403b0be9a882540f1922577abba4c872ager@chromium.org// Check that we actually get the object back as returnvalue
535c838251403b0be9a882540f1922577abba4c872ager@chromium.orgvar x = Object.defineProperties(obj, desc);
545c838251403b0be9a882540f1922577abba4c872ager@chromium.org
555c838251403b0be9a882540f1922577abba4c872ager@chromium.orgassertEquals(x.foo, 10);
565c838251403b0be9a882540f1922577abba4c872ager@chromium.orgassertEquals(x.bar, 42);
57394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
58394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
59394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Make sure that all property descriptors are calculated before any
60394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// modifications are done.
61394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
62394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comvar object = {};
63394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
64394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comassertThrows(function() {
65394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    Object.defineProperties(object, {
66394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com      foo: { value: 1 },
67394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com      bar: { value: 2, get: function() { return 3; } }
68394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    });
69394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  }, TypeError);
70394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
71394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comassertEquals(undefined, object.foo);
72394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comassertEquals(undefined, object.bar);
73