mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 09:15:07 +00:00
LibWeb: Make TextDecoder GC-allocated
This commit is contained in:
parent
7e508456a0
commit
018d236439
4 changed files with 33 additions and 29 deletions
|
@ -9,9 +9,31 @@
|
|||
#include <LibWeb/Bindings/IDLAbstractOperations.h>
|
||||
#include <LibWeb/Bindings/Wrapper.h>
|
||||
#include <LibWeb/Encoding/TextDecoder.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
|
||||
namespace Web::Encoding {
|
||||
|
||||
DOM::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> TextDecoder::create_with_global_object(HTML::Window& window, FlyString encoding)
|
||||
{
|
||||
auto decoder = TextCodec::decoder_for(encoding);
|
||||
if (!decoder)
|
||||
return DOM::SimpleException { DOM::SimpleExceptionType::TypeError, String::formatted("Invalid encoding {}", encoding) };
|
||||
|
||||
return JS::NonnullGCPtr(*window.heap().allocate<TextDecoder>(window.realm(), window, *decoder, move(encoding), false, false));
|
||||
}
|
||||
|
||||
// https://encoding.spec.whatwg.org/#dom-textdecoder
|
||||
TextDecoder::TextDecoder(HTML::Window& window, TextCodec::Decoder& decoder, FlyString encoding, bool fatal, bool ignore_bom)
|
||||
: PlatformObject(window.realm())
|
||||
, m_decoder(decoder)
|
||||
, m_encoding(move(encoding))
|
||||
, m_fatal(fatal)
|
||||
, m_ignore_bom(ignore_bom)
|
||||
{
|
||||
}
|
||||
|
||||
TextDecoder::~TextDecoder() = default;
|
||||
|
||||
// https://encoding.spec.whatwg.org/#dom-textdecoder-decode
|
||||
DOM::ExceptionOr<String> TextDecoder::decode(JS::Handle<JS::Object> const& input) const
|
||||
{
|
||||
|
|
|
@ -8,35 +8,22 @@
|
|||
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibTextCodec/Decoder.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::Encoding {
|
||||
|
||||
// https://encoding.spec.whatwg.org/#textdecoder
|
||||
class TextDecoder
|
||||
: public RefCounted<TextDecoder>
|
||||
, public Bindings::Wrappable {
|
||||
class TextDecoder : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(TextDecoder, Bindings::PlatformObject);
|
||||
|
||||
public:
|
||||
using WrapperType = Bindings::TextDecoderWrapper;
|
||||
static DOM::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> create_with_global_object(HTML::Window&, FlyString encoding);
|
||||
|
||||
static DOM::ExceptionOr<NonnullRefPtr<TextDecoder>> create(FlyString encoding)
|
||||
{
|
||||
auto decoder = TextCodec::decoder_for(encoding);
|
||||
if (!decoder)
|
||||
return DOM::SimpleException { DOM::SimpleExceptionType::TypeError, String::formatted("Invalid encoding {}", encoding) };
|
||||
|
||||
return adopt_ref(*new TextDecoder(*decoder, move(encoding), false, false));
|
||||
}
|
||||
|
||||
static DOM::ExceptionOr<NonnullRefPtr<TextDecoder>> create_with_global_object(HTML::Window&, FlyString label)
|
||||
{
|
||||
return TextDecoder::create(move(label));
|
||||
}
|
||||
virtual ~TextDecoder() override;
|
||||
|
||||
DOM::ExceptionOr<String> decode(JS::Handle<JS::Object> const&) const;
|
||||
|
||||
|
@ -44,15 +31,9 @@ public:
|
|||
bool fatal() const { return m_fatal; }
|
||||
bool ignore_bom() const { return m_ignore_bom; };
|
||||
|
||||
protected:
|
||||
private:
|
||||
// https://encoding.spec.whatwg.org/#dom-textdecoder
|
||||
TextDecoder(TextCodec::Decoder& decoder, FlyString encoding, bool fatal, bool ignore_bom)
|
||||
: m_decoder(decoder)
|
||||
, m_encoding(move(encoding))
|
||||
, m_fatal(fatal)
|
||||
, m_ignore_bom(ignore_bom)
|
||||
{
|
||||
}
|
||||
TextDecoder(HTML::Window&, TextCodec::Decoder&, FlyString encoding, bool fatal, bool ignore_bom);
|
||||
|
||||
TextCodec::Decoder& m_decoder;
|
||||
FlyString m_encoding;
|
||||
|
@ -61,3 +42,5 @@ protected:
|
|||
};
|
||||
|
||||
}
|
||||
|
||||
WRAPPER_HACK(TextDecoder, Web::Encoding)
|
||||
|
|
|
@ -461,7 +461,6 @@ class OptionConstructor;
|
|||
class RangePrototype;
|
||||
class ResizeObserverWrapper;
|
||||
class SelectionWrapper;
|
||||
class TextDecoderWrapper;
|
||||
class URLSearchParamsIteratorWrapper;
|
||||
class URLSearchParamsWrapper;
|
||||
class URLWrapper;
|
||||
|
|
|
@ -51,7 +51,7 @@ libweb_js_wrapper(DOM/StaticRange NO_INSTANCE)
|
|||
libweb_js_wrapper(DOM/Text NO_INSTANCE)
|
||||
libweb_js_wrapper(DOM/TreeWalker NO_INSTANCE)
|
||||
libweb_js_wrapper(DOMParsing/XMLSerializer NO_INSTANCE)
|
||||
libweb_js_wrapper(Encoding/TextDecoder)
|
||||
libweb_js_wrapper(Encoding/TextDecoder NO_INSTANCE)
|
||||
libweb_js_wrapper(Encoding/TextEncoder NO_INSTANCE)
|
||||
libweb_js_wrapper(Fetch/Headers ITERABLE)
|
||||
libweb_js_wrapper(FileAPI/Blob)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue