hirofa / spidermonkey_runtime Goto Github PK
View Code? Open in Web Editor NEWthis is a rust wrapper for the spidermonkey javascript engine, it uses the mozjs project
License: GNU General Public License v3.0
this is a rust wrapper for the spidermonkey javascript engine, it uses the mozjs project
License: GNU General Public License v3.0
method to createa new instance of a proxy class
also needs reflection::new_instance(proxy_name: &str)
or just reference sagudevs repo
see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports
todo:
and esses.invoke_rust_op* methods in es
Move text from docs folder to Doc comments, so they appear with the rest of API docs.
or is that for ESsesLib only?
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).
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
pass return_value: MutableHandleValue instead of returning JSVal
implement an API for the fetch function, implementing party should be able to pass a callback to resolvet the url and return a response object
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
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)
refactor methods, getter, setters to return a Result<JSVal, String> so we can throw errors from Proxy classes
-- -D warnings
or maybe RUSTFLAGS: -D warnings
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
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?
Now, as the base work is done, you can additional functionality to GitHub actions, here is list of my favorite:
I have implemented them here, so just say which functionality do you want and I will make PR.
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
es_utils::report_error(cx, "poof");
// 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()
This repo uses 11 dependencies. Mozjs is logical, but others ...
From some dependencies only one function is used.
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?
Log a message when a promise without a catch handler is rejected
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.