Bug 828137, part 2 - Make [[Set]] always fail on window elements. With this change, `window[0] = null;` is a TypeError in strict mode code. r=bz.
authorJason Orendorff <jorendorff@mozilla.com>
Wed, 11 Feb 2015 11:47:39 -0600
changeset 233119 68f9f9c4868b5eb78e7f7052046d8940137b01b3
parent 233118 1d5e0ae90498a2675c5779fd32a27e03e2bb21ff
child 233120 8ca34e768b426122758b5c8c6bb689c121aabbd6
push id28403
push usercbook@mozilla.com
push dateThu, 12 Mar 2015 08:14:30 +0000
treeherdermozilla-central@b6329532e4e9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs828137
milestone39.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 828137, part 2 - Make [[Set]] always fail on window elements. With this change, `window[0] = null;` is a TypeError in strict mode code. r=bz.
dom/base/nsGlobalWindow.cpp
dom/base/test/test_window_indexing.html
dom/imptests/failures/html/html/browsers/the-window-object/mochitest.ini
dom/imptests/failures/html/html/browsers/the-window-object/test_window-indexed-properties-strict.html.json
testing/web-platform/meta/html/browsers/the-window-object/window-indexed-properties-strict.html.ini
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -910,19 +910,19 @@ bool
 nsOuterWindowProxy::set(JSContext *cx, JS::Handle<JSObject*> proxy,
                         JS::Handle<JSObject*> receiver,
                         JS::Handle<jsid> id,
                         JS::MutableHandle<JS::Value> vp,
                         JS::ObjectOpResult &result) const
 {
   int32_t index = GetArrayIndexFromId(cx, id);
   if (IsArrayIndex(index)) {
-    // Reject (which means throw if and only if strict) the set.
-    // XXX See bug 828137.
-    return result.succeed();
+    // Reject the set.  It's up to the caller to decide whether to throw a
+    // TypeError.  If the caller is strict mode JS code, it'll throw.
+    return result.failReadOnly();
   }
 
   return js::Wrapper::set(cx, proxy, receiver, id, vp, result);
 }
 
 bool
 nsOuterWindowProxy::getOwnEnumerablePropertyKeys(JSContext *cx, JS::Handle<JSObject*> proxy,
                                                  JS::AutoIdVector &props) const
--- a/dom/base/test/test_window_indexing.html
+++ b/dom/base/test/test_window_indexing.html
@@ -38,16 +38,22 @@ https://bugzilla.mozilla.org/show_bug.cg
 
   var x = $("x");
   var y = $("y");
 
   is(x.contentWindow, window[0], "First frame should have correct window");
   is(y.contentWindow, window[1], "Second frame should have correct window");
 
   // set() hook test
+  throws(TypeError, function () {
+    "use strict";
+    window[1] = "FAIL strict";
+  });
+
+  // set() hook test
   window[1] = "FAIL";
   is(window[1].name, "y", "Second frame is still y");
   y.parentNode.removeChild(y);
   ok(!("1" in window), "We no longer have two subframes");
   is(window[1], undefined, "We should not have a value here");
 
   // defineProperty() hook test
   function throws(errorCtor, f) {
@@ -66,16 +72,20 @@ https://bugzilla.mozilla.org/show_bug.cg
     Object.defineProperty(window, "1", { value: "FAIL2", configurable: true,
                                          writable: true });
   });
   y.parentNode.removeChild(y);
   ok(!("1" in window), "We no longer have two subframes, again");
   is(window[1], undefined, "We should not have a value here either");
 
   // More set() hook test
+  throws(TypeError, function () {
+    "use strict";
+    window[1] = "FAIL3 strict";
+  });
   window[1] = "FAIL3";
   ok(!("1" in window), "We shouldn't allow indexed expandos");
   is(window[1], undefined, "We should not have a value for an indexed expando");
   var desc = Object.getOwnPropertyDescriptor(window, "1");
   is(desc, undefined, "We really really shouldn't have indexed expandos");
 
   x.parentNode.appendChild(y);
   is(window[1], y.contentWindow, "Second frame should now be visible");
--- a/dom/imptests/failures/html/html/browsers/the-window-object/mochitest.ini
+++ b/dom/imptests/failures/html/html/browsers/the-window-object/mochitest.ini
@@ -1,9 +1,8 @@
 # THIS FILE IS AUTOGENERATED BY parseFailures.py - DO NOT EDIT
 [DEFAULT]
 support-files =
 
 
-[test_window-indexed-properties-strict.html.json]
 [test_window-named-properties.html.json]
 skip-if = true # bug 859075
 [test_window-properties.html.json]
deleted file mode 100644
--- a/dom/imptests/failures/html/html/browsers/the-window-object/test_window-indexed-properties-strict.html.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
-  "Indexed properties of the window object (strict mode) 1": true,
-  "Indexed properties of the window object (strict mode) 2": true
-}
deleted file mode 100644
--- a/testing/web-platform/meta/html/browsers/the-window-object/window-indexed-properties-strict.html.ini
+++ /dev/null
@@ -1,8 +0,0 @@
-[window-indexed-properties-strict.html]
-  type: testharness
-  [Indexed properties of the window object (strict mode) 1]
-    expected: FAIL
-
-  [Indexed properties of the window object (strict mode) 2]
-    expected: FAIL
-