Skip to content

Commit a7cfa6a

Browse files
authored
Added Wrapped NewArrayBufferWithContents to Header (#484)
Reformatted C++ Files with clang-format Signed-off-by: Redfire <[email protected]>
1 parent 5fb90b6 commit a7cfa6a

File tree

3 files changed

+43
-40
lines changed

3 files changed

+43
-40
lines changed

mozjs-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mozjs_sys"
33
description = "System crate for the Mozilla SpiderMonkey JavaScript engine."
44
repository.workspace = true
5-
version = "0.128.0-2"
5+
version = "0.128.0-3"
66
authors = ["Mozilla"]
77
links = "mozjs"
88
build = "build.rs"

mozjs-sys/src/jsapi.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -71,46 +71,47 @@ JSLinearString* AtomToLinearString(JSAtom* atom) {
7171

7272
// Wrappers around UniquePtr functions
7373
/**
74-
* Create a new ArrayBuffer with the given contents. The contents must not be
75-
* modified by any other code, internal or external.
76-
*
77-
* !!! IMPORTANT !!!
78-
* If and only if an ArrayBuffer is successfully created and returned,
79-
* ownership of |contents| is transferred to the new ArrayBuffer.
80-
*
81-
* When the ArrayBuffer is ready to be disposed of, `freeFunc(contents,
82-
* freeUserData)` will be called to release the ArrayBuffer's reference on the
83-
* contents.
84-
*
85-
* `freeFunc()` must not call any JSAPI functions that could cause a garbage
86-
* collection.
87-
*
88-
* The caller must keep the buffer alive until `freeFunc()` is called, or, if
89-
* `freeFunc` is null, until the JSRuntime is destroyed.
90-
*
91-
* The caller must not access the buffer on other threads. The JS engine will
92-
* not allow the buffer to be transferred to other threads. If you try to
93-
* transfer an external ArrayBuffer to another thread, the data is copied to a
94-
* new malloc buffer. `freeFunc()` must be threadsafe, and may be called from
95-
* any thread.
96-
*
97-
* This allows ArrayBuffers to be used with embedder objects that use reference
98-
* counting, for example. In that case the caller is responsible
99-
* for incrementing the reference count before passing the contents to this
100-
* function. This also allows using non-reference-counted contents that must be
101-
* freed with some function other than free().
102-
*/
103-
JSObject* NewExternalArrayBuffer(
104-
JSContext* cx, size_t nbytes, void* contents,
105-
JS::BufferContentsFreeFunc freeFunc, void* freeUserData) {
106-
js::UniquePtr<void, JS::BufferContentsDeleter> dataPtr{contents, {freeFunc, freeUserData}};
74+
* Create a new ArrayBuffer with the given contents. The contents must not be
75+
* modified by any other code, internal or external.
76+
*
77+
* !!! IMPORTANT !!!
78+
* If and only if an ArrayBuffer is successfully created and returned,
79+
* ownership of |contents| is transferred to the new ArrayBuffer.
80+
*
81+
* When the ArrayBuffer is ready to be disposed of, `freeFunc(contents,
82+
* freeUserData)` will be called to release the ArrayBuffer's reference on the
83+
* contents.
84+
*
85+
* `freeFunc()` must not call any JSAPI functions that could cause a garbage
86+
* collection.
87+
*
88+
* The caller must keep the buffer alive until `freeFunc()` is called, or, if
89+
* `freeFunc` is null, until the JSRuntime is destroyed.
90+
*
91+
* The caller must not access the buffer on other threads. The JS engine will
92+
* not allow the buffer to be transferred to other threads. If you try to
93+
* transfer an external ArrayBuffer to another thread, the data is copied to a
94+
* new malloc buffer. `freeFunc()` must be threadsafe, and may be called from
95+
* any thread.
96+
*
97+
* This allows ArrayBuffers to be used with embedder objects that use reference
98+
* counting, for example. In that case the caller is responsible
99+
* for incrementing the reference count before passing the contents to this
100+
* function. This also allows using non-reference-counted contents that must be
101+
* freed with some function other than free().
102+
*/
103+
JSObject* NewExternalArrayBuffer(JSContext* cx, size_t nbytes, void* contents,
104+
JS::BufferContentsFreeFunc freeFunc,
105+
void* freeUserData) {
106+
js::UniquePtr<void, JS::BufferContentsDeleter> dataPtr{
107+
contents, {freeFunc, freeUserData}};
107108
return NewExternalArrayBuffer(cx, nbytes, std::move(dataPtr));
108109
}
109110

110-
JSObject* NewArrayBufferWithContents(
111-
JSContext* cx, size_t nbytes, void* contents) {
112-
js::UniquePtr<void, JS::FreePolicy> dataPtr{contents};
113-
return NewArrayBufferWithContents(cx, nbytes, contents);
111+
JSObject* NewArrayBufferWithContents(JSContext* cx, size_t nbytes,
112+
void* contents) {
113+
js::UniquePtr<void, JS::FreePolicy> dataPtr{contents};
114+
return NewArrayBufferWithContents(cx, nbytes, contents);
114115
}
115116

116117
// Reexport some methods
@@ -269,8 +270,7 @@ bool CreateError(JSContext* cx, JSExnType type, JS::HandleObject stack,
269270
JS::MutableHandleValue rval) {
270271
return JS::CreateError(
271272
cx, type, stack, fileName, lineNumber,
272-
JS::ColumnNumberOneOrigin(columnNumber),
273-
report, message,
273+
JS::ColumnNumberOneOrigin(columnNumber), report, message,
274274
JS::Rooted<mozilla::Maybe<JS::Value>>(cx, mozilla::ToMaybe(&cause)),
275275
rval);
276276
}

mozjs-sys/src/jsapi.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ JSObject* NewExternalArrayBuffer(
8484
JSContext* cx, size_t nbytes, void* contents,
8585
JS::BufferContentsFreeFunc freeFunc, void* freeUserData = nullptr);
8686

87+
JSObject* NewArrayBufferWithContents(
88+
JSContext* cx, size_t nbytes, void* contents);
89+
8790
// Reexport some methods
8891

8992
bool JS_ForOfIteratorInit(

0 commit comments

Comments
 (0)