Mozilla/mozilla/js/rhino/testsrc/doctests/object.keys.doctest
nboyd%atg.com a45aee6384 Implement new Object constructor methods from ecmascript 5
Fixes bug 489329
Patch by Raphael Speyer


git-svn-id: svn://10.0.0.236/trunk@257293 18797224-902f-48f8-a5cc-f745e15eee43
2009-05-27 16:47:16 +00:00

56 lines
1.3 KiB
Plaintext

js> load('testsrc/doctests/util.js');
js> Object.keys;
function keys() { [native code for Object.keys, arity=1] }
js> expectTypeError(function() { Object.keys() })
js> [undefined, null, true, 1, 'hello'].forEach(function(value) {
> expectTypeError(function() { Object.keys(value) })
> })
js> Object.keys({}).toSource();
[]
js> Object.keys({a:2}).toSource();
["a"]
js> Object.keys({a:1, b:2}).toSource();
["a", "b"]
js> Object.keys({'a.b':1, 'c d':2}).toSource();
["a.b", "c d"]
js> Object.keys([]).toSource();
[]
js> Object.keys(['a', 'b', 'c']).toSource();
["0", "1", "2"]
js> function UserDefined() { this.a = 1; this.b = 2 };
js> var obj = new UserDefined()
js> Object.keys(obj).toSource()
["a", "b"]
js> UserDefined.prototype.c = 3;
3
js> Object.keys(obj).toSource()
["a", "b"]
js> // test properties of result are enumerable
js> for (var p in Object.keys({a:2, b:3})) print(p)
0
1
js> // test that properties of result are writable
js> var k = Object.keys({a:2, b:3});
js> k[1] = 'c'; k.toSource();
["a", "c"]
js> // test that properties of result are configurable
js> var k = Object.keys({a:2, b:3})
js> delete k[1];
true
js> k
a,
js> // TODO test that the attributes of the properties can be changed
js> var k = Object.keys({ a:1, 3:2 });
js> typeof k[1];
string