Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port JS API to new Context API #2969

Merged
merged 1 commit into from
Jun 24, 2022
Merged

Port JS API to new Context API #2969

merged 1 commit into from
Jun 24, 2022

Conversation

epilys
Copy link
Contributor

@epilys epilys commented Jun 22, 2022

All done.

Status: some bugs in Memory tests.

Also js-wasi tests are failing.

#2892

@epilys epilys added this to the v3.0 milestone Jun 22, 2022
@epilys epilys self-assigned this Jun 22, 2022
@epilys
Copy link
Contributor Author

epilys commented Jun 22, 2022

Ok so the blocking problem is here:

pub fn call(
&self,
_ctx: &mut impl AsContextMut,
_params: &[Value],
) -> Result<Box<[Value]>, RuntimeError> {
unimplemented!("Can't call functions with ContextMut as first parameter yet.");
/*
let arr = js_sys::Array::new_with_length(params.len() as u32);
for (i, param) in params.iter().enumerate() {
let js_value = param.as_jsvalue(&ctx.as_context_ref());
arr.set(i as u32, js_value);
}
let result = js_sys::Reflect::apply(
&self.handle.get(ctx.as_context_ref().objects()).function,
&wasm_bindgen::JsValue::NULL,
&arr,
)?;
let result_types = self.handle.get(ctx.as_context_ref().objects()).ty.results();
match result_types.len() {
0 => Ok(Box::new([])),
1 => {
let value = param_from_js(&result_types[0], &result);
Ok(vec![value].into_boxed_slice())
}
_n => {
let result_array: Array = result.into();
Ok(result_array
.iter()
.enumerate()
.map(|(i, js_val)| param_from_js(&result_types[i], &js_val))
.collect::<Vec<_>>()
.into_boxed_slice())
}
}
*/
}

When calling arbritary JS functions, we should put the context ContextMut<'_, _> as first argument of the js function. Doesn't that mean we have to expose it as a JS Object therefore JsValue with wasm-bindgen? Have I misunderstood how functions will be interacting with the context in general?

CC @Amanieu if you have the time to shed some light.

@epilys epilys linked an issue Jun 22, 2022 that may be closed by this pull request
@epilys epilys marked this pull request as ready for review June 23, 2022 11:01
@epilys epilys merged commit 82ea866 into context_api Jun 24, 2022
@bors bors bot deleted the context_api_js branch June 24, 2022 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate JS to the new Context API
2 participants