Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Unified Diff: test/mjsunit/harmony/reflect-define-property.js

Issue 1421033002: [es6] Partially implement Reflect.defineProperty. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address a comment and rebase. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/harmony/reflect.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/reflect-define-property.js
diff --git a/test/mjsunit/object-define-property.js b/test/mjsunit/harmony/reflect-define-property.js
similarity index 80%
copy from test/mjsunit/object-define-property.js
copy to test/mjsunit/harmony/reflect-define-property.js
index 4c495c6824f5ca65d702173b791e56150f26b52b..afd3ff6595f7420a0063ef28192da4da4e4742cb 100644
--- a/test/mjsunit/object-define-property.js
+++ b/test/mjsunit/harmony/reflect-define-property.js
@@ -1,4 +1,4 @@
-// Copyright 2012 the V8 project authors. All rights reserved.
+// Copyright 2012-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,14 +25,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Tests the object.defineProperty method - ES 15.2.3.6
+// Tests the Reflect.defineProperty method - ES6 26.1.3
+// This is adapted from mjsunit/object-define-property.js.
+
+// Flags: --allow-natives-syntax --harmony-reflect
-// Flags: --allow-natives-syntax
// Check that an exception is thrown when null is passed as object.
var exception = false;
try {
- Object.defineProperty(null, null, null);
+ Reflect.defineProperty(null, null, null);
} catch (e) {
exception = true;
assertTrue(/called on non-object/.test(e));
@@ -42,7 +44,7 @@ assertTrue(exception);
// Check that an exception is thrown when undefined is passed as object.
exception = false;
try {
- Object.defineProperty(undefined, undefined, undefined);
+ Reflect.defineProperty(undefined, undefined, undefined);
} catch (e) {
exception = true;
assertTrue(/called on non-object/.test(e));
@@ -52,7 +54,7 @@ assertTrue(exception);
// Check that an exception is thrown when non-object is passed as object.
exception = false;
try {
- Object.defineProperty(0, "foo", undefined);
+ Reflect.defineProperty(0, "foo", undefined);
} catch (e) {
exception = true;
assertTrue(/called on non-object/.test(e));
@@ -112,16 +114,12 @@ var dataWritable = { value: 3000, writable: true};
// Check that we can't add property with undefined attributes.
-try {
- Object.defineProperty(obj1, "foo", undefined);
- assertTrue(false);
-} catch (e) {
- assertTrue(/must be an object/.test(e));
-}
+assertThrows(function() { Reflect.defineProperty(obj1, "foo", undefined) },
+ TypeError);
// Make sure that we can add a property with an empty descriptor and
// that it has the default descriptor values.
-Object.defineProperty(obj1, "foo", emptyDesc);
+assertTrue(Reflect.defineProperty(obj1, "foo", emptyDesc));
// foo should be undefined as it has no get, set or value
assertEquals(undefined, obj1.foo);
@@ -143,16 +141,12 @@ desc = Object.getOwnPropertyDescriptor(obj1, "bar");
assertEquals(desc, undefined);
// Make sure that foo can't be reset (as configurable is false).
-try {
- Object.defineProperty(obj1, "foo", accessorConfigurable);
-} catch (e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj1, "foo", accessorConfigurable));
// Accessor properties
-Object.defineProperty(obj1, "bar", accessorConfigurable);
+assertTrue(Reflect.defineProperty(obj1, "bar", accessorConfigurable));
desc = Object.getOwnPropertyDescriptor(obj1, "bar");
assertTrue(desc.configurable);
assertFalse(desc.enumerable);
@@ -167,7 +161,7 @@ assertEquals(2, val1);
assertEquals(2, obj1.bar);
// Redefine bar with non configurable test
-Object.defineProperty(obj1, "bar", accessorNoConfigurable);
+assertTrue(Reflect.defineProperty(obj1, "bar", accessorNoConfigurable));
desc = Object.getOwnPropertyDescriptor(obj1, "bar");
assertFalse(desc.configurable);
assertFalse(desc.enumerable);
@@ -184,23 +178,13 @@ assertEquals(2, val2);
assertEquals(2, obj1.bar);
// Try to redefine bar again - should fail as configurable is false.
-try {
- Object.defineProperty(obj1, "bar", accessorConfigurable);
- assertTrue(false);
-} catch(e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj1, "bar", accessorConfigurable));
// Try to redefine bar again using the data descriptor - should fail.
-try {
- Object.defineProperty(obj1, "bar", dataConfigurable);
- assertTrue(false);
-} catch(e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj1, "bar", dataConfigurable));
// Redefine using same descriptor - should succeed.
-Object.defineProperty(obj1, "bar", accessorNoConfigurable);
+assertTrue(Reflect.defineProperty(obj1, "bar", accessorNoConfigurable));
desc = Object.getOwnPropertyDescriptor(obj1, "bar");
assertFalse(desc.configurable);
assertFalse(desc.enumerable);
@@ -217,7 +201,7 @@ assertEquals(4, val2);
assertEquals(4, obj1.bar);
// Define an accessor that has only a setter.
-Object.defineProperty(obj1, "setOnly", accessorOnlySet);
+assertTrue(Reflect.defineProperty(obj1, "setOnly", accessorOnlySet));
desc = Object.getOwnPropertyDescriptor(obj1, "setOnly");
assertTrue(desc.configurable);
assertFalse(desc.enumerable);
@@ -229,7 +213,7 @@ assertEquals(1, obj1.setOnly = 1);
assertEquals(1, val3);
// Add a getter - should not touch the setter.
-Object.defineProperty(obj1, "setOnly", accessorOnlyGet);
+assertTrue(Reflect.defineProperty(obj1, "setOnly", accessorOnlyGet));
desc = Object.getOwnPropertyDescriptor(obj1, "setOnly");
assertTrue(desc.configurable);
assertFalse(desc.enumerable);
@@ -242,9 +226,9 @@ assertEquals(2, val3);
// The above should also work if redefining just a getter or setter on
// an existing property with both a getter and a setter.
-Object.defineProperty(obj1, "both", accessorConfigurable);
+assertTrue(Reflect.defineProperty(obj1, "both", accessorConfigurable));
-Object.defineProperty(obj1, "both", accessorOnlySet);
+assertTrue(Reflect.defineProperty(obj1, "both", accessorOnlySet));
desc = Object.getOwnPropertyDescriptor(obj1, "both");
assertTrue(desc.configurable);
assertFalse(desc.enumerable);
@@ -258,7 +242,7 @@ assertEquals(3, val3);
// Data properties
-Object.defineProperty(obj1, "foobar", dataConfigurable);
+assertTrue(Reflect.defineProperty(obj1, "foobar", dataConfigurable));
desc = Object.getOwnPropertyDescriptor(obj1, "foobar");
assertEquals(obj1.foobar, 1000);
assertEquals(desc.value, 1000);
@@ -273,7 +257,7 @@ assertEquals(obj1.foobar, 1000);
// Redefine to writable descriptor - now writing to foobar should be allowed.
-Object.defineProperty(obj1, "foobar", dataWritable);
+assertTrue(Reflect.defineProperty(obj1, "foobar", dataWritable));
desc = Object.getOwnPropertyDescriptor(obj1, "foobar");
assertEquals(obj1.foobar, 3000);
assertEquals(desc.value, 3000);
@@ -290,7 +274,7 @@ assertEquals(obj1.foobar, 1001);
// Redefine with non configurable data property.
-Object.defineProperty(obj1, "foobar", dataNoConfigurable);
+assertTrue(Reflect.defineProperty(obj1, "foobar", dataNoConfigurable));
desc = Object.getOwnPropertyDescriptor(obj1, "foobar");
assertEquals(obj1.foobar, 2000);
assertEquals(desc.value, 2000);
@@ -301,24 +285,14 @@ assertEquals(desc.get, undefined);
assertEquals(desc.set, undefined);
// Try redefine again - shold fail because configurable is now false.
-try {
- Object.defineProperty(obj1, "foobar", dataConfigurable);
- assertTrue(false);
-} catch (e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj1, "foobar", dataConfigurable));
// Try redefine again with accessor property - shold also fail.
-try {
- Object.defineProperty(obj1, "foobar", dataConfigurable);
- assertTrue(false);
-} catch (e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj1, "foobar", dataConfigurable));
// Redifine with the same descriptor - should succeed (step 6).
-Object.defineProperty(obj1, "foobar", dataNoConfigurable);
+assertTrue(Reflect.defineProperty(obj1, "foobar", dataNoConfigurable));
desc = Object.getOwnPropertyDescriptor(obj1, "foobar");
assertEquals(obj1.foobar, 2000);
assertEquals(desc.value, 2000);
@@ -333,10 +307,10 @@ assertEquals(desc.set, undefined);
var obj2 = {};
// Make accessor - redefine to data
-Object.defineProperty(obj2, "foo", accessorConfigurable);
+assertTrue(Reflect.defineProperty(obj2, "foo", accessorConfigurable));
// Redefine to data property
-Object.defineProperty(obj2, "foo", dataConfigurable);
+assertTrue(Reflect.defineProperty(obj2, "foo", dataConfigurable));
desc = Object.getOwnPropertyDescriptor(obj2, "foo");
assertEquals(obj2.foo, 1000);
assertEquals(desc.value, 1000);
@@ -348,7 +322,7 @@ assertEquals(desc.set, undefined);
// Redefine back to accessor
-Object.defineProperty(obj2, "foo", accessorConfigurable);
+assertTrue(Reflect.defineProperty(obj2, "foo", accessorConfigurable));
desc = Object.getOwnPropertyDescriptor(obj2, "foo");
assertTrue(desc.configurable);
assertFalse(desc.enumerable);
@@ -362,10 +336,10 @@ assertEquals(4, val2);
assertEquals(3, obj2.foo);
// Make data - redefine to accessor
-Object.defineProperty(obj2, "bar", dataConfigurable)
+assertTrue(Reflect.defineProperty(obj2, "bar", dataConfigurable))
// Redefine to accessor property
-Object.defineProperty(obj2, "bar", accessorConfigurable);
+assertTrue(Reflect.defineProperty(obj2, "bar", accessorConfigurable));
desc = Object.getOwnPropertyDescriptor(obj2, "bar");
assertTrue(desc.configurable);
assertFalse(desc.enumerable);
@@ -379,7 +353,7 @@ assertEquals(4, val2);
assertEquals(4, obj2.foo);
// Redefine back to data property
-Object.defineProperty(obj2, "bar", dataConfigurable);
+assertTrue(Reflect.defineProperty(obj2, "bar", dataConfigurable));
desc = Object.getOwnPropertyDescriptor(obj2, "bar");
assertEquals(obj2.bar, 1000);
assertEquals(desc.value, 1000);
@@ -412,7 +386,7 @@ assertEquals(1, obj3.foo);
// Redefine to accessor property (non configurable) - note that enumerable
// which we do not redefine should remain the same (true).
-Object.defineProperty(obj3, "foo", accessorNoConfigurable);
+assertTrue(Reflect.defineProperty(obj3, "foo", accessorNoConfigurable));
desc = Object.getOwnPropertyDescriptor(obj3, "foo");
assertFalse(desc.configurable);
assertTrue(desc.enumerable);
@@ -430,7 +404,7 @@ obj3.__defineSetter__("bar", set);
// Redefine back to data property
-Object.defineProperty(obj3, "bar", dataConfigurable);
+assertTrue(Reflect.defineProperty(obj3, "bar", dataConfigurable));
desc = Object.getOwnPropertyDescriptor(obj3, "bar");
assertEquals(obj3.bar, 1000);
assertEquals(desc.value, 1000);
@@ -446,7 +420,7 @@ var func = function (){return 42;};
obj4.bar = func;
assertEquals(42, obj4.bar());
-Object.defineProperty(obj4, "bar", accessorConfigurable);
+assertTrue(Reflect.defineProperty(obj4, "bar", accessorConfigurable));
desc = Object.getOwnPropertyDescriptor(obj4, "bar");
assertTrue(desc.configurable);
assertTrue(desc.enumerable);
@@ -521,11 +495,11 @@ try {
var obj5 = {};
// Enumerable will default to false.
-Object.defineProperty(obj5, 'foo', accessorNoConfigurable);
+assertTrue(Reflect.defineProperty(obj5, 'foo', accessorNoConfigurable));
desc = Object.getOwnPropertyDescriptor(obj5, 'foo');
// First, test that we are actually allowed to set the accessor if all
// values are of the descriptor are the same as the existing one.
-Object.defineProperty(obj5, 'foo', accessorNoConfigurable);
+assertTrue(Reflect.defineProperty(obj5, 'foo', accessorNoConfigurable));
// Different setter.
var descDifferent = {
@@ -535,12 +509,7 @@ var descDifferent = {
get: getter2
};
-try {
- Object.defineProperty(obj5, 'foo', descDifferent);
- assertTrue(false);
-} catch (e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj5, 'foo', descDifferent));
// Different getter.
descDifferent = {
@@ -550,12 +519,7 @@ descDifferent = {
get: getter1
};
-try {
- Object.defineProperty(obj5, 'foo', descDifferent);
- assertTrue(false);
-} catch (e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj5, 'foo', descDifferent));
// Different enumerable.
descDifferent = {
@@ -565,12 +529,7 @@ descDifferent = {
get: getter2
};
-try {
- Object.defineProperty(obj5, 'foo', descDifferent);
- assertTrue(false);
-} catch (e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj5, 'foo', descDifferent));
// Different configurable.
descDifferent = {
@@ -580,12 +539,7 @@ descDifferent = {
get: getter2
};
-try {
- Object.defineProperty(obj5, 'foo', descDifferent);
- assertTrue(false);
-} catch (e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj5, 'foo', descDifferent));
// No difference.
descDifferent = {
@@ -595,7 +549,7 @@ descDifferent = {
get: getter2
};
// Make sure we can still redefine if all properties are the same.
-Object.defineProperty(obj5, 'foo', descDifferent);
+assertTrue(Reflect.defineProperty(obj5, 'foo', descDifferent));
// Make sure that obj5 still holds the original values.
desc = Object.getOwnPropertyDescriptor(obj5, 'foo');
@@ -607,10 +561,10 @@ assertFalse(desc.configurable);
// Also exercise step 6 on data property, writable and enumerable
// defaults to false.
-Object.defineProperty(obj5, 'bar', dataNoConfigurable);
+assertTrue(Reflect.defineProperty(obj5, 'bar', dataNoConfigurable));
// Test that redefinition with the same property descriptor is possible
-Object.defineProperty(obj5, 'bar', dataNoConfigurable);
+assertTrue(Reflect.defineProperty(obj5, 'bar', dataNoConfigurable));
// Different value.
descDifferent = {
@@ -620,12 +574,7 @@ descDifferent = {
value: 1999
};
-try {
- Object.defineProperty(obj5, 'bar', descDifferent);
- assertTrue(false);
-} catch (e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj5, 'bar', descDifferent));
// Different writable.
descDifferent = {
@@ -635,12 +584,7 @@ descDifferent = {
value: 2000
};
-try {
- Object.defineProperty(obj5, 'bar', descDifferent);
- assertTrue(false);
-} catch (e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj5, 'bar', descDifferent));
// Different enumerable.
@@ -651,12 +595,7 @@ descDifferent = {
value: 2000
};
-try {
- Object.defineProperty(obj5, 'bar', descDifferent);
- assertTrue(false);
-} catch (e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj5, 'bar', descDifferent));
// Different configurable.
@@ -667,12 +606,7 @@ descDifferent = {
value: 2000
};
-try {
- Object.defineProperty(obj5, 'bar', descDifferent);
- assertTrue(false);
-} catch (e) {
- assertTrue(/Cannot redefine property/.test(e));
-}
+assertFalse(Reflect.defineProperty(obj5, 'bar', descDifferent));
// No difference.
descDifferent = {
@@ -682,7 +616,7 @@ descDifferent = {
value:2000
};
// Make sure we can still redefine if all properties are the same.
-Object.defineProperty(obj5, 'bar', descDifferent);
+assertTrue(Reflect.defineProperty(obj5, 'bar', descDifferent));
// Make sure that obj5 still holds the original values.
desc = Object.getOwnPropertyDescriptor(obj5, 'bar');
@@ -696,34 +630,20 @@ assertFalse(desc.configurable);
var descMinusZero = {value: -0, configurable: false};
var descPlusZero = {value: +0, configurable: false};
-Object.defineProperty(obj5, 'minuszero', descMinusZero);
+assertTrue(Reflect.defineProperty(obj5, 'minuszero', descMinusZero));
// Make sure we can redefine with -0.
-Object.defineProperty(obj5, 'minuszero', descMinusZero);
+assertTrue(Reflect.defineProperty(obj5, 'minuszero', descMinusZero));
-exception = false;
-try {
- Object.defineProperty(obj5, 'minuszero', descPlusZero);
-} catch (e) {
- exception = true;
- assertTrue(/Cannot redefine property/.test(e));
-}
-assertTrue(exception);
+assertFalse(Reflect.defineProperty(obj5, 'minuszero', descPlusZero));
-Object.defineProperty(obj5, 'pluszero', descPlusZero);
+assertTrue(Reflect.defineProperty(obj5, 'pluszero', descPlusZero));
// Make sure we can redefine with +0.
-Object.defineProperty(obj5, 'pluszero', descPlusZero);
+assertTrue(Reflect.defineProperty(obj5, 'pluszero', descPlusZero));
-exception = false;
-try {
- Object.defineProperty(obj5, 'pluszero', descMinusZero);
-} catch (e) {
- exception = true;
- assertTrue(/Cannot redefine property/.test(e));
-}
-assertTrue(exception);
+assertFalse(Reflect.defineProperty(obj5, 'pluszero', descMinusZero));
var obj6 = {};
@@ -744,7 +664,7 @@ var descElementAllFalse = { value: 'foofalse',
// Redefine existing property.
-Object.defineProperty(obj6, '1', descElement);
+assertTrue(Reflect.defineProperty(obj6, '1', descElement));
desc = Object.getOwnPropertyDescriptor(obj6, '1');
assertEquals(desc.value, 'foobar');
assertTrue(desc.writable);
@@ -752,7 +672,7 @@ assertTrue(desc.enumerable);
assertTrue(desc.configurable);
// Redefine existing property with configurable: false.
-Object.defineProperty(obj6, '2', descElementNonConfigurable);
+assertTrue(Reflect.defineProperty(obj6, '2', descElementNonConfigurable));
desc = Object.getOwnPropertyDescriptor(obj6, '2');
assertEquals(desc.value, 'barfoo');
assertTrue(desc.writable);
@@ -762,7 +682,7 @@ assertFalse(desc.configurable);
// Can use defineProperty to change the value of a non
// configurable property.
try {
- Object.defineProperty(obj6, '2', descElement);
+ assertTrue(Reflect.defineProperty(obj6, '2', descElement));
desc = Object.getOwnPropertyDescriptor(obj6, '2');
assertEquals(desc.value, 'foobar');
} catch (e) {
@@ -771,24 +691,17 @@ try {
// Ensure that we can't change the descriptor of a
// non configurable property.
-exception = false;
-try {
- var descAccessor = { get: function() { return 0; } };
- Object.defineProperty(obj6, '2', descAccessor);
-} catch (e) {
- exception = true;
- assertTrue(/Cannot redefine property/.test(e));
-}
-assertTrue(exception);
+var descAccessor = { get: function() { return 0; } };
+assertFalse(Reflect.defineProperty(obj6, '2', descAccessor));
-Object.defineProperty(obj6, '2', descElementNonWritable);
+assertTrue(Reflect.defineProperty(obj6, '2', descElementNonWritable));
desc = Object.getOwnPropertyDescriptor(obj6, '2');
assertEquals(desc.value, 'foofoo');
assertFalse(desc.writable);
assertTrue(desc.enumerable);
assertFalse(desc.configurable);
-Object.defineProperty(obj6, '3', descElementNonWritable);
+assertTrue(Reflect.defineProperty(obj6, '3', descElementNonWritable));
desc = Object.getOwnPropertyDescriptor(obj6, '3');
assertEquals(desc.value, 'foofoo');
assertFalse(desc.writable);
@@ -796,7 +709,7 @@ assertTrue(desc.enumerable);
assertTrue(desc.configurable);
// Redefine existing property with configurable: false.
-Object.defineProperty(obj6, '4', descElementNonEnumerable);
+assertTrue(Reflect.defineProperty(obj6, '4', descElementNonEnumerable));
desc = Object.getOwnPropertyDescriptor(obj6, '4');
assertEquals(desc.value, 'barbar');
assertTrue(desc.writable);
@@ -804,7 +717,7 @@ assertFalse(desc.enumerable);
assertTrue(desc.configurable);
// Redefine existing property with configurable: false.
-Object.defineProperty(obj6, '5', descElementAllFalse);
+assertTrue(Reflect.defineProperty(obj6, '5', descElementAllFalse));
desc = Object.getOwnPropertyDescriptor(obj6, '5');
assertEquals(desc.value, 'foofalse');
assertFalse(desc.writable);
@@ -812,7 +725,7 @@ assertFalse(desc.enumerable);
assertFalse(desc.configurable);
// Define non existing property - all attributes should default to false.
-Object.defineProperty(obj6, '15', descElement);
+assertTrue(Reflect.defineProperty(obj6, '15', descElement));
desc = Object.getOwnPropertyDescriptor(obj6, '15');
assertEquals(desc.value, 'foobar');
assertFalse(desc.writable);
@@ -843,7 +756,7 @@ var descElementAllFalse = { value: 'foofalse',
// Redefine existing property.
-Object.defineProperty(arr, '1', descElement);
+assertTrue(Reflect.defineProperty(arr, '1', descElement));
desc = Object.getOwnPropertyDescriptor(arr, '1');
assertEquals(desc.value, 'foobar');
assertTrue(desc.writable);
@@ -851,7 +764,7 @@ assertTrue(desc.enumerable);
assertTrue(desc.configurable);
// Redefine existing property with configurable: false.
-Object.defineProperty(arr, '2', descElementNonConfigurable);
+assertTrue(Reflect.defineProperty(arr, '2', descElementNonConfigurable));
desc = Object.getOwnPropertyDescriptor(arr, '2');
assertEquals(desc.value, 'barfoo');
assertTrue(desc.writable);
@@ -861,7 +774,7 @@ assertFalse(desc.configurable);
// Can use defineProperty to change the value of a non
// configurable property of an array.
try {
- Object.defineProperty(arr, '2', descElement);
+ assertTrue(Reflect.defineProperty(arr, '2', descElement));
desc = Object.getOwnPropertyDescriptor(arr, '2');
assertEquals(desc.value, 'foobar');
} catch (e) {
@@ -870,24 +783,17 @@ try {
// Ensure that we can't change the descriptor of a
// non configurable property.
-exception = false;
-try {
- var descAccessor = { get: function() { return 0; } };
- Object.defineProperty(arr, '2', descAccessor);
-} catch (e) {
- exception = true;
- assertTrue(/Cannot redefine property/.test(e));
-}
-assertTrue(exception);
+var descAccessor = { get: function() { return 0; } };
+assertFalse(Reflect.defineProperty(arr, '2', descAccessor));
-Object.defineProperty(arr, '2', descElementNonWritable);
+assertTrue(Reflect.defineProperty(arr, '2', descElementNonWritable));
desc = Object.getOwnPropertyDescriptor(arr, '2');
assertEquals(desc.value, 'foofoo');
assertFalse(desc.writable);
assertTrue(desc.enumerable);
assertFalse(desc.configurable);
-Object.defineProperty(arr, '3', descElementNonWritable);
+assertTrue(Reflect.defineProperty(arr, '3', descElementNonWritable));
desc = Object.getOwnPropertyDescriptor(arr, '3');
assertEquals(desc.value, 'foofoo');
assertFalse(desc.writable);
@@ -895,7 +801,7 @@ assertTrue(desc.enumerable);
assertTrue(desc.configurable);
// Redefine existing property with configurable: false.
-Object.defineProperty(arr, '4', descElementNonEnumerable);
+assertTrue(Reflect.defineProperty(arr, '4', descElementNonEnumerable));
desc = Object.getOwnPropertyDescriptor(arr, '4');
assertEquals(desc.value, 'barbar');
assertTrue(desc.writable);
@@ -903,7 +809,7 @@ assertFalse(desc.enumerable);
assertTrue(desc.configurable);
// Redefine existing property with configurable: false.
-Object.defineProperty(arr, '5', descElementAllFalse);
+assertTrue(Reflect.defineProperty(arr, '5', descElementAllFalse));
desc = Object.getOwnPropertyDescriptor(arr, '5');
assertEquals(desc.value, 'foofalse');
assertFalse(desc.writable);
@@ -911,7 +817,7 @@ assertFalse(desc.enumerable);
assertFalse(desc.configurable);
// Define non existing property - all attributes should default to false.
-Object.defineProperty(arr, '15', descElement);
+assertTrue(Reflect.defineProperty(arr, '15', descElement));
desc = Object.getOwnPropertyDescriptor(arr, '15');
assertEquals(desc.value, 'foobar');
assertFalse(desc.writable);
@@ -920,44 +826,44 @@ assertFalse(desc.configurable);
// Define non-array property, check that .length is unaffected.
assertEquals(16, arr.length);
-Object.defineProperty(arr, '0x20', descElement);
+assertTrue(Reflect.defineProperty(arr, '0x20', descElement));
assertEquals(16, arr.length);
// See issue 968: http://code.google.com/p/v8/issues/detail?id=968
var o = { x : 42 };
-Object.defineProperty(o, "x", { writable: false });
+assertTrue(Reflect.defineProperty(o, "x", { writable: false }));
assertEquals(42, o.x);
o.x = 37;
assertEquals(42, o.x);
o = { x : 42 };
-Object.defineProperty(o, "x", {});
+assertTrue(Reflect.defineProperty(o, "x", {}));
assertEquals(42, o.x);
o.x = 37;
// Writability is preserved.
assertEquals(37, o.x);
var o = { };
-Object.defineProperty(o, "x", { writable: false });
+assertTrue(Reflect.defineProperty(o, "x", { writable: false }));
assertEquals(undefined, o.x);
o.x = 37;
assertEquals(undefined, o.x);
o = { get x() { return 87; } };
-Object.defineProperty(o, "x", { writable: false });
+assertTrue(Reflect.defineProperty(o, "x", { writable: false }));
assertEquals(undefined, o.x);
o.x = 37;
assertEquals(undefined, o.x);
// Ignore inherited properties.
o = { __proto__ : { x : 87 } };
-Object.defineProperty(o, "x", { writable: false });
+assertTrue(Reflect.defineProperty(o, "x", { writable: false }));
assertEquals(undefined, o.x);
o.x = 37;
assertEquals(undefined, o.x);
function testDefineProperty(obj, propertyName, desc, resultDesc) {
- Object.defineProperty(obj, propertyName, desc);
+ assertTrue(Reflect.defineProperty(obj, propertyName, desc));
var actualDesc = Object.getOwnPropertyDescriptor(obj, propertyName);
assertEquals(resultDesc.enumerable, actualDesc.enumerable);
assertEquals(resultDesc.configurable, actualDesc.configurable);
@@ -1022,31 +928,31 @@ testDefineProperty(o, 'p',
// can make a writable, non-configurable field non-writable
o = { p : 42 };
-Object.defineProperty(o, 'p', { configurable: false });
+assertTrue(Reflect.defineProperty(o, 'p', { configurable: false }));
testDefineProperty(o, 'p',
{ writable: false },
{ value : 42, writable : false, enumerable : true, configurable : false });
// redefine of get only property with generic descriptor
o = {};
-Object.defineProperty(o, 'p',
- { get : getter1, enumerable: true, configurable: true });
+assertTrue(Reflect.defineProperty(o, 'p',
+ { get : getter1, enumerable: true, configurable: true }));
testDefineProperty(o, 'p',
{ enumerable : false, configurable : false },
{ get: getter1, set: undefined, enumerable : false, configurable : false });
// redefine of get/set only property with generic descriptor
o = {};
-Object.defineProperty(o, 'p',
- { get: getter1, set: setter1, enumerable: true, configurable: true });
+assertTrue(Reflect.defineProperty(o, 'p',
+ { get: getter1, set: setter1, enumerable: true, configurable: true }));
testDefineProperty(o, 'p',
{ enumerable : false, configurable : false },
{ get: getter1, set: setter1, enumerable : false, configurable : false });
// redefine of set only property with generic descriptor
o = {};
-Object.defineProperty(o, 'p',
- { set : setter1, enumerable: true, configurable: true });
+assertTrue(Reflect.defineProperty(o, 'p',
+ { set : setter1, enumerable: true, configurable: true }));
testDefineProperty(o, 'p',
{ enumerable : false, configurable : false },
{ get: undefined, set: setter1, enumerable : false, configurable : false });
@@ -1056,7 +962,7 @@ testDefineProperty(o, 'p',
o = {};
for (var i = 0; i < 1000; i++) {
// Non-enumerable property forces dictionary mode.
- Object.defineProperty(o, i, {value: i, enumerable: false});
+ assertTrue(Reflect.defineProperty(o, i, {value: i, enumerable: false}));
}
assertEquals(999, o[999]);
@@ -1066,17 +972,17 @@ assertEquals(999, o[999]);
/*
(function test(arg0) {
// Here arguments[0] is a fast alias on arg0.
- Object.defineProperty(arguments, "0", {
+ Reflect.defineProperty(arguments, "0", {
value:1,
enumerable:false
});
// Here arguments[0] is a slow alias on arg0.
- Object.defineProperty(arguments, "0", {
+ Reflect.defineProperty(arguments, "0", {
value:2,
writable:false
});
// Here arguments[0] is no alias at all.
- Object.defineProperty(arguments, "0", {
+ Reflect.defineProperty(arguments, "0", {
value:3
});
assertEquals(2, arg0);
@@ -1102,7 +1008,8 @@ function testGetterOnProto(expected, o) {
}
obj1 = {};
-Object.defineProperty(obj1, "quebec", { get: getter, configurable: true });
+assertTrue(
+ Reflect.defineProperty(obj1, "quebec", { get: getter, configurable: true }));
obj2 = Object.create(obj1);
obj3 = Object.create(obj2);
@@ -1112,7 +1019,7 @@ testGetterOnProto(111, obj3);
testGetterOnProto(111, obj3);
testGetterOnProto(111, obj3);
-Object.defineProperty(obj1, "quebec", { get: anotherGetter });
+assertTrue(Reflect.defineProperty(obj1, "quebec", { get: anotherGetter }));
testGetterOnProto(222, obj3);
testGetterOnProto(222, obj3);
@@ -1132,7 +1039,8 @@ function testSetterOnProto(expected, o) {
}
obj1 = {};
-Object.defineProperty(obj1, "romeo", { set: setter, configurable: true });
+assertTrue(
+ Reflect.defineProperty(obj1, "romeo", { set: setter, configurable: true }));
obj2 = Object.create(obj1);
obj3 = Object.create(obj2);
@@ -1142,7 +1050,7 @@ testSetterOnProto(445, obj3);
testSetterOnProto(445, obj3);
testSetterOnProto(445, obj3);
-Object.defineProperty(obj1, "romeo", { set: anotherSetter });
+assertTrue(Reflect.defineProperty(obj1, "romeo", { set: anotherSetter }));
testSetterOnProto(446, obj3);
testSetterOnProto(446, obj3);
@@ -1157,8 +1065,8 @@ function testSetterOnProtoStrict(o) {
}
obj1 = {};
-Object.defineProperty(obj1, "sierra",
- { get: getter, set: setter, configurable: true });
+assertTrue(Reflect.defineProperty(obj1, "sierra",
+ { get: getter, set: setter, configurable: true }));
obj2 = Object.create(obj1);
obj3 = Object.create(obj2);
@@ -1168,8 +1076,8 @@ testSetterOnProtoStrict(obj3);
testSetterOnProtoStrict(obj3);
testSetterOnProtoStrict(obj3);
-Object.defineProperty(obj1, "sierra",
- { get: getter, set: undefined, configurable: true });
+assertTrue(Reflect.defineProperty(obj1, "sierra",
+ { get: getter, set: undefined, configurable: true }));
exception = false;
try {
@@ -1193,7 +1101,8 @@ function C() {}
Assign(new C);
Assign(new C);
%OptimizeFunctionOnNextCall(Assign);
-Object.defineProperty(C.prototype, "blubb", {get: function() { return -42; }});
+assertTrue(
+ Reflect.defineProperty(C.prototype, "blubb", {get: function() {return -42}}));
Assign(new C);
// Test that changes to the prototype of a simple constructor are not ignored,
« no previous file with comments | « test/mjsunit/harmony/reflect.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698