2.0: Rewrite data.js (Incl. event, manipulation, tests)

This commit is contained in:
Rick Waldron
2013-02-03 15:27:55 -05:00
parent ed0e2d1e8a
commit 7f94a5cc3a
7 changed files with 361 additions and 365 deletions

View File

@@ -0,0 +1,20 @@
<!doctype html>
<html>
<script src="/dist/jquery.js"></script>
<script>
function report( event ) {
var payload = {
event: event.type
};
return top.postMessage( JSON.stringify(payload), "*" );
}
jQuery( window ).on( "beforeunload", function( event ) {
report( event );
}).on( "load", function( event ) {
setTimeout(function() {
window.location.reload();
}, 50);
});
</script>
</html>

View File

@@ -200,47 +200,53 @@ var Globals = (function() {
*/
QUnit.expectJqData = function( elems, key ) {
var i, elem, expando;
QUnit.current_testEnvironment.checkJqData = true;
if ( elems.jquery && elems.toArray ) {
elems = elems.toArray();
}
if ( !jQuery.isArray( elems ) ) {
elems = [ elems ];
}
// As of jQuery 2.0, there will be no "cache"-data is
// stored and managed completely below the API surface
if ( jQuery.cache ) {
QUnit.current_testEnvironment.checkJqData = true;
for ( i = 0; i < elems.length; i++ ) {
elem = elems[i];
// jQuery.data only stores data for nodes in jQuery.cache,
// for other data targets the data is stored in the object itself,
// in that case we can't test that target for memory leaks.
// But we don't have to since in that case the data will/must will
// be available as long as the object is not garbage collected by
// the js engine, and when it is, the data will be removed with it.
if ( !elem.nodeType ) {
// Fixes false positives for dataTests(window), dataTests({}).
continue;
if ( elems.jquery && elems.toArray ) {
elems = elems.toArray();
}
if ( !jQuery.isArray( elems ) ) {
elems = [ elems ];
}
expando = elem[ jQuery.expando ];
for ( i = 0; i < elems.length; i++ ) {
elem = elems[i];
if ( expando === undefined ) {
// In this case the element exists fine, but
// jQuery.data (or internal data) was never (in)directly
// called.
// Since this method was called it means some data was
// expected to be found, but since there is nothing, fail early
// (instead of in teardown).
notStrictEqual( expando, undefined, "Target for expectJqData must have an expando, for else there can be no data to expect." );
} else {
if ( expectedDataKeys[expando] ) {
expectedDataKeys[expando].push( key );
// jQuery.data only stores data for nodes in jQuery.cache,
// for other data targets the data is stored in the object itself,
// in that case we can't test that target for memory leaks.
// But we don't have to since in that case the data will/must will
// be available as long as the object is not garbage collected by
// the js engine, and when it is, the data will be removed with it.
if ( !elem.nodeType ) {
// Fixes false positives for dataTests(window), dataTests({}).
continue;
}
expando = elem[ jQuery.expando ];
if ( expando === undefined ) {
// In this case the element exists fine, but
// jQuery.data (or internal data) was never (in)directly
// called.
// Since this method was called it means some data was
// expected to be found, but since there is nothing, fail early
// (instead of in teardown).
notStrictEqual( expando, undefined, "Target for expectJqData must have an expando, for else there can be no data to expect." );
} else {
expectedDataKeys[expando] = [ key ];
if ( expectedDataKeys[expando] ) {
expectedDataKeys[expando].push( key );
} else {
expectedDataKeys[expando] = [ key ];
}
}
}
}
};
QUnit.config.urlConfig.push( {
id: "jqdata",
@@ -334,7 +340,7 @@ var Globals = (function() {
} else {
delete jQuery.ajaxSettings;
}
// Cleanup globals
Globals.cleanup();