зеркало из https://github.com/mozilla/gecko-dev.git
Bug 633133 - Define in operator for HTMLCollections and <select>. r=jst
This commit is contained in:
Родитель
5178abf4ed
Коммит
6af6210abd
|
@ -8123,6 +8123,34 @@ nsDOMTokenListSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
|
|||
|
||||
// Named Array helper
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNamedArraySH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||
JSObject *obj, jsid id, PRUint32 flags,
|
||||
JSObject **objp, PRBool *_retval)
|
||||
{
|
||||
if ((!(JSRESOLVE_ASSIGNING & flags)) && JSID_IS_STRING(id) &&
|
||||
!ObjectIsNativeWrapper(cx, obj)) {
|
||||
nsresult rv;
|
||||
nsWrapperCache *cache;
|
||||
|
||||
nsISupports* item = GetNamedItem(GetNative(wrapper, obj),
|
||||
nsDependentJSString(id), &cache, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (item) {
|
||||
JSAutoRequest ar(cx);
|
||||
*_retval = ::JS_DefinePropertyById(cx, obj, id, JSVAL_VOID, nsnull,
|
||||
nsnull, JSPROP_ENUMERATE | JSPROP_SHARED);
|
||||
|
||||
*objp = obj;
|
||||
|
||||
return *_retval ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return nsArraySH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||
JSObject *obj, jsid id, jsval *vp,
|
||||
|
@ -9346,6 +9374,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,
|
||||
|
|
|
@ -807,6 +807,10 @@ protected:
|
|||
{
|
||||
}
|
||||
|
||||
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||
JSObject *obj, jsid id, PRUint32 flags,
|
||||
JSObject **objp, PRBool *_retval);
|
||||
|
||||
virtual nsISupports* GetNamedItem(nsISupports *aNative,
|
||||
const nsAString& aName,
|
||||
nsWrapperCache **cache,
|
||||
|
@ -1075,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);
|
||||
|
|
|
@ -135,6 +135,7 @@ _TEST_FILES = \
|
|||
test_bug617296.html \
|
||||
test_bug620947.html \
|
||||
test_bug622361.html \
|
||||
test_bug633133.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=633133
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 633133</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<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>
|
||||
</div>
|
||||
<select id="select">
|
||||
<option>option1</option>
|
||||
<option>option2</option>
|
||||
</select>
|
||||
<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>
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче