Meta: Support nullable BufferSource as Optional in IDL generator

This IDL change is needed for webaudio's WaveShaperNode, where a
null BufferSource for a curve attribute results in a zero-length buffer.

WebGL also has a nullable BufferSource arg in bufferData(...). But
there, a null data/srcData value returns GL_INVALID_VALUE.
This commit is contained in:
Jonathan Gamble
2026-02-12 05:46:19 -06:00
committed by Alexander Kalenik
parent 95955f40b1
commit 793a4eeb8e
Notes: github-actions[bot] 2026-03-26 23:04:44 +00:00
5 changed files with 59 additions and 16 deletions

View File

@@ -34,12 +34,19 @@ void WebGLRenderingContextOverloads::buffer_data(WebIDL::UnsignedLong target, We
glBufferData(target, size, 0, usage);
}
void WebGLRenderingContextOverloads::buffer_data(WebIDL::UnsignedLong target, GC::Root<WebIDL::BufferSource> data, WebIDL::UnsignedLong usage)
void WebGLRenderingContextOverloads::buffer_data(WebIDL::UnsignedLong target, Optional<GC::Root<WebIDL::BufferSource>> data, WebIDL::UnsignedLong usage)
{
m_context->make_current();
auto span = MUST(get_offset_span<u8 const>(*data, /* src_offset= */ 0));
glBufferData(target, span.size(), span.data(), usage);
// https://registry.khronos.org/webgl/specs/latest/1.0/#5.14.5
// If the passed data is null then an INVALID_VALUE error is generated.
if (!data.has_value()) {
set_error(GL_INVALID_VALUE);
return;
}
auto span = MUST(get_offset_span<u8 const>(*data.value(), /* src_offset= */ 0));
glBufferData(target, static_cast<GLsizeiptr>(span.size()), span.data(), usage);
}
void WebGLRenderingContextOverloads::buffer_sub_data(WebIDL::UnsignedLong target, WebIDL::LongLong offset, GC::Root<WebIDL::BufferSource> data)