mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-30 18:12:45 +00:00 
			
		
		
		
	 9fe12c1851
			
		
	
	
		9fe12c1851
		
	
	
	
	
		
			
			This is a minor refactor of IDL::get_buffer_source_copy() letting it return ErrorOr<ByteBuffer> instead of Optional<ByteBuffer>. This also updates all places that use IDL::get_buffer_source_copy().
		
			
				
	
	
		
			27 lines
		
	
	
	
		
			878 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
	
		
			878 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <AK/FlyString.h>
 | |
| #include <LibJS/Runtime/TypedArray.h>
 | |
| #include <LibWeb/Bindings/IDLAbstractOperations.h>
 | |
| #include <LibWeb/Bindings/Wrapper.h>
 | |
| #include <LibWeb/Encoding/TextDecoder.h>
 | |
| 
 | |
| namespace Web::Encoding {
 | |
| 
 | |
| // https://encoding.spec.whatwg.org/#dom-textdecoder-decode
 | |
| DOM::ExceptionOr<String> TextDecoder::decode(JS::Handle<JS::Object> const& input) const
 | |
| {
 | |
|     // FIXME: Implement the streaming stuff.
 | |
| 
 | |
|     auto data_buffer_or_error = Bindings::IDL::get_buffer_source_copy(*input.cell());
 | |
|     if (data_buffer_or_error.is_error())
 | |
|         return DOM::OperationError::create("Failed to copy bytes from ArrayBuffer");
 | |
|     auto& data_buffer = data_buffer_or_error.value();
 | |
|     return m_decoder.to_utf8({ data_buffer.data(), data_buffer.size() });
 | |
| }
 | |
| 
 | |
| }
 |