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

@@ -37,12 +37,19 @@ void WebGL2RenderingContextOverloads::buffer_data(WebIDL::UnsignedLong target, W
glBufferData(target, size, 0, usage);
}
void WebGL2RenderingContextOverloads::buffer_data(WebIDL::UnsignedLong target, GC::Root<WebIDL::BufferSource> src_data, WebIDL::UnsignedLong usage)
void WebGL2RenderingContextOverloads::buffer_data(WebIDL::UnsignedLong target, Optional<GC::Root<WebIDL::BufferSource>> src_data, WebIDL::UnsignedLong usage)
{
m_context->make_current();
auto data = MUST(get_offset_span<u8 const>(*src_data, /* src_offset= */ 0));
glBufferData(target, data.size(), data.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 (!src_data.has_value()) {
set_error(GL_INVALID_VALUE);
return;
}
auto data = MUST(get_offset_span<u8 const>(*src_data.value(), /* src_offset= */ 0));
glBufferData(target, static_cast<GLsizeiptr>(data.size()), data.data(), usage);
}
void WebGL2RenderingContextOverloads::buffer_sub_data(WebIDL::UnsignedLong target, WebIDL::LongLong dst_byte_offset, GC::Root<WebIDL::BufferSource> src_data)