mbbill / jsc.js Goto Github PK
View Code? Open in Web Editor NEWJavaScriptCore on WebAssembly
Home Page: https://mbbill.github.io/JSC.js/
JavaScriptCore on WebAssembly
Home Page: https://mbbill.github.io/JSC.js/
Any way to access scope that executed jsc_eval?
Or the global scope?
Thank you for this work! Could you please provide some typical use cases of JSC
?
I'm interested in trying to get this running inside of a DFINITY wasm canister. I think if I get a wasm file and a candid file I can get to a point to poke it with a stick, but I'm not sure if this project produces the candid file. If I have to custom build it, any idea what the function signatures would be to call line entries dynamically? https://sdk.dfinity.org/docs/developers-guide/work-with-languages.html
I've only been able to reproduce this bug in the WebAssembly build produced by Emscripten 1.38.21. I haven't been able to reproduce the bug with the asmjs build on the old demo page. (I wonder if the bug might still be present there but with different triggering circumstances.) I haven't tried any other builds.
If you enter this specific sequence after freshly loading the page, then the result of the last item is just the single unicode character \u0010
:
JSC.js Shell
Downloading contents, please wait...
Preparing...
wasm streaming compile failed: TypeError: Response has unsupported MIME type
falling back to ArrayBuffer instantiation
All downloads complete.
Running...
JSC >>> 1+2
3
JSC >>> 1000000
1000000
JSC >>> 5/0
Infinity
JSC >>> 3
3
JSC >>> 2*3
�
JSC >>>
Alternatively, you can just run this in the console to show the bug quickly:
console.log(JSON.stringify(jsc_eval('1+2') +':' + jsc_eval('1000000') +':'+ jsc_eval('5/0') +':'+ jsc_eval('3') +':'+ jsc_eval('2*3')))
The result will be
"3:1000000:Infinity:3:\u0010"
This issue is consistently reproducible in multiple browsers.
I've tried varying the sequence a bit. I don't think the specific numbers or arithmetic matter much; I think the trigger has to do with the string lengths of the inputs and outputs but I'm not really sure.
This project looks great. I would like to use it for another project I am working on. But I am not sure if I can use this project since I cannot find a license file. Would you be so kind to add the license you choose to the repository?
Thank you and nice work!
Error : TypeError: WebAssembly.instantiate(): Import #0 module="a" error: module is not an object or function
Here is the wasm code I think it is referring too : (import "a" "a" (func $import0)) (import "a" "b" (func $import1 (param i32) (result i32))) (import "a" "c" (func $import2 (param i32 i32 i32 i32) (result i32))) (import "a" "d" (func $import3 (result i32))) (import "a" "e" (func $import4 (param i32))) (import "a" "f" (func $import5 (param i32 i32 i32) (result i32)))
Compared to the demo wasm file : (import "env" "b" (func $import0)) (import "env" "c" (func $import1 (param i32))) (import "env" "d" (func $import2 (param i32) (result i32))) (import "asm2wasm" "f64-rem" (func $import3 (param f64 f64) (result f64))) (import "env" "e" (func $import4 (result i32))) (import "env" "f" (func $import5 (param f64) (result f64))) (import "env" "g" (func $import6 (param i32))) (import "env" "h" (func $import7 (param i32))) (import "env" "i" (func $import8 (result i32))) (import "env" "j" (func $import9 (param i32 i32))) (import "env" "k" (func $import10 (param i32 i32) (result i32)))
Just a note I compiled it with the error mentioned in a previous post but it outputs the wasm file before that error.
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.
I made a wrapper for this project using the engine and the javascript provided by emscripten.
https://github.com/TristonStuart/JS_To_JSC
The goal of the wrapper is to allow easy javascript use of the jsc_compile and evaluate functions.
It also allows conversion from the hex string provided to a UTF8 string which reduces the size of the string by half.
The wrapper can import .jsc files, make .jsc files, set the encoding of jsc (either hex, UTF8 raw, or UTF8). The wrapper also has a UTF8 encoding shifted from 0-255 to 183-438 to allow for easier copy and pasting. It can also translate these from their encoding to a byte array.
gn gen out --args="target_os="win""
ninja -C out
Error : ninja: Entering directory "out" [1/1096] CXX obj/Source/JavaScriptCore/bytecode/ArrayAllocationProfile.obj FAILED: obj/Source/JavaScriptCore/bytecode/ArrayAllocationProfile.obj cl.exe /showIncludes /FC @obj/Source/JavaScriptCore/bytecode/ArrayAllocationProfile.obj.rsp /c ../Source/JavaScriptCore/bytecode/ArrayAllocationProfile.cpp /Foobj/Source/JavaScriptCore/bytecode/ArrayAllocationProfile.obj /Fd"obj/Source/JavaScriptCore/jsc.pdb" CreateProcess failed: The system cannot find the file specified. [2/1096] CXX obj/Source/JavaScriptCore/bytecode/CallLinkStatus.obj FAILED: obj/Source/JavaScriptCore/bytecode/CallLinkStatus.obj cl.exe /showIncludes /FC @obj/Source/JavaScriptCore/bytecode/CallLinkStatus.obj.rsp /c ../Source/JavaScriptCore/bytecode/CallLinkStatus.cpp /Foobj/Source/JavaScriptCore/bytecode/CallLinkStatus.obj /Fd"obj/Source/JavaScriptCore/jsc.pdb" CreateProcess failed: The system cannot find the file specified. [3/1096] CXX obj/Source/JavaScriptCore/bytecode/CallVariant.obj FAILED: obj/Source/JavaScriptCore/bytecode/CallVariant.obj cl.exe /showIncludes /FC @obj/Source/JavaScriptCore/bytecode/CallVariant.obj.rsp /c ../Source/JavaScriptCore/bytecode/CallVariant.cpp /Foobj/Source/JavaScriptCore/bytecode/CallVariant.obj /Fd"obj/Source/JavaScriptCore/jsc.pdb" CreateProcess failed: The system cannot find the file specified. [4/1096] CXX obj/Source/JavaScriptCore/bytecode/CodeBlockHash.obj FAILED: obj/Source/JavaScriptCore/bytecode/CodeBlockHash.obj cl.exe /showIncludes /FC @obj/Source/JavaScriptCore/bytecode/CodeBlockHash.obj.rsp /c ../Source/JavaScriptCore/bytecode/CodeBlockHash.cpp /Foobj/Source/JavaScriptCore/bytecode/CodeBlockHash.obj /Fd"obj/Source/JavaScriptCore/jsc.pdb" CreateProcess failed: The system cannot find the file specified. [5/1096] CXX obj/Source/JavaScriptCore/bytecode/BytecodeBasicBlock.obj FAILED: obj/Source/JavaScriptCore/bytecode/BytecodeBasicBlock.obj cl.exe /showIncludes /FC @obj/Source/JavaScriptCore/bytecode/BytecodeBasicBlock.obj.rsp /c ../Source/JavaScriptCore/bytecode/BytecodeBasicBlock.cpp /Foobj/Source/JavaScriptCore/bytecode/BytecodeBasicBlock.obj /Fd"obj/Source/JavaScriptCore/jsc.pdb" CreateProcess failed: The system cannot find the file specified. [6/1096] CXX obj/Source/JavaScriptCore/bytecode/BytecodeGeneratorification.obj FAILED: obj/Source/JavaScriptCore/bytecode/BytecodeGeneratorification.obj cl.exe /showIncludes /FC @obj/Source/JavaScriptCore/bytecode/BytecodeGeneratorification.obj.rsp /c ../Source/JavaScriptCore/bytecode/BytecodeGeneratorification.cpp /Foobj/Source/JavaScriptCore/bytecode/BytecodeGeneratorification.obj /Fd"obj/Source/JavaScriptCore/jsc.pdb" CreateProcess failed: The system cannot find the file specified. [7/1096] CXX obj/Source/JavaScriptCore/bindings/ScriptValue.obj FAILED: obj/Source/JavaScriptCore/bindings/ScriptValue.obj cl.exe /showIncludes /FC @obj/Source/JavaScriptCore/bindings/ScriptValue.obj.rsp /c ../Source/JavaScriptCore/bindings/ScriptValue.cpp /Foobj/Source/JavaScriptCore/bindings/ScriptValue.obj /Fd"obj/Source/JavaScriptCore/jsc.pdb" CreateProcess failed: The system cannot find the file specified. [8/1096] CXX obj/Source/JavaScriptCore/bytecode/BytecodeLivenessAnalysis.obj FAILED: obj/Source/JavaScriptCore/bytecode/BytecodeLivenessAnalysis.obj cl.exe /showIncludes /FC @obj/Source/JavaScriptCore/bytecode/BytecodeLivenessAnalysis.obj.rsp /c ../Source/JavaScriptCore/bytecode/BytecodeLivenessAnalysis.cpp /Foobj/Source/JavaScriptCore/bytecode/BytecodeLivenessAnalysis.obj /Fd"obj/Source/JavaScriptCore/jsc.pdb" CreateProcess failed: The system cannot find the file specified. [9/1096] CXX obj/Source/JavaScriptCore/bytecode/AccessCase.obj FAILED: obj/Source/JavaScriptCore/bytecode/AccessCase.obj cl.exe /showIncludes /FC @obj/Source/JavaScriptCore/bytecode/AccessCase.obj.rsp /c ../Source/JavaScriptCore/bytecode/AccessCase.cpp /Foobj/Source/JavaScriptCore/bytecode/AccessCase.obj /Fd"obj/Source/JavaScriptCore/jsc.pdb" CreateProcess failed: The system cannot find the file specified. [10/1096] CXX obj/Source/JavaScriptCore/bytecode/AccessCaseSnippetParams.obj FAILED: obj/Source/JavaScriptCore/bytecode/AccessCaseSnippetParams.obj cl.exe /showIncludes /FC @obj/Source/JavaScriptCore/bytecode/AccessCaseSnippetParams.obj.rsp /c ../Source/JavaScriptCore/bytecode/AccessCaseSnippetParams.cpp /Foobj/Source/JavaScriptCore/bytecode/AccessCaseSnippetParams.obj /Fd"obj/Source/JavaScriptCore/jsc.pdb" CreateProcess failed: The system cannot find the file specified. ninja: build stopped: subcommand failed.
Files are missing.
just wondering how this compares to the built-in javascript
Trying to contact a server inside of jsc
Can i integrate it with my app?
Trying to build this project.
I am using windows 10.
I have this git clone and emsdk in a folder called jsc.
so emsdk : ./jsc/emsdk
this project : ./jsc/JSC.js
I installed Ninja to C:/Ninja and added it to my path.
Here are the commands I ran
C:\Users\trist\Desktop\jsc\JSC.js>C:\Users\trist\Desktop\jsc\emsdk\emsdk_env.bat
C:\Users\trist\Desktop\jsc\JSC.js>C:\Users\trist\Desktop\jsc\JSC.js\buildtools\win\gn.exe gen out --args="target_os=\"wasm\""
C:\Users\trist\Desktop\jsc\JSC.js>ninja -C out
Here is a pastebin of the error in full : https://pastebin.com/bZjE3xUH
Just a side note that the installation steps are outdated and the files reference do not exist (build/gn/download.bat) for example
hi! do you remember which version of emsdk you used? i use the latest (3.1.10) and there were compile errors where i can bypass which the following change:
--- a/Source/WTF/wtf/Compiler.h
+++ b/Source/WTF/wtf/Compiler.h
@@ -167,7 +167,8 @@
/* In GCC functions marked with no_sanitize_address cannot call functions that are marked with always_inline and not marked with no_sanitize_address.
* Therefore we need to give up on the enforcement of ALWAYS_INLINE when bulding with ASAN. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368 */
#if !defined(ALWAYS_INLINE) && COMPILER(GCC_COMPATIBLE) && defined(NDEBUG) && !COMPILER(MINGW) && !(COMPILER(GCC) && ASAN_ENABLED)
-#define ALWAYS_INLINE inline __attribute__((__always_inline__))
+// #define ALWAYS_INLINE inline __attribute__((__always_inline__))
+#define ALWAYS_INLINE inline
#endif
#if !defined(ALWAYS_INLINE) && COMPILER(MSVC) && defined(NDEBUG)
* Unmerged path build/BUILD.gn
however, the jsc_eval always reports an error from whatever given js input, even the simple one like 1 + 1
.
the code will fail at this point where errMsg is : -1
JSC.js/Source/JavaScriptCore/JSCJS/jscjs.cpp
Lines 187 to 191 in fc2a917
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.