Reviewers: rossberg,

Message:
PTAL

Description:
[strong] Implement per-object restrictions behaviour of delete operator

Implements the strong mode proposal's restrictions on the behaviour of the
delete operator for strong objects.

Setting the strong bit is still wip, so this change will only affect those
objects that have the bit correctly set (currently only function). The tests
reflect this, and will be expanded as more objects can be marked as strong.

BUG=v8:3956
LOG=N

Please review this at https://codereview.chromium.org/1144453002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+55, -0 lines):
  M src/messages.h
  M src/runtime.js
  A test/mjsunit/strong/strong-object-delete.js


Index: src/messages.h
diff --git a/src/messages.h b/src/messages.h
index 5b538c683c60cb4a6d72914efb33d3d7f00c59a8..ac6deffc6a1fe1bf5a9ca3a8785f6c097a308954 100644
--- a/src/messages.h
+++ b/src/messages.h
@@ -257,6 +257,9 @@ class CallSite {
T(VarRedeclaration, "Identifier '%' has already been declared") \ T(WithExpression, "% has no properties") \ T(WrongArgs, "%: Arguments list has wrong type") \ + T(StrongDeleteProperty, \ + "Cannot delete property '%', property deletion from strong object % is " \ + "not permitted") \ /* ReferenceError */ \ T(NonMethod, "'super' is referenced from non-method") \ T(NotDefined, "% is not defined") \
Index: src/runtime.js
diff --git a/src/runtime.js b/src/runtime.js
index 49f58bbceaabb4f93895635435b67e572938cbe3..9ba9218b60504fdd6323dd6655241b88d8641f57 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -508,6 +508,9 @@ SHR_STRONG = function SHR_STRONG(y) {

 // ECMA-262, section 11.4.1, page 46.
 DELETE = function DELETE(key, language_mode) {
+  if (IS_STRONG(this)) {
+    throw %MakeTypeError(kStrongDeleteProperty, key, this);
+  }
   return %DeleteProperty(%$toObject(this), %$toName(key), language_mode);
 }

Index: test/mjsunit/strong/strong-object-delete.js
diff --git a/test/mjsunit/strong/strong-object-delete.js b/test/mjsunit/strong/strong-object-delete.js
new file mode 100644
index 0000000000000000000000000000000000000000..312c43cf712dc915e6e83f092fd24305330074aa
--- /dev/null
+++ b/test/mjsunit/strong/strong-object-delete.js
@@ -0,0 +1,49 @@
+// 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.
+// Currently it's pointless to actually try setting any properties before
+// deleting, since strong functions are created frozen. This will change as more
+// things become strong.
+
+var sloppyFunction = function(){};
+var strictFunction = function(){"use strict";};
+var strongFunction = function(){"use strong";};
+
+var deleteFromObject = function(o){delete o.foo;};
+var deleteFromObjectKeyed = function(o){delete o["foo"];};
+var deleteFromObjectKeyedVar = function(o){var a = "foo"; delete o[a];};
+
+var sloppyObjects = [sloppyFunction];
+
+var strictObjects = [strictFunction];
+
+var strongObjects = [strongFunction];
+
+var nonStrongObjects = sloppyObjects.concat(strictObjects);
+
+var deleteFuncs = [deleteFromObject, deleteFromObjectKeyed,
+                   deleteFromObjectKeyedVar
+                  ];
+
+for (var deleteFunc of deleteFuncs) {
+  for (var o of nonStrongObjects) {
+    assertDoesNotThrow(function(){deleteFunc(o)});
+    %OptimizeFunctionOnNextCall(deleteFunc);
+    assertDoesNotThrow(function(){deleteFunc(o)});
+    %DeoptimizeFunction(deleteFunc);
+    assertDoesNotThrow(function(){deleteFunc(o)});
+  }
+  for (var o of strongObjects) {
+    assertThrows(function(){deleteFunc(o)}, TypeError);
+    %OptimizeFunctionOnNextCall(deleteFunc);
+    assertThrows(function(){deleteFunc(o)}, TypeError);
+    %DeoptimizeFunction(deleteFunc);
+    assertThrows(function(){deleteFunc(o)}, TypeError);
+    assertDoesNotThrow(function(){delete o;});
+  }
+}


--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to