| Index: Source/modules/encoding/TextDecoder.cpp
|
| diff --git a/Source/bindings/v8/ExceptionState.cpp b/Source/modules/encoding/TextDecoder.cpp
|
| similarity index 53%
|
| copy from Source/bindings/v8/ExceptionState.cpp
|
| copy to Source/modules/encoding/TextDecoder.cpp
|
| index 26ea567f9cab9fc1a6f509cbe621d65e70544171..69d37d050a4bf4165db0af3150655c7f24844327 100644
|
| --- a/Source/bindings/v8/ExceptionState.cpp
|
| +++ b/Source/modules/encoding/TextDecoder.cpp
|
| @@ -29,53 +29,70 @@
|
| */
|
|
|
| #include "config.h"
|
| -#include "bindings/v8/ExceptionState.h"
|
|
|
| -#include "bindings/v8/V8ThrowException.h"
|
| +#include "modules/encoding/TextDecoder.h"
|
| +
|
| +#include "bindings/v8/ExceptionState.h"
|
| #include "core/dom/ExceptionCode.h"
|
| +#include "wtf/text/TextEncodingRegistry.h"
|
|
|
| namespace WebCore {
|
|
|
| -void ExceptionState::clearException()
|
| -{
|
| - m_code = 0;
|
| - m_exception.clear();
|
| -}
|
| -
|
| -void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& message)
|
| +PassRefPtr<TextDecoder> TextDecoder::create(const String& label, const Dictionary& options, ExceptionState& es)
|
| {
|
| - ASSERT(ec);
|
| - m_code = ec;
|
| - setException(V8ThrowException::createDOMException(ec, message, m_isolate));
|
| -}
|
| + const String& encodingLabel = label.isNull() ? String("utf-8") : label;
|
|
|
| -void ExceptionState::setException(v8::Handle<v8::Value> exception)
|
| -{
|
| - if (exception.IsEmpty()) {
|
| - clearException();
|
| - return;
|
| + WTF::TextEncoding encoding(encodingLabel);
|
| + if (!encoding.isValid()) {
|
| + es.throwTypeError();
|
| + return 0;
|
| }
|
|
|
| - m_exception.set(m_isolate, exception);
|
| + bool fatal = false;
|
| + options.get("fatal", fatal);
|
| +
|
| + return adoptRef(new TextDecoder(encoding.name(), fatal));
|
| }
|
|
|
| -void ExceptionState::throwTypeError(const String& message)
|
| +
|
| +TextDecoder::TextDecoder(const String& encoding, bool fatal)
|
| + : m_encoding(encoding)
|
| + , m_codec(newTextCodec(m_encoding))
|
| + , m_fatal(fatal)
|
| {
|
| - m_code = TypeError;
|
| - setException(V8ThrowException::createTypeError(message, m_isolate));
|
| }
|
|
|
| -NonThrowExceptionState::NonThrowExceptionState()
|
| - : ExceptionState(0) { }
|
| +TextDecoder::~TextDecoder()
|
| +{
|
| +}
|
|
|
| -void NonThrowExceptionState::throwDOMException(const ExceptionCode& ec, const String&)
|
| +String TextDecoder::encoding() const
|
| {
|
| - m_code = ec;
|
| + return String(m_encoding.name()).lower();
|
| }
|
|
|
| -void NonThrowExceptionState::throwTypeError(const String&)
|
| +String TextDecoder::decode(ArrayBufferView* input, const Dictionary& options, ExceptionState& es)
|
| {
|
| - m_code = TypeError;
|
| + bool stream = false;
|
| + options.get("stream", stream);
|
| +
|
| + const char* start = input ? static_cast<const char*>(input->baseAddress()) : 0;
|
| + size_t length = input ? input->byteLength() : 0;
|
| +
|
| + bool flush = !stream;
|
| +
|
| + // FIXME: Not all TextCodec implementations handle |flush| - notably TextCodecUTF16
|
| + // ignores it and never flushes!
|
| +
|
| + bool sawError = false;
|
| + String s = m_codec->decode(start, length, flush, m_fatal, sawError);
|
| +
|
| + if (m_fatal && sawError) {
|
| + es.throwDOMException(EncodingError, "The encoded data was not valid.");
|
| + return String();
|
| + }
|
| +
|
| + return s;
|
| }
|
|
|
| } // namespace WebCore
|
|
|