Bug 1886451: Add missing ifdef Nightly guards. r=dminor
[gecko.git] / js / public / SharedArrayBuffer.h
blobf427b7c8062464c35d9409bb078a5989df48f74a
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 /* ArrayBuffer functionality. */
8 #ifndef js_SharedArrayBuffer_h
9 #define js_SharedArrayBuffer_h
11 #include <stddef.h> // size_t
12 #include <stdint.h> // uint8_t
14 #include "jstypes.h" // JS_PUBLIC_API
16 struct JS_PUBLIC_API JSContext;
17 class JS_PUBLIC_API JSObject;
19 namespace JS {
20 class JS_PUBLIC_API AutoRequireNoGC;
22 // CREATION
24 /**
25 * Create a new SharedArrayBuffer with the given byte length. This
26 * may only be called if
27 * JS::RealmCreationOptionsRef(cx).getSharedMemoryAndAtomicsEnabled() is
28 * true.
30 extern JS_PUBLIC_API JSObject* NewSharedArrayBuffer(JSContext* cx,
31 size_t nbytes);
33 // TYPE TESTING
35 /**
36 * Check whether obj supports the JS::GetSharedArrayBuffer* APIs. Note that
37 * this may return false if a security wrapper is encountered that denies the
38 * unwrapping. If this test succeeds, then it is safe to call the various
39 * accessor JSAPI calls defined below.
41 extern JS_PUBLIC_API bool IsSharedArrayBufferObject(JSObject* obj);
43 // ACCESSORS
45 extern JS_PUBLIC_API JSObject* UnwrapSharedArrayBuffer(JSObject* obj);
47 extern JS_PUBLIC_API size_t GetSharedArrayBufferByteLength(JSObject* obj);
49 extern JS_PUBLIC_API uint8_t* GetSharedArrayBufferData(JSObject* obj,
50 bool* isSharedMemory,
51 const AutoRequireNoGC&);
53 // Ditto for SharedArrayBuffer.
55 // There is an isShared out argument for API consistency (eases use from DOM).
56 // It will always be set to true.
57 extern JS_PUBLIC_API void GetSharedArrayBufferLengthAndData(
58 JSObject* obj, size_t* length, bool* isSharedMemory, uint8_t** data);
60 /**
61 * Returns true if there are any live SharedArrayBuffer objects, including those
62 * for wasm memories, associated with the context. This is conservative,
63 * because it does not run GC. Some dead objects may not have been collected
64 * yet and thus will be thought live.
66 extern JS_PUBLIC_API bool ContainsSharedArrayBuffer(JSContext* cx);
68 /**
69 * Return the isShared flag of a ArrayBufferView subtypes, which denotes whether
70 * the underlying buffer is a SharedArrayBuffer.
72 * |obj| must have passed a JS_IsArrayBufferViewObject test, or somehow
73 * be known that it would pass such a test: it is a ArrayBufferView subtypes or
74 * a wrapper of a ArrayBufferView subtypes, and the unwrapping will succeed.
76 extern JS_PUBLIC_API bool IsArrayBufferViewShared(JSObject* obj);
78 } // namespace JS
80 #endif /* js_SharedArrayBuffer_h */