Bug 1120512 - Update comment for TestIntegrityLevel and add a testcase. r=evilpie
authorTooru Fujisawa <arai_a@mac.com>
Sat, 07 Feb 2015 23:54:45 +0900
changeset 227988 f79ee4ad3b68bd6804753474b14f358b4abaac59
parent 227987 9a3a666c17d74f93eb2b38578816bf238bc95778
child 227989 8caf0fdad89448b96cdee117dfe42ff8b54d542f
push id28251
push userphilringnalda@gmail.com
push dateSun, 08 Feb 2015 01:56:30 +0000
treeherdermozilla-central@1bf20efa7777 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpie
bugs1120512
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1120512 - Update comment for TestIntegrityLevel and add a testcase. r=evilpie
js/src/jit-test/tests/proxy/testTestIntegrityLevel.js
js/src/jsobj.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/proxy/testTestIntegrityLevel.js
@@ -0,0 +1,30 @@
+// isSealed/isFrozen should short-circuit.
+
+var count = 0;
+var target = Object.preventExtensions({a: 1, b: 2, c: 3});
+var p = new Proxy(target, {
+    getOwnPropertyDescriptor(t, id) {
+        count++;
+        return Object.getOwnPropertyDescriptor(t, id);
+    }
+});
+assertEq(Object.isSealed(p), false);
+assertEq(count, 1);
+
+count = 0;
+assertEq(Object.isFrozen(p), false);
+assertEq(count, 1);
+
+Object.seal(target);
+count = 0;
+assertEq(Object.isSealed(p), true);
+assertEq(count, 3);
+
+count = 0;
+assertEq(Object.isFrozen(p), false);
+assertEq(count, 1);
+
+Object.freeze(target);
+count = 0;
+assertEq(Object.isFrozen(p), true);
+assertEq(count, 3);
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -1167,41 +1167,40 @@ js::TestIntegrityLevel(JSContext *cx, Ha
         return true;
     }
 
     // Steps 7-8.
     AutoIdVector props(cx);
     if (!GetPropertyKeys(cx, obj, JSITER_HIDDEN | JSITER_OWNONLY | JSITER_SYMBOLS, &props))
         return false;
 
-    // Steps 9-11. The spec does not permit stopping as soon as we find out the
-    // answer is false, so we are cheating a little here (bug 1120512).
+    // Step 11.
     RootedId id(cx);
     Rooted<PropertyDescriptor> desc(cx);
     for (size_t i = 0, len = props.length(); i < len; i++) {
         id = props[i];
 
+        // Steps 11.a-b.
         if (!GetOwnPropertyDescriptor(cx, obj, id, &desc))
             return false;
 
+        // Step 11.c.
         if (!desc.object())
             continue;
 
-        // If the property is configurable, this object is neither sealed nor
-        // frozen. If the property is a writable data property, this object is
-        // not frozen.
+        // Steps 11.c.i-ii.
         if (!desc.isPermanent() ||
             (level == IntegrityLevel::Frozen && desc.isDataDescriptor() && desc.isWritable()))
         {
             *result = false;
             return true;
         }
     }
 
-    // All properties checked out. This object is sealed/frozen.
+    // Step 12.
     *result = true;
     return true;
 }
 
 
 /* * */
 
 /*