Repository navigation
Conversation
Signed-off-by: Bentaimia Haddadi <[email protected]>
Signed-off-by: Bentaimia Haddadi <[email protected]>
gterzian
left a comment
There was a problem hiding this comment.
Thanks for the contrib again! Let's change the new_initialized method a bit.
| T: TypedArrayElement + TypedArrayElementCreator, | ||
| T::Element: Clone + Copy, | ||
| { | ||
| pub fn new_initialized(js_object: Option<*mut JSObject>) -> HeapTypedArray<T> { |
There was a problem hiding this comment.
So let's add an pub enum like so:
HeapTypedArrayInit {
Object(*mut JSObject),
Info {
len: usize
}
}
And let's make it the init argument to this method.
The Info variant should be creating the array using a rooted object and call create_typed_array_with_length(which should be private).
There was a problem hiding this comment.
Re the Object variant, I hope it can be typed later as a result of doing #31320
There was a problem hiding this comment.
This is much better, I updated the code, thanks
Signed-off-by: Bentaimia Haddadi <[email protected]>
Signed-off-by: Bentaimia Haddadi <[email protected]>
Signed-off-by: Bentaimia Haddadi <[email protected]>
gterzian
left a comment
There was a problem hiding this comment.
Thanks for the contrib! Couple of changes suggested...
| fn Data(&self, _: JSContext) -> Uint8ClampedArray { | ||
| self.data | ||
| .get_internal() | ||
| .expect("Failed to get Data from ImageData.") |
There was a problem hiding this comment.
Let's return JsError as we did in the other PR.
There was a problem hiding this comment.
should we do it for other changes we merged, we have lot of .get_internal().expect ?
There was a problem hiding this comment.
I think so, but it depends on the spec. It would be good to do this in a separate PR so each cases can be investigated separately(it may require updating test expectations also).
There was a problem hiding this comment.
I think we only return error when function returns Fallible but not in this case?
There was a problem hiding this comment.
yes! Although we can check the spec to see if the function should be fallible...
There was a problem hiding this comment.
From the spec, I Don't see Data fallible, what do you think?
There was a problem hiding this comment.
The spec doesn't say it direclty, but wording like "initialize the data attribute of imageData to a new Uint8ClampedArray object" implies using the Web IDL and JS operations which are in fact fallible.
Let's return JsError, by adding the Throws attribute to
| .expect("Creating TypedArray from length should never fail"); | ||
| let heap_typed_array = HeapTypedArray::<T>::default(); | ||
| heap_typed_array | ||
| .set_data(cx, unsafe { typed_array.as_slice() }) |
There was a problem hiding this comment.
unsafe is unnecessary, because the entire module allows it.
There was a problem hiding this comment.
I still get this operation is unsafe and requires an unsafe function or block when I remove it
There was a problem hiding this comment.
I thought it's better to keep unsafe here instead of using it in new_with_jsobject
There was a problem hiding this comment.
ah yes sorry, you need unsafe blocks for unsafe calls(but there is no need to mark the method as allowing unsafe, which is what I had in mind somehow).
| create_typed_array_with_length::<T>(cx, len as usize, array.handle_mut()) | ||
| .expect("Creating TypedArray from length should never fail"); | ||
| let heap_typed_array = HeapTypedArray::<T>::default(); | ||
| heap_typed_array |
There was a problem hiding this comment.
I think you can simply do heap_typed_array.internal.set(*typed_array)
There was a problem hiding this comment.
Yes heap_typed_array.internal.set(*array) should be okey
| let array = array_res.map_err(|_| { | ||
| let heap_typed_array = | ||
| new_initialized_heap_typed_array(HeapTypedArrayInit::Object(jsobject)); | ||
| let array = heap_typed_array.acquire_data(cx).map_err(|_| { |
There was a problem hiding this comment.
acquire_data detaches the buffer, so instead we want to use get_internal.
Signed-off-by: Bentaimia Haddadi <[email protected]>
…JS_Object-in-bindings
| fn Data(&self, _: JSContext) -> Uint8ClampedArray { | ||
| self.data | ||
| .get_internal() | ||
| .expect("Failed to get Data from ImageData.") |
There was a problem hiding this comment.
The spec doesn't say it direclty, but wording like "initialize the data attribute of imageData to a new Uint8ClampedArray object" implies using the Web IDL and JS operations which are in fact fallible.
Let's return JsError, by adding the Throws attribute to
| } | ||
| } | ||
|
|
||
| pub fn new_initialized_heap_typed_array<T>(init: HeapTypedArrayInit) -> HeapTypedArray<T> |
There was a problem hiding this comment.
Let's return a result, and return the error from create_typed_array_with_length. (creating the buffer is falling, as we saw in the other PR).
…array Signed-off-by: Bentaimia Haddadi <[email protected]>
Signed-off-by: Bentaimia Haddadi <[email protected]>
gterzian
left a comment
There was a problem hiding this comment.
Awesome! LGTM with just one nit...
Signed-off-by: Bentaimia Haddadi <[email protected]>
Signed-off-by: Bentaimia Haddadi <[email protected]>
|
I'll add it to the queue, although it may require a rebase. |
…JS_Object-in-bindings
Part #31064, we would like to remove the direct use of
unsafe NonNull<JSObject>, and replace it with use of the appropriate safe wrapper found in typedarray.rs, in this PR we are replacingunsafe NonNull<JSObject>withUint8ClampedArray, according to spec./mach build -ddoes not report any errors./mach test-tidydoes not report any errors