mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 725907 - for-of improvements, part 3: Implement .iterator() for arraylike DOM objects. r=bzbarsky.
--HG-- extra : rebase_source : 0820d3654318f217b8836a086234736d3aba3819
This commit is contained in:
parent
4516dd9ea0
commit
61def7a5da
@ -63,6 +63,8 @@ _TEST_FILES = \
|
||||
test_lookupGetter.html \
|
||||
test_InstanceOf.html \
|
||||
test_traceProtos.html \
|
||||
test_forOf.html \
|
||||
forOf_iframe.html \
|
||||
$(NULL)
|
||||
|
||||
|
||||
|
13
dom/bindings/test/forOf_iframe.html
Normal file
13
dom/bindings/test/forOf_iframe.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>iframe content for test_forOf_iframe.html</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="basket">
|
||||
<span id="egg0"></span>
|
||||
<span id="egg1"><span id="duckling1"></span></span>
|
||||
<span id="egg2"></span>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
94
dom/bindings/test/test_forOf.html
Normal file
94
dom/bindings/test/test_forOf.html
Normal file
@ -0,0 +1,94 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=725907
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 725907</title>
|
||||
<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=725907">Mozilla Bug 725907</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<div id="basket">
|
||||
<span id="egg0"></span>
|
||||
<span id="egg1"><span id="duckling1"></span></span>
|
||||
<span id="egg2"></span>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 725907 **/
|
||||
|
||||
function runTestsForDocument(document, msgSuffix) {
|
||||
function is(a, b, msg) { SimpleTest.is(a, b, msg + msgSuffix); }
|
||||
function isnot(a, b, msg) { SimpleTest.isnot(a, b, msg + msgSuffix); }
|
||||
|
||||
var basket = document.getElementById("basket");
|
||||
var egg3 = document.createElement("span");
|
||||
egg3.id = "egg3";
|
||||
|
||||
var log = '';
|
||||
for (var x of basket.childNodes) {
|
||||
if (x.nodeType != x.TEXT_NODE)
|
||||
log += x.id + ";";
|
||||
}
|
||||
is(log, "egg0;egg1;egg2;", "'for (x of div.childNodes)' should iterate over child nodes");
|
||||
|
||||
log = '';
|
||||
for (var x of basket.childNodes) {
|
||||
if (x.nodeType != x.TEXT_NODE) {
|
||||
log += x.id + ";";
|
||||
if (x.id == "egg1")
|
||||
basket.appendChild(egg3);
|
||||
}
|
||||
}
|
||||
is(log, "egg0;egg1;egg2;egg3;", "'for (x of div.childNodes)' should see elements added during iteration");
|
||||
|
||||
var iter1 = basket.childNodes.iterator();
|
||||
var iter2 = basket.childNodes.iterator();
|
||||
isnot(iter1, iter2, "nodelist.iterator() returns a new iterator each time");
|
||||
|
||||
log = '';
|
||||
basket.appendChild(document.createTextNode("some text"));
|
||||
for (var x of basket.children)
|
||||
log += x.id + ";";
|
||||
is(log, "egg0;egg1;egg2;egg3;", "'for (x of div.children)' should iterate over child elements");
|
||||
|
||||
var iter1 = basket.children.iterator();
|
||||
var iter2 = basket.children.iterator();
|
||||
isnot(iter1, iter2, ".iterator() returns a new iterator each time");
|
||||
|
||||
var count = 0;
|
||||
for (var x of document.getElementsByClassName("hazardous-materials"))
|
||||
count++;
|
||||
is(count, 0, "'for (x of emptyNodeList)' loop should run zero times");
|
||||
|
||||
var log = '';
|
||||
for (var x of document.querySelectorAll("span"))
|
||||
log += x.id + ";";
|
||||
is(log, "egg0;egg1;duckling1;egg2;egg3;", "for-of loop should work with a querySelectorAll() NodeList");
|
||||
}
|
||||
|
||||
/* All the tests run twice. First, in this document, so without any wrappers. */
|
||||
runTestsForDocument(document, "");
|
||||
|
||||
/* And once using the document of an iframe, so working with cross-compartment wrappers. */
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
function iframeLoaded(iframe) {
|
||||
runTestsForDocument(iframe.contentWindow.document, " (in iframe)");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<iframe src="forOf_iframe.html" onload="iframeLoaded(this)"></iframe>
|
||||
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -37,6 +37,8 @@ static jsid s_prototype_id = JSID_VOID;
|
||||
|
||||
static jsid s_length_id = JSID_VOID;
|
||||
|
||||
static jsid s_iterator_id = JSID_VOID;
|
||||
|
||||
static jsid s_VOID_id = JSID_VOID;
|
||||
|
||||
bool
|
||||
@ -59,6 +61,7 @@ DefineStaticJSVals(JSContext *cx)
|
||||
|
||||
return SET_JSID_TO_STRING(cx, prototype) &&
|
||||
SET_JSID_TO_STRING(cx, length) &&
|
||||
SET_JSID_TO_STRING(cx, iterator) &&
|
||||
DefinePropertyStaticJSVals(cx);
|
||||
}
|
||||
|
||||
@ -1163,13 +1166,6 @@ template<class LC>
|
||||
bool
|
||||
ListBase<LC>::iterate(JSContext *cx, JSObject *proxy, unsigned flags, Value *vp)
|
||||
{
|
||||
if (flags == JSITER_FOR_OF) {
|
||||
JSObject *iterobj = JS_NewElementIterator(cx, proxy);
|
||||
if (!iterobj)
|
||||
return false;
|
||||
vp->setObject(*iterobj);
|
||||
return true;
|
||||
}
|
||||
return ProxyHandler::iterate(cx, proxy, flags, vp);
|
||||
}
|
||||
|
||||
|
@ -696,6 +696,7 @@ def writeStubFile(filename, config, interfaces):
|
||||
if clazz.indexGetter:
|
||||
#methodsList.append(" { s_%s_id, &item, 1 }" % clazz.indexGetter.name)
|
||||
f.write(string.Template(indexGetterTemplate).substitute(clazz))
|
||||
methodsList.append(" { s_iterator_id, JS_ArrayIterator, 0}")
|
||||
if clazz.indexSetter:
|
||||
f.write(string.Template(indexSetterTemplate).substitute(clazz))
|
||||
if clazz.nameGetter:
|
||||
|
Loading…
Reference in New Issue
Block a user