WebIDL: use FLoat32Array (#30990)

* inital

* audiobuffer: return float 32 array as channel data

* add on heap float 32 array type

* fix warnings

* add list of webidl interfaces to ignore for float 32

* codegen: remove duplication of builtin return type handling

* bindings: derive default for float 32 array wrapper

* bindings: allow unsafe code in typedarrays module

* bindings: rename float 32 array wrapper

* bindings: rename HeapFloat32Array is_set method to is_initialized

* bindings: assert float 32 array is initialized before data can be acquired

* bindings: use let syntax for error handling in float 32 array wrapper

* bindings: use copy_from_slice where possible in float 32 array wrapper

* bindings: rename args in typedarray copy methods

* codegen: use idl type in builtin names for float 32 array

* bindings: add a util to create float 32 arrays, use in dom matrix readonly

* codegen: tidy

* bindings: box the heap inside heaped float 32 arrays
This commit is contained in:
Gregory Terzian 2024-01-11 17:43:36 +08:00 committed by GitHub
parent 90f70e3408
commit e145c51234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 159 additions and 87 deletions

View file

@ -119,7 +119,8 @@ builtinNames = {
IDLType.Tags.unrestricted_float: 'f32',
IDLType.Tags.float: 'Finite<f32>',
IDLType.Tags.unrestricted_double: 'f64',
IDLType.Tags.double: 'Finite<f64>'
IDLType.Tags.double: 'Finite<f64>',
IDLType.Tags.float32array: 'Float32Array'
}
numericTags = [
@ -1459,16 +1460,26 @@ def getConversionConfigForType(type, isEnforceRange, isClamp, treatNullAs):
return "()"
def todo_switch_float_32(des):
return des.interface.identifier.name in ['XRView', 'XRRigidTransform', 'XRRay', 'GamepadPose']
def builtin_return_type(returnType):
result = CGGeneric(builtinNames[returnType.tag()])
if returnType.nullable():
result = CGWrapper(result, pre="Option<", post=">")
return result
# Returns a CGThing containing the type of the return value.
def getRetvalDeclarationForType(returnType, descriptorProvider):
if returnType is None or returnType.isUndefined():
# Nothing to declare
return CGGeneric("()")
if returnType.isPrimitive() and returnType.tag() in builtinNames:
result = CGGeneric(builtinNames[returnType.tag()])
if returnType.nullable():
result = CGWrapper(result, pre="Option<", post=">")
return result
return builtin_return_type(returnType)
if returnType.isTypedArray() and returnType.tag() in builtinNames and not todo_switch_float_32(descriptorProvider):
return builtin_return_type(returnType)
if returnType.isDOMString():
result = CGGeneric("DOMString")
if returnType.nullable():
@ -6494,6 +6505,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::rust::define_properties',
'js::rust::get_object_class',
'js::typedarray',
'js::typedarray::Float32Array',
'crate::dom',
'crate::dom::bindings',
'crate::dom::bindings::codegen::InterfaceObjectMap',