rhino1.7.7.testsrc.doctests.object.getownpropertydescriptor.doctest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rhino Show documentation
Show all versions of rhino Show documentation
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.
// 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.getOwnPropertyDescriptor;
function getOwnPropertyDescriptor() { [native code for Object.getOwnPropertyDescriptor, arity=2] }
js> expectTypeError(function() { Object.getOwnPropertyDescriptor() })
js> var desc = Object.getOwnPropertyDescriptor({undefined:3});
js> desc.value
3
js> [undefined, null, true, 1, 'hello'].forEach(function(value) {
> expectTypeError(function() { Object.getOwnPropertyDescriptor(value, 'p') })
> })
js> Object.getOwnPropertyDescriptor({}, 'p') === undefined;
true
js> var desc = Object.getOwnPropertyDescriptor({p:1}, 'p');
js> desc.value
1
js> desc.writable
true
js> desc.enumerable
true
js> desc.configurable
true
js> var desc = Object.getOwnPropertyDescriptor({ get p() {}, set p() {} }, 'p');
js> desc.value === undefined;
true
js> desc.writable === undefined;
true
js> desc.get.toSource()
(function () {})
js> desc.set.toSource()
(function () {})
js> desc.enumerable
true
js> desc.configurable
true
js> desc.__proto__ === Object.prototype
true
js> desc.__parent__;
[object global]
js> var func = function(){}
js> func.a = 1; Object.getOwnPropertyDescriptor(func, 'a').toSource()
({value:1, writable:true, enumerable:true, configurable:true})
js> Object.getOwnPropertyDescriptor({undefined: 1}, undefined).toSource()
({value:1, writable:true, enumerable:true, configurable:true})
js> Object.getOwnPropertyDescriptor({0:1}, 0).toSource()
({value:1, writable:true, enumerable:true, configurable:true})
js> Object.getOwnPropertyDescriptor([1], 0).toSource()
({value:1, writable:true, enumerable:true, configurable:true})
js> Object.getOwnPropertyDescriptor([1], '0').toSource()
({value:1, writable:true, enumerable:true, configurable:true})
js> Object.getOwnPropertyDescriptor([1], 1) === undefined
true
js> Object.getOwnPropertyDescriptor([1], -1) === undefined
true
js> var arr = [];
js> arr.a = 1;
1
js> Object.getOwnPropertyDescriptor(arr, 'a').toSource()
({value:1, writable:true, enumerable:true, configurable:true})
js> var arr = Object.defineProperty([], 'a', {value:1, writable:false,})
js> var desc = Object.getOwnPropertyDescriptor(arr, 'a'); ([desc.value, desc.writable]).toSource()
[1, false]
© 2015 - 2024 Weber Informatics LLC | Privacy Policy