[Info-vax] [OT] The wonders of Javascript...

Simon Clubley clubley at remove_me.eisner.decus.org-Earth.UFP
Sun Mar 1 09:15:25 EST 2015


[Yes, I know it's OT for comp.os.vms, but I thought some might
find the following interesting.]

Due to a mistake (I got distracted), I ran the following line of code
before adding code to define and initialise resume_offset elsewhere:

ndm_database[this.db_idx].file_size =
        conn_database[this.db_idx].channel.contentLength
        + ndm_database[this.db_idx].resume_offset;

Turns out that in Javascript integer + undefined variable equals a
silent NaN and not a syntax error:

info: ndm: file_size = NaN, contentLength = 72306438, resume_offset = undefined

Even better, at some point along it's path from the addon script to the
front end content script (Firefox isolates addon and content scripts
and requires you to communicate by posting messages between them), the
NaN had been transformed in a way which rendered the formatted value as
zero on the front end HTML display instead of as a NaN...

Oh, the wonders of Javascript (part 482!)...

As well as adding features which make modern languages nicer to use
than traditional languages, it would be nice if some modern language
designers also included the robustness features from traditional
languages. In no sane language should it be possible to add using an
undefined variable without generating a syntax error.

The above info: line was generated by a console.log() statement
immediately following the above addition and the fact the Javascript
interpreter even executed the console.log() call after the above error
instead of aborting execution says a lot about Javascript... :-)

Simon.

-- 
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world



More information about the Info-vax mailing list