Index: test/mjsunit/strong/object-delete.js |
diff --git a/test/mjsunit/strong/object-delete.js b/test/mjsunit/strong/object-delete.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9148138c008beb9cfdd82d2e1763e25fcfe4b1e0 |
--- /dev/null |
+++ b/test/mjsunit/strong/object-delete.js |
@@ -0,0 +1,136 @@ |
+// Copyright 2015 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Flags: --strong-mode --allow-natives-syntax |
+ |
+// TODO(conradw): Track implementation of strong bit for other objects, add |
+// tests. |
+ |
+function getSloppyObjects() { |
+ return [(function(){}), ({})]; |
+} |
+ |
+function getStrictObjects() { |
+ "use strict"; |
+ return [(function(){}), ({})]; |
+} |
+ |
+function getStrongObjects() { |
+ "use strong"; |
+// Strong functions can't have properties added to them, and will be tested as a |
rossberg
2015/05/22 11:34:50
Instead of this, why not make the test below check
conradw
2015/05/22 13:37:57
It's kind of nasty because I interleave asserts th
|
+// special case. |
+ return [({})]; |
+} |
+ |
+function strongFunction() { |
+ "use strong"; |
+} |
+ |
+function deleteFromObjectSloppy(o) { |
+ return delete o.foo; |
+} |
+ |
+function deleteFromObjectKeyedSloppy(o) { |
+ return delete o["foo"]; |
rossberg
2015/05/22 11:34:50
Change this to an actual computation (e.g., Date()
conradw
2015/05/22 13:37:57
Done. Added as another case (want to keep both of
|
+} |
+ |
+function deleteFromObjectKeyedVarSloppy(o) { |
+ var a = "foo"; |
+ return delete o[a]; |
+} |
+ |
+function deleteFromObjectWith(o) { |
+ with(o){ |
+ return delete foo; |
+ } |
+} |
+ |
+function deleteFromObjectStrict(o) { |
+ "use strict"; |
+ return delete o.foo; |
+} |
+ |
+function deleteFromObjectKeyedStrict(o) { |
+ "use strict"; |
+ return delete o["foo"]; |
+} |
+ |
+function deleteFromObjectKeyedVarStrict(o) { |
+ "use strict"; |
+ var a = "foo"; |
+ return delete o[a]; |
+} |
+ |
+function testStrongObjectDelete() { |
+ "use strict"; |
+ let sloppyObjects = getSloppyObjects(); |
+ let strictObjects = getStrictObjects(); |
+ let strongObjects = getStrongObjects(); |
+ let nonStrongObjects = sloppyObjects.concat(strictObjects); |
+ |
+ let deleteFuncsSloppy = [deleteFromObjectSloppy, deleteFromObjectKeyedSloppy, |
+ deleteFromObjectKeyedletSloppy, deleteFromObjectWith |
+ ]; |
+ let deleteFuncsStrict = [deleteFromObjectStrict, deleteFromObjectKeyedStrict, |
+ deleteFromObjectKeyedletStrict |
+ ]; |
+ |
+ for (let deleteFunc of deleteFuncsSloppy) { |
+ for (let o of nonStrongObjects) { |
+ Object.defineProperty(o, "foo", {configurable:true, value:"bar"}); |
+ assertTrue(deleteFunc(o)); |
+ assertFalse(o.hasOwnProperty("foo")); |
+ %OptimizeFunctionOnNextCall(deleteFunc); |
+ Object.defineProperty(o, "foo", {configurable:true, value:"bar"}); |
+ assertTrue(deleteFunc(o)); |
+ assertFalse(o.hasOwnProperty("foo")); |
+ %DeoptimizeFunction(deleteFunc); |
+ Object.defineProperty(o, "foo", {configurable:true, value:"bar"}); |
+ assertTrue(deleteFunc(o)); |
+ assertFalse(o.hasOwnProperty("foo")); |
+ } |
+ for (let o of strongObjects) { |
+ Object.defineProperty(o, "foo", {configurable:true, value:"bar"}); |
+ assertFalse(deleteFunc(o)); |
+ assertTrue(o.hasOwnProperty("foo")); |
+ %OptimizeFunctionOnNextCall(deleteFunc); |
+ assertFalse(deleteFunc(o)); |
+ assertTrue(o.hasOwnProperty("foo")); |
+ %DeoptimizeFunction(deleteFunc); |
+ assertFalse(deleteFunc(o)); |
+ assertTrue(o.hasOwnProperty("foo")); |
+ assertTrue(delete o); |
+ } |
+ assertFalse(deleteFunc(strongFunction)); |
+ } |
+ for (let deleteFunc of deleteFuncsStrict) { |
+ for (let o of nonStrongObjects) { |
+ Object.defineProperty(o, "foo", {configurable:true, value:"bar"}); |
+ assertTrue(deleteFunc(o)); |
+ assertFalse(o.hasOwnProperty("foo")); |
+ %OptimizeFunctionOnNextCall(deleteFunc); |
+ Object.defineProperty(o, "foo", {configurable:true, value:"bar"}); |
+ assertTrue(deleteFunc(o)); |
+ assertFalse(o.hasOwnProperty("foo")); |
+ %DeoptimizeFunction(deleteFunc); |
+ Object.defineProperty(o, "foo", {configurable:true, value:"bar"}); |
+ assertTrue(deleteFunc(o)); |
+ assertFalse(o.hasOwnProperty("foo")); |
+ } |
+ for (let o of strongObjects) { |
+ Object.defineProperty(o, "foo", {configurable:true, value:"bar"}); |
+ assertThrows(deleteFunc(o), TypeError); |
+ assertTrue(o.hasOwnProperty("foo")); |
+ %OptimizeFunctionOnNextCall(deleteFunc); |
+ assertThrows(deleteFunc(o), TypeError); |
+ assertTrue(o.hasOwnProperty("foo")); |
+ %DeoptimizeFunction(deleteFunc); |
+ assertThrows(deleteFunc(o), TypeError); |
+ assertTrue(o.hasOwnProperty("foo")); |
+ assertTrue(delete o); |
+ } |
+ assertThrows(deleteFunc(strongFunction), TypeError); |
+ } |
+} |
+testStrongObjectDelete(); |