From 2087c357972e7cb432437e50866907ad09274378 Mon Sep 17 00:00:00 2001 From: Samson <16504129+sagudev@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:52:31 +0100 Subject: [PATCH] Hide readablestream behind streams feature (#518) Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- mozjs-sys/Cargo.toml | 2 +- mozjs-sys/src/jsapi.cpp | 4 +++- mozjs-sys/src/jsglue.cpp | 8 +++++++- mozjs/src/generate_wrappers.sh | 2 ++ mozjs/src/jsapi_wrappers.in | 19 +++++++++++++++++++ mozjs/src/rust.rs | 6 ++++++ 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/mozjs-sys/Cargo.toml b/mozjs-sys/Cargo.toml index 3c4bd8940a4..396832b0d0f 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.3-1" +version = "0.128.3-2" authors = ["Mozilla"] links = "mozjs" build = "build.rs" diff --git a/mozjs-sys/src/jsapi.cpp b/mozjs-sys/src/jsapi.cpp index 5d5c4184b27..04353bd0941 100644 --- a/mozjs-sys/src/jsapi.cpp +++ b/mozjs-sys/src/jsapi.cpp @@ -32,7 +32,9 @@ #include "js/ScalarType.h" #include "js/SharedArrayBuffer.h" #include "js/SourceText.h" -#include "js/Stream.h" +#ifdef MOZ_JS_STREAMS +# include "js/Stream.h" +#endif #include "js/String.h" #include "js/StructuredClone.h" #include "js/Symbol.h" diff --git a/mozjs-sys/src/jsglue.cpp b/mozjs-sys/src/jsglue.cpp index 7a9518da2d9..698b65161c2 100644 --- a/mozjs-sys/src/jsglue.cpp +++ b/mozjs-sys/src/jsglue.cpp @@ -26,7 +26,9 @@ #include "js/Proxy.h" #include "js/RegExp.h" #include "js/ScalarType.h" -#include "js/Stream.h" +#ifdef MOZ_JS_STREAMS +# include "js/Stream.h" +#endif #include "js/StructuredClone.h" #include "js/Wrapper.h" #include "js/experimental/JSStencil.h" @@ -86,6 +88,7 @@ class RustJobQueue : public JS::JobQueue { } }; +#ifdef MOZ_JS_STREAMS struct ReadableStreamUnderlyingSourceTraps { void (*requestData)(const void* source, JSContext* cx, JS::HandleObject stream, size_t desiredSize); @@ -142,6 +145,7 @@ class RustReadableStreamUnderlyingSource virtual void finalize() { return mTraps.finalize(this); } }; +#endif struct JSExternalStringCallbacksTraps { void (*latin1Finalize)(const void* privateData, JS::Latin1Char* chars); @@ -1075,6 +1079,7 @@ JS::JobQueue* CreateJobQueue(const JobQueueTraps* aTraps, const void* aQueue) { void DeleteJobQueue(JS::JobQueue* queue) { delete queue; } +#ifdef MOZ_JS_STREAMS JS::ReadableStreamUnderlyingSource* CreateReadableStreamUnderlyingSource( const ReadableStreamUnderlyingSourceTraps* aTraps, const void* aSource) { return new RustReadableStreamUnderlyingSource(*aTraps, aSource); @@ -1084,6 +1089,7 @@ void DeleteReadableStreamUnderlyingSource( JS::ReadableStreamUnderlyingSource* source) { delete source; } +#endif JSExternalStringCallbacks* CreateJSExternalStringCallbacks( const JSExternalStringCallbacksTraps* aTraps, void* privateData) { diff --git a/mozjs/src/generate_wrappers.sh b/mozjs/src/generate_wrappers.sh index 52a5a8c5b4e..b6942a3fa10 100755 --- a/mozjs/src/generate_wrappers.sh +++ b/mozjs/src/generate_wrappers.sh @@ -36,6 +36,8 @@ find_latest_version_of_file_and_parse() { # parse reformated file grep_heur "target/wrap_$1" | $gsed 's/\(.*\)/wrap!('"$2"': \1);/g' > "mozjs/src/$2_wrappers.in" + $gsed -i '/Readable/i \ + #[cfg(feature = "streams")]' "mozjs/src/$2_wrappers.in" } find_latest_version_of_file_and_parse jsapi.rs jsapi diff --git a/mozjs/src/jsapi_wrappers.in b/mozjs/src/jsapi_wrappers.in index aedd4f7cf8b..ca316db04e1 100644 --- a/mozjs/src/jsapi_wrappers.in +++ b/mozjs/src/jsapi_wrappers.in @@ -162,24 +162,43 @@ wrap!(jsapi: pub fn GetSavedFrameAsyncCause(cx: *mut JSContext, principals: *mut wrap!(jsapi: pub fn GetSavedFrameAsyncParent(cx: *mut JSContext, principals: *mut JSPrincipals, savedFrame: HandleObject, asyncParentp: MutableHandleObject, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult); wrap!(jsapi: pub fn GetSavedFrameParent(cx: *mut JSContext, principals: *mut JSPrincipals, savedFrame: HandleObject, parentp: MutableHandleObject, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult); wrap!(jsapi: pub fn ConvertSavedFrameToPlainObject(cx: *mut JSContext, savedFrame: HandleObject, selfHosted: SavedFrameSelfHosted) -> *mut JSObject); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn NewReadableDefaultStreamObject(cx: *mut JSContext, underlyingSource: HandleObject, size: HandleFunction, highWaterMark: f64, proto: HandleObject) -> *mut JSObject); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn NewReadableExternalSourceStreamObject(cx: *mut JSContext, underlyingSource: *mut ReadableStreamUnderlyingSource, nsISupportsObject_alreadyAddreffed: *mut ::std::os::raw::c_void, proto: HandleObject) -> *mut JSObject); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamGetExternalUnderlyingSource(cx: *mut JSContext, stream: HandleObject, source: *mut *mut ReadableStreamUnderlyingSource) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamReleaseExternalUnderlyingSource(cx: *mut JSContext, stream: HandleObject) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamUpdateDataAvailableFromSource(cx: *mut JSContext, stream: HandleObject, availableData: u32) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamGetMode(cx: *mut JSContext, stream: HandleObject, mode: *mut ReadableStreamMode) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamIsReadable(cx: *mut JSContext, stream: HandleObject, result: *mut bool) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamIsLocked(cx: *mut JSContext, stream: HandleObject, result: *mut bool) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamIsDisturbed(cx: *mut JSContext, stream: HandleObject, result: *mut bool) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamCancel(cx: *mut JSContext, stream: HandleObject, reason: HandleValue) -> *mut JSObject); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamGetReader(cx: *mut JSContext, stream: HandleObject, mode: ReadableStreamReaderMode) -> *mut JSObject); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamTee(cx: *mut JSContext, stream: HandleObject, branch1Stream: MutableHandleObject, branch2Stream: MutableHandleObject) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamClose(cx: *mut JSContext, stream: HandleObject) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamReaderIsClosed(cx: *mut JSContext, reader: HandleObject, result: *mut bool) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamEnqueue(cx: *mut JSContext, stream: HandleObject, chunk: HandleValue) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamError(cx: *mut JSContext, stream: HandleObject, error: HandleValue) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamReaderCancel(cx: *mut JSContext, reader: HandleObject, reason: HandleValue) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamReaderReleaseLock(cx: *mut JSContext, reader: HandleObject) -> bool); + #[cfg(feature = "streams")] wrap!(jsapi: pub fn ReadableStreamDefaultReaderRead(cx: *mut JSContext, reader: HandleObject) -> *mut JSObject); wrap!(jsapi: pub fn IsWasmModuleObject(obj: HandleObject) -> bool); wrap!(jsapi: pub fn GetWasmModule(obj: HandleObject) -> RefPtr); diff --git a/mozjs/src/rust.rs b/mozjs/src/rust.rs index b13e1bc1d64..deeb9648554 100644 --- a/mozjs/src/rust.rs +++ b/mozjs/src/rust.rs @@ -1163,8 +1163,11 @@ pub mod wrappers { use crate::jsapi::PromiseState; use crate::jsapi::PromiseUserInputEventHandlingState; use crate::jsapi::ReadOnlyCompileOptions; + #[cfg(feature = "streams")] use crate::jsapi::ReadableStreamMode; + #[cfg(feature = "streams")] use crate::jsapi::ReadableStreamReaderMode; + #[cfg(feature = "streams")] use crate::jsapi::ReadableStreamUnderlyingSource; use crate::jsapi::Realm; use crate::jsapi::RefPtr; @@ -1313,8 +1316,11 @@ pub mod jsapi_wrapped { use crate::jsapi::PromiseUserInputEventHandlingState; use crate::jsapi::PropertyKey; use crate::jsapi::ReadOnlyCompileOptions; + #[cfg(feature = "streams")] use crate::jsapi::ReadableStreamMode; + #[cfg(feature = "streams")] use crate::jsapi::ReadableStreamReaderMode; + #[cfg(feature = "streams")] use crate::jsapi::ReadableStreamUnderlyingSource; use crate::jsapi::Realm; use crate::jsapi::RefPtr;