Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Fix IE8 problems in $log and general startup #5478

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/ng/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<p>" +
"<a name='x'>a</a>" +
"<a name='y'>b</a>" +
"<a name='x'>c</a>" +
"</p>";

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,
Expand Down