diff --git a/Libraries/LibWeb/Encoding/TextEncoder.cpp b/Libraries/LibWeb/Encoding/TextEncoder.cpp index 700f768f86..7db30bc5d3 100644 --- a/Libraries/LibWeb/Encoding/TextEncoder.cpp +++ b/Libraries/LibWeb/Encoding/TextEncoder.cpp @@ -51,7 +51,7 @@ GC::Ref TextEncoder::encode(String const& input) const } // https://encoding.spec.whatwg.org/#dom-textencoder-encodeinto -TextEncoderEncodeIntoResult TextEncoder::encode_into(String const& source, GC::Root const& destination) const +TextEncoderEncodeIntoResult TextEncoder::encode_into(String const& source, GC::Root const& destination) const { // AD-HOC: Return early if destination is detached. This is not explicitly handled in the spec, // however no bytes are copied as destinations size is always zero in this case. @@ -59,7 +59,7 @@ TextEncoderEncodeIntoResult TextEncoder::encode_into(String const& source, GC::R if (destination->viewed_array_buffer()->is_detached()) return { 0, 0 }; - auto data = destination->viewed_array_buffer()->buffer().bytes().slice(destination->byte_offset(), destination->byte_length()); + auto data = destination->data(); // 1. Let read be 0. WebIDL::UnsignedLongLong read = 0; @@ -85,7 +85,7 @@ TextEncoderEncodeIntoResult TextEncoder::encode_into(String const& source, GC::R // 6.4. Otherwise: // 6.4.1. If destination’s byte length − written is greater than or equal to the number of bytes in result, then: - if (destination->byte_length() - written >= result.size()) { + if (data.size() - written >= result.size()) { // 6.4.1.1. If item is greater than U+FFFF, then increment read by 2. if (item > 0xffff) { read += 2; diff --git a/Libraries/LibWeb/Encoding/TextEncoder.h b/Libraries/LibWeb/Encoding/TextEncoder.h index e6bfc22c63..f48df6d76e 100644 --- a/Libraries/LibWeb/Encoding/TextEncoder.h +++ b/Libraries/LibWeb/Encoding/TextEncoder.h @@ -37,7 +37,7 @@ public: virtual ~TextEncoder() override; GC::Ref encode(String const& input) const; - TextEncoderEncodeIntoResult encode_into(String const& source, GC::Root const& destination) const; + TextEncoderEncodeIntoResult encode_into(String const& source, GC::Root const& destination) const; protected: // https://encoding.spec.whatwg.org/#dom-textencoder diff --git a/Libraries/LibWeb/Geometry/DOMMatrix.cpp b/Libraries/LibWeb/Geometry/DOMMatrix.cpp index 7a24db3656..9c331c55d6 100644 --- a/Libraries/LibWeb/Geometry/DOMMatrix.cpp +++ b/Libraries/LibWeb/Geometry/DOMMatrix.cpp @@ -159,14 +159,10 @@ WebIDL::ExceptionOr> DOMMatrix::from_matrix(JS::VM& vm, DOMMa } // https://drafts.fxtf.org/geometry/#dom-dommatrix-fromfloat32array -WebIDL::ExceptionOr> DOMMatrix::from_float32_array(JS::VM& vm, GC::Root const& array32) +WebIDL::ExceptionOr> DOMMatrix::from_float32_array(JS::VM& vm, GC::Root const& array) { - if (!is(*array32->raw_object())) - return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "Float32Array"); - auto& realm = *vm.current_realm(); - auto& float32_array = static_cast(*array32->raw_object()); - ReadonlySpan elements = float32_array.data(); + ReadonlySpan elements = array->data(); // If array32 has 6 elements, return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers taking the values from array32 in the provided order. if (elements.size() == 6) @@ -184,14 +180,10 @@ WebIDL::ExceptionOr> DOMMatrix::from_float32_array(JS::VM& vm } // https://drafts.fxtf.org/geometry/#dom-dommatrix-fromfloat64array -WebIDL::ExceptionOr> DOMMatrix::from_float64_array(JS::VM& vm, GC::Root const& array64) +WebIDL::ExceptionOr> DOMMatrix::from_float64_array(JS::VM& vm, GC::Root const& array) { - if (!is(*array64->raw_object())) - return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "Float64Array"); - auto& realm = *vm.current_realm(); - auto& float64_array = static_cast(*array64->raw_object()); - ReadonlySpan elements = float64_array.data(); + ReadonlySpan elements = array->data(); // If array64 has 6 elements, return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers taking the values from array64 in the provided order. if (elements.size() == 6) diff --git a/Libraries/LibWeb/Geometry/DOMMatrix.h b/Libraries/LibWeb/Geometry/DOMMatrix.h index 410bd03cdb..fcc1ff87d3 100644 --- a/Libraries/LibWeb/Geometry/DOMMatrix.h +++ b/Libraries/LibWeb/Geometry/DOMMatrix.h @@ -28,8 +28,8 @@ public: virtual ~DOMMatrix() override; static WebIDL::ExceptionOr> from_matrix(JS::VM&, DOMMatrixInit other = {}); - static WebIDL::ExceptionOr> from_float32_array(JS::VM&, GC::Root const& array32); - static WebIDL::ExceptionOr> from_float64_array(JS::VM&, GC::Root const& array64); + static WebIDL::ExceptionOr> from_float32_array(JS::VM&, GC::Root const&); + static WebIDL::ExceptionOr> from_float64_array(JS::VM&, GC::Root const&); void set_m11(double value); void set_m12(double value); diff --git a/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp b/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp index b4984f508c..2e6cb583bb 100644 --- a/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp +++ b/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp @@ -230,14 +230,10 @@ WebIDL::ExceptionOr> DOMMatrixReadOnly::from_matrix(J } // https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-fromfloat32array -WebIDL::ExceptionOr> DOMMatrixReadOnly::from_float32_array(JS::VM& vm, GC::Root const& array32) +WebIDL::ExceptionOr> DOMMatrixReadOnly::from_float32_array(JS::VM& vm, GC::Root const& array) { - if (!is(*array32)) - return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "Float32Array"); - auto& realm = *vm.current_realm(); - auto& float32_array = static_cast(*array32->raw_object()); - ReadonlySpan elements = float32_array.data(); + ReadonlySpan elements = array->data(); // If array32 has 6 elements, return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers taking the values from array32 in the provided order. if (elements.size() == 6) @@ -255,14 +251,10 @@ WebIDL::ExceptionOr> DOMMatrixReadOnly::from_float32_ } // https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-fromfloat64array -WebIDL::ExceptionOr> DOMMatrixReadOnly::from_float64_array(JS::VM& vm, GC::Root const& array64) +WebIDL::ExceptionOr> DOMMatrixReadOnly::from_float64_array(JS::VM& vm, GC::Root const& array) { - if (!is(*array64)) - return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "Float64Array"); - auto& realm = *vm.current_realm(); - auto& float64_array = static_cast(*array64->raw_object()); - ReadonlySpan elements = float64_array.data(); + ReadonlySpan elements = array->data(); // If array64 has 6 elements, return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers taking the values from array64 in the provided order. if (elements.size() == 6) diff --git a/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h b/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h index fc54e040a2..7853bb4f9e 100644 --- a/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h +++ b/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.h @@ -63,8 +63,8 @@ public: virtual ~DOMMatrixReadOnly() override; static WebIDL::ExceptionOr> from_matrix(JS::VM&, DOMMatrixInit& other); - static WebIDL::ExceptionOr> from_float32_array(JS::VM&, GC::Root const& array32); - static WebIDL::ExceptionOr> from_float64_array(JS::VM&, GC::Root const& array64); + static WebIDL::ExceptionOr> from_float32_array(JS::VM&, GC::Root const&); + static WebIDL::ExceptionOr> from_float64_array(JS::VM&, GC::Root const&); // https://drafts.fxtf.org/geometry/#dommatrix-attributes double m11() const { return m_matrix[0, 0]; } diff --git a/Libraries/LibWeb/HTML/ImageData.cpp b/Libraries/LibWeb/HTML/ImageData.cpp index c61c6df51a..c18e1957d9 100644 --- a/Libraries/LibWeb/HTML/ImageData.cpp +++ b/Libraries/LibWeb/HTML/ImageData.cpp @@ -47,17 +47,10 @@ WebIDL::ExceptionOr> ImageData::construct_impl(JS::Realm& rea } // https://html.spec.whatwg.org/multipage/canvas.html#dom-imagedata-with-data -WebIDL::ExceptionOr> ImageData::create(JS::Realm& realm, GC::Root const& data, u32 sw, Optional sh, Optional const& settings) +WebIDL::ExceptionOr> ImageData::create(JS::Realm& realm, GC::Root const& uint8_clamped_array_data, u32 sw, Optional sh, Optional const& settings) { - auto& vm = realm.vm(); - - if (!is(*data->raw_object())) - return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "Uint8ClampedArray"); - - auto& uint8_clamped_array_data = static_cast(*data->raw_object()); - // 1. Let length be the number of bytes in data. - auto length = uint8_clamped_array_data.byte_length().length(); + auto length = uint8_clamped_array_data->byte_length().length(); // 2. If length is not a nonzero integral multiple of four, then throw an "InvalidStateError" DOMException. if (length == 0 || length % 4 != 0) @@ -81,10 +74,10 @@ WebIDL::ExceptionOr> ImageData::create(JS::Realm& realm, GC:: // 7. Initialize this given sw, sh, settings set to settings, and source set to data. // FIXME: This seems to be a spec issue, sh is an optional but height always have a value. - return initialize(realm, height, sw, settings, uint8_clamped_array_data); + return initialize(realm, height, sw, settings, *uint8_clamped_array_data); } -WebIDL::ExceptionOr> ImageData::construct_impl(JS::Realm& realm, GC::Root const& data, u32 sw, Optional sh, Optional const& settings) +WebIDL::ExceptionOr> ImageData::construct_impl(JS::Realm& realm, GC::Root const& data, u32 sw, Optional sh, Optional const& settings) { return ImageData::create(realm, data, sw, move(sh), settings); } diff --git a/Libraries/LibWeb/HTML/ImageData.h b/Libraries/LibWeb/HTML/ImageData.h index 648db72640..ff6374b273 100644 --- a/Libraries/LibWeb/HTML/ImageData.h +++ b/Libraries/LibWeb/HTML/ImageData.h @@ -28,10 +28,10 @@ class ImageData final public: [[nodiscard]] static GC::Ref create(JS::Realm&); [[nodiscard]] static WebIDL::ExceptionOr> create(JS::Realm&, u32 sw, u32 sh, Optional const& settings = {}); - [[nodiscard]] static WebIDL::ExceptionOr> create(JS::Realm&, GC::Root const& data, u32 sw, Optional sh = {}, Optional const& settings = {}); + [[nodiscard]] static WebIDL::ExceptionOr> create(JS::Realm&, GC::Root const& data, u32 sw, Optional sh = {}, Optional const& settings = {}); [[nodiscard]] static WebIDL::ExceptionOr> construct_impl(JS::Realm&, u32 sw, u32 sh, Optional const& settings = {}); - [[nodiscard]] static WebIDL::ExceptionOr> construct_impl(JS::Realm&, GC::Root const& data, u32 sw, Optional sh = {}, Optional const& settings = {}); + [[nodiscard]] static WebIDL::ExceptionOr> construct_impl(JS::Realm&, GC::Root const& data, u32 sw, Optional sh = {}, Optional const& settings = {}); virtual ~ImageData() override; diff --git a/Libraries/LibWeb/WebAudio/AnalyserNode.cpp b/Libraries/LibWeb/WebAudio/AnalyserNode.cpp index 60087df2bb..14bce2b9e7 100644 --- a/Libraries/LibWeb/WebAudio/AnalyserNode.cpp +++ b/Libraries/LibWeb/WebAudio/AnalyserNode.cpp @@ -135,9 +135,8 @@ Vector AnalyserNode::current_frequency_data() } // https://webaudio.github.io/web-audio-api/#dom-analysernode-getfloatfrequencydata -WebIDL::ExceptionOr AnalyserNode::get_float_frequency_data(GC::Root const& array) +WebIDL::ExceptionOr AnalyserNode::get_float_frequency_data(GC::Root const& array) { - // Write the current frequency data into array. If array has fewer elements than the frequencyBinCount, // the excess elements will be dropped. If array has more elements than the frequencyBinCount, the // excess elements will be ignored. The most recent fftSize frames are used in computing the frequency data. @@ -147,22 +146,17 @@ WebIDL::ExceptionOr AnalyserNode::get_float_frequency_data(GC::Rootvm(); - - if (!is(*array->raw_object())) - return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "Float32Array"); - auto& output_array = static_cast(*array->raw_object()); - - size_t floats_to_write = min(output_array.data().size(), frequency_bin_count()); + auto output_data = array->data(); + size_t floats_to_write = min(output_data.size(), static_cast(frequency_bin_count())); for (size_t i = 0; i < floats_to_write; i++) { - output_array.data()[i] = frequency_data[i]; + output_data[i] = frequency_data[i]; } return {}; } // https://webaudio.github.io/web-audio-api/#dom-analysernode-getbytefrequencydata -WebIDL::ExceptionOr AnalyserNode::get_byte_frequency_data(GC::Root const& array) +WebIDL::ExceptionOr AnalyserNode::get_byte_frequency_data(GC::Root const& array) { // FIXME: If another call to getByteFrequencyData() or getFloatFrequencyData() occurs within the same render // quantum as a previous call, the current frequency data is not updated with the same data. Instead, @@ -194,17 +188,17 @@ WebIDL::ExceptionOr AnalyserNode::get_byte_frequency_data(GC::Rootviewed_array_buffer()->buffer(); - size_t bytes_to_write = min(array->byte_length(), frequency_bin_count()); + auto output_data = array->data(); + size_t bytes_to_write = min(output_data.size(), static_cast(frequency_bin_count())); for (size_t i = 0; i < bytes_to_write; i++) - output_buffer[i] = byte_data[i]; + output_data[i] = byte_data[i]; return {}; } // https://webaudio.github.io/web-audio-api/#dom-analysernode-getfloattimedomaindata -WebIDL::ExceptionOr AnalyserNode::get_float_time_domain_data(GC::Root const& array) +WebIDL::ExceptionOr AnalyserNode::get_float_time_domain_data(GC::Root const& array) { // Write the current time-domain data (waveform data) into array. If array has fewer elements than the // value of fftSize, the excess elements will be dropped. If array has more elements than the value of @@ -212,22 +206,17 @@ WebIDL::ExceptionOr AnalyserNode::get_float_time_domain_data(GC::Root time_domain_data = current_time_domain_data(); - auto& vm = this->vm(); - - if (!is(*array->raw_object())) - return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "Float32Array"); - auto& output_array = static_cast(*array->raw_object()); - - size_t floats_to_write = min(output_array.data().size(), frequency_bin_count()); + auto output_data = array->data(); + size_t floats_to_write = min(output_data.size(), static_cast(fft_size())); for (size_t i = 0; i < floats_to_write; i++) { - output_array.data()[i] = time_domain_data[i]; + output_data[i] = time_domain_data[i]; } return {}; } // https://webaudio.github.io/web-audio-api/#dom-analysernode-getbytetimedomaindata -WebIDL::ExceptionOr AnalyserNode::get_byte_time_domain_data(GC::Root const& array) +WebIDL::ExceptionOr AnalyserNode::get_byte_time_domain_data(GC::Root const& array) { // Write the current time-domain data (waveform data) into array. If array’s byte length is less than // fftSize, the excess elements will be dropped. If array’s byte length is greater than the fftSize, @@ -247,11 +236,11 @@ WebIDL::ExceptionOr AnalyserNode::get_byte_time_domain_data(GC::Root(x)); } - auto& output_buffer = array->viewed_array_buffer()->buffer(); - size_t bytes_to_write = min(array->byte_length(), fft_size()); + auto output_data = array->data(); + size_t bytes_to_write = min(output_data.size(), static_cast(fft_size())); for (size_t i = 0; i < bytes_to_write; i++) - output_buffer[i] = byte_data[i]; + output_data[i] = byte_data[i]; return {}; } diff --git a/Libraries/LibWeb/WebAudio/AnalyserNode.h b/Libraries/LibWeb/WebAudio/AnalyserNode.h index a81fbea8bc..35a90ecb9e 100644 --- a/Libraries/LibWeb/WebAudio/AnalyserNode.h +++ b/Libraries/LibWeb/WebAudio/AnalyserNode.h @@ -33,10 +33,10 @@ public: virtual WebIDL::UnsignedLong number_of_inputs() override { return 1; } virtual WebIDL::UnsignedLong number_of_outputs() override { return 1; } - WebIDL::ExceptionOr get_float_frequency_data(GC::Root const& array); // Float32Array - WebIDL::ExceptionOr get_byte_frequency_data(GC::Root const& array); // Uint8Array - WebIDL::ExceptionOr get_float_time_domain_data(GC::Root const& array); // Float32Array - WebIDL::ExceptionOr get_byte_time_domain_data(GC::Root const& array); // Uint8Array + WebIDL::ExceptionOr get_float_frequency_data(GC::Root const&); + WebIDL::ExceptionOr get_byte_frequency_data(GC::Root const&); + WebIDL::ExceptionOr get_float_time_domain_data(GC::Root const&); + WebIDL::ExceptionOr get_byte_time_domain_data(GC::Root const&); unsigned long fft_size() const { return m_fft_size; } unsigned long frequency_bin_count() const { return m_fft_size / 2; } diff --git a/Libraries/LibWeb/WebAudio/AudioBuffer.cpp b/Libraries/LibWeb/WebAudio/AudioBuffer.cpp index bf10a11844..c332d3a715 100644 --- a/Libraries/LibWeb/WebAudio/AudioBuffer.cpp +++ b/Libraries/LibWeb/WebAudio/AudioBuffer.cpp @@ -82,7 +82,7 @@ WebIDL::ExceptionOr> AudioBuffer::get_channel_data(Web } // https://webaudio.github.io/web-audio-api/#dom-audiobuffer-copyfromchannel -WebIDL::ExceptionOr AudioBuffer::copy_from_channel(GC::Root const& destination, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset) const +WebIDL::ExceptionOr AudioBuffer::copy_from_channel(GC::Root const& destination, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset) const { // The copyFromChannel() method copies the samples from the specified channel of the AudioBuffer to the destination array. // @@ -91,10 +91,7 @@ WebIDL::ExceptionOr AudioBuffer::copy_from_channel(GC::Rootvm(); - if (!is(*destination->raw_object())) - return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "Float32Array"); - auto& float32_array = static_cast(*destination->raw_object()); - if (float32_array.viewed_array_buffer()->is_shared_array_buffer()) + if (destination->viewed_array_buffer()->is_shared_array_buffer()) return vm.throw_completion(JS::ErrorType::SharedArrayBuffer, "Float32Array"); auto const channel = TRY(get_channel_data(channel_number)); @@ -103,14 +100,15 @@ WebIDL::ExceptionOr AudioBuffer::copy_from_channel(GC::Root= channel_length) return {}; - u32 count = min(float32_array.data().size(), channel_length - buffer_offset); - channel->data().slice(buffer_offset, count).copy_to(float32_array.data()); + auto destination_data = destination->data(); + auto count = min(destination_data.size(), channel_length - buffer_offset); + channel->data().slice(buffer_offset, count).copy_to(destination_data.slice(0, count)); return {}; } // https://webaudio.github.io/web-audio-api/#dom-audiobuffer-copytochannel -WebIDL::ExceptionOr AudioBuffer::copy_to_channel(GC::Root const& source, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset) +WebIDL::ExceptionOr AudioBuffer::copy_to_channel(GC::Root const& source, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset) { // The copyToChannel() method copies the samples to the specified channel of the AudioBuffer from the source array. // @@ -121,10 +119,7 @@ WebIDL::ExceptionOr AudioBuffer::copy_to_channel(GC::Rootvm(); - if (!is(*source->raw_object())) - return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "Float32Array"); - auto const& float32_array = static_cast(*source->raw_object()); - if (float32_array.viewed_array_buffer()->is_shared_array_buffer()) + if (source->viewed_array_buffer()->is_shared_array_buffer()) return vm.throw_completion(JS::ErrorType::SharedArrayBuffer, "Float32Array"); auto channel = TRY(get_channel_data(channel_number)); @@ -133,8 +128,9 @@ WebIDL::ExceptionOr AudioBuffer::copy_to_channel(GC::Root= channel_length) return {}; - u32 count = min(float32_array.data().size(), channel_length - buffer_offset); - float32_array.data().slice(0, count).copy_to(channel->data().slice(buffer_offset, count)); + auto source_data = source->data(); + auto count = min(source_data.size(), channel_length - buffer_offset); + source_data.slice(0, count).copy_to(channel->data().slice(buffer_offset, count)); return {}; } diff --git a/Libraries/LibWeb/WebAudio/AudioBuffer.h b/Libraries/LibWeb/WebAudio/AudioBuffer.h index d98e367bbd..13c6ee0e24 100644 --- a/Libraries/LibWeb/WebAudio/AudioBuffer.h +++ b/Libraries/LibWeb/WebAudio/AudioBuffer.h @@ -37,8 +37,8 @@ public: double duration() const; WebIDL::UnsignedLong number_of_channels() const; WebIDL::ExceptionOr> get_channel_data(WebIDL::UnsignedLong channel) const; - WebIDL::ExceptionOr copy_from_channel(GC::Root const&, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset = 0) const; - WebIDL::ExceptionOr copy_to_channel(GC::Root const&, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset = 0); + WebIDL::ExceptionOr copy_from_channel(GC::Root const&, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset = 0) const; + WebIDL::ExceptionOr copy_to_channel(GC::Root const&, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset = 0); private: explicit AudioBuffer(JS::Realm&, AudioBufferOptions const&); diff --git a/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp b/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp index aaab28093c..607facccf4 100644 --- a/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp +++ b/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp @@ -227,7 +227,7 @@ void BaseAudioContext::queue_control_message(ControlMessage message) } // https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-decodeaudiodata -GC::Ref BaseAudioContext::decode_audio_data(GC::Root audio_data, GC::Ptr success_callback, GC::Ptr error_callback) +GC::Ref BaseAudioContext::decode_audio_data(GC::Root const& audio_data, GC::Ptr success_callback, GC::Ptr error_callback) { auto& realm = this->realm(); @@ -252,7 +252,7 @@ GC::Ref BaseAudioContext::decode_audio_data(GC::Root BaseAudioContext::decode_audio_data(GC::Root promise, [[maybe_unused]] GC::Root audio_data, GC::Ptr success_callback, GC::Ptr error_callback) +void BaseAudioContext::queue_a_decoding_operation(GC::Ref promise, [[maybe_unused]] GC::Root audio_data, GC::Ptr success_callback, GC::Ptr error_callback) { auto& realm = this->realm(); diff --git a/Libraries/LibWeb/WebAudio/BaseAudioContext.h b/Libraries/LibWeb/WebAudio/BaseAudioContext.h index acee0a4d6d..daf58c3650 100644 --- a/Libraries/LibWeb/WebAudio/BaseAudioContext.h +++ b/Libraries/LibWeb/WebAudio/BaseAudioContext.h @@ -88,7 +88,7 @@ public: WebIDL::UnsignedLong number_of_output_channels); WebIDL::ExceptionOr> create_stereo_panner(); - GC::Ref decode_audio_data(GC::Root, GC::Ptr, GC::Ptr); + GC::Ref decode_audio_data(GC::Root const&, GC::Ptr, GC::Ptr); void queue_control_message(ControlMessage); @@ -109,7 +109,7 @@ private: // https://webaudio.github.io/web-audio-api/#render-quantum-size static constexpr WebIDL::UnsignedLong s_render_quantum_size { 128 }; - void queue_a_decoding_operation(GC::Ref, GC::Root, GC::Ptr, GC::Ptr); + void queue_a_decoding_operation(GC::Ref, GC::Root, GC::Ptr, GC::Ptr); u64 m_next_node_id { 0 }; diff --git a/Libraries/LibWeb/WebAudio/BiquadFilterNode.cpp b/Libraries/LibWeb/WebAudio/BiquadFilterNode.cpp index fff7965b42..1e3efca049 100644 --- a/Libraries/LibWeb/WebAudio/BiquadFilterNode.cpp +++ b/Libraries/LibWeb/WebAudio/BiquadFilterNode.cpp @@ -66,7 +66,7 @@ GC::Ref BiquadFilterNode::gain() const } // https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-getfrequencyresponse -WebIDL::ExceptionOr BiquadFilterNode::get_frequency_response(GC::Root const& frequency_hz, GC::Root const& mag_response, GC::Root const& phase_response) +WebIDL::ExceptionOr BiquadFilterNode::get_frequency_response(GC::Root const& frequency_hz, GC::Root const& mag_response, GC::Root const& phase_response) { (void)frequency_hz; (void)mag_response; diff --git a/Libraries/LibWeb/WebAudio/BiquadFilterNode.h b/Libraries/LibWeb/WebAudio/BiquadFilterNode.h index 4f39ec3ff8..cad11c0937 100644 --- a/Libraries/LibWeb/WebAudio/BiquadFilterNode.h +++ b/Libraries/LibWeb/WebAudio/BiquadFilterNode.h @@ -38,7 +38,7 @@ public: GC::Ref detune() const; GC::Ref q() const; GC::Ref gain() const; - WebIDL::ExceptionOr get_frequency_response(GC::Root const&, GC::Root const&, GC::Root const&); + WebIDL::ExceptionOr get_frequency_response(GC::Root const&, GC::Root const&, GC::Root const&); static WebIDL::ExceptionOr> create(JS::Realm&, GC::Ref, BiquadFilterOptions const& = {}); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, GC::Ref, BiquadFilterOptions const& = {}); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index aefe287ccf..e01043fcf3 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -953,53 +953,128 @@ static void generate_object_to_cpp(SourceGenerator& scoped_generator, IDL::Type static void generate_buffer_source_to_cpp(SourceGenerator& scoped_generator, IDL::Type const& type, bool optional) { - size_t buffer_source_nesting_level = optional ? 2 : 1; - auto buffer_source_indent = ByteString::repeated(' ', buffer_source_nesting_level * 4); - scoped_generator.set("buffer_source.indent", buffer_source_indent); + auto is_exact_javascript_buffer_source_type = is_javascript_builtin_buffer_source_type(type); + if (is_exact_javascript_buffer_source_type) + scoped_generator.set("parameter.type.buffer_cpp", ByteString::formatted("JS::{}", type.name())); + else + scoped_generator.set("parameter.type.buffer_cpp", "WebIDL::BufferSource"); if (optional || type.is_nullable()) { scoped_generator.append(R"~~~( - Optional> @cpp_name@; + Optional> @cpp_name@; )~~~"); } else { scoped_generator.append(R"~~~( - GC::Root @cpp_name@; + GC::Root<@parameter.type.buffer_cpp@> @cpp_name@; )~~~"); } - if (optional) { - scoped_generator.append(R"~~~( + if (optional && type.is_nullable()) { + if (is_exact_javascript_buffer_source_type) { + scoped_generator.append(R"~~~( if (!@js_name@@js_suffix@.is_undefined()) { -)~~~"); - } else if (type.is_nullable()) { - scoped_generator.append(R"~~~( - if (@js_name@@js_suffix@.is_undefined()) - return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); -)~~~"); + if (!@js_name@@js_suffix@.is_null()) { + auto @cpp_name@_builtin_buffer = @js_name@@js_suffix@.as_if<@parameter.type.buffer_cpp@>(); + if (!@cpp_name@_builtin_buffer) { + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); + } + + @cpp_name@ = GC::make_root(*@cpp_name@_builtin_buffer); + } } - - if (type.is_nullable()) { - scoped_generator.append(R"~~~( -@buffer_source.indent@if (!@js_name@@js_suffix@.is_null()) { )~~~"); + } else { + scoped_generator.append(R"~~~( + if (!@js_name@@js_suffix@.is_undefined()) { + if (!@js_name@@js_suffix@.is_null()) { + if (!@js_name@@js_suffix@.is_object() || !(is(@js_name@@js_suffix@.as_object()) || is(@js_name@@js_suffix@.as_object()) || is(@js_name@@js_suffix@.as_object()))) { + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); + } + + @cpp_name@ = GC::make_root(realm.create(@js_name@@js_suffix@.as_object())); + } } - - scoped_generator.append(R"~~~( -@buffer_source.indent@ if (!@js_name@@js_suffix@.is_object() || !(is(@js_name@@js_suffix@.as_object()) || is(@js_name@@js_suffix@.as_object()) || is(@js_name@@js_suffix@.as_object()))) -@buffer_source.indent@ return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); - -@buffer_source.indent@ @cpp_name@ = GC::make_root(realm.create(@js_name@@js_suffix@.as_object())); -)~~~"); - - if (type.is_nullable()) { - scoped_generator.append(R"~~~( -@buffer_source.indent@} )~~~"); + } + return; } if (optional) { - scoped_generator.append(R"~~~( + if (is_exact_javascript_buffer_source_type) { + scoped_generator.append(R"~~~( + if (!@js_name@@js_suffix@.is_undefined()) { + auto @cpp_name@_builtin_buffer = @js_name@@js_suffix@.as_if<@parameter.type.buffer_cpp@>(); + if (!@cpp_name@_builtin_buffer) { + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); + } + + @cpp_name@ = GC::make_root(*@cpp_name@_builtin_buffer); } +)~~~"); + } else { + scoped_generator.append(R"~~~( + if (!@js_name@@js_suffix@.is_undefined()) { + if (!@js_name@@js_suffix@.is_object() || !(is(@js_name@@js_suffix@.as_object()) || is(@js_name@@js_suffix@.as_object()) || is(@js_name@@js_suffix@.as_object()))) { + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); + } + + @cpp_name@ = GC::make_root(realm.create(@js_name@@js_suffix@.as_object())); + } +)~~~"); + } + return; + } + + if (type.is_nullable()) { + if (is_exact_javascript_buffer_source_type) { + scoped_generator.append(R"~~~( + if (@js_name@@js_suffix@.is_undefined()) { + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); + } + + if (!@js_name@@js_suffix@.is_null()) { + auto @cpp_name@_builtin_buffer = @js_name@@js_suffix@.as_if<@parameter.type.buffer_cpp@>(); + if (!@cpp_name@_builtin_buffer) { + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); + } + + @cpp_name@ = GC::make_root(*@cpp_name@_builtin_buffer); + } +)~~~"); + } else { + scoped_generator.append(R"~~~( + if (@js_name@@js_suffix@.is_undefined()) { + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); + } + + if (!@js_name@@js_suffix@.is_null()) { + if (!@js_name@@js_suffix@.is_object() || !(is(@js_name@@js_suffix@.as_object()) || is(@js_name@@js_suffix@.as_object()) || is(@js_name@@js_suffix@.as_object()))) { + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); + } + + @cpp_name@ = GC::make_root(realm.create(@js_name@@js_suffix@.as_object())); + } +)~~~"); + } + return; + } + + if (is_exact_javascript_buffer_source_type) { + scoped_generator.append(R"~~~( + auto @cpp_name@_builtin_buffer = @js_name@@js_suffix@.as_if<@parameter.type.buffer_cpp@>(); + if (!@cpp_name@_builtin_buffer) { + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); + } + + @cpp_name@ = GC::make_root(*@cpp_name@_builtin_buffer); +)~~~"); + } else { + scoped_generator.append(R"~~~( + if (!@js_name@@js_suffix@.is_object() || !(is(@js_name@@js_suffix@.as_object()) || is(@js_name@@js_suffix@.as_object()) || is(@js_name@@js_suffix@.as_object()))) { + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); + } + + @cpp_name@ = GC::make_root(realm.create(@js_name@@js_suffix@.as_object())); )~~~"); } } diff --git a/Tests/LibWeb/Text/expected/wpt-import/encoding/encodeInto.any.txt b/Tests/LibWeb/Text/expected/wpt-import/encoding/encodeInto.any.txt index 3d6e4bedbd..865fbc1e02 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/encoding/encodeInto.any.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/encoding/encodeInto.any.txt @@ -2,8 +2,7 @@ Harness status: OK Found 111 tests -85 Pass -26 Fail +111 Pass Pass encodeInto() into ArrayBuffer with Hi and destination length 0, offset 0, filler 0 Pass encodeInto() into SharedArrayBuffer with Hi and destination length 0, offset 0, filler 0 Pass encodeInto() into ArrayBuffer with Hi and destination length 0, offset 4, filler 0 @@ -88,30 +87,30 @@ Pass encodeInto() into ArrayBuffer with ¥¥ and destination length 4, offset 0, Pass encodeInto() into SharedArrayBuffer with ¥¥ and destination length 4, offset 0, filler random Pass encodeInto() into ArrayBuffer with ¥¥ and destination length 4, offset 4, filler random Pass encodeInto() into SharedArrayBuffer with ¥¥ and destination length 4, offset 4, filler random -Fail Invalid encodeInto() destination: DataView, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: DataView, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: Int8Array, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: Int8Array, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: Int16Array, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: Int16Array, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: Int32Array, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: Int32Array, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: Uint16Array, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: Uint16Array, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: Uint32Array, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: Uint32Array, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: Uint8ClampedArray, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: Uint8ClampedArray, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: BigInt64Array, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: BigInt64Array, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: BigUint64Array, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: BigUint64Array, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: Float16Array, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: Float16Array, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: Float32Array, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: Float32Array, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: Float64Array, backed by: ArrayBuffer -Fail Invalid encodeInto() destination: Float64Array, backed by: SharedArrayBuffer -Fail Invalid encodeInto() destination: ArrayBuffer -Fail Invalid encodeInto() destination: SharedArrayBuffer +Pass Invalid encodeInto() destination: DataView, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: DataView, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: Int8Array, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: Int8Array, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: Int16Array, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: Int16Array, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: Int32Array, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: Int32Array, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: Uint16Array, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: Uint16Array, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: Uint32Array, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: Uint32Array, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: Uint8ClampedArray, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: Uint8ClampedArray, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: BigInt64Array, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: BigInt64Array, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: BigUint64Array, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: BigUint64Array, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: Float16Array, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: Float16Array, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: Float32Array, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: Float32Array, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: Float64Array, backed by: ArrayBuffer +Pass Invalid encodeInto() destination: Float64Array, backed by: SharedArrayBuffer +Pass Invalid encodeInto() destination: ArrayBuffer +Pass Invalid encodeInto() destination: SharedArrayBuffer Pass encodeInto() and a detached output buffer \ No newline at end of file