function jsrt_eval($code) { global $bc, $jsi_break; #-- store current runtime context (all interpreter state vars # and the 'bytecode', but not the global variables) $old_bc = $bc; $old_rt = array($jsi_break); #-- run code js_exec($code, "_CLEAN=1"); #-- restore previous runtime context $bc = $old_bc; list($jsi_break) = $old_rt; }
function js($script = "", $flags = 0x3) { #-- start buffer ob_start(); ob_implicit_flush(0); #-- compile, exec js_exec($script, $flags); #-- get result $r = ob_get_contents(); ob_end_clean(); return $r; }