-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
Tracking issue for implemented methods on JsTypedArray
#3252
Comments
If I understand correctly, the methods need to call the respective method on |
Yes, but some methods like |
Hi @jedel1043 and @AryaveerSR Just to get better the issue, are these implementations okay, or am I missing something? /// Calls `TypedArray.prototype.keys()`.
pub fn keys(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
TypedArray::keys(&self.inner, &[], context)
}
/// Calls `TypedArray.prototype.entries()`.
pub fn entries(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
TypedArray::entries(&self.inner, &[], context)
}
/// Calls `TypedArray.prototype.findLast()`.
pub fn find_last(&self, predicate: JsFunction, context: &mut Context<'_>) -> JsResult<JsValue> {
TypedArray::find_last(&self.inner, &[predicate.into()], context)
} |
@AngeloChecked Yes, those implementations are good! It would be cool to see |
I'm not working on this at the moment; I'm a bit busy implementing other builtins. |
Hi @jedel1043, Alright, I believe I can help with this now. But i have a question for you: do you have for me any tips or guidelines for figuring out the type signatures of these functions?
|
Yep, that's pretty much on point. Our rule is just to use the type system as strictly as we can when returning values, so if a method only returns an index, we return |
Hi @jedel1043, sorry for bombarding you with questions: I'm using /// boa_engine/src/object/builtins/jstypedarray.rs
/// Calls `TypedArray.prototype.entries()`.
pub fn entries(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
BuiltinTypedArray::entries(&self.inner.clone().into(), &[], context)
} https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries /// boa_examples/src/bin/jstypedarray.rs
let mut result = vec![];
let data: Vec<u8> = vec![1, 2, 3];
let array = JsUint8Array::from_iter(data, context)?;
let mut iterator = array.entries(context)?.get_iterator(context, None, None)?;
while !iterator.step(context)? {
let item = iterator.value(context)?.as_object().unwrap().clone();
let js_array = JsArray::from_object(item)?;
let index = js_array.get(0, context)?.as_number().unwrap();
let value = js_array.get(1, context)?.as_number().unwrap();
result.push((index, value))
}
assert_eq!(vec![(0f64, 1f64), (1f64, 2f64), (2f64, 4f64)], result); https://github.com/boa-dev/boa/blob/main/boa_examples/src/bin/jstypedarray.rs ///boa_engine/src/builtins/iterables/mod.rs
/// [spec]: https://tc39.es/ecma262/#sec-iteratorstep
pub fn step(&mut self, context: &mut Context<'_>) -> JsResult<bool> {
self.step_with(None, context)
}
/// Gets the current value of the `IteratorRecord`.
pub fn value(&mut self, context: &mut Context<'_>) -> JsResult<JsValue> {
self.set_done_on_err(|iter| iter.last_result.value(context))
} https://github.com/boa-dev/boa/blob/main/boa_engine/src/builtins/iterable/mod.rs#L421 |
@AngeloChecked I think you can skip iterator related methods for now. We haven't designed a good public API for Js iterators, so I'd prefer to wait until we have iterators done instead of rushing and exposing internal APIs that may as well change in the future. |
Implementation in https://github.com/boa-dev/boa/blob/main/boa_engine/src/object/builtins/jstypedarray.rs
Desired features
&[u8]
or&Vec<u8>
The text was updated successfully, but these errors were encountered: