Timers and modules#55
Open
davidgraeff wants to merge 2 commits into
Open
Conversation
added 2 commits
December 4, 2019 18:45
* Patch makefile in build.rs to allow for cross compiling. * Add quickjs-libc.h to wrapper.h and regenerate bindings.rs for module support. * just: Let bindgen generate to src/bindings.rs * Use src/bindings.rs directly in lib.rs instead of including a file from OUT (faster compile time!) Signed-off-by: David Gräff <david.graeff@web.de>
…earTimeout). Add module support. Add compile/run_bytecode methods.
1. The bindings.rs file grew to one huge file with many different aspects covered. It is now split into value/marshal for ser/deserializing of JsValues and owned_value_ref for the OwnedValueRef type and utils for general utility methods.
2. DroppableValue was used in two ways: Either as a OwnedValueRef with a context pointer (instead of a ContextWrapper like OwnedValueRef uses it) or for the Properties enumeration. DroppableValue has been completely removed instead and OwnedValueRef takes a context pointer now. For properties enumeration a new type has been introduced (see value/marshal.rs).
3. impl ContextWrapper has been split into multiple impl ContextWrapper's, so that the callback API, timer API, module support each stay in their own rust-modules. bindings.rs is now purely for state keeping and the eval related API with about 500 LOC instead of 2k LOC.
4. Compiling to bytecode and running from bytecode has been added.
5. The timer API setTimeout/clearTimeout has been added. resolve_value required a few changes to "wait" for all timers to expire before returning.
6. Allow callback function arguments for `add_callback` and `create_callback` APIs. A new OpaqueJsFunction type (a simple-type wrapper around OwnedValueRef) is introduced for this. Usage example:
fn register_state_listener(id: String, callback_function: OpaqueJsFunction) -> i32 {
let _ = callback_function.invoke(vec![id]);
0
}
context.add_callback("notifyOnStateChange", register_state_listener)?;
7. Allow for a "generic" function argument for `add_callback` and `create_callback` APIs. This is useful if a js-api consumer is allowed to hand in a number, a string, a boolean. Usage example:
fn set_named_output(var_name: String, var_value: JsSimpleArgumentValue) -> JsValue {
println!("setNamedOutputValue {} {:?}", var_name, var_value);
JsValue::Null
}
Signed-off-by: David Gräff <david.graeff@web.de>
Owner
|
Hey sorry for the delay, I'll get to it this weekend. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds module support (not binary modules, just other files imported via the ES6 module syntax) and the js timer API (setTimeout, clearTimeout).
I wasn't really happy with bindings.rs being that one big huge file and refactored. This led to a big PR diff, but I'm willing to split this into smaller change-sets if the overall structure is something that this project want to go forward with.
The changes in detail. First commit:
Second commit:
The bindings.rs file grew to one huge file with many different aspects covered. It is now split into value/marshal for ser/deserializing of JsValues and owned_value_ref for the OwnedValueRef type and utils for general utility methods.
DroppableValue was used in two ways: Either as a OwnedValueRef with a context pointer (instead of a ContextWrapper like OwnedValueRef uses it) or for the Properties enumeration. DroppableValue has been completely removed instead and OwnedValueRef takes a context pointer now. For properties enumeration a new type has been introduced (see value/marshal.rs).
impl ContextWrapper has been split into multiple impl ContextWrapper's, so that the callback API, timer API, module support each stay in their own rust-modules. bindings.rs is now purely for state keeping and the eval related API with about 500 LOC instead of 2k LOC.
Compiling to bytecode and running from bytecode has been added.
The timer API setTimeout/clearTimeout has been added. resolve_value required a few changes to "wait" for all timers to expire before returning.
Allow callback function arguments for
add_callbackandcreate_callbackAPIs. A new OpaqueJsFunction type (a simple-type wrapper around OwnedValueRef) is introduced for this. Usage example:add_callbackandcreate_callbackAPIs. This is useful if a js-api consumer is allowed to hand in a number, a string, a boolean. Usage example: