lundi 2 mars 2015

Instruct node.js to treat undefined as defined but null or false?

I'm working on an interop project between JSBN and Crypto++. I'm using Node.js 0.12.0. I'm a C++/Crypto++ guy, so the Javascript and Node.js are not my specialty.


When I attempt to load a few of the JSBN Javascript files in node.js, I get an error:



$ node cryptopp-jsbn.js
/Users/test/cryptopp-jsbn/jsbn.js:70
if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
^
ReferenceError: navigator is not defined
at Object.<anonymous> (/Users/test/cryptopp-jsbn/jsbn.js:70:13)
at Module._compile (module.js:460:26)
...


I know I can get through them with code similar to the following. The fix works fine because the JSBN code drops into a non-navigator block.



var has_navigator = typeof(navigator) != 'undefined';
if(j_lm && has_navigator && (navigator.appName == "Microsoft Internet Explorer")) {
BigInteger.prototype.am = am2;
dbits = 30;
}
...


I'd prefer not to fix this everywhere there's a problem. Rather, I'd like to tell node.js to treat everything that's undefined as defined but null or false.


I've been through the nodejs(1) man pages, but I don't see the setting. (It may be implied or enabled with something like Harmony or Crankshaft, but I'm no wiser).


Is it possible to tell node.js to treat undefined as defined but null or false? If so, how?


Aucun commentaire:

Enregistrer un commentaire