Bug 633133 - Resolve ids and names in HTMLSelectElement. part 2/2. r=jst, a=blocker

This commit is contained in:
Blake Kaplan 2011-02-24 19:36:33 +01:00
parent cacaebbb27
commit 51ea26c26c
4 changed files with 42 additions and 1 deletions

View File

@ -9403,6 +9403,31 @@ nsHTMLFormElementSH::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
// 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,

View File

@ -1079,6 +1079,9 @@ protected:
}
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);

View File

@ -15,6 +15,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633133
<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">
@ -28,6 +32,14 @@ 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>

View File

@ -536,7 +536,8 @@ XrayWrapper<Base>::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid
return false;
}
desc->obj = wrapper;
if (desc->obj)
desc->obj = wrapper;
return cx->compartment->wrap(cx, desc_in);
}