Browse files

.run(), passing literal modification test

  • Loading branch information...
1 parent a01c859 commit 8124e582967cf59c9d6dd71103842424f5f0d797 @substack committed Nov 6, 2012
Showing with 17 additions and 3 deletions.
  1. +1 −0 example/run.js
  2. +1 −2 index.js
  3. +15 −1 test/scope.js
View
1 example/run.js
@@ -4,3 +4,4 @@ var scoper = require('../');
var src = fs.readFileSync(process.argv[2], 'utf8');
var c = Function('return ' + scoper(src))();
console.dir(c);
+c.run();
View
3 index.js
@@ -33,10 +33,9 @@ module.exports = function (src) {
+ Object.keys(literal).map(function (id) {
return JSON.stringify(id) + ':' + '[' + literal[id].join(',') + ']'
}, '').join(',\n') + '};\n'
- + out
+ ';return {' + Object.keys(names).map(function (name) {
return JSON.stringify(name) + ':' + names[name];
- })
+ }) + ',run:function(){' + out + '}'
+ '}})()'
;
View
16 test/scope.js
@@ -7,7 +7,21 @@ var src = fs.readFileSync(__dirname + '/src/source.js', 'utf8');
test('run', function (t) {
t.plan(1);
- Function([ 'console' ], 'return ' + scoper(src))({
+ var c = Function([ 'console' ], 'return ' + scoper(src))({
log : function (n) { t.equal(n, 1378) }
});
+ c.run();
+});
+
+test('modify a literal', function (t) {
+ t.plan(2);
+
+ var expected = [ 1378, 2378 ];
+ var c = Function([ 'console' ], 'return ' + scoper(src))({
+ log : function (n) { t.equal(n, expected.shift()) }
+ });
+ c.run();
+
+ c.literal[''][1] += 100;
+ c.run();
});

0 comments on commit 8124e58

Please sign in to comment.