Bug 633133 - Resolve ids and names in HTMLSelectElement. part 2/2. r=jst, a=blocker
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 24 Feb 2011 19:36:33 +0100
changeset 63079 c2c9c3eb5c2c4414e20bd1ada65880b559913ecc
parent 63078 6c27993ee8096e0c8ea9e5f6f1833ec45363b12f
child 63080 a5eccf9bebda5031c9c2031283f5df5303e92c19
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersjst, blocker
bugs633133
milestone2.0b13pre
Bug 633133 - Resolve ids and names in HTMLSelectElement. part 2/2. r=jst, a=blocker
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfo.h
dom/tests/mochitest/bugs/test_bug633133.html
js/src/xpconnect/wrappers/XrayWrapper.cpp
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -9399,16 +9399,41 @@ nsHTMLFormElementSH::NewEnumerate(nsIXPC
 
   return NS_OK;
 }
 
 
 // HTMLSelectElement helper
 
 NS_IMETHODIMP
+nsHTMLSelectElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
+                                  JSObject *obj, jsid id, PRUint32 flags,
+                                  JSObject **objp, PRBool *_retval)
+{
+  PRInt32 n = GetArrayIndexFromId(cx, id);
+  if (n >= 0) {
+    nsHTMLSelectElement *s =
+      nsHTMLSelectElement::FromSupports(GetNative(wrapper, obj));
+
+    nsHTMLOptionCollection *options = s->GetOptions();
+    if (options) {
+      nsresult rv;
+      nsISupports *node = options->GetNodeAt(n, &rv);
+      if (node) {
+        *objp = obj;
+        *_retval = JS_DefineElement(cx, obj, n, JSVAL_VOID, nsnull, nsnull,
+                                    JSPROP_ENUMERATE | JSPROP_SHARED);
+      }
+    }
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsHTMLSelectElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
                                    JSContext *cx, JSObject *obj, jsid id,
                                    jsval *vp, PRBool *_retval)
 {
   PRInt32 n = GetArrayIndexFromId(cx, id);
 
   nsresult rv = NS_OK;
   if (n >= 0) {
--- a/dom/base/nsDOMClassInfo.h
+++ b/dom/base/nsDOMClassInfo.h
@@ -1074,16 +1074,19 @@ protected:
   {
   }
 
   virtual ~nsHTMLSelectElementSH()
   {
   }
 
 public:
+  NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
+                        JSObject *obj, jsid id, PRUint32 flags,
+                        JSObject **objp, PRBool *_retval);
   NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                          JSObject *obj, jsid id, jsval *vp,
                          PRBool *_retval);
   NS_IMETHOD SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                          JSObject *obj, jsid id, jsval *vp, PRBool *_retval);
 
   static nsresult SetOption(JSContext *cx, jsval *vp, PRUint32 aIndex,
                             nsIDOMNSHTMLOptionCollection *aOptCollection);
--- a/dom/tests/mochitest/bugs/test_bug633133.html
+++ b/dom/tests/mochitest/bugs/test_bug633133.html
@@ -10,25 +10,37 @@ https://bugzilla.mozilla.org/show_bug.cg
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633133">Mozilla Bug 633133</a>
 <p id="display"></p>
 <div id="content" style="display: none">
   <div id='foo'></div>
   <div name='bar'></div>
+  <select id="select">
+    <option>option1</option>
+    <option>option2</option>
+  </select>
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 633133 **/
 
 var divCollection = document.getElementsByTagName('div');
 
 ok("foo" in divCollection, "'foo' should be in the div collection");
 ok("bar" in divCollection, "'bar' should be in the div collection");
 ok(!("" in divCollection), "empty string shouldn't be in the div collection");
 ok(!("foobar" in divCollection), "'foobar' shouldn't be in the div collection");
 
+var select = $('select');
+is(select[0].text, "option1", "select elements work");
+Math.sin();
+ok(1 in select, "in works");
+is(select[1].text, "option2", "can get it too");
+ok(!(2 in select), "in works for elements out of range");
+is(select[2], undefined, "can get them too and they're undefined");
+
 </script>
 </pre>
 </body>
 </html>
--- a/js/src/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/src/xpconnect/wrappers/XrayWrapper.cpp
@@ -531,17 +531,18 @@ XrayWrapper<Base>::getPropertyDescriptor
                 return false;
 
             if (!JS_GetPropertyDescriptorById(cx, wnObject, id,
                                               (set ? JSRESOLVE_ASSIGNING : 0) | JSRESOLVE_QUALIFIED,
                                               desc))
                 return false;
         }
 
-        desc->obj = wrapper;
+        if (desc->obj)
+            desc->obj = wrapper;
         return cx->compartment->wrap(cx, desc_in);
     }
 
     if (!this->resolveOwnProperty(cx, wrapper, id, set, desc_in))
         return false;
 
     if (desc->obj)
         return true;