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/. */
7 #ifndef mozilla_dom_BodyUtil_h
8 #define mozilla_dom_BodyUtil_h
13 #include "mozilla/dom/File.h"
14 #include "mozilla/dom/FormData.h"
16 #include "js/Utility.h" // JS::FreePolicy
23 class BodyUtil final
{
29 * Creates an array buffer from an array, assigning the result to |aValue|.
30 * The array buffer takes ownership of |aInput|, which must be allocated
33 static void ConsumeArrayBuffer(JSContext
* aCx
,
34 JS::MutableHandle
<JSObject
*> aValue
,
35 uint32_t aInputLength
,
36 UniquePtr
<uint8_t[], JS::FreePolicy
> aInput
,
40 * Creates an in-memory blob from an array. The blob takes ownership of
41 * |aInput|, which must be allocated by |malloc|.
43 static already_AddRefed
<Blob
> ConsumeBlob(nsIGlobalObject
* aParent
,
44 const nsString
& aMimeType
,
45 uint32_t aInputLength
,
46 uint8_t* aInput
, ErrorResult
& aRv
);
49 * Creates a form data object from a UTF-8 encoded |aStr|. Returns |nullptr|
50 * and sets |aRv| to MSG_BAD_FORMDATA if |aStr| contains invalid data.
52 static already_AddRefed
<FormData
> ConsumeFormData(
53 nsIGlobalObject
* aParent
, const nsCString
& aMimeType
,
54 const nsACString
& aMixedCaseMimeType
, const nsCString
& aStr
,
58 * UTF-8 decodes |aInput| into |aText|. The caller may free |aInput|
59 * once this method returns.
61 static nsresult
ConsumeText(uint32_t aInputLength
, uint8_t* aInput
,
65 * Parses a UTF-8 encoded |aStr| as JSON, assigning the result to |aValue|.
66 * Sets |aRv| to a syntax error if |aStr| contains invalid data.
68 static void ConsumeJson(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aValue
,
69 const nsString
& aStr
, ErrorResult
& aRv
);
73 } // namespace mozilla
75 #endif // mozilla_dom_BodyUtil_h