2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-09-28 14:19:18 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_textencoder_h_
|
|
|
|
#define mozilla_dom_textencoder_h_
|
|
|
|
|
2013-08-23 09:17:10 +04:00
|
|
|
#include "mozilla/dom/NonRefcountedDOMObject.h"
|
2012-09-28 14:19:18 +04:00
|
|
|
#include "mozilla/dom/TextEncoderBinding.h"
|
2013-08-23 09:17:10 +04:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
#include "nsIUnicodeEncoder.h"
|
2012-09-28 14:19:18 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-08-23 09:17:10 +04:00
|
|
|
class ErrorResult;
|
|
|
|
|
2012-09-28 14:19:18 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class TextEncoder final : public NonRefcountedDOMObject
|
2012-09-28 14:19:18 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// The WebIDL constructor.
|
2013-08-23 09:17:10 +04:00
|
|
|
|
|
|
|
static TextEncoder*
|
2012-12-03 20:07:49 +04:00
|
|
|
Constructor(const GlobalObject& aGlobal,
|
2012-10-25 06:03:21 +04:00
|
|
|
const nsAString& aEncoding,
|
2012-09-28 14:19:18 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-08-23 09:17:10 +04:00
|
|
|
nsAutoPtr<TextEncoder> txtEncoder(new TextEncoder());
|
2012-09-28 14:19:18 +04:00
|
|
|
txtEncoder->Init(aEncoding, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return txtEncoder.forget();
|
|
|
|
}
|
|
|
|
|
2013-08-23 09:17:10 +04:00
|
|
|
TextEncoder()
|
2012-09-28 14:19:18 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~TextEncoder()
|
|
|
|
{}
|
|
|
|
|
Bug 1117172 part 2. Change the non-wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, Codegen.py, and
StructuredClone.cpp. The rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/WrapObject\((JSContext *\* *(?:aCx|cx)),(\s*)(JS::MutableHandle<JSObject\*> aReflector)/WrapObject(\1,\2JS::Handle<JSObject*> aGivenProto,\2\3/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx)), this, aReflector/\1, this, aGivenProto, aReflector/'
2015-03-19 17:13:32 +03:00
|
|
|
bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
|
2012-09-28 14:19:18 +04:00
|
|
|
{
|
Bug 1117172 part 2. Change the non-wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, Codegen.py, and
StructuredClone.cpp. The rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/WrapObject\((JSContext *\* *(?:aCx|cx)),(\s*)(JS::MutableHandle<JSObject\*> aReflector)/WrapObject(\1,\2JS::Handle<JSObject*> aGivenProto,\2\3/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx)), this, aReflector/\1, this, aGivenProto, aReflector/'
2015-03-19 17:13:32 +03:00
|
|
|
return TextEncoderBinding::Wrap(aCx, this, aGivenProto, aReflector);
|
2012-09-28 14:19:18 +04:00
|
|
|
}
|
|
|
|
|
2013-08-23 09:17:10 +04:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates provided encoding and throws an exception if invalid encoding.
|
|
|
|
* If no encoding is provided then mEncoding is default initialised to "utf-8".
|
|
|
|
*
|
|
|
|
* @param aEncoding Optional encoding (case insensitive) provided.
|
|
|
|
* (valid values are "utf-8", "utf-16", "utf-16be")
|
|
|
|
* Default value is "utf-8" if no encoding is provided.
|
|
|
|
* @return aRv EncodingError exception else null.
|
|
|
|
*/
|
|
|
|
void Init(const nsAString& aEncoding, ErrorResult& aRv);
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Return the encoding name.
|
|
|
|
*
|
|
|
|
* @param aEncoding, current encoding.
|
|
|
|
*/
|
|
|
|
void GetEncoding(nsAString& aEncoding);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encodes incoming utf-16 code units/ DOM string to the requested encoding.
|
|
|
|
*
|
|
|
|
* @param aCx Javascript context.
|
|
|
|
* @param aObj the wrapper of the TextEncoder
|
|
|
|
* @param aString utf-16 code units to be encoded.
|
2014-06-12 00:26:52 +04:00
|
|
|
* @return JSObject* The Uint8Array wrapped in a JS object. Returned via
|
|
|
|
* the aRetval out param.
|
2013-08-23 09:17:10 +04:00
|
|
|
*/
|
2014-06-12 00:26:52 +04:00
|
|
|
void Encode(JSContext* aCx,
|
2014-11-21 22:58:45 +03:00
|
|
|
JS::Handle<JSObject*> aObj,
|
|
|
|
const nsAString& aString,
|
|
|
|
JS::MutableHandle<JSObject*> aRetval,
|
|
|
|
ErrorResult& aRv);
|
2012-09-28 14:19:18 +04:00
|
|
|
private:
|
2013-08-23 09:17:10 +04:00
|
|
|
nsCString mEncoding;
|
|
|
|
nsCOMPtr<nsIUnicodeEncoder> mEncoder;
|
2012-09-28 14:19:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // dom
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_textencoder_h_
|