Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/encoding/TextEncoder.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "mozilla/dom/TextEncoder.h"
8
#include "mozilla/Encoding.h"
9
10
namespace mozilla {
11
namespace dom {
12
13
void
14
TextEncoder::Init()
15
0
{
16
0
}
17
18
void
19
TextEncoder::Encode(JSContext* aCx,
20
                    JS::Handle<JSObject*> aObj,
21
                    const nsAString& aString,
22
                    JS::MutableHandle<JSObject*> aRetval,
23
                    ErrorResult& aRv)
24
0
{
25
0
  nsAutoCString utf8;
26
0
  nsresult rv;
27
0
  const Encoding* ignored;
28
0
  Tie(rv, ignored) = UTF_8_ENCODING->Encode(aString, utf8);
29
0
  if (NS_FAILED(rv)) {
30
0
    aRv.Throw(rv);
31
0
    return;
32
0
  }
33
0
34
0
  JSAutoRealm ar(aCx, aObj);
35
0
  JSObject* outView = Uint8Array::Create(
36
0
    aCx, utf8.Length(), reinterpret_cast<const uint8_t*>(utf8.BeginReading()));
37
0
  if (!outView) {
38
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
39
0
    return;
40
0
  }
41
0
42
0
  aRetval.set(outView);
43
0
}
44
45
void
46
TextEncoder::GetEncoding(nsAString& aEncoding)
47
0
{
48
0
  aEncoding.AssignLiteral("utf-8");
49
0
}
50
51
} // namespace dom
52
} // namespace mozilla