coolaj86/node-browser-compat — pull request #4 by zbjornson (2013-07-22 18:33:12+00:00)
Title: Call toString on args to match browser behavior.

Browsers appear to call .toString on btoa args. This package has unpredictable behavior if you pass it a non-string:

````
> $ node
> var btoa = require("btoa");
undefined
> btoa((Date.now() * Math.random()).toString())
'ODczNzg4ODA3MjY3LjYwOTE='
> btoa(Date.now() * Math.random())
FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory
> btoa(Date.now() * Math.random())
FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() length exceeds max acceptable value
> btoa((Date.now() * Math.random()))
''
````

If the number is small(?), the output is wrong:

````
// browser:
> btoa(1234)
'MTIzNA=='
// current node-btoa
> btoa(1234)
'AAC4mHwCAAAAAP////8AAAAAeAR8AgAAAAABAAAAAAAAAKCHigAAAAAAANN6AgAAAABIMXwCAAAAAGiZfAIAAAAAAAAAAAAAAACQp5cAAAAAABhBfAIAAAAAuAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAABwmnwCAAAAAGiZfAIAAAAA/////8kAAAAAAAAAAAAAAFiafAIAAAAAAgAAAAAAAABomnwCAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAABAAAAsJyXAAAAAAAYQXwCAAAAALkAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAADomXwCAAAAAP////8AAAAAKAR8AgAAAAAQN3wCAAAAAHCafAIAAAAAAAAAAAAAAAD///8fAAAAABhBfAIAAAAAaEZ8AgAAAABwkHwCAAAAAGiEfAIAAAAAKG58AgAAAACIenwCAAAAADBvfAIAAAAAkHt8AgAAAAAYQXwCAAAAAGhGfAIAAAAAcJB8AgAAAABohHwCAAAAAChufAIAAAAAiHp8AgAAAAAwb3wCAAAAAJB7fAIAAAAA2Fh8AgAAAACQXXwCAAAAALBnfAIAAAAA4Fl8AgAAAAC4aHwCAAAAABhBfAIAAAAAaEZ8AgAAAABwkHwCAAAAAGiEf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