[SM91] Update to Spidermonkey 91.1.3 APIs
[0ad.git] / libraries / source / spidermonkey / include-win32-release / js / MemoryFunctions.h
blob3e8b4137f2c511eaca5111cf413998ec16c76e6b
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* Low-level memory-allocation functions. */
8 #ifndef js_MemoryFunctions_h
9 #define js_MemoryFunctions_h
11 #include "mozilla/Assertions.h" // MOZ_ASSERT
13 #include <stddef.h> // size_t
15 #include "jstypes.h" // JS_PUBLIC_API
17 struct JS_PUBLIC_API JSContext;
18 class JS_PUBLIC_API JSFreeOp;
19 class JS_PUBLIC_API JSObject;
20 struct JS_PUBLIC_API JSRuntime;
22 extern JS_PUBLIC_API void* JS_malloc(JSContext* cx, size_t nbytes);
24 extern JS_PUBLIC_API void* JS_realloc(JSContext* cx, void* p, size_t oldBytes,
25 size_t newBytes);
27 /**
28 * A wrapper for |js_free(p)| that may delay |js_free(p)| invocation as a
29 * performance optimization. |cx| may be nullptr.
31 extern JS_PUBLIC_API void JS_free(JSContext* cx, void* p);
33 /**
34 * Same as above, but for buffers that will be used with the BYOB
35 * (Bring Your Own Buffer) JSString creation functions, such as
36 * JS_NewLatin1String and JS_NewUCString
38 extern JS_PUBLIC_API void* JS_string_malloc(JSContext* cx, size_t nbytes);
40 extern JS_PUBLIC_API void* JS_string_realloc(JSContext* cx, void* p,
41 size_t oldBytes, size_t newBytes);
43 extern JS_PUBLIC_API void JS_string_free(JSContext* cx, void* p);
45 /**
46 * A wrapper for |js_free(p)| that may delay |js_free(p)| invocation as a
47 * performance optimization as specified by the given JSFreeOp instance.
49 extern JS_PUBLIC_API void JS_freeop(JSFreeOp* fop, void* p);
51 namespace JS {
53 /**
54 * The different possible memory uses to pass to Add/RemoveAssociatedMemory.
56 #define JS_FOR_EACH_PUBLIC_MEMORY_USE(_) \
57 _(XPCWrappedNative) \
58 _(DOMBinding) \
59 _(CTypeFFIType) \
60 _(CTypeFFITypeElements) \
61 _(CTypeFunctionInfo) \
62 _(CTypeFieldInfo) \
63 _(CDataBufferPtr) \
64 _(CDataBuffer) \
65 _(CClosureInfo) \
66 _(CTypesInt64) \
67 _(Embedding1) \
68 _(Embedding2) \
69 _(Embedding3) \
70 _(Embedding4) \
71 _(Embedding5)
73 enum class MemoryUse : uint8_t {
74 #define DEFINE_MEMORY_USE(Name) Name,
75 JS_FOR_EACH_PUBLIC_MEMORY_USE(DEFINE_MEMORY_USE)
76 #undef DEFINE_MEMORY_USE
79 /**
80 * Advise the GC of external memory owned by a JSObject. This is used to
81 * determine when to collect zones. Calls must be matched by calls to
82 * RemoveAssociatedMemory() when the memory is deallocated or no longer owned by
83 * the object.
85 extern JS_PUBLIC_API void AddAssociatedMemory(JSObject* obj, size_t nbytes,
86 MemoryUse use);
88 /**
89 * Advise the GC that external memory reported by JS::AddAssociatedMemory() is
90 * no longer owned by a JSObject. Calls must match those to
91 * AddAssociatedMemory().
93 extern JS_PUBLIC_API void RemoveAssociatedMemory(JSObject* obj, size_t nbytes,
94 MemoryUse use);
96 } // namespace JS
98 #endif /* js_MemoryFunctions_h */