|
1 | 1 | (function() { |
2 | 2 |
|
3 | 3 | module('Objects'); |
4 | | - /* global iObject, iElement, iArguments, iFunction, iArray, iString, iNumber, iBoolean, iDate, iError, iRegExp, iNaN, iNull, iUndefined, ActiveXObject */ |
5 | 4 |
|
6 | 5 | test('keys', function() { |
7 | 6 | deepEqual(_.keys({one : 1, two : 2}), ['one', 'two'], 'can extract the keys from an object'); |
|
437 | 436 | b = _({x: 1, y: 2}).chain(); |
438 | 437 | equal(_.isEqual(a.isEqual(b), _(true)), true, '`isEqual` can be chained'); |
439 | 438 |
|
440 | | - // Objects from another frame. |
441 | | - ok(_.isEqual({}, iObject), 'Objects with equivalent members created in different documents are equal'); |
442 | | - |
443 | | - // Array from another frame. |
444 | | - ok(_.isEqual([1, 2, 3], iArray), 'Arrays with equivalent elements created in different documents are equal'); |
445 | | - |
446 | 439 | // Objects without a `constructor` property |
447 | 440 | if (Object.create) { |
448 | 441 | a = Object.create(null, {x: {value: 1, enumerable: true}}); |
|
477 | 470 | ok(!_.isEmpty(args('')), 'non-empty arguments object is not empty'); |
478 | 471 | }); |
479 | 472 |
|
480 | | - // Setup remote variables for iFrame tests. |
481 | | - var iframe = document.createElement('iframe'); |
482 | | - iframe.frameBorder = iframe.height = iframe.width = 0; |
483 | | - document.body.appendChild(iframe); |
484 | | - var iDoc = (iDoc = iframe.contentDocument || iframe.contentWindow).document || iDoc; |
485 | | - iDoc.write( |
486 | | - [ |
487 | | - '<script>', |
488 | | - 'parent.iElement = document.createElement("div");', |
489 | | - 'parent.iArguments = (function(){ return arguments; })(1, 2, 3);', |
490 | | - 'parent.iArray = [1, 2, 3];', |
491 | | - 'parent.iString = new String("hello");', |
492 | | - 'parent.iNumber = new Number(100);', |
493 | | - 'parent.iFunction = (function(){});', |
494 | | - 'parent.iDate = new Date();', |
495 | | - 'parent.iRegExp = /hi/;', |
496 | | - 'parent.iNaN = NaN;', |
497 | | - 'parent.iNull = null;', |
498 | | - 'parent.iBoolean = new Boolean(false);', |
499 | | - 'parent.iUndefined = undefined;', |
500 | | - 'parent.iObject = {};', |
501 | | - 'parent.iError = new Error();', |
502 | | - '</script>' |
503 | | - ].join('\n') |
504 | | - ); |
505 | | - iDoc.close(); |
506 | | - |
507 | 473 | test('isElement', function() { |
508 | 474 | ok(!_.isElement('div'), 'strings are not dom elements'); |
509 | 475 | ok(_.isElement(document.body), 'the body tag is a DOM element'); |
510 | | - ok(_.isElement(iElement), 'even from another frame'); |
511 | 476 | }); |
512 | 477 |
|
513 | 478 | test('isArguments', function() { |
|
517 | 482 | ok(_.isArguments(args), 'but the arguments object is an arguments object'); |
518 | 483 | ok(!_.isArguments(_.toArray(args)), 'but not when it\'s converted into an array'); |
519 | 484 | ok(!_.isArguments([1, 2, 3]), 'and not vanilla arrays.'); |
520 | | - ok(_.isArguments(iArguments), 'even from another frame'); |
521 | 485 | }); |
522 | 486 |
|
523 | 487 | test('isObject', function() { |
524 | 488 | ok(_.isObject(arguments), 'the arguments object is object'); |
525 | 489 | ok(_.isObject([1, 2, 3]), 'and arrays'); |
526 | 490 | ok(_.isObject(document.body), 'and DOM element'); |
527 | | - ok(_.isObject(iElement), 'even from another frame'); |
528 | 491 | ok(_.isObject(function () {}), 'and functions'); |
529 | | - ok(_.isObject(iFunction), 'even from another frame'); |
530 | 492 | ok(!_.isObject(null), 'but not null'); |
531 | 493 | ok(!_.isObject(undefined), 'and not undefined'); |
532 | 494 | ok(!_.isObject('string'), 'and not string'); |
|
539 | 501 | ok(!_.isArray(undefined), 'undefined vars are not arrays'); |
540 | 502 | ok(!_.isArray(arguments), 'the arguments object is not an array'); |
541 | 503 | ok(_.isArray([1, 2, 3]), 'but arrays are'); |
542 | | - ok(_.isArray(iArray), 'even from another frame'); |
543 | 504 | }); |
544 | 505 |
|
545 | 506 | test('isString', function() { |
546 | 507 | var obj = new String('I am a string object'); |
547 | 508 | ok(!_.isString(document.body), 'the document body is not a string'); |
548 | 509 | ok(_.isString([1, 2, 3].join(', ')), 'but strings are'); |
549 | | - ok(_.isString(iString), 'even from another frame'); |
550 | 510 | ok(_.isString('I am a string literal'), 'string literals are'); |
551 | 511 | ok(_.isString(obj), 'so are String objects'); |
552 | 512 | }); |
|
558 | 518 | ok(_.isNumber(3 * 4 - 7 / 10), 'but numbers are'); |
559 | 519 | ok(_.isNumber(NaN), 'NaN *is* a number'); |
560 | 520 | ok(_.isNumber(Infinity), 'Infinity is a number'); |
561 | | - ok(_.isNumber(iNumber), 'even from another frame'); |
562 | 521 | ok(!_.isNumber('1'), 'numeric strings are not numbers'); |
563 | 522 | }); |
564 | 523 |
|
|
573 | 532 | ok(!_.isBoolean(null), 'null is not a boolean'); |
574 | 533 | ok(_.isBoolean(true), 'but true is'); |
575 | 534 | ok(_.isBoolean(false), 'and so is false'); |
576 | | - ok(_.isBoolean(iBoolean), 'even from another frame'); |
577 | 535 | }); |
578 | 536 |
|
579 | 537 | test('isFunction', function() { |
|
582 | 540 | ok(!_.isFunction('moe'), 'strings are not functions'); |
583 | 541 | ok(!_.isFunction(document.createElement('div')), 'elements are not functions'); |
584 | 542 | ok(_.isFunction(_.isFunction), 'but functions are'); |
585 | | - ok(_.isFunction(iFunction), 'even from another frame'); |
586 | 543 | ok(_.isFunction(function(){}), 'even anonymous ones'); |
587 | 544 | }); |
588 | 545 |
|
589 | 546 | test('isDate', function() { |
590 | 547 | ok(!_.isDate(100), 'numbers are not dates'); |
591 | 548 | ok(!_.isDate({}), 'objects are not dates'); |
592 | 549 | ok(_.isDate(new Date()), 'but dates are'); |
593 | | - ok(_.isDate(iDate), 'even from another frame'); |
594 | 550 | }); |
595 | 551 |
|
596 | 552 | test('isRegExp', function() { |
597 | 553 | ok(!_.isRegExp(_.identity), 'functions are not RegExps'); |
598 | 554 | ok(_.isRegExp(/identity/), 'but RegExps are'); |
599 | | - ok(_.isRegExp(iRegExp), 'even from another frame'); |
600 | 555 | }); |
601 | 556 |
|
602 | 557 | test('isFinite', function() { |
|
620 | 575 | ok(!_.isNaN(null), 'null is not NaN'); |
621 | 576 | ok(!_.isNaN(0), '0 is not NaN'); |
622 | 577 | ok(_.isNaN(NaN), 'but NaN is'); |
623 | | - ok(_.isNaN(iNaN), 'even from another frame'); |
624 | 578 | ok(_.isNaN(new Number(NaN)), 'wrapped NaN is still NaN'); |
625 | 579 | }); |
626 | 580 |
|
627 | 581 | test('isNull', function() { |
628 | 582 | ok(!_.isNull(undefined), 'undefined is not null'); |
629 | 583 | ok(!_.isNull(NaN), 'NaN is not null'); |
630 | 584 | ok(_.isNull(null), 'but null is'); |
631 | | - ok(_.isNull(iNull), 'even from another frame'); |
632 | 585 | }); |
633 | 586 |
|
634 | 587 | test('isUndefined', function() { |
|
638 | 591 | ok(!_.isUndefined(NaN), 'NaN is defined'); |
639 | 592 | ok(_.isUndefined(), 'nothing is undefined'); |
640 | 593 | ok(_.isUndefined(undefined), 'undefined is undefined'); |
641 | | - ok(_.isUndefined(iUndefined), 'even from another frame'); |
642 | 594 | }); |
643 | 595 |
|
644 | 596 | test('isError', function() { |
645 | 597 | ok(!_.isError(1), 'numbers are not Errors'); |
646 | 598 | ok(!_.isError(null), 'null is not an Error'); |
647 | 599 | ok(!_.isError(Error), 'functions are not Errors'); |
648 | 600 | ok(_.isError(new Error()), 'Errors are Errors'); |
649 | | - ok(_.isError(iError), 'even from another frame'); |
650 | 601 | ok(_.isError(new EvalError()), 'EvalErrors are Errors'); |
651 | 602 | ok(_.isError(new RangeError()), 'RangeErrors are Errors'); |
652 | 603 | ok(_.isError(new ReferenceError()), 'ReferenceErrors are Errors'); |
|
655 | 606 | ok(_.isError(new URIError()), 'URIErrors are Errors'); |
656 | 607 | }); |
657 | 608 |
|
658 | | - if (window.ActiveXObject) { |
659 | | - test('IE host objects', function() { |
660 | | - var xml = new ActiveXObject('Msxml2.DOMDocument.3.0'); |
661 | | - ok(!_.isNumber(xml)); |
662 | | - ok(!_.isBoolean(xml)); |
663 | | - ok(!_.isNaN(xml)); |
664 | | - ok(!_.isFunction(xml)); |
665 | | - ok(!_.isNull(xml)); |
666 | | - ok(!_.isUndefined(xml)); |
667 | | - }); |
668 | | - |
669 | | - test('#1621 IE 11 compat mode DOM elements are not functions', function() { |
670 | | - var fn = function() {}; |
671 | | - var xml = new ActiveXObject('Msxml2.DOMDocument.3.0'); |
672 | | - var div = document.createElement('div'); |
673 | | - |
674 | | - // JIT the function |
675 | | - var count = 200; |
676 | | - while (count--) { |
677 | | - _.isFunction(fn); |
678 | | - } |
679 | | - |
680 | | - equal(_.isFunction(xml), false); |
681 | | - equal(_.isFunction(div), false); |
682 | | - equal(_.isFunction(fn), true); |
683 | | - }); |
684 | | - } |
685 | | - |
686 | 609 | test('tap', function() { |
687 | 610 | var intercepted = null; |
688 | 611 | var interceptor = function(obj) { intercepted = obj; }; |
|
0 commit comments