Bug 1890793: Assert CallArgs::newTarget is not gray. r=spidermonkey-reviewers,sfink...
[gecko.git] / dom / base / BodyUtil.h
blob6639b54729fed89c1814a5cb317c62fef6f90535
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
10 #include "nsString.h"
11 #include "nsError.h"
13 #include "mozilla/dom/File.h"
14 #include "mozilla/dom/FormData.h"
16 #include "js/Utility.h" // JS::FreePolicy
18 namespace mozilla {
19 class ErrorResult;
21 namespace dom {
23 class BodyUtil final {
24 private:
25 BodyUtil() = delete;
27 public:
28 /**
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
31 * by |malloc|.
33 static void ConsumeArrayBuffer(JSContext* aCx,
34 JS::MutableHandle<JSObject*> aValue,
35 uint32_t aInputLength,
36 UniquePtr<uint8_t[], JS::FreePolicy> aInput,
37 ErrorResult& aRv);
39 /**
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);
48 /**
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,
55 ErrorResult& aRv);
57 /**
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,
62 nsString& aText);
64 /**
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);
72 } // namespace dom
73 } // namespace mozilla
75 #endif // mozilla_dom_BodyUtil_h