Commit 55a65bb6 authored by bashi@chromium.org's avatar bashi@chromium.org

Encoding API: Add TextDecodeOptions and TextDecoderOptions

Replacing generic Dictionary. No changes in behavior.
Tests under fast/encoding cover this change.

BUG=403150

Review URL: https://codereview.chromium.org/564463002

git-svn-id: svn://svn.chromium.org/blink/trunk@181890 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f92b9734
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// http://encoding.spec.whatwg.org/#textdecoder
[
GarbageCollected
] dictionary TextDecodeOptions {
boolean stream = false;
};
......@@ -39,7 +39,7 @@
namespace blink {
TextDecoder* TextDecoder::create(const String& label, const Dictionary& options, ExceptionState& exceptionState)
TextDecoder* TextDecoder::create(const String& label, const TextDecoderOptions& options, ExceptionState& exceptionState)
{
WTF::TextEncoding encoding(label);
// The replacement encoding is not valid, but the Encoding API also
......@@ -49,13 +49,7 @@ TextDecoder* TextDecoder::create(const String& label, const Dictionary& options,
return 0;
}
bool fatal = false;
DictionaryHelper::get(options, "fatal", fatal);
bool ignoreBOM = false;
DictionaryHelper::get(options, "ignoreBOM", ignoreBOM);
return new TextDecoder(encoding, fatal, ignoreBOM);
return new TextDecoder(encoding, options.fatal(), options.ignoreBOM());
}
......@@ -82,15 +76,12 @@ String TextDecoder::encoding() const
return name;
}
String TextDecoder::decode(ArrayBufferView* input, const Dictionary& options, ExceptionState& exceptionState)
String TextDecoder::decode(ArrayBufferView* input, const TextDecodeOptions& options, ExceptionState& exceptionState)
{
bool stream = false;
DictionaryHelper::get(options, "stream", stream);
const char* start = input ? static_cast<const char*>(input->baseAddress()) : 0;
size_t length = input ? input->byteLength() : 0;
WTF::FlushBehavior flush = stream ? WTF::DoNotFlush : WTF::DataEOF;
WTF::FlushBehavior flush = options.stream() ? WTF::DoNotFlush : WTF::DataEOF;
bool sawError = false;
String s = m_codec->decode(start, length, flush, m_fatal, sawError);
......@@ -113,4 +104,10 @@ String TextDecoder::decode(ArrayBufferView* input, const Dictionary& options, Ex
return s;
}
String TextDecoder::decode(ExceptionState& exceptionState)
{
TextDecodeOptions* options = TextDecodeOptions::create();
return decode(0, *options, exceptionState);
}
} // namespace blink
......@@ -31,8 +31,9 @@
#ifndef TextDecoder_h
#define TextDecoder_h
#include "bindings/core/v8/Dictionary.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "modules/encoding/TextDecodeOptions.h"
#include "modules/encoding/TextDecoderOptions.h"
#include "platform/heap/Handle.h"
#include "wtf/ArrayBufferView.h"
#include "wtf/text/TextCodec.h"
......@@ -46,15 +47,15 @@ class ExceptionState;
class TextDecoder FINAL : public GarbageCollectedFinalized<TextDecoder>, public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static TextDecoder* create(const String& label, const Dictionary&, ExceptionState&);
static TextDecoder* create(const String& label, const TextDecoderOptions&, ExceptionState&);
~TextDecoder();
// Implement the IDL
String encoding() const;
bool fatal() const { return m_fatal; }
bool ignoreBOM() const { return m_ignoreBOM; }
String decode(ArrayBufferView*, const Dictionary&, ExceptionState&);
String decode(ExceptionState& exceptionState) { return decode(0, Dictionary(), exceptionState); }
String decode(ArrayBufferView*, const TextDecodeOptions&, ExceptionState&);
String decode(ExceptionState&);
void trace(Visitor*) { }
......
......@@ -31,7 +31,7 @@
[
RuntimeEnabled=EncodingAPI,
Exposed=(Window,Worker),
Constructor(optional DOMString label = "utf-8", optional Dictionary options),
Constructor(optional DOMString label = "utf-8", optional TextDecoderOptions options),
RaisesException=Constructor,
GarbageCollected,
MeasureAs=TextDecoderConstructor
......@@ -39,5 +39,5 @@
readonly attribute DOMString encoding;
readonly attribute boolean fatal;
readonly attribute boolean ignoreBOM;
[RaisesException, MeasureAs=TextDecoderDecode] DOMString decode(optional ArrayBufferView input, optional Dictionary options);
[RaisesException, MeasureAs=TextDecoderDecode] DOMString decode(optional ArrayBufferView input, optional TextDecodeOptions options);
};
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// http://encoding.spec.whatwg.org/#textdecoder
[
GarbageCollected
] dictionary TextDecoderOptions {
boolean fatal = false;
boolean ignoreBOM = false;
};
......@@ -276,6 +276,8 @@
'websockets/CloseEvent.idl',
],
'modules_dictionary_idl_files': [
'encoding/TextDecodeOptions.idl',
'encoding/TextDecoderOptions.idl',
'notifications/NotificationOptions.idl',
'webmidi/MIDIOptions.idl',
],
......@@ -291,6 +293,10 @@
'<(blink_modules_output_dir)/IndexedDBNames.h',
],
'generated_modules_dictionary_files': [
'<(blink_modules_output_dir)/encoding/TextDecodeOptions.cpp',
'<(blink_modules_output_dir)/encoding/TextDecodeOptions.h',
'<(blink_modules_output_dir)/encoding/TextDecoderOptions.cpp',
'<(blink_modules_output_dir)/encoding/TextDecoderOptions.h',
'<(blink_modules_output_dir)/notifications/NotificationOptions.cpp',
'<(blink_modules_output_dir)/notifications/NotificationOptions.h',
'<(blink_modules_output_dir)/webmidi/MIDIOptions.cpp',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment