| Index: test/mjsunit/harmony/reflect-own-keys.js
|
| diff --git a/test/mjsunit/object-get-own-property-names.js b/test/mjsunit/harmony/reflect-own-keys.js
|
| similarity index 51%
|
| copy from test/mjsunit/object-get-own-property-names.js
|
| copy to test/mjsunit/harmony/reflect-own-keys.js
|
| index aee6585680b8767d40963e0da52f762b9a0f6640..6f5dacf1c83f9df6dcd4507c5af7aacf152e0537 100644
|
| --- a/test/mjsunit/object-get-own-property-names.js
|
| +++ b/test/mjsunit/harmony/reflect-own-keys.js
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2009 the V8 project authors. All rights reserved.
|
| +// Copyright 2015 the V8 project authors. All rights reserved.
|
| // Redistribution and use in source and binary forms, with or without
|
| // modification, are permitted provided that the following conditions are
|
| // met:
|
| @@ -25,82 +25,69 @@
|
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| -// Test ES5 section 15.2.3.4 Object.getOwnPropertyNames.
|
| +// This is adapted from mjsunit/object-get-own-property-names.js.
|
| +
|
| +// Flags: --harmony-reflect
|
| +
|
|
|
| // Check simple cases.
|
| var obj = { a: 1, b: 2};
|
| -var propertyNames = Object.getOwnPropertyNames(obj);
|
| -propertyNames.sort();
|
| -assertEquals(2, propertyNames.length);
|
| -assertEquals("a", propertyNames[0]);
|
| -assertEquals("b", propertyNames[1]);
|
| +var keys = Reflect.ownKeys(obj);
|
| +assertEquals(2, keys.length);
|
| +assertEquals("a", keys[0]);
|
| +assertEquals("b", keys[1]);
|
|
|
| var obj = { a: function(){}, b: function(){} };
|
| -var propertyNames = Object.getOwnPropertyNames(obj);
|
| -propertyNames.sort();
|
| -assertEquals(2, propertyNames.length);
|
| -assertEquals("a", propertyNames[0]);
|
| -assertEquals("b", propertyNames[1]);
|
| +var keys = Reflect.ownKeys(obj);
|
| +assertEquals(2, keys.length);
|
| +assertEquals("a", keys[0]);
|
| +assertEquals("b", keys[1]);
|
|
|
| // Check slow case
|
| var obj = { a: 1, b: 2, c: 3 };
|
| delete obj.b;
|
| -var propertyNames = Object.getOwnPropertyNames(obj)
|
| -propertyNames.sort();
|
| -assertEquals(2, propertyNames.length);
|
| -assertEquals("a", propertyNames[0]);
|
| -assertEquals("c", propertyNames[1]);
|
| +var keys = Reflect.ownKeys(obj)
|
| +assertEquals(2, keys.length);
|
| +assertEquals("a", keys[0]);
|
| +assertEquals("c", keys[1]);
|
|
|
| // Check that non-enumerable properties are being returned.
|
| -var propertyNames = Object.getOwnPropertyNames([1, 2]);
|
| -propertyNames.sort();
|
| -assertEquals(3, propertyNames.length);
|
| -assertEquals("0", propertyNames[0]);
|
| -assertEquals("1", propertyNames[1]);
|
| -assertEquals("string", typeof propertyNames[0]);
|
| -assertEquals("string", typeof propertyNames[1]);
|
| -assertEquals("length", propertyNames[2]);
|
| +var keys = Reflect.ownKeys([1, 2]);
|
| +assertEquals(3, keys.length);
|
| +assertEquals("0", keys[0]);
|
| +assertEquals("1", keys[1]);
|
| +assertEquals("string", typeof keys[0]);
|
| +assertEquals("string", typeof keys[1]);
|
| +assertEquals("length", keys[2]);
|
|
|
| // Check that no proto properties are returned.
|
| var obj = { foo: "foo" };
|
| obj.__proto__ = { bar: "bar" };
|
| -propertyNames = Object.getOwnPropertyNames(obj);
|
| -propertyNames.sort();
|
| -assertEquals(1, propertyNames.length);
|
| -assertEquals("foo", propertyNames[0]);
|
| +keys = Reflect.ownKeys(obj);
|
| +assertEquals(1, keys.length);
|
| +assertEquals("foo", keys[0]);
|
|
|
| // Check that getter properties are returned.
|
| var obj = {};
|
| obj.__defineGetter__("getter", function() {});
|
| -propertyNames = Object.getOwnPropertyNames(obj);
|
| -propertyNames.sort();
|
| -assertEquals(1, propertyNames.length);
|
| -assertEquals("getter", propertyNames[0]);
|
| +keys = Reflect.ownKeys(obj);
|
| +assertEquals(1, keys.length);
|
| +assertEquals("getter", keys[0]);
|
|
|
| // Check that implementation does not access Array.prototype.
|
| var savedConcat = Array.prototype.concat;
|
| Array.prototype.concat = function() { return []; }
|
| -propertyNames = Object.getOwnPropertyNames({0: 'foo', bar: 'baz'});
|
| -assertEquals(2, propertyNames.length);
|
| -assertEquals('0', propertyNames[0]);
|
| -assertEquals('bar', propertyNames[1]);
|
| -assertSame(Array.prototype, propertyNames.__proto__);
|
| +keys = Reflect.ownKeys({0: 'foo', bar: 'baz'});
|
| +assertEquals(2, keys.length);
|
| +assertEquals('0', keys[0]);
|
| +assertEquals('bar', keys[1]);
|
| +assertSame(Array.prototype, keys.__proto__);
|
| Array.prototype.concat = savedConcat;
|
|
|
| -assertEquals(Object.getOwnPropertyNames(4), []);
|
| -assertEquals(Object.getOwnPropertyNames("foo"), ["0", "1", "2", "length"]);
|
| -assertEquals(Object.getOwnPropertyNames(true), []);
|
| -
|
| -try {
|
| - Object.getOwnPropertyNames(undefined);
|
| - assertTrue(false);
|
| -} catch (e) {
|
| - assertTrue(/Cannot convert undefined or null to object/.test(e));
|
| -}
|
| +assertThrows(function() { Reflect.ownKeys(4) }, TypeError);
|
| +assertThrows(function() { Reflect.ownKeys("foo") }, TypeError);
|
| +assertThrows(function() { Reflect.ownKeys(true) }, TypeError);
|
|
|
| -try {
|
| - Object.getOwnPropertyNames(null);
|
| - assertTrue(false);
|
| -} catch (e) {
|
| - assertTrue(/Cannot convert undefined or null to object/.test(e));
|
| -}
|
| +assertEquals(Reflect.ownKeys(Object(4)), []);
|
| +assertEquals(Reflect.ownKeys(Object("foo")), ["0", "1", "2", "length"]);
|
| +assertEquals(Reflect.ownKeys(Object(true)), []);
|
|
|