Open gterzian opened 10 months ago
@jdm Does this make sense? Do you know why this wasn't done to begin with?
Had a quick look everywhere, it seems there are really four cases:
js::typedarray
(the majority). Dealt with in this issueReadableStream
, see https://github.com/servo/servo/issues/30891object?
in WebIDL. See https://github.com/servo/servo/issues/30892It may be that what is required is simply implementing ToJSValConvertible
for the various types in js::rust::typedarray
In some ways it would in that case still be nicer to wrap the use of js::
inside dom/bindings
...
This seems reasonable to me! I'm not sure why we didn't integrate the concrete types originally.
Part of https://github.com/servo/servo/issues/30862
Where appropriate, we should remove the direct use of unsafe
NonNull<JSObject>
, and replace it with use of the appropriate safe wrapper found in/mozjs/src/typedarray.rs
.Example: AudioBuffer's
getChannelData
WedIDL says to return a
Float32Array
, but implementation returns aNonNull<JSObject>
:https://github.com/servo/servo/blob/8bbcf0abafc22cd840cd03f36b5b3b7d2d815493/components/script/dom/audiobuffer.rs#L265
The return value of the WebIDL method is backed by a
Heap<*mut JSObject>
on the dom struct.Solution:
use js::typedarray::Float32Array
instead ofjs::jsapi::JSObject
.Bonus: wrap the use of
js::typedarray
inside something atdom/bindings/
. (maybe seebindings/iterable.rs
for an example)How to do it?
codegen starts at(probably needs other updates): https://github.com/servo/servo/blob/8bbcf0abafc22cd840cd03f36b5b3b7d2d815493/components/script/dom/bindings/codegen/CodegenRust.py#L1463
_Methods
are generated.dom/bindings
so that we don't usejs::
directly elsewhere. For example, this kind of code should be hidden from view. In some way this is probably not a bonus, but a prerequisite for 3.More investigation is probably necessary.