jsengine 2.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

JSEngine for dart, based on jerryscript.

Prerequisite #

Make sure you have created the libjerrywrapper.so (so file if linux system, or respective shared lib file).
Build instruction for jerryscriptwrapper shared lib is present inside jerryscriptwrapper folder of this source code.

Usage #

A simple usage example:

import 'package:jsengine/jsengine.dart';

JSEngine jsEngine = JSEngine(pathToLibSoFile: "jerryscriptwrapper/build/libjerryscriptwrapper.so");
  String mapfunct = 'function(doc){emit(doc.name,doc.age); }';
  String cf ="var giveEmitObject = function(){var map_results = [];var emit = function(key,value){ map_results.push({key:key, value: value});};return {map_results: map_results, emit: emit};};var mapThisDoc = function(documentStr){ var document = JSON.parse(documentStr); var emitObj= giveEmitObject(); var emit = emitObj.emit; ($mapfunct)(document); return JSON.stringify(emitObj.map_results);};mapThisDoc('{\"name\":\"Anurag Vohra\",\"age\":30}');";
  String result = jsEngine.runJSCode(cf);

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Observation #

If your test are getting hanged, then delete the "build/testfile.dill.track.dill"

2.0.1 #

  • Added validateJScode to validate a code before running.
  • Improved test cases and error handling
  • runJSCode function now returns error Strings in case its not able to runt he code. The error will be helpful in debugging the issue.

2.0.0 #

  • This release takes a completely different approach. It uses Jerryscript engine to evaulate the JS code.
  • Uses isolate and Future api to give maximum performance.
  • Complete reinvention of the wheel.

1.0.1 #

  • Updated README file: issue tracker link and Description. No functional changes.

1.0.0 #

  • Initial version, created by Anurag Vohra

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:jsengine/jsengine.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String jsoutput = 'Unknown';
  JSEngine jsEngine = JSEngine();
  int counter;

  @override
  void initState() {
    super.initState();
    counter=30;
  }


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
              children: <Widget>[
                Text(jsoutput),
                RaisedButton(child: Text("Press to see JS runs"), onPressed: () async{
                  counter = counter+1;
                  JSEngine jsEngine = JSEngine();
                  String mapfunct = 'function(doc){emit(doc.name,doc.age); }';
                  String cf ='''var giveEmitObject = function(){var map_results = [];var emit = function(key,value){ map_results.push({key:key, value: value});};return {map_results: map_results, emit: emit};};var mapThisDoc = function(documentStr){ var document = JSON.parse(documentStr); var emitObj= giveEmitObject(); var emit = emitObj.emit; ($mapfunct)(document); return JSON.stringify(emitObj.map_results);};mapThisDoc('{"name":"Anurag Vohra","age":$counter}');''';
                  print("reevaluating");
                  jsoutput = await jsEngine.runJSCode(cf);
                  setState(() { });
                },)
              ],
            )
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  jsengine: ^2.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:jsengine/jsengine.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
33
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
62
Learn more about scoring.

We analyzed this package on Jul 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:jsengine/jsengine.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:jsengine/jsengine.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:jsengine/jsengine.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:jsengine/jsengine.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [jsengine] that is in a package requiring null.

Health suggestions

Fix lib/jsengine.dart. (-1.49 points)

Analysis of lib/jsengine.dart reported 3 hints:

line 15 col 15: The value of the local variable 'isolate' isn't used.

line 36 col 15: The value of the local variable 'isolate' isn't used.

line 72 col 12: This function has a return type of 'Pointer

Fix lib/src/otherlibsextensions.dart. (-0.50 points)

Analysis of lib/src/otherlibsextensions.dart reported 1 hint:

line 29 col 17: This function has a return type of 'String', but doesn't end with a return statement.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
ffi ^0.1.3 0.1.3
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test