Coder Social home page Coder Social logo

hirofa / spidermonkey_runtime Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 2.0 11.34 MB

this is a rust wrapper for the spidermonkey javascript engine, it uses the mozjs project

License: GNU General Public License v3.0

Rust 99.83% JavaScript 0.17%
rust script-engine mozjs-crate mozjs ecma-script javascript spidermonkey promises rust-ops modules

spidermonkey_runtime's People

Contributors

actions-user avatar andrieshiemstra avatar sagudev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spidermonkey_runtime's Issues

Proxy update: Results

refactor methods, getter, setters to return a Result<JSVal, String> so we can throw errors from Proxy classes

IDEA: Is api really easy?

If I understand correctly you call rust function from JS like:
esses.invoke_rust_op_sync("print", "this will be printed")
is it possible to invoke it like:
print("this will be printed")

Writing rust functions for JS is still pretty hard (not hard as writing it directly for mozjs):

fn reg_op(rt: &EsRuntimeWrapper) {
    rt.register_op(
        "my_rusty_op",
        Arc::new(|_rt, args: Vec<EsValueFacade>| {
            let a = args.get(0).unwrap().get_i32();
            let b = args.get(1).unwrap().get_i32();
            Ok(EsValueFacade::new_i32(a * b))
        }),
    );
}

My idea is that adding rusty code to JS should be as close as writing normal rust code and than just telling es_runtime to use that function (preferably even without special types, using Rusts types).

Storing EsValueFacade from function call

Hi, first of all thanks for this nice simplification of the Spider Monkey interface.

Now I'm rather new to Rust and this library and I wanted to add a global function to "register" functions. These functions are saved in a map and called later. My code looks like this:

let rt = EsRuntimeBuilder::new().build();

let mut map = HashMap::new();

rt.add_global_sync_function("test", |args| {
  map.insert(args[0].get_string(), &args[1]);
  Ok(EsValueFacade::undefined())
});

This won't compile (Error message: (dyn es_runtime::esvaluefacade::EsValueConvertible + std::marker::Send + 'static) cannot be shared between threads safely).

I don't expect it to work like this but this was my only approach. I'd guess doing it like this will conflict with the GC as it doesn't know whether the arguments are still used.

Now my question is: Is there a proper way of saving a EsValueFacade in a map and being able to use it later which won't conflict with the GC and the Rust compiler?

moduleloading, add metadata / support relative paths

https://doc.servo.org/mozjs/jsapi/fn.SetModuleMetadataHook.html
setmoduleprivate , this adds a private obj to the module?
this is populated by populateImportMeta? set url

we want this so we can alter the moduleLoader to also have a url which imports the new module so we can support relative paths

url should allways be full path so loading /mod,mes from one module or the other can load a different module entirely, caching should be done by full path

impl es_utils::report_error

currently there is a lot of error reporting done with the JSAPI method like so

unsafe {
    JS_ReportErrorASCII(cx, b"poof\0".as_ptr() as *const libc::c_char);
}

we need a pub fn report_error(err: &str); in es_utils.rs which does the above so the occurances in

  • the rest of the code may be replaced with this:
es_utils::report_error(cx, "poof");
  • the util should look something like this
// in es_utils.rs
pub fn report_error(cx: 8mut JSContext, err: &str) {
    let err_string = format!(b"{}\0", err);
    unsafe {
        JS_ReportErrorASCII(cx, err_string.as_str().as_ptr() as *const libc::c_char);
    }
}
  • There is also a JS_ReportErrorUTF8 we may want to figure out if and when we need that

  • the current report_es_ex() in es_utils.rs should be renamed to ```fetch_pending_exception()

Finish inline documentation

  • for at least
    • EsValueFacade
    • EsProxy
    • Proxy
    • EsRuntime(Builder)
    • SmRuntime
  • later
    • jsapi_utils.rs
    • arrays.rs
    • functions.rs
    • modules.rs
    • objects.rs
    • promises.rs
    • rooting.rs

Extend Github Actions

Now, as the base work is done, you can additional functionality to GitHub actions, here is list of my favorite:

  • Automatic format
  • Docs generation and publishing it to GitHub pages
  • Annotations (clippy lints)
  • Add cache to speed up rebuilding process

I have implemented them here, so just say which functionality do you want and I will make PR.

import native features

implement an API to add features (objects) based on import events rather than just code

this is a modification to the current code loader which can return either code or an object (or null when a feature is installed by impl)

Question@sagu about clippy config

the clippy workflow started giving errors about a 404 @

##[error]An action could not be found at the URI 'https://api.github.com/repos/actions-rs/clippy-check/tarball/annotations-fallback'

i updated this to v1 in cc59e11

it works now but the actions takes only 7m instead of the usual 12-14 minutes

i can only find examples about the v1 variant so my question is what is the annotations-fallback variant and should this still work or is my modification to v1 ok?

TypedArrays and EsValueFacade revamp

  • typedArrays from and to Vecs

  • EsValueFacade should get a TYPE enum and store it's value in a Any instead of the current ever growing if else if statements

  • or something like a JSValCovertable for each type

  • rewrite prmise stuff so we don't need es files anymore
  • rewrite EsValueFacade
  • add typedarrays stuff for EsValueFacade

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.