JSC.js
JSC.js copied to clipboard
Different results from JSC_Eval to JSC_Eval_Bytecode
I am getting different results when evaluation js vs compiling that js and evaluating it with jsc_eval_bytecode. Here is the code :
function add(x, y){
return x + y;
}
function subtract(x, y){
return x - y;
}
function multiply(x, y){
return x * y;
}
function devide(x, y){
return x / y;
}
function pow(x, y){
return Math.pow(x, y);
}
class NMath{
constructor(){
this.add = add;
this.subtract = subtract;
this.multiply = multiply;
this.devide = devide;
this.pow = pow;
}
smors(x){
var arr = x.split('');
var narr = [];
var total = 1;
for (let i=0; i < arr.length; i++){
narr.push(this.multiply(arr[i].charCodeAt(), 2));
}
for (let i=0; i < narr.length; i++){
total = total + narr[i] - this.devide((narr[i - 1])? narr[i-1] : 1, 3);
}
return total;
}
}
let pp = new NMath();
pp.smors('hello');
If I do Module.cwrap('jsc_eval', 'string', ['string'])
I get 784 as the result.
If I compile it and evaluate that I get this error :
Exception: SyntaxError: Unexpected identifier ''. Expected an opening '(' before a method's parameter list.
No idea what is causing this as I am just using the string returned from Module.cwrap('jsc_compile')
to feed to jsc_eval.
https://github.com/mbbill/JSC.js/issues/10#issuecomment-629558789
Have you seen this https://webkit.org/blog/9329/a-new-bytecode-format-for-javascriptcore/ ? I have no idea about webkit and compiling to bytecode. But if there is anyway you could check if there is a fix for this that would be amazing.
The link you posted is the foundation of JSC.js's bytecode compiler. If you look at the code JSC.js is basically calling into the bytecode compiler to dump the code cache and then output as binary array. It's was not possible before JSC introduce that feature, and that's why I started this project years ago but only tested bytecode compiler since last year.
Ah so you don’t know if they have updated it?
unless I do another update and try again.
ah is that hard to do?
not hard, just takes time
Are you planning on updating it soon?
maybe not very soon, but I'll try to find some time when possible
Would be very nice! Thanks for your hard work!