Debian Codegraph @

rhino/testsrc/doctests/object.defineproperties.doctest

raw
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 js> load('testsrc/doctests/util.js');
6
7 js> Object.defineProperties
8 function defineProperties() { [native code for Object.defineProperties, arity=2] }
9
10 js> expectTypeError(function() { Object.defineProperties() });
11 js> expectTypeError(function() { Object.defineProperties({}) });
12 js> [undefined, null, true, 1, 'hello'].forEach(function(value) {
13 > expectTypeError(function() { Object.defineProperties(value, {}) })
14 > })
15
16 js> Object.defineProperties({}, {p: {value:1}}).p
17 1
18
19 js> var obj = Object.defineProperties({}, {a: {value:1}, b: {value:2}});
20 js> [obj.a, obj.b].toSource();
21 [1, 2]
22
23 js> Object.defineProperties({}, {'wierd name': {value:1}})['wierd name']
24 1
25
26 js> Object.defineProperties({}, {}).toSource()
27 ({})
28
29 js> var obj = {a:1};
30 js> var obj = Object.defineProperties(obj, {a:{value:2}, b:{value:3}});
31 js> [obj.a, obj.b].toSource()
32 [2, 3]
33
34 js> expectTypeError(function() { Object.defineProperties({}, {a: null}) })
35 js> expectTypeError(function() { Object.defineProperties({}, {a: 1}) })
36 js> expectTypeError(function() { Object.defineProperties({}, {a: {get: 1}}) })
37
38 js> var obj = {a:1}
39 js> expectTypeError(function() {
40 > obj = Object.defineProperties(obj, {b: {value:1}, c:1});
41 > });
42 js> obj.b
43 js>
44
45 js> Object.defineProperties({}, {'0.0': {value:1}, 0: {value:2}})['0']
46 2