SharedArrayBuffer.h (2812B)
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/. */ 5 6 /* ArrayBuffer functionality. */ 7 8 #ifndef js_SharedArrayBuffer_h 9 #define js_SharedArrayBuffer_h 10 11 #include <stddef.h> // size_t 12 #include <stdint.h> // uint8_t 13 14 #include "jstypes.h" // JS_PUBLIC_API 15 16 struct JS_PUBLIC_API JSContext; 17 class JS_PUBLIC_API JSObject; 18 19 namespace JS { 20 class JS_PUBLIC_API AutoRequireNoGC; 21 22 // CREATION 23 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. 29 */ 30 extern JS_PUBLIC_API JSObject* NewSharedArrayBuffer(JSContext* cx, 31 size_t nbytes); 32 33 // TYPE TESTING 34 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. 40 */ 41 extern JS_PUBLIC_API bool IsSharedArrayBufferObject(JSObject* obj); 42 43 // ACCESSORS 44 45 extern JS_PUBLIC_API JSObject* UnwrapSharedArrayBuffer(JSObject* obj); 46 47 extern JS_PUBLIC_API size_t GetSharedArrayBufferByteLength(JSObject* obj); 48 49 extern JS_PUBLIC_API uint8_t* GetSharedArrayBufferData(JSObject* obj, 50 bool* isSharedMemory, 51 const AutoRequireNoGC&); 52 53 // Ditto for SharedArrayBuffer. 54 // 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); 59 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. 65 */ 66 extern JS_PUBLIC_API bool ContainsSharedArrayBuffer(JSContext* cx); 67 68 /** 69 * Return the isShared flag of a ArrayBufferView subtypes, which denotes whether 70 * the underlying buffer is a SharedArrayBuffer. 71 * 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. 75 */ 76 extern JS_PUBLIC_API bool IsArrayBufferViewShared(JSObject* obj); 77 78 } // namespace JS 79 80 #endif /* js_SharedArrayBuffer_h */