Skip to content

Commit

Permalink
Do not call getElements on a script tag. Avoids unnecessary execution…
Browse files Browse the repository at this point in the history
…. Fixes #10176.
  • Loading branch information
timmywil committed Oct 12, 2011
1 parent 92b06d3 commit 3ad0ba6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/manipulation.js
Expand Up @@ -530,10 +530,10 @@ jQuery.each({
});

function getAll( elem ) {
if ( "getElementsByTagName" in elem ) {
if ( typeof elem.getElementsByTagName !== "undefined" ) {
return elem.getElementsByTagName( "*" );

} else if ( "querySelectorAll" in elem ) {
} else if ( typeof elem.querySelectorAll !== "undefined" ) {
return elem.querySelectorAll( "*" );

} else {
Expand All @@ -549,9 +549,11 @@ function fixDefaultChecked( elem ) {
}
// Finds all inputs and passes them to fixDefaultChecked
function findInputs( elem ) {
if ( jQuery.nodeName( elem, "input" ) ) {
var nodeName = (elem.nodeName || "").toLowerCase();
if ( nodeName === "input" ) {
fixDefaultChecked( elem );
} else if ( "getElementsByTagName" in elem ) {
// Skip scripts, get other children
} else if ( nodeName !== "script" && typeof elem.getElementsByTagName !== "undefined" ) {
jQuery.grep( elem.getElementsByTagName("input"), fixDefaultChecked );
}
}
Expand Down
10 changes: 8 additions & 2 deletions test/unit/manipulation.js
Expand Up @@ -531,7 +531,7 @@ test("append(xml)", function() {
});

test("appendTo(String|Element|Array<Element>|jQuery)", function() {
expect(16);
expect(17);

var defaultText = "Try them out:"
jQuery("<b>buga</b>").appendTo("#first");
Expand Down Expand Up @@ -579,7 +579,7 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
jQuery("#moretests div:last").click();

QUnit.reset();
var div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests");
div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests");

equals( div.length, 2, "appendTo returns the inserted elements" );

Expand All @@ -603,6 +603,12 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
equals( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." );

QUnit.reset();

stop();
jQuery.getScript('data/test.js', function() {
jQuery('script[src*="data\\/test\\.js"]').remove();
start();
});
});

var testPrepend = function(val) {
Expand Down

0 comments on commit 3ad0ba6

Please sign in to comment.