Bug 1092737 part 1. Update TextEncoder to various spec changes. r=emk

This commit is contained in:
Boris Zbarsky 2014-11-21 14:58:45 -05:00
parent d35c2686c4
commit be526b5304
4 changed files with 16 additions and 38 deletions

View File

@ -44,8 +44,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=882653
[ 'document.createTreeWalker(document, 0xFFFFFFFF, { acceptNode: 5 }).nextNode()',
"Property 'acceptNode' is not callable.",
"non-callable callback interface operation property" ],
[ '(new TextEncoder).encode("", new RegExp())',
"Argument 2 of TextEncoder.encode can't be converted to a dictionary.",
[ '(new TextDecoder).decode(new Uint8Array(), new RegExp())',
"Argument 2 of TextDecoder.decode can't be converted to a dictionary.",
"regexp passed for a dictionary" ],
[ 'URL.createObjectURL(null, null)',
"Argument 1 is not valid for any of the 2-argument overloads of URL.createObjectURL.",

View File

@ -1,3 +1,4 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -38,8 +39,7 @@ void
TextEncoder::Encode(JSContext* aCx,
JS::Handle<JSObject*> aObj,
const nsAString& aString,
const bool aStream,
JS::MutableHandle<JSObject*> aRetval,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv)
{
// Run the steps of the encoding algorithm.
@ -63,14 +63,11 @@ TextEncoder::Encode(JSContext* aCx,
int32_t dstLen = maxLen;
rv = mEncoder->Convert(data, &srcLen, buf, &dstLen);
// If the internal streaming flag is not set, then reset
// the encoding algorithm state to the default values for encoding.
if (!aStream) {
int32_t finishLen = maxLen - dstLen;
rv = mEncoder->Finish(buf + dstLen, &finishLen);
if (NS_SUCCEEDED(rv)) {
dstLen += finishLen;
}
// Now reset the encoding algorithm state to the default values for encoding.
int32_t finishLen = maxLen - dstLen;
rv = mEncoder->Finish(buf + dstLen, &finishLen);
if (NS_SUCCEEDED(rv)) {
dstLen += finishLen;
}
JSObject* outView = nullptr;

View File

@ -1,3 +1,4 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -46,15 +47,6 @@ public:
return TextEncoderBinding::Wrap(aCx, this, aTookOwnership);
}
void Encode(JSContext* aCx,
JS::Handle<JSObject*> aObj,
const nsAString& aString,
const TextEncodeOptions& aOptions,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv) {
TextEncoder::Encode(aCx, aObj, aString, aOptions.mStream, aRetval, aRv);
}
protected:
/**
@ -82,20 +74,14 @@ public:
* @param aCx Javascript context.
* @param aObj the wrapper of the TextEncoder
* @param aString utf-16 code units to be encoded.
* @param aOptions Streaming option. Initialised by default to false.
* If the streaming option is false, then the encoding
* algorithm state will get reset. If set to true then
* the previous encoding is reused/continued.
* @return JSObject* The Uint8Array wrapped in a JS object. Returned via
* the aRetval out param.
*/
void Encode(JSContext* aCx,
JS::Handle<JSObject*> aObj,
const nsAString& aString,
const bool aStream,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv);
JS::Handle<JSObject*> aObj,
const nsAString& aString,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv);
private:
nsCString mEncoding;
nsCOMPtr<nsIUnicodeEncoder> mEncoder;

View File

@ -15,11 +15,6 @@
interface TextEncoder {
[Constant]
readonly attribute DOMString encoding;
[Throws]
Uint8Array encode(optional DOMString input = "", optional TextEncodeOptions options);
[Throws, NewObject]
Uint8Array encode(optional ScalarValueString input = "");
};
dictionary TextEncodeOptions {
boolean stream = false;
};