Please enable JavaScript to use RhodeCode Enterprise
Commit Description:
utf8mb4
Commit Description:
utf8mb4
var falafel = require ( '../' );
var vm = require ( 'vm' );
var termExps = [
'Identifier' ,
'CallExpression' ,
'BinaryExpression' ,
'UpdateExpression' ,
'UnaryExpression'
]. reduce ( function ( acc , key ) { acc [ key ] = true ; return acc }, {});
function terminated ( node ) {
for ( var p = node ; p . parent ; p = p . parent ) {
if ( termExps [ p . type ]) return true ;
}
return false ;
}
var src = '{"a":[2,~9,prompt(":d")],"b":4,"c":prompt("beep"),"d":6}' ;
var offsets = [];
var output = falafel ( '(' + src + ')' , function ( node ) {
var isLeaf = node . parent
&& ! terminated ( node . parent ) && terminated ( node )
;
if ( isLeaf ) {
var s = node . source ();
var prompted = false ;
var res = vm . runInNewContext ( '(' + s + ')' , {
prompt : function ( x ) {
setTimeout ( function () {
node . update ( x . toUpperCase ());
}, Math . random () * 50 );
prompted = true ;
}
});
if ( ! prompted ) {
var s_ = JSON . stringify ( res );
node . update ( s_ );
}
}
});
setTimeout ( function () {
console . log ( src );
console . log ( '---' );
console . log ( output );
}, 200 );
Site-wide shortcuts
/
Use quick search box
g h
Goto home page
g g
Goto my private gists page
g G
Goto my public gists page
n r
New repository page
n g
New gist page
Repositories
g s
Goto summary page
g c
Goto changelog page
g f
Goto files page
g F
Goto files page with file search activated
g p
Goto pull requests page
g o
Goto repository settings
g O
Goto repository permissions settings