diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Angular.js | 14 | ||||
| -rw-r--r-- | src/Injector.js | 6 | ||||
| -rw-r--r-- | src/angular-mocks.js | 83 |
3 files changed, 53 insertions, 50 deletions
diff --git a/src/Angular.js b/src/Angular.js index 0dfea2f4..72a892e5 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -80,7 +80,6 @@ var _undefined = undefined, $name = 'name', $noop = 'noop', $null = 'null', - $number = 'number', $object = 'object', $string = 'string', $value = 'value', @@ -94,6 +93,7 @@ var _undefined = undefined, jQuery, // delay binding slice = [].slice, push = [].push, + toString = Object.prototype.toString, error = window[$console] ? bind(window[$console], window[$console]['error'] || noop) : noop, @@ -363,7 +363,7 @@ function isString(value){return typeof value == $string;} * @param {*} value Reference to check. * @returns {boolean} True if `value` is a `Number`. */ -function isNumber(value){return typeof value == $number;} +function isNumber(value){return typeof value == 'number';} /** @@ -377,7 +377,9 @@ function isNumber(value){return typeof value == $number;} * @param {*} value Reference to check. * @returns {boolean} True if `value` is a `Date`. */ -function isDate(value){return value instanceof Date;} +function isDate(value){ + return toString.apply(value) == '[object Date]'; +} /** @@ -391,7 +393,9 @@ function isDate(value){return value instanceof Date;} * @param {*} value Reference to check. * @returns {boolean} True if `value` is an `Array`. */ -function isArray(value) {return value instanceof Array;} +function isArray(value) { + return toString.apply(value) == '[object Array]'; +} /** @@ -769,7 +773,7 @@ function equals(o1, o2) { if (o1 === null || o2 === null) return false; var t1 = typeof o1, t2 = typeof o2, length, key, keySet; if (t1 == t2 && t1 == 'object') { - if (o1 instanceof Array) { + if (isArray(o1)) { if ((length = o1.length) == o2.length) { for(key=0; key<length; key++) { if (!equals(o1[key], o2[key])) return false; diff --git a/src/Injector.js b/src/Injector.js index 838a911d..eacb8699 100644 --- a/src/Injector.js +++ b/src/Injector.js @@ -107,7 +107,7 @@ function createInjector(modulesToLoad, moduleRegistry) { path.shift(); } case 'object': - if (value instanceof Array) { + if (isArray(value)) { return invoke(null, value); } default: @@ -122,11 +122,11 @@ function createInjector(modulesToLoad, moduleRegistry) { length, key; - if (fn instanceof Function) { + if (typeof fn == 'function') { $inject = inferInjectionArgs(fn); length = $inject.length; } else { - if (fn instanceof Array) { + if (isArray(fn)) { $inject = fn; length = $inject.length; fn = $inject[--length]; diff --git a/src/angular-mocks.js b/src/angular-mocks.js index 970a1b6d..907b0492 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -476,92 +476,92 @@ angular.mock.$LogProvider = function(){ * */ angular.mock.TzDate = function (offset, timestamp) { + var self = new Date(0); if (angular.isString(timestamp)) { var tsStr = timestamp; - this.origDate = angular.fromJson(angular.toJson({date:timestamp})).date; + self.origDate = angular.fromJson(angular.toJson({date:timestamp})).date; - timestamp = this.origDate.getTime(); + timestamp = self.origDate.getTime(); if (isNaN(timestamp)) throw { name: "Illegal Argument", message: "Arg '" + tsStr + "' passed into TzDate constructor is not a valid date string" }; } else { - this.origDate = new Date(timestamp); + self.origDate = new Date(timestamp); } var localOffset = new Date(timestamp).getTimezoneOffset(); - this.offsetDiff = localOffset*60*1000 - offset*1000*60*60; - this.date = new Date(timestamp + this.offsetDiff); + self.offsetDiff = localOffset*60*1000 - offset*1000*60*60; + self.date = new Date(timestamp + self.offsetDiff); - this.getTime = function() { - return this.date.getTime() - this.offsetDiff; + self.getTime = function() { + return self.date.getTime() - self.offsetDiff; }; - this.toLocaleDateString = function() { - return this.date.toLocaleDateString(); + self.toLocaleDateString = function() { + return self.date.toLocaleDateString(); }; - this.getFullYear = function() { - return this.date.getFullYear(); + self.getFullYear = function() { + return self.date.getFullYear(); }; - this.getMonth = function() { - return this.date.getMonth(); + self.getMonth = function() { + return self.date.getMonth(); }; - this.getDate = function() { - return this.date.getDate(); + self.getDate = function() { + return self.date.getDate(); }; - this.getHours = function() { - return this.date.getHours(); + self.getHours = function() { + return self.date.getHours(); }; - this.getMinutes = function() { - return this.date.getMinutes(); + self.getMinutes = function() { + return self.date.getMinutes(); }; - this.getSeconds = function() { - return this.date.getSeconds(); + self.getSeconds = function() { + return self.date.getSeconds(); }; - this.getTimezoneOffset = function() { + self.getTimezoneOffset = function() { return offset * 60; }; - this.getUTCFullYear = function() { - return this.origDate.getUTCFullYear(); + self.getUTCFullYear = function() { + return self.origDate.getUTCFullYear(); }; - this.getUTCMonth = function() { - return this.origDate.getUTCMonth(); + self.getUTCMonth = function() { + return self.origDate.getUTCMonth(); }; - this.getUTCDate = function() { - return this.origDate.getUTCDate(); + self.getUTCDate = function() { + return self.origDate.getUTCDate(); }; - this.getUTCHours = function() { - return this.origDate.getUTCHours(); + self.getUTCHours = function() { + return self.origDate.getUTCHours(); }; - this.getUTCMinutes = function() { - return this.origDate.getUTCMinutes(); + self.getUTCMinutes = function() { + return self.origDate.getUTCMinutes(); }; - this.getUTCSeconds = function() { - return this.origDate.getUTCSeconds(); + self.getUTCSeconds = function() { + return self.origDate.getUTCSeconds(); }; - this.getDay = function() { - return this.origDate.getDay(); + self.getDay = function() { + return self.origDate.getDay(); }; //hide all methods not implemented in this mock that the Date prototype exposes - var self = this, - unimplementedMethods = ['getMilliseconds', 'getUTCDay', + var unimplementedMethods = ['getMilliseconds', 'getUTCDay', 'getUTCMilliseconds', 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds', 'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear', 'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds', @@ -570,12 +570,11 @@ angular.mock.TzDate = function (offset, timestamp) { angular.forEach(unimplementedMethods, function(methodName) { self[methodName] = function() { - throw { - name: "MethodNotImplemented", - message: "Method '" + methodName + "' is not implemented in the TzDate mock" - }; + throw Error("Method '" + methodName + "' is not implemented in the TzDate mock"); }; }); + + return self; } //make "tzDateInstance instanceof Date" return true |
