Skip to content

Commit

Permalink
use Object.prototype.toString
Browse files Browse the repository at this point in the history
  • Loading branch information
Inviz committed Jan 24, 2015
1 parent ff53287 commit 5168adf
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/error-reporter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#
class ErrorReporter

_toString: Object.prototype.toString


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

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

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

unless @_toString.call(message) is '[object String]'
unless Object.prototype.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 Object.prototype.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 Object.prototype.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 5168adf

Please sign in to comment.