Bug 1164210 - $$() should return a true Array. r=bgrins

--HG--
extra : rebase_source : bfac12d67aba41ecc913c3005a6dba3e8559ddfc
This commit is contained in:
John Pavlicek 2015-06-08 15:27:00 +02:00
Родитель 688784a9e5
Коммит 71fe1cf7b4
4 изменённых файлов: 83 добавлений и 2 удалений

Просмотреть файл

@ -77,7 +77,7 @@ let test = asyncTest(function*() {
[result] = yield waitForMessages({
webconsole: hud,
messages: [{
text: "NodeList [",
text: "Array [",
category: CATEGORY_OUTPUT,
objects: true,
}],

Просмотреть файл

@ -19,6 +19,7 @@ support-files =
[test_jsterm.html]
[test_jsterm_cd_iframe.html]
[test_jsterm_last_result.html]
[test_jsterm_queryselector.html]
[test_network_get.html]
[test_network_longstring.html]
[test_network_post.html]

Просмотреть файл

@ -0,0 +1,77 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for the querySelector / querySelectorAll helpers</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript;version=1.8" src="common.js"></script>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test for the querySelector / querySelectorAll helpers</p>
<script class="testbody" type="text/javascript;version=1.8">
SimpleTest.waitForExplicitFinish();
let gState;
function evaluateJS(input) {
return new Promise((resolve) => gState.client.evaluateJS(input, resolve));
}
function startTest() {
removeEventListener("load", startTest);
attachConsole([], state => {
gState = state;
let tests = [checkQuerySelectorAll, checkQuerySelectorAllNotExist];
runTests(tests, testEnd);
}, true);
}
let checkQuerySelectorAll = Task.async(function*() {
info ("$$ returns an array");
let response = yield evaluateJS("$$('body')");
basicResultCheck(response, "$$('body')", {
type: "object",
class: "Array",
preview: {
length: 1
}
});
nextTest();
});
let checkQuerySelectorAllNotExist = Task.async(function*() {
info ("$$ returns an array even if query yields no results");
let response = yield evaluateJS("$$('foobar')");
basicResultCheck(response, "$$('foobar')", {
type: "object",
class: "Array",
preview: {
length: 0
}
});
nextTest();
});
function basicResultCheck(response, input, output) {
checkObject(response, {
from: gState.actor,
input: input,
result: output,
});
ok(!response.exception, "no eval exception");
ok(!response.helperResult, "no helper result");
}
function testEnd() {
closeDebugger(gState, function() {
gState = null;
SimpleTest.finish();
});
}
addEventListener("load", startTest);
</script>
</body>
</html>

Просмотреть файл

@ -1643,7 +1643,10 @@ WebConsoleCommands._registerOriginal("$", function JSTH_$(aOwner, aSelector)
*/
WebConsoleCommands._registerOriginal("$$", function JSTH_$$(aOwner, aSelector)
{
return aOwner.window.document.querySelectorAll(aSelector);
let results = aOwner.window.document.querySelectorAll(aSelector);
let nodes = aOwner.window.wrappedJSObject.Array.from(results);
return nodes;
});
/**