For a project I'm working on I need to record what version of an algorithm
was used to generate some pseudo-random data for an indefinitely long
time. I don't need to preserve the exact algorithm, but I do need to know
if it has changed. For the seeds/initialization vectors/lookup data I'm
relying on a SHA-1 digest of JSON encodings, but I'd also like to be able
to sign some related Javascript (generally some simple getters that do
things like convert a number to a string, or concatenate two strings,
etc.).
Function.toString() can produce a string representation of methods, but it
seems to just provide back whatever the string was that it was compiled
from:
% node
> var a = function (b) { console.log("b = %s", b.toString()); }
> a.toString();
'function (b) { console.log("b = %s", b.toString()); }'
> var a = function (b) { console.log("b = %s", b.toString()); /* dump b to
console */ }
> a.toString();
'function (b) { console.log("b = %s", b.toString()); /* dump b to console
*/ }'
Since comments and white-space are likely to change over time without
actually changing the algorithm I'd like to reduce this to a more canonical
form. As far as I can tell there's no built-in way to do this in node/V8,
but there are a couple minifiers that could be used (e.g. UglifyJS or
Closure Compiler). However I don't know how stable those minifiers are
going to be over the scale of years nor how suitable they are for run time
use. My current instinct would be to try to get at V8's parsed AST for the
function, serialize it to a string and feed that into the digest but I'm
not sure if there's a straightforward means of doing that. Anyone have
thoughts (or prior art) on this subject?
--Ken
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en