Skip to content

Commit

Permalink
Merge pull request #3427 from ichernev:fix-ie8
Browse files Browse the repository at this point in the history
[misc] ie8: Fix IE8
  • Loading branch information
ichernev committed Sep 12, 2016
2 parents ccbd89a + c3988f1 commit 7706054
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/lib/utils/is-object.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default function isObject(input) {
return Object.prototype.toString.call(input) === '[object Object]';
// IE8 will treat undefined and null as object if it wasn't for
// input != null
return input != null && Object.prototype.toString.call(input) === '[object Object]';
}
7 changes: 4 additions & 3 deletions src/test/helpers/common-locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ export function defineCommonLocaleTests(locale, options) {
test('weekday parsing correctness', function (assert) {
var i, m;

if (locale === 'tr' || locale === 'az') {
// There is a lower-case letter (ı), that converted to upper then
// lower changes to i
if (locale === 'tr' || locale === 'az' || locale === 'ro') {
// tr, az: There is a lower-case letter (ı), that converted to
// upper then lower changes to i
// ro: there is the letter ț which behaves weird under IE8
expect(0);
return;
}
Expand Down
26 changes: 18 additions & 8 deletions src/test/moment/to_type.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { module, test } from '../qunit';
import { module, test, expect } from '../qunit';
import moment from '../../moment';

module('to type');
Expand Down Expand Up @@ -29,15 +29,25 @@ test('toDate returns a copy of the internal date', function (assert) {
});

test('toJSON', function (assert) {
var expected = new Date().toISOString();
assert.deepEqual(moment(expected).toJSON(), expected, 'toJSON invalid');
if (Date.prototype.toISOString) {
var expected = new Date().toISOString();
assert.deepEqual(moment(expected).toJSON(), expected, 'toJSON invalid');
} else {
// IE8
expect(0);
}
});

test('toJSON works when moment is frozen', function (assert) {
var expected = new Date().toISOString();
var m = moment(expected);
if (Object.freeze != null) {
Object.freeze(m);
if (Date.prototype.toISOString) {
var expected = new Date().toISOString();
var m = moment(expected);
if (Object.freeze != null) {
Object.freeze(m);
}
assert.deepEqual(m.toJSON(), expected, 'toJSON when frozen invalid');
} else {
// IE8
expect(0);
}
assert.deepEqual(m.toJSON(), expected, 'toJSON when frozen invalid');
});

0 comments on commit 7706054

Please sign in to comment.