Skip to content

Commit

Permalink
explicitly point toString to Object.prototype.toString
Browse files Browse the repository at this point in the history
  • Loading branch information
Inviz committed Jan 24, 2015
1 parent bf1d4b7 commit ff53287
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
12 changes: 7 additions & 5 deletions lib/error-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ var ErrorReporter,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

ErrorReporter = (function() {
ErrorReporter.prototype._toString = Object.prototype.toString;

ErrorReporter.prototype._sourceCode = null;

function ErrorReporter(sourceCode) {
this.reportError = __bind(this.reportError, this);
if (sourceCode == null) {
throw new Error('Source code not provided');
}
if (toString.call(sourceCode) !== '[object String]') {
if (this._toString.call(sourceCode) !== '[object String]') {
throw new TypeError('Source code must be a string');
}
this._sourceCode = sourceCode;
Expand All @@ -20,7 +22,7 @@ ErrorReporter = (function() {
if (message == null) {
throw new Error('Message not provided');
}
if (toString.call(message) !== '[object String]') {
if (this._toString.call(message) !== '[object String]') {
throw new TypeError('Message must be a string');
}
if (message.length === 0) {
Expand All @@ -29,7 +31,7 @@ ErrorReporter = (function() {
if (lineNumber == null) {
throw new Error('Line number not provided');
}
if (toString.call(lineNumber) !== '[object Number]') {
if (this._toString.call(lineNumber) !== '[object Number]') {
throw new TypeError('Line number must be a number');
}
if (lineNumber <= 0) {
Expand All @@ -38,7 +40,7 @@ ErrorReporter = (function() {
if (columnNumber == null) {
throw new Error('Column number not provided');
}
if (toString.call(columnNumber) !== '[object Number]') {
if (this._toString.call(columnNumber) !== '[object Number]') {
throw new TypeError('Column number must be a number');
}
if (columnNumber <= 0) {
Expand Down Expand Up @@ -90,4 +92,4 @@ ErrorReporter = (function() {

})();

module.exports = ErrorReporter;
module.exports = ErrorReporter;
11 changes: 7 additions & 4 deletions src/error-reporter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#
class ErrorReporter

_toString: Object.prototype.toString


# @property [String] The source code to report errors on.
# @private
#
Expand All @@ -29,7 +32,7 @@ class ErrorReporter
constructor: (sourceCode) ->
throw new Error 'Source code not provided' unless sourceCode?

unless toString.call(sourceCode) is '[object String]'
unless @_toString.call(sourceCode) is '[object String]'
throw new TypeError 'Source code must be a string'

@_sourceCode = sourceCode
Expand All @@ -46,23 +49,23 @@ class ErrorReporter
reportError: (message, lineNumber, columnNumber) =>
throw new Error 'Message not provided' unless message?

unless toString.call(message) is '[object String]'
unless @_toString.call(message) is '[object String]'
throw new TypeError 'Message must be a string'

throw new Error 'Message must not be empty' if message.length is 0


throw new Error 'Line number not provided' unless lineNumber?

unless toString.call(lineNumber) is '[object Number]'
unless @_toString.call(lineNumber) is '[object Number]'
throw new TypeError 'Line number must be a number'

throw new RangeError 'Line number is invalid' if lineNumber <= 0


throw new Error 'Column number not provided' unless columnNumber?

unless toString.call(columnNumber) is '[object Number]'
unless @_toString.call(columnNumber) is '[object Number]'
throw new TypeError 'Column number must be a number'

throw new RangeError 'Column number is invalid' if columnNumber <= 0
Expand Down

0 comments on commit ff53287

Please sign in to comment.