From 405c8b39c777dc1212beaa40c4cd018f4544c35b Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 18 Dec 2013 18:51:56 -0800 Subject: [PATCH 1/2] fix(forEach): allow looping over result of querySelectorAll in IE8 In IE8 the result object of calling `node.querySelectorAll` does not have a `hasOwnPropery` function. However, it should be usable with `forEach`. Related to #5400. --- src/Angular.js | 4 +++- test/AngularSpec.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Angular.js b/src/Angular.js index 88ea452b3749..386682a325e7 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -213,7 +213,9 @@ function forEach(obj, iterator, context) { if (obj) { if (isFunction(obj)){ for (key in obj) { - if (key != 'prototype' && key != 'length' && key != 'name' && obj.hasOwnProperty(key)) { + // Need to check if hasOwnProperty exists, + // as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function + if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) { iterator.call(context, obj[key], key); } } diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 36d4926e709b..7fe65f4c8051 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -504,6 +504,21 @@ describe('angular', function() { expect(log).toEqual(['0:a', '1:c']); }); + if (document.querySelectorAll) { + it('should handle the result of querySelectorAll in IE8 as it has no hasOwnProperty function', function() { + document.body.innerHTML = "

" + + "a" + + "b" + + "c" + + "

"; + + var htmlCollection = document.querySelectorAll('[name="x"]'), + log = []; + + forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML)}); + expect(log).toEqual(['0:a', '1:c']); + }); + } it('should handle arguments objects like arrays', function() { var args, From 96ffd38b4bd20c4b6c647715039003f5429d8bf8 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 18 Dec 2013 18:52:36 -0800 Subject: [PATCH 2/2] fix($log): should work in IE8 In IE8, reading `console.log.apply` throws an error. Catching this errow now. Fixes #5400. Fixes #5147. --- src/ng/log.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ng/log.js b/src/ng/log.js index c64e04f311ff..1d9a001a321b 100644 --- a/src/ng/log.js +++ b/src/ng/log.js @@ -139,9 +139,16 @@ function $LogProvider(){ function consoleLog(type) { var console = $window.console || {}, - logFn = console[type] || console.log || noop; + logFn = console[type] || console.log || noop, + hasApply = false; - if (logFn.apply) { + // Note: reading logFn.apply throws an error in IE11 in IE8 document mode. + // The reason behind this is that console.log has type "object" in IE8... + try { + hasApply = !! logFn.apply; + } catch (e) {} + + if (hasApply) { return function() { var args = []; forEach(arguments, function(arg) {