File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -265,17 +265,9 @@ proto.write = function (buffer) {
265265 break ;
266266 default :
267267 this . tState = START ;
268- var result = Number ( this . string ) ;
269-
270- if ( isNaN ( result ) ) {
271- return this . charError ( buffer , i ) ;
272- }
273-
274- if ( ( this . string . match ( / [ 0 - 9 ] + / ) == this . string ) && ( result . toString ( ) != this . string ) ) {
275- // Long string of digits which is an ID string and not valid and/or safe JavaScript integer Number
276- this . onToken ( STRING , this . string ) ;
277- } else {
278- this . onToken ( NUMBER , result ) ;
268+ var error = this . numberReviver ( this . string ) ;
269+ if ( error ) {
270+ return error ;
279271 }
280272
281273 this . offset += this . string . length - 1 ;
@@ -412,6 +404,23 @@ proto.onToken = function (token, value) {
412404 }
413405} ;
414406
407+ // Override to implement your own number reviver.
408+ // Any value returned is treated as error and will interrupt parsing.
409+ proto . numberReviver = function ( text ) {
410+ var result = Number ( text ) ;
411+
412+ if ( isNaN ( result ) ) {
413+ return this . charError ( buffer , i ) ;
414+ }
415+
416+ if ( ( text . match ( / [ 0 - 9 ] + / ) == text ) && ( result . toString ( ) != text ) ) {
417+ // Long string of digits which is an ID string and not valid and/or safe JavaScript integer Number
418+ this . onToken ( STRING , text ) ;
419+ } else {
420+ this . onToken ( NUMBER , result ) ;
421+ }
422+ }
423+
415424Parser . C = C ;
416425
417426module . exports = Parser ;
You can’t perform that action at this time.
0 commit comments