Reviewers: rossberg, arv,

Message:
PTAL

Description:
[strong] Implement per-object restrictions behaviour of property freezing

Implements the strong mode proposal's restrictions on changing a strong object's
writable, non-configurable property to non-writable.

Setting the strong bit is still wip, so this change will only affect those
objects that have the bit correctly set. 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/1142393003/

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

Affected files (+63, -2 lines):
  M src/v8natives.js
  A test/mjsunit/strong/object-freeze-property.js


Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index 180c05e1ebc81c4385dba9e6a347f0863ee93d47..13897adb5ed65b1ecedc7e60b024e5a5b0af84c9 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -805,14 +805,16 @@ function DefineObjectProperty(obj, p, desc, should_throw) {
         }
         // Step 10a
         if (IsDataDescriptor(current) && IsDataDescriptor(desc)) {
-          if (!current.isWritable() && desc.isWritable()) {
+          var currentIsWritable = current.isWritable();
+          if (currentIsWritable != desc.isWritable() &&
+                  (!currentIsWritable || IS_STRONG(obj))) {
             if (should_throw) {
               throw MakeTypeError(kRedefineDisallowed, p);
             } else {
               return false;
             }
           }
-          if (!current.isWritable() && desc.hasValue() &&
+          if (!currentIsWritable && desc.hasValue() &&
               !$sameValue(desc.getValue(), current.getValue())) {
             if (should_throw) {
               throw MakeTypeError(kRedefineDisallowed, p);
Index: test/mjsunit/strong/object-freeze-property.js
diff --git a/test/mjsunit/strong/object-freeze-property.js b/test/mjsunit/strong/object-freeze-property.js
new file mode 100644
index 0000000000000000000000000000000000000000..e28642223b30e70e917efbce51adbc86203abd40
--- /dev/null
+++ b/test/mjsunit/strong/object-freeze-property.js
@@ -0,0 +1,59 @@
+// 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.
+  return [({})];
+}
+
+function testStrongObjectFreezeProp() {
+  "use strict";
+  let sloppyObjects = getSloppyObjects();
+  let strictObjects = getStrictObjects();
+  let strongObjects = getStrongObjects();
+  let nonStrongObjects = sloppyObjects.concat(strictObjects);
+
+  for (let o of nonStrongObjects) {
+    Object.defineProperty(o, "foo", { enumerable:true, writable:true });
+    assertDoesNotThrow(
+      function() {Object.defineProperty(o, "foo", { enumerable:true })});
+  }
+  for (let o of strongObjects) {
+    let defProp = function(o) {
+      Object.defineProperty(o, "foo", { enumerable:true })
+    };
+    let defProps = function(o) {
+      let props = {};
+      Object.defineProperty(props, "foo", { enumerable:true });
+      Object.defineProperties(o, props);
+    };
+    let freeze = function(o) { Object.freeze(o) };
+    Object.defineProperty(o, "foo", { enumerable:true, writable:true });
+    for (let func of [defProp, defProps, freeze]) {
+      assertThrows(function(){func(o)}, TypeError);
+      assertThrows(function(){func(o)}, TypeError);
+      assertThrows(function(){func(o)}, TypeError);
+      %OptimizeFunctionOnNextCall(func);
+      assertThrows(function(){func(o)}, TypeError);
+      %DeoptimizeFunction(func);
+      assertThrows(function(){func(o)}, TypeError);
+    }
+  }
+}
+testStrongObjectFreezeProp();


--
--
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