diff --git a/mozjs-sys/Cargo.toml b/mozjs-sys/Cargo.toml index dfc38944d9..3a39144aa2 100644 --- a/mozjs-sys/Cargo.toml +++ b/mozjs-sys/Cargo.toml @@ -2,7 +2,7 @@ name = "mozjs_sys" description = "System crate for the Mozilla SpiderMonkey JavaScript engine." repository.workspace = true -version = "0.128.0-2" +version = "0.128.0-3" authors = ["Mozilla"] links = "mozjs" build = "build.rs" diff --git a/mozjs-sys/src/jsapi.cpp b/mozjs-sys/src/jsapi.cpp index 7e8e87a4b4..650814284b 100644 --- a/mozjs-sys/src/jsapi.cpp +++ b/mozjs-sys/src/jsapi.cpp @@ -71,46 +71,47 @@ JSLinearString* AtomToLinearString(JSAtom* atom) { // Wrappers around UniquePtr functions /** -* Create a new ArrayBuffer with the given contents. The contents must not be -* modified by any other code, internal or external. -* -* !!! IMPORTANT !!! -* If and only if an ArrayBuffer is successfully created and returned, -* ownership of |contents| is transferred to the new ArrayBuffer. -* -* When the ArrayBuffer is ready to be disposed of, `freeFunc(contents, -* freeUserData)` will be called to release the ArrayBuffer's reference on the -* contents. -* -* `freeFunc()` must not call any JSAPI functions that could cause a garbage -* collection. -* -* The caller must keep the buffer alive until `freeFunc()` is called, or, if -* `freeFunc` is null, until the JSRuntime is destroyed. -* -* The caller must not access the buffer on other threads. The JS engine will -* not allow the buffer to be transferred to other threads. If you try to -* transfer an external ArrayBuffer to another thread, the data is copied to a -* new malloc buffer. `freeFunc()` must be threadsafe, and may be called from -* any thread. -* -* This allows ArrayBuffers to be used with embedder objects that use reference -* counting, for example. In that case the caller is responsible -* for incrementing the reference count before passing the contents to this -* function. This also allows using non-reference-counted contents that must be -* freed with some function other than free(). -*/ -JSObject* NewExternalArrayBuffer( - JSContext* cx, size_t nbytes, void* contents, - JS::BufferContentsFreeFunc freeFunc, void* freeUserData) { - js::UniquePtr dataPtr{contents, {freeFunc, freeUserData}}; + * Create a new ArrayBuffer with the given contents. The contents must not be + * modified by any other code, internal or external. + * + * !!! IMPORTANT !!! + * If and only if an ArrayBuffer is successfully created and returned, + * ownership of |contents| is transferred to the new ArrayBuffer. + * + * When the ArrayBuffer is ready to be disposed of, `freeFunc(contents, + * freeUserData)` will be called to release the ArrayBuffer's reference on the + * contents. + * + * `freeFunc()` must not call any JSAPI functions that could cause a garbage + * collection. + * + * The caller must keep the buffer alive until `freeFunc()` is called, or, if + * `freeFunc` is null, until the JSRuntime is destroyed. + * + * The caller must not access the buffer on other threads. The JS engine will + * not allow the buffer to be transferred to other threads. If you try to + * transfer an external ArrayBuffer to another thread, the data is copied to a + * new malloc buffer. `freeFunc()` must be threadsafe, and may be called from + * any thread. + * + * This allows ArrayBuffers to be used with embedder objects that use reference + * counting, for example. In that case the caller is responsible + * for incrementing the reference count before passing the contents to this + * function. This also allows using non-reference-counted contents that must be + * freed with some function other than free(). + */ +JSObject* NewExternalArrayBuffer(JSContext* cx, size_t nbytes, void* contents, + JS::BufferContentsFreeFunc freeFunc, + void* freeUserData) { + js::UniquePtr dataPtr{ + contents, {freeFunc, freeUserData}}; return NewExternalArrayBuffer(cx, nbytes, std::move(dataPtr)); } -JSObject* NewArrayBufferWithContents( - JSContext* cx, size_t nbytes, void* contents) { - js::UniquePtr dataPtr{contents}; - return NewArrayBufferWithContents(cx, nbytes, contents); +JSObject* NewArrayBufferWithContents(JSContext* cx, size_t nbytes, + void* contents) { + js::UniquePtr dataPtr{contents}; + return NewArrayBufferWithContents(cx, nbytes, contents); } // Reexport some methods @@ -269,8 +270,7 @@ bool CreateError(JSContext* cx, JSExnType type, JS::HandleObject stack, JS::MutableHandleValue rval) { return JS::CreateError( cx, type, stack, fileName, lineNumber, - JS::ColumnNumberOneOrigin(columnNumber), - report, message, + JS::ColumnNumberOneOrigin(columnNumber), report, message, JS::Rooted>(cx, mozilla::ToMaybe(&cause)), rval); } diff --git a/mozjs-sys/src/jsapi.hpp b/mozjs-sys/src/jsapi.hpp index 509a27911e..3dd884351f 100644 --- a/mozjs-sys/src/jsapi.hpp +++ b/mozjs-sys/src/jsapi.hpp @@ -84,6 +84,9 @@ JSObject* NewExternalArrayBuffer( JSContext* cx, size_t nbytes, void* contents, JS::BufferContentsFreeFunc freeFunc, void* freeUserData = nullptr); +JSObject* NewArrayBufferWithContents( + JSContext* cx, size_t nbytes, void* contents); + // Reexport some methods bool JS_ForOfIteratorInit(