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/ErrorResult.h"
14 #include "mozilla/dom/File.h"
15 #include "mozilla/dom/FormData.h"
20 class BodyUtil final
{
26 * Creates an array buffer from an array, assigning the result to |aValue|.
27 * The array buffer takes ownership of |aInput|, which must be allocated
30 static void ConsumeArrayBuffer(JSContext
* aCx
,
31 JS::MutableHandle
<JSObject
*> aValue
,
32 uint32_t aInputLength
, uint8_t* aInput
,
36 * Creates an in-memory blob from an array. The blob takes ownership of
37 * |aInput|, which must be allocated by |malloc|.
39 static already_AddRefed
<Blob
> ConsumeBlob(nsIGlobalObject
* aParent
,
40 const nsString
& aMimeType
,
41 uint32_t aInputLength
,
42 uint8_t* aInput
, ErrorResult
& aRv
);
45 * Creates a form data object from a UTF-8 encoded |aStr|. Returns |nullptr|
46 * and sets |aRv| to MSG_BAD_FORMDATA if |aStr| contains invalid data.
48 static already_AddRefed
<FormData
> ConsumeFormData(nsIGlobalObject
* aParent
,
49 const nsCString
& aMimeType
,
50 const nsCString
& aStr
,
54 * UTF-8 decodes |aInput| into |aText|. The caller may free |aInput|
55 * once this method returns.
57 static nsresult
ConsumeText(uint32_t aInputLength
, uint8_t* aInput
,
61 * Parses a UTF-8 encoded |aStr| as JSON, assigning the result to |aValue|.
62 * Sets |aRv| to a syntax error if |aStr| contains invalid data.
64 static void ConsumeJson(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aValue
,
65 const nsString
& aStr
, ErrorResult
& aRv
);
69 } // namespace mozilla
71 #endif // mozilla_dom_BodyUtil_h