All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rhino1.7.6.testsrc.doctests.object.defineproperties.doctest Maven / Gradle / Ivy

Go to download

Rhino is an open-source implementation of JavaScript written entirely in Java. It is typically embedded into Java applications to provide scripting to end users.

There is a newer version: 1.7.15
Show newest version
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

js> load('testsrc/doctests/util.js');

js> Object.defineProperties
function defineProperties() { [native code for Object.defineProperties, arity=2] }

js> expectTypeError(function() { Object.defineProperties() });
js> expectTypeError(function() { Object.defineProperties({}) });
js> [undefined, null, true, 1, 'hello'].forEach(function(value) { 
  >   expectTypeError(function() { Object.defineProperties(value, {}) }) 
  > })

js> Object.defineProperties({}, {p: {value:1}}).p
1

js> var obj = Object.defineProperties({}, {a: {value:1}, b: {value:2}});
js> [obj.a, obj.b].toSource();
[1, 2]

js> Object.defineProperties({}, {'wierd name': {value:1}})['wierd name']
1

js> Object.defineProperties({}, {}).toSource()
({})

js> var obj = {a:1};
js> var obj = Object.defineProperties(obj, {a:{value:2}, b:{value:3}});
js> [obj.a, obj.b].toSource()
[2, 3]

js> expectTypeError(function() { Object.defineProperties({}, {a: null}) })
js> expectTypeError(function() { Object.defineProperties({}, {a: 1}) })
js> expectTypeError(function() { Object.defineProperties({}, {a: {get: 1}}) })

js> var obj = {a:1}
js> expectTypeError(function() { 
  >   obj = Object.defineProperties(obj, {b: {value:1}, c:1});
  > });
js> obj.b
js>

js> Object.defineProperties({}, {'0.0': {value:1}, 0: {value:2}})['0']
2




© 2015 - 2024 Weber Informatics LLC | Privacy Policy