Git Product home page Git Product logo

quickjs_dart's Introduction

QuickJS Dart

A dart binding for QuickJS, a modern Javascript interpreter written in C by Fabrice Bellard

We can run javascript VM embedded to DartVM, using Dart:FFI

ENV requirement

  1. dart lang 2.8+
  2. clang
  3. llvm(optional)
  4. ios 9+
  5. android api 21+

Quick Start

// dart code

import 'package:quickjs_dart/quickjs_dart.dart';

void main(){

   JSEngine(); // initialize engine

   String jsString = r"""
      function testAdd(x,y){
         return x+y;
      }
      testAdd
   """
   var engine= JSEngine.instance; // singleton

   var testAdd = engine.evalScript(jsString);

   print(testAdd.isFunction()); // true
   
   var result= testAdd.callJS([engine.newInt32(12),engine.newInt32(34)]); // 2 params, 12 and 34;
   
   result.jsPrint(); // use `console.log` in javascript, 46 is the result;
}

Table of Content

  1. QuickJS Dart
    1. ENV requirement
    2. Quick Start
    3. Table of Content
    4. Build and Run (local machine only)
    5. Why not V8/jscore, and why QuickJS
    6. Why not PlatformChannel/MethodChannel and why Dart:FFI
    7. Docs and APIs

Build and Run (local machine only)

  1. build quickjs lib for ios/android/dartVM

    sh ~/.build_all.sh

    or build android only

    sh ~/.build_android.sh

    or bulid ios only

    sh ~/.build_ios.sh
  2. run dart on dart vm

     dart main.dart
  3. if you come up with file system relative paths not allowed in hardened programs with macos, run this

    codesign --remove-signature /usr/local/bin/dart
  4. run flutter example, android or ios

    note: run flutter doctor -v to examine the flutter env is correctly

    Then you can run example app

    cd example && flutter run

Why not V8/jscore, and why QuickJS

V8 is too big for small app and IOT devices. jscore is a bit old and slow for modern app.

Quickjs follows latest Javascript standard (ES2020) now. And it is fast enough, see benchmark

Why not PlatformChannel/MethodChannel and why Dart:FFI

PlatformChannel/MethodChannel(s) are designed for communication, post and receive data, and use features that had been made by exisiting Android/iOS/Native modules. It's not managed by Dart/Flutter itself.

Using Dart:FFI, we get possibilities to expand the dart/flutter. We can call native function, back and forward, adding Callbacks, manage memory of functions and values.

Docs and APIs

Do it later

quickjs_dart's People

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quickjs_dart's Issues

Doesn't work on Real device of iOS

Update 2020.09.21
Android fixed
iOS encounter framework with simulator, will fix later

Update 2020.09.18
Seems that Android on release mode also failed.
The runtime maybe not update during the process.

Update 2020.09.14
Seems that the eval function does not work after JSEngine is initialized. Still don't know why, but we can work around by providing global eval function when engine starts, not after. That one time only solution.


Simulator works, but not on real device.

May be it's something wrong with the build script , Cmakefiles.txt or even the source code itself.

Somehow it's unclear, hope some one could help me with this.

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.