From 7754555441262bf1684b7da84eed845d35a62b84 Mon Sep 17 00:00:00 2001 From: Redfire Date: Sat, 2 Dec 2023 23:24:22 +0800 Subject: [PATCH 1/7] Modified `Range::new` to take Raw Pointers --- mozjs-sys/src/jsimpls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mozjs-sys/src/jsimpls.rs b/mozjs-sys/src/jsimpls.rs index 4f74d6ca4ca..2b63737090f 100644 --- a/mozjs-sys/src/jsimpls.rs +++ b/mozjs-sys/src/jsimpls.rs @@ -547,7 +547,7 @@ impl JS::ForOfIterator { } impl mozilla::Range { - pub fn new(start: &mut T, end: &mut T) -> mozilla::Range { + pub fn new(start: *mut T, end: *mut T) -> mozilla::Range { mozilla::Range { mStart: mozilla::RangedPtr { mPtr: start, From c7c5a1d0a03adb776db798daecfbf5ba6da08052 Mon Sep 17 00:00:00 2001 From: Redfire Date: Sat, 2 Dec 2023 23:51:54 +0800 Subject: [PATCH 2/7] Added Test for `mozilla::Range::new` --- mozjs-sys/build.rs | 1 - mozjs/tests/range.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 mozjs/tests/range.rs diff --git a/mozjs-sys/build.rs b/mozjs-sys/build.rs index c3a7196431e..b8f2959cd73 100644 --- a/mozjs-sys/build.rs +++ b/mozjs-sys/build.rs @@ -30,7 +30,6 @@ const ENV_VARS: &'static [&'static str] = &[ const EXTRA_FILES: &'static [&'static str] = &[ "makefile.cargo", - "src/rustfmt.toml", "src/jsglue.hpp", "src/jsglue.cpp", ]; diff --git a/mozjs/tests/range.rs b/mozjs/tests/range.rs new file mode 100644 index 00000000000..2e6e6d006ca --- /dev/null +++ b/mozjs/tests/range.rs @@ -0,0 +1,49 @@ +use std::ptr; + +use mozjs::jsapi::mozilla::Range; +use mozjs::jsapi::{BigIntIsUint64, JS_NewGlobalObject, StringToBigInt, StringToBigInt1}; +use mozjs::jsapi::{JSAutoRealm, OnNewGlobalHookOption}; +use mozjs::rooted; +use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; + +#[test] +fn range() { + let engine = JSEngine::init().unwrap(); + let runtime = Runtime::new(engine.handle()); + let context = runtime.cx(); + let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; + let c_option = RealmOptions::default(); + + unsafe { + rooted!(in(context) let global = JS_NewGlobalObject( + context, + &SIMPLE_GLOBAL_CLASS, + ptr::null_mut(), + h_option, + &*c_option, + )); + let _ac = JSAutoRealm::new(context, global.get()); + + // Number.MAX_SAFE_INTEGER + 10 + let int = 9007199254741001; + let mut string = int.to_string(); + let range = string.as_bytes_mut().as_mut_ptr_range(); + let chars = Range::new(range.start, range.end); + rooted!(in(context) let bigint = StringToBigInt(context, chars)); + assert!(!bigint.get().is_null()); + + let mut result = 0; + assert!(BigIntIsUint64(bigint.get(), &mut result)); + assert_eq!(result, int); + + let mut chars: Vec<_> = string.encode_utf16().collect(); + let range = chars.as_mut_ptr_range(); + let chars = Range::new(range.start, range.end); + rooted!(in(context) let bigint = StringToBigInt1(context, chars)); + assert!(!bigint.get().is_null()); + + let mut result = 0; + assert!(BigIntIsUint64(bigint.get(), &mut result)); + assert_eq!(result, int); + } +} From 1ae106f4f2c09ade21f6f4fab3713a3745bbce94 Mon Sep 17 00:00:00 2001 From: Redfire Date: Fri, 8 Dec 2023 18:03:39 +0800 Subject: [PATCH 3/7] Added Glue for mozilla::Range Parameters --- mozjs-sys/build.rs | 3 +++ mozjs/build.rs | 1 + mozjs/src/jsglue.cpp | 27 ++++++++++++++++++++++++++- mozjs/tests/range.rs | 7 ++++--- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/mozjs-sys/build.rs b/mozjs-sys/build.rs index b8f2959cd73..272386a19d5 100644 --- a/mozjs-sys/build.rs +++ b/mozjs-sys/build.rs @@ -457,8 +457,11 @@ const BLACKLIST_FUNCTIONS: &'static [&'static str] = &[ "JS::GetScriptPrivate", "JS::GetScriptTranscodingBuildId", "JS::GetScriptedCallerPrivate", + "JS::LossyTwoByteCharsToNewLatin1CharsZ", "JS::MaybeGetScriptPrivate", + "JS::StringToBigInt", "JS::dbg::FireOnGarbageCollectionHook", + "JS_CopyStringChars", "JS_EncodeStringToUTF8BufferPartial", "JS_GetEmptyStringValue", "JS_GetErrorType", diff --git a/mozjs/build.rs b/mozjs/build.rs index ccf2cbd4373..3969b430274 100644 --- a/mozjs/build.rs +++ b/mozjs/build.rs @@ -120,6 +120,7 @@ fn main() { const BLACKLIST_TYPES: &'static [&'static str] = &[ "JS::.*", "already_AddRefed", + "mozilla::Range", // we don't want it null "EncodedStringCallback", ]; diff --git a/mozjs/src/jsglue.cpp b/mozjs/src/jsglue.cpp index 2d23b0a34a1..2661f46ca5e 100644 --- a/mozjs/src/jsglue.cpp +++ b/mozjs/src/jsglue.cpp @@ -15,11 +15,12 @@ #endif #include "assert.h" +#include "js/BigInt.h" // JS::StringToBigInt #include "js/BuildId.h" #include "js/Class.h" #include "js/Id.h" #include "js/MemoryMetrics.h" -#include "js/Modules.h" // include for JS::GetModulePrivate +#include "js/Modules.h" // JS::GetModulePrivate #include "js/Principals.h" #include "js/Promise.h" #include "js/Proxy.h" @@ -555,6 +556,12 @@ bool ShouldMeasureObject(JSObject* obj, nsISupports** iface) { return false; } +typedef mozilla::Range RangeLatin1; + +typedef mozilla::Range RangeConstUtf16; + +typedef mozilla::Range RangeUtf16; + extern "C" { JSPrincipals* CreateRustJSPrincipals(const JSPrincipalsCallbacks& callbacks, @@ -1121,4 +1128,22 @@ void FinishOffThreadStencil( *stencil = std::move(retval); } +JS::BigInt* JS_StringToBigInt(JSContext* cx, mozilla::Range chars) { + return JS::StringToBigInt(cx, chars); +} + +JS::BigInt* JS_StringToBigInt1(JSContext* cx, mozilla::Range chars) { + return JS::StringToBigInt(cx, chars); +} + +bool CopyStringChars(JSContext* cx, mozilla::Range dest, + JSString* str) { + return JS_CopyStringChars(cx, dest, str); +} + +JS::Latin1CharsZ LossyTwoByteCharsToNewLatin1CharsZ( + JSContext* cx, const mozilla::Range tbchars) { + return JS::LossyTwoByteCharsToNewLatin1CharsZ(cx, tbchars); +} + } // extern "C" diff --git a/mozjs/tests/range.rs b/mozjs/tests/range.rs index 2e6e6d006ca..81d618fefd1 100644 --- a/mozjs/tests/range.rs +++ b/mozjs/tests/range.rs @@ -1,8 +1,9 @@ use std::ptr; use mozjs::jsapi::mozilla::Range; -use mozjs::jsapi::{BigIntIsUint64, JS_NewGlobalObject, StringToBigInt, StringToBigInt1}; +use mozjs::jsapi::{BigIntIsUint64, JS_NewGlobalObject}; use mozjs::jsapi::{JSAutoRealm, OnNewGlobalHookOption}; +use mozjs::glue::{JS_StringToBigInt, JS_StringToBigInt1}; use mozjs::rooted; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; @@ -29,7 +30,7 @@ fn range() { let mut string = int.to_string(); let range = string.as_bytes_mut().as_mut_ptr_range(); let chars = Range::new(range.start, range.end); - rooted!(in(context) let bigint = StringToBigInt(context, chars)); + rooted!(in(context) let bigint = JS_StringToBigInt(context, chars)); assert!(!bigint.get().is_null()); let mut result = 0; @@ -39,7 +40,7 @@ fn range() { let mut chars: Vec<_> = string.encode_utf16().collect(); let range = chars.as_mut_ptr_range(); let chars = Range::new(range.start, range.end); - rooted!(in(context) let bigint = StringToBigInt1(context, chars)); + rooted!(in(context) let bigint = JS_StringToBigInt1(context, chars)); assert!(!bigint.get().is_null()); let mut result = 0; From 557eed8fefd28b0ac7b0250e8b1e33d39513235d Mon Sep 17 00:00:00 2001 From: Redfire Date: Fri, 8 Dec 2023 18:34:47 +0800 Subject: [PATCH 4/7] Switched Glue Functions to Take In Pointers --- mozjs/src/jsglue.cpp | 16 ++++++++-------- mozjs/tests/range.rs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mozjs/src/jsglue.cpp b/mozjs/src/jsglue.cpp index 2661f46ca5e..2bf90800ec6 100644 --- a/mozjs/src/jsglue.cpp +++ b/mozjs/src/jsglue.cpp @@ -1128,22 +1128,22 @@ void FinishOffThreadStencil( *stencil = std::move(retval); } -JS::BigInt* JS_StringToBigInt(JSContext* cx, mozilla::Range chars) { - return JS::StringToBigInt(cx, chars); +JS::BigInt* JS_StringToBigInt(JSContext* cx, const mozilla::Range* chars) { + return JS::StringToBigInt(cx, *chars); } -JS::BigInt* JS_StringToBigInt1(JSContext* cx, mozilla::Range chars) { - return JS::StringToBigInt(cx, chars); +JS::BigInt* JS_StringToBigInt1(JSContext* cx, const mozilla::Range* chars) { + return JS::StringToBigInt(cx, *chars); } -bool CopyStringChars(JSContext* cx, mozilla::Range dest, +bool CopyStringChars(JSContext* cx, const mozilla::Range* dest, JSString* str) { - return JS_CopyStringChars(cx, dest, str); + return JS_CopyStringChars(cx, *dest, str); } JS::Latin1CharsZ LossyTwoByteCharsToNewLatin1CharsZ( - JSContext* cx, const mozilla::Range tbchars) { - return JS::LossyTwoByteCharsToNewLatin1CharsZ(cx, tbchars); + JSContext* cx, const mozilla::Range* tbchars) { + return JS::LossyTwoByteCharsToNewLatin1CharsZ(cx, *tbchars); } } // extern "C" diff --git a/mozjs/tests/range.rs b/mozjs/tests/range.rs index 81d618fefd1..bf7ede84f66 100644 --- a/mozjs/tests/range.rs +++ b/mozjs/tests/range.rs @@ -30,7 +30,7 @@ fn range() { let mut string = int.to_string(); let range = string.as_bytes_mut().as_mut_ptr_range(); let chars = Range::new(range.start, range.end); - rooted!(in(context) let bigint = JS_StringToBigInt(context, chars)); + rooted!(in(context) let bigint = JS_StringToBigInt(context, &chars)); assert!(!bigint.get().is_null()); let mut result = 0; @@ -40,7 +40,7 @@ fn range() { let mut chars: Vec<_> = string.encode_utf16().collect(); let range = chars.as_mut_ptr_range(); let chars = Range::new(range.start, range.end); - rooted!(in(context) let bigint = JS_StringToBigInt1(context, chars)); + rooted!(in(context) let bigint = JS_StringToBigInt1(context, &chars)); assert!(!bigint.get().is_null()); let mut result = 0; From 47ca02ce487ab0e6c85d7cf0c92fdf3746da7c3d Mon Sep 17 00:00:00 2001 From: Redfire Date: Fri, 8 Dec 2023 18:53:57 +0800 Subject: [PATCH 5/7] Reformatted Code --- mozjs-sys/build.rs | 7 ++----- mozjs/tests/range.rs | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/mozjs-sys/build.rs b/mozjs-sys/build.rs index 272386a19d5..65f93925cd2 100644 --- a/mozjs-sys/build.rs +++ b/mozjs-sys/build.rs @@ -28,11 +28,8 @@ const ENV_VARS: &'static [&'static str] = &[ "STLPORT_LIBS", ]; -const EXTRA_FILES: &'static [&'static str] = &[ - "makefile.cargo", - "src/jsglue.hpp", - "src/jsglue.cpp", -]; +const EXTRA_FILES: &'static [&'static str] = + &["makefile.cargo", "src/jsglue.hpp", "src/jsglue.cpp"]; /// Which version of moztools we expect #[cfg(windows)] diff --git a/mozjs/tests/range.rs b/mozjs/tests/range.rs index bf7ede84f66..a6407e545e9 100644 --- a/mozjs/tests/range.rs +++ b/mozjs/tests/range.rs @@ -1,9 +1,9 @@ use std::ptr; +use mozjs::glue::{JS_StringToBigInt, JS_StringToBigInt1}; use mozjs::jsapi::mozilla::Range; use mozjs::jsapi::{BigIntIsUint64, JS_NewGlobalObject}; use mozjs::jsapi::{JSAutoRealm, OnNewGlobalHookOption}; -use mozjs::glue::{JS_StringToBigInt, JS_StringToBigInt1}; use mozjs::rooted; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; From ea24396c6ba65336d4ac5db191ff3ac13a0a1e5b Mon Sep 17 00:00:00 2001 From: Redfire Date: Fri, 8 Dec 2023 21:17:32 +0800 Subject: [PATCH 6/7] Removed Unnecessary Typedefs --- mozjs/src/jsglue.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mozjs/src/jsglue.cpp b/mozjs/src/jsglue.cpp index 2bf90800ec6..1d2d1853482 100644 --- a/mozjs/src/jsglue.cpp +++ b/mozjs/src/jsglue.cpp @@ -556,12 +556,6 @@ bool ShouldMeasureObject(JSObject* obj, nsISupports** iface) { return false; } -typedef mozilla::Range RangeLatin1; - -typedef mozilla::Range RangeConstUtf16; - -typedef mozilla::Range RangeUtf16; - extern "C" { JSPrincipals* CreateRustJSPrincipals(const JSPrincipalsCallbacks& callbacks, From 8bc8cb4b67f7f5a33a73a1e0f6f3a8157c077d03 Mon Sep 17 00:00:00 2001 From: Redfire Date: Fri, 8 Dec 2023 21:19:37 +0800 Subject: [PATCH 7/7] Formatted C++ Code --- mozjs-sys/src/jsglue.hpp | 39 +++++++++++++---- mozjs/src/jsglue.cpp | 92 ++++++++++++++++++++-------------------- 2 files changed, 77 insertions(+), 54 deletions(-) diff --git a/mozjs-sys/src/jsglue.hpp b/mozjs-sys/src/jsglue.hpp index ba3b882621e..b2abb6b23f2 100644 --- a/mozjs-sys/src/jsglue.hpp +++ b/mozjs-sys/src/jsglue.hpp @@ -48,7 +48,6 @@ #include "jsapi.h" #include "jsfriendapi.h" - namespace glue { // Reexport some functions that are marked inline. @@ -108,14 +107,36 @@ bool JS_ValueIsUndefined(const JS::Value* value); // These types are using maybe so we manually unwrap them in these wrappers -bool FromPropertyDescriptor(JSContext *cx, JS::Handle desc, JS::MutableHandle vp); -bool JS_GetOwnPropertyDescriptorById(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc, bool* isNone); -bool JS_GetOwnPropertyDescriptor(JSContext* cx, JS::HandleObject obj, const char* name, JS::MutableHandle desc, bool* isNone); -bool JS_GetOwnUCPropertyDescriptor(JSContext* cx, JS::HandleObject obj, const char16_t* name, size_t namelen, JS::MutableHandle desc, bool* isNone); -bool JS_GetPropertyDescriptorById(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle desc, JS::MutableHandleObject holder, bool* isNone); -bool JS_GetPropertyDescriptor(JSContext* cx, JS::HandleObject obj, const char* name, JS::MutableHandle desc, JS::MutableHandleObject holder, bool* isNone); -bool JS_GetUCPropertyDescriptor(JSContext* cx, JS::HandleObject obj, const char16_t* name, size_t namelen, JS::MutableHandle desc, JS::MutableHandleObject holder, bool* isNone); -bool SetPropertyIgnoringNamedGetter(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v, JS::HandleValue receiver, JS::Handle ownDesc, JS::ObjectOpResult& result); +bool FromPropertyDescriptor(JSContext* cx, + JS::Handle desc, + JS::MutableHandle vp); +bool JS_GetOwnPropertyDescriptorById( + JSContext* cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandle desc, bool* isNone); +bool JS_GetOwnPropertyDescriptor(JSContext* cx, JS::HandleObject obj, + const char* name, + JS::MutableHandle desc, + bool* isNone); +bool JS_GetOwnUCPropertyDescriptor( + JSContext* cx, JS::HandleObject obj, const char16_t* name, size_t namelen, + JS::MutableHandle desc, bool* isNone); +bool JS_GetPropertyDescriptorById( + JSContext* cx, JS::HandleObject obj, JS::HandleId id, + JS::MutableHandle desc, + JS::MutableHandleObject holder, bool* isNone); +bool JS_GetPropertyDescriptor(JSContext* cx, JS::HandleObject obj, + const char* name, + JS::MutableHandle desc, + JS::MutableHandleObject holder, bool* isNone); +bool JS_GetUCPropertyDescriptor(JSContext* cx, JS::HandleObject obj, + const char16_t* name, size_t namelen, + JS::MutableHandle desc, + JS::MutableHandleObject holder, bool* isNone); +bool SetPropertyIgnoringNamedGetter(JSContext* cx, JS::HandleObject obj, + JS::HandleId id, JS::HandleValue v, + JS::HandleValue receiver, + JS::Handle ownDesc, + JS::ObjectOpResult& result); bool CreateError(JSContext* cx, JSExnType type, JS::HandleObject stack, JS::HandleString fileName, uint32_t lineNumber, diff --git a/mozjs/src/jsglue.cpp b/mozjs/src/jsglue.cpp index 1d2d1853482..39bdeec4ca2 100644 --- a/mozjs/src/jsglue.cpp +++ b/mozjs/src/jsglue.cpp @@ -15,7 +15,7 @@ #endif #include "assert.h" -#include "js/BigInt.h" // JS::StringToBigInt +#include "js/BigInt.h" // JS::StringToBigInt #include "js/BuildId.h" #include "js/Class.h" #include "js/Id.h" @@ -29,8 +29,8 @@ #include "js/Stream.h" #include "js/StructuredClone.h" #include "js/Wrapper.h" -#include "js/experimental/JitInfo.h" #include "js/experimental/JSStencil.h" +#include "js/experimental/JitInfo.h" #include "js/experimental/TypedData.h" #include "js/friend/ErrorMessages.h" #include "jsapi.h" @@ -85,11 +85,12 @@ class RustJobQueue : public JS::JobQueue { }; struct ReadableStreamUnderlyingSourceTraps { - void (*requestData)(const void* source, JSContext* cx, JS::HandleObject stream, - size_t desiredSize); + void (*requestData)(const void* source, JSContext* cx, + JS::HandleObject stream, size_t desiredSize); void (*writeIntoReadRequestBuffer)(const void* source, JSContext* cx, - JS::HandleObject stream, JS::HandleObject chunk, - size_t length, size_t* bytesWritten); + JS::HandleObject stream, + JS::HandleObject chunk, size_t length, + size_t* bytesWritten); void (*cancel)(const void* source, JSContext* cx, JS::HandleObject stream, JS::HandleValue reason, JS::Value* resolve_to); void (*onClosed)(const void* source, JSContext* cx, JS::HandleObject stream); @@ -114,10 +115,11 @@ class RustReadableStreamUnderlyingSource } virtual void writeIntoReadRequestBuffer(JSContext* cx, - JS::HandleObject stream, JS::HandleObject chunk, - size_t length, size_t* bytesWritten) { - return mTraps.writeIntoReadRequestBuffer(mSource, cx, stream, chunk, - length, bytesWritten); + JS::HandleObject stream, + JS::HandleObject chunk, size_t length, + size_t* bytesWritten) { + return mTraps.writeIntoReadRequestBuffer(mSource, cx, stream, chunk, length, + bytesWritten); } virtual JS::Value cancel(JSContext* cx, JS::HandleObject stream, @@ -170,7 +172,7 @@ struct ProxyTraps { bool (*getOwnPropertyDescriptor)( JSContext* cx, JS::HandleObject proxy, JS::HandleId id, - JS::MutableHandle desc, bool *isNone); + JS::MutableHandle desc, bool* isNone); bool (*defineProperty)(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, JS::Handle desc, JS::ObjectOpResult& result); @@ -226,7 +228,7 @@ struct ProxyTraps { bool (*defaultValue)(JSContext* cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue vp); void (*trace)(JSTracer* trc, JSObject* proxy); - void (*finalize)(JS::GCContext *cx, JSObject* proxy); + void (*finalize)(JS::GCContext* cx, JSObject* proxy); size_t (*objectMoved)(JSObject* proxy, JSObject* old); bool (*isCallable)(JSObject* obj); @@ -325,7 +327,8 @@ static int HandlerFamily; mTraps.trace ? mTraps.trace(trc, proxy) : _base::trace(trc, proxy); \ } \ \ - virtual void finalize(JS::GCContext* context, JSObject* proxy) const override { \ + virtual void finalize(JS::GCContext* context, JSObject* proxy) \ + const override { \ mTraps.finalize ? mTraps.finalize(context, proxy) \ : _base::finalize(context, proxy); \ } \ @@ -381,11 +384,13 @@ class WrapperProxyHandler : public js::Wrapper { virtual bool getOwnPropertyDescriptor( JSContext* cx, JS::HandleObject proxy, JS::HandleId id, - JS::MutableHandle> desc) const override { + JS::MutableHandle> desc) + const override { if (mTraps.getOwnPropertyDescriptor) { JS::Rooted pd(cx); bool isNone = true; - bool result = mTraps.getOwnPropertyDescriptor(cx, proxy, id, &pd, &isNone); + bool result = + mTraps.getOwnPropertyDescriptor(cx, proxy, id, &pd, &isNone); if (isNone) { desc.set(mozilla::Nothing()); } else { @@ -451,7 +456,8 @@ class ForwardingProxyHandler : public js::BaseProxyHandler { virtual bool getOwnPropertyDescriptor( JSContext* cx, JS::HandleObject proxy, JS::HandleId id, - JS::MutableHandle> desc) const override { + JS::MutableHandle> desc) + const override { JS::Rooted pd(cx); bool isNone = true; bool result = mTraps.getOwnPropertyDescriptor(cx, proxy, id, &pd, &isNone); @@ -575,10 +581,10 @@ void* GetRustJSPrincipalsPrivate(JSPrincipals* principals) { bool InvokeGetOwnPropertyDescriptor( const void* handler, JSContext* cx, JS::HandleObject proxy, JS::HandleId id, - JS::MutableHandle desc, bool *isNone) { + JS::MutableHandle desc, bool* isNone) { JS::Rooted> mpd(cx); bool result = static_cast(handler) - ->getOwnPropertyDescriptor(cx, proxy, id, &mpd); + ->getOwnPropertyDescriptor(cx, proxy, id, &mpd); *isNone = mpd.isNothing(); if (!*isNone) { desc.set(*mpd); @@ -781,7 +787,8 @@ JSObject* UnwrapObjectStatic(JSObject* obj) { return js::CheckedUnwrapStatic(obj); } -JSObject* UnwrapObjectDynamic(JSObject* obj, JSContext* cx, bool stopAtWindowProxy) { +JSObject* UnwrapObjectDynamic(JSObject* obj, JSContext* cx, + bool stopAtWindowProxy) { return js::CheckedUnwrapDynamic(obj, cx, stopAtWindowProxy); } @@ -981,7 +988,7 @@ bool WriteBytesToJSStructuredCloneData(const uint8_t* src, size_t len, // MSVC uses a different calling convention for functions // that return non-POD values. Unfortunately, this includes anything -// with a constructor, such as JS::Value and JS::RegExpFlags, so we +// with a constructor, such as JS::Value and JS::RegExpFlags, so we // can't call these from Rust. These wrapper functions are only here // to ensure the calling convention is right. // https://web.archive.org/web/20180929193700/https://mozilla.logbot.info/jsapi/20180622#c14918658 @@ -1021,7 +1028,8 @@ void JS_GetReservedSlot(JSObject* obj, uint32_t index, JS::Value* dest) { *dest = JS::GetReservedSlot(obj, index); } -void JS_GetRegExpFlags(JSContext* cx, JS::HandleObject obj, JS::RegExpFlags* flags) { +void JS_GetRegExpFlags(JSContext* cx, JS::HandleObject obj, + JS::RegExpFlags* flags) { *flags = JS::GetRegExpFlags(cx, obj); } @@ -1095,49 +1103,43 @@ bool DescribeScriptedCaller(JSContext* cx, char* buffer, size_t buflen, return true; } -void SetDataPropertyDescriptor( - JS::MutableHandle desc, - JS::HandleValue value, - uint32_t attrs -) { +void SetDataPropertyDescriptor(JS::MutableHandle desc, + JS::HandleValue value, uint32_t attrs) { desc.set(JS::PropertyDescriptor::Data(value, attrs)); } void SetAccessorPropertyDescriptor( - JS::MutableHandle desc, - JS::HandleObject getter, - JS::HandleObject setter, - uint32_t attrs -) { + JS::MutableHandle desc, JS::HandleObject getter, + JS::HandleObject setter, uint32_t attrs) { desc.set(JS::PropertyDescriptor::Accessor(getter, setter, attrs)); } -void FinishOffThreadStencil( - JSContext* cx, - JS::OffThreadToken* token, - JS::InstantiationStorage* storage, - already_AddRefed* stencil -) { - already_AddRefed retval = JS::FinishOffThreadStencil(cx, token, storage); +void FinishOffThreadStencil(JSContext* cx, JS::OffThreadToken* token, + JS::InstantiationStorage* storage, + already_AddRefed* stencil) { + already_AddRefed retval = + JS::FinishOffThreadStencil(cx, token, storage); *stencil = std::move(retval); } -JS::BigInt* JS_StringToBigInt(JSContext* cx, const mozilla::Range* chars) { - return JS::StringToBigInt(cx, *chars); +JS::BigInt* JS_StringToBigInt( + JSContext* cx, const mozilla::Range* chars) { + return JS::StringToBigInt(cx, *chars); } -JS::BigInt* JS_StringToBigInt1(JSContext* cx, const mozilla::Range* chars) { - return JS::StringToBigInt(cx, *chars); +JS::BigInt* JS_StringToBigInt1(JSContext* cx, + const mozilla::Range* chars) { + return JS::StringToBigInt(cx, *chars); } bool CopyStringChars(JSContext* cx, const mozilla::Range* dest, - JSString* str) { - return JS_CopyStringChars(cx, *dest, str); + JSString* str) { + return JS_CopyStringChars(cx, *dest, str); } JS::Latin1CharsZ LossyTwoByteCharsToNewLatin1CharsZ( JSContext* cx, const mozilla::Range* tbchars) { - return JS::LossyTwoByteCharsToNewLatin1CharsZ(cx, *tbchars); + return JS::LossyTwoByteCharsToNewLatin1CharsZ(cx, *tbchars); } } // extern "C"