Giter Club home page Giter Club logo

jsc.js's Introduction

JSC.js is a JavaScript engine that can run on top of your browser's JavaScript engine. It's based on the JavaScript engine (JavaScriptCore) of WebKit and compiled to wasm with emscripten. Therefore, if you're using Safari, you are running its JavaScript engine on top of itself.

The size of JSC.wasm is around 4MB (compressed js and mem file).

Demo: Link

ScreenShot

Build

Preparation

  • install emscripten
  • install python, ruby, ninja, etc.
  • start a terminal.
  • go to emsdk installation path and run emsdk_env.bat
  • go to JSC.js folder and run prep_env.bat

Build with gn

> gn gen out --args="target_os=\"wasm\""
> ninja -C out

Build test shell on Windows

Usually, you don't need this but with the test shell, you can easily debug and test JSC.js on windows when there's no good debugger for JSC.js on wasm.

Preparation

  • install python, ruby, etc.
  • start a terminal.
  • install visual studio
  • run vcvarsall.bat amd64 in terminal

Build with gn

> gn gen out --args="target_os=\"win\""
> ninja -C out

jsc.js's People

Contributors

macil avatar mbbill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsc.js's Issues

Corrupt results from jsc_eval sometimes in WebAssembly build

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.

License?

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!

Candid Files

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

Error when instantiating wasm file

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.

Use Cases

Thank you for this work! Could you please provide some typical use cases of JSC?

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.

Failed at checkSyntax

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

checkSyntax(vm, makeSource(sourceStr, sourceOrigin), error);
if (error.isValid()) {
errMsg = error.message() + ":" + String::number(error.line());
return false;
}

benchmarks?

just wondering how this compares to the built-in javascript

HELPPPP

Can i integrate it with my app?

Javascript Wrapper for compiling js to jsc.

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.

[Error] Build Stopped: subcommand failed

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

Error When Building With target_os=win

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.

Access globals?

Any way to access scope that executed jsc_eval?
Or the global scope?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.