Created
October 2, 2014 21:22
-
-
Save DinisCruz/245716893d783ea740ea to your computer and use it in GitHub Desktop.
BSON serialization (pop a calculator)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "bsjon_parsing", | |
"version": "1.0.0", | |
"description": "npm json parsing tests", | |
"main": "index.js", | |
"scripts": { | |
"test": "mocha -w --compilers coffee:coffee-script/register ./**/*.*" | |
}, | |
"author": "Dinis Cruz <dinis.cruz@owasp.org> (http://blog.diniscruz.com/)", | |
"license": "ISC", | |
"dependencies": { | |
"bson": "^0.2.15" | |
}, | |
"devDependencies": { | |
"chai": "^1.9.2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BSON = require('bson/lib/bson/bson.js').BSON | |
expect = require('chai').expect | |
describe 'test node bjon',-> | |
#based on https://github.com/mongodb/js-bson/blob/master/test/node/bson_test.js#L1512 | |
it 'simmple serialization', -> | |
doc = {a: 1, func: ()-> console.log('hello world') } | |
buffer = BSON.serialize(doc, true, true, true); | |
expect(buffer.length).to.equal(91) | |
deserializedDoc = BSON.deserialize(buffer); | |
console.log(typeof deserializedDoc.func) | |
console.log(deserializedDoc.func) | |
deserializedDoc = BSON.deserialize(buffer, {evalFunctions:true, cacheFunctions:true}); | |
console.log(deserializedDoc.func) | |
deserializedDoc.func() | |
it 'open ', (done)-> | |
doc = {a: 1, func: ()-> require('child_process').spawn('open',['/Applications/Calculator.app']) } | |
buffer = BSON.serialize(doc, true, true, true); | |
deserializedDoc = BSON.deserialize(buffer, {evalFunctions:true}); | |
child = deserializedDoc.func() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment