Skip to content

Commit 01d777e

Browse files
authored
Cleaned Up Glue and Allowlists (#438)
* Cleaned Up Glue and Allowlists * Removed Unused Glue Functions * Added Glue Functions to Blocklist * Added More Glue Functions for Value Returns * Regenerated Wrappers
1 parent 655655e commit 01d777e

File tree

8 files changed

+53
-45
lines changed

8 files changed

+53
-45
lines changed

mozjs-sys/build.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,26 +417,24 @@ const WHITELIST_TYPES: &'static [&'static str] = &["JS.*", "js::.*", "mozilla::.
417417

418418
/// Global variables we want to generate bindings to.
419419
const WHITELIST_VARS: &'static [&'static str] = &[
420+
"JS::FalseHandleValue",
420421
"JS::NullHandleValue",
421422
"JS::TrueHandleValue",
422423
"JS::UndefinedHandleValue",
423424
"JSCLASS_.*",
424425
"JSFUN_.*",
425426
"JSITER_.*",
426427
"JSPROP_.*",
427-
"JSREG_.*",
428428
"JS_.*",
429429
"js::Proxy.*",
430430
];
431431

432432
/// Functions we want to generate bindings to.
433433
const WHITELIST_FUNCTIONS: &'static [&'static str] = &[
434-
"ExceptionStackOrNull",
435434
"glue::.*",
436435
"JS::.*",
437436
"js::.*",
438437
"JS_.*",
439-
".*_TO_JSID",
440438
"JS_DeprecatedStringHasLatin1Chars",
441439
];
442440

@@ -446,29 +444,38 @@ const BLACKLIST_FUNCTIONS: &'static [&'static str] = &[
446444
"JS::CreateError",
447445
"JS::DecodeMultiStencilsOffThread",
448446
"JS::DecodeStencilOffThread",
447+
"JS::DescribeScriptedCaller",
449448
"JS::EncodeStencil",
450449
"JS::FinishDecodeMultiStencilsOffThread",
451450
"JS::FinishIncrementalEncoding",
451+
"JS::FinishOffThreadStencil",
452452
"JS::FromPropertyDescriptor",
453453
"JS::GetExceptionCause",
454+
"JS::GetModulePrivate",
454455
"JS::GetOptimizedEncodingBuildId",
456+
"JS::GetPromiseResult",
457+
"JS::GetRegExpFlags",
458+
"JS::GetScriptPrivate",
455459
"JS::GetScriptTranscodingBuildId",
460+
"JS::GetScriptedCallerPrivate",
461+
"JS::MaybeGetScriptPrivate",
456462
"JS::dbg::FireOnGarbageCollectionHook",
457463
"JS_EncodeStringToUTF8BufferPartial",
464+
"JS_GetEmptyStringValue",
458465
"JS_GetErrorType",
459466
"JS_GetOwnPropertyDescriptorById",
460467
"JS_GetOwnPropertyDescriptor",
461468
"JS_GetOwnUCPropertyDescriptor",
462469
"JS_GetPropertyDescriptorById",
463470
"JS_GetPropertyDescriptor",
471+
"JS_GetReservedSlot",
464472
"JS_GetUCPropertyDescriptor",
465473
"JS_NewLatin1String",
466474
"JS_NewUCStringDontDeflate",
467475
"JS_NewUCString",
468476
"JS_PCToLineNumber",
469477
"js::AppendUnique",
470478
"js::SetPropertyIgnoringNamedGetter",
471-
"JS::FinishOffThreadStencil",
472479
"std::.*",
473480
];
474481

@@ -479,10 +486,9 @@ const BLACKLIST_FUNCTIONS: &'static [&'static str] = &[
479486
/// features that don't have an equivalent in rust, such as partial template
480487
/// specialization.
481488
const OPAQUE_TYPES: &'static [&'static str] = &[
482-
"JS::Auto.*Impl",
483489
"JS::StackGCVector.*",
484490
"JS::PersistentRooted.*",
485-
"JS::detail::CallArgsBase.*",
491+
"JS::detail::CallArgsBase",
486492
"js::detail::UniqueSelector.*",
487493
"mozilla::BufferList",
488494
"mozilla::Maybe.*",
@@ -510,7 +516,7 @@ const BLACKLIST_TYPES: &'static [&'static str] = &[
510516
"JS::MutableHandleVector",
511517
"JS::Rooted.*Vector",
512518
"JS::RootedValueArray",
513-
// Classes we don't use and we cannot generate theri
519+
// Classes we don't use and we cannot generate their
514520
// types properly from bindgen so we'll skip them for now.
515521
"JS::dbg::Builder",
516522
"JS::dbg::Builder_BuiltThing",

mozjs-sys/src/jsglue.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ JS::shadow::Zone* JS_AsShadowZone(JS::Zone* zone) {
3030
return JS::shadow::Zone::from(zone);
3131
}
3232

33+
// Currently Unused, see jsimpls.rs (JS::CallArgs::from_vp)
3334
JS::CallArgs JS_CallArgsFromVp(unsigned argc, JS::Value* vp) {
3435
return JS::CallArgsFromVp(argc, vp);
3536
}
@@ -56,6 +57,18 @@ void JS_StackCapture_FirstSubsumedFrame(JSContext* cx,
5657
mozilla::PodAssign(capture, &subsumed);
5758
}
5859

60+
size_t GetLinearStringLength(JSLinearString* s) {
61+
return JS::GetLinearStringLength(s);
62+
}
63+
64+
uint16_t GetLinearStringCharAt(JSLinearString* s, size_t idx) {
65+
return JS::GetLinearStringCharAt(s, idx);
66+
}
67+
68+
JSLinearString* AtomToLinearString(JSAtom* atom) {
69+
return JS::AtomToLinearString(atom);
70+
}
71+
5972
// Reexport some methods
6073

6174
bool JS_ForOfIteratorInit(
@@ -103,18 +116,6 @@ bool JS_ValueIsUndefined(const JS::Value* value) {
103116
return value->isUndefined();
104117
}
105118

106-
size_t GetLinearStringLength(JSLinearString* s) {
107-
return JS::GetLinearStringLength(s);
108-
}
109-
110-
uint16_t GetLinearStringCharAt(JSLinearString* s, size_t idx) {
111-
return JS::GetLinearStringCharAt(s, idx);
112-
}
113-
114-
JSLinearString* AtomToLinearString(JSAtom* atom) {
115-
return JS::AtomToLinearString(atom);
116-
}
117-
118119
// These types are using maybe so we manually unwrap them in these wrappers
119120

120121
bool FromPropertyDescriptor(JSContext* cx,
@@ -236,11 +237,12 @@ JSExnType GetErrorType(const JS::Value& val) {
236237
return *type;
237238
}
238239

239-
JS::Value GetExceptionCause(JSObject* exc) {
240+
void GetExceptionCause(JSObject* exc, JS::MutableHandleValue dest) {
240241
auto cause = JS::GetExceptionCause(exc);
241242
if (cause.isNothing()) {
242-
return JS::NullValue();
243+
dest.setNull();
244+
} else {
245+
dest.set(*cause);
243246
}
244-
return *cause;
245247
}
246248
} // namespace glue

mozjs-sys/src/jsglue.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ void JS_StackCapture_FirstSubsumedFrame(JSContext* cx,
7070
bool ignoreSelfHostedFrames,
7171
JS::StackCapture*);
7272

73+
size_t GetLinearStringLength(JSLinearString* s);
74+
uint16_t GetLinearStringCharAt(JSLinearString* s, size_t idx);
75+
JSLinearString* AtomToLinearString(JSAtom* atom);
76+
7377
// Reexport some methods
7478

7579
bool JS_ForOfIteratorInit(
@@ -102,10 +106,6 @@ bool JS_ValueIsNull(const JS::Value* value);
102106

103107
bool JS_ValueIsUndefined(const JS::Value* value);
104108

105-
size_t GetLinearStringLength(JSLinearString* s);
106-
uint16_t GetLinearStringCharAt(JSLinearString* s, size_t idx);
107-
JSLinearString* AtomToLinearString(JSAtom* atom);
108-
109109
// These types are using maybe so we manually unwrap them in these wrappers
110110

111111
bool FromPropertyDescriptor(JSContext *cx, JS::Handle<JS::PropertyDescriptor> desc, JS::MutableHandle<JS::Value> vp);
@@ -125,7 +125,7 @@ bool CreateError(JSContext* cx, JSExnType type, JS::HandleObject stack,
125125

126126
JSExnType GetErrorType(const JS::Value& val);
127127

128-
JS::Value GetExceptionCause(JSObject* exc);
128+
void GetExceptionCause(JSObject* exc, JS::MutableHandleValue dest);
129129

130130
} // namespace glue
131131

mozjs-sys/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#![allow(unused_extern_crates)]
66

7-
// This extern crates are needed for linking
7+
// These extern crates are needed for linking
88
extern crate encoding_c;
99
extern crate encoding_c_mem;
1010
extern crate libz_sys;
@@ -31,7 +31,7 @@ mod generated {
3131
}*/
3232

3333
/// Configure a panic hook to redirect rust panics to MFBT's MOZ_Crash.
34-
/// See https://searchfox.org/mozilla-esr115/source/mozglue/static/rust/lib.rs#106
34+
/// See <https://searchfox.org/mozilla-esr115/source/mozglue/static/rust/lib.rs#106>
3535
#[no_mangle]
3636
pub extern "C" fn install_rust_hooks() {
3737
//std::panic::set_hook(Box::new(panic_hook));

mozjs/src/conversions.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929
#![deny(missing_docs)]
3030

3131
use crate::error::throw_type_error;
32-
use crate::glue::RUST_JS_NumberValue;
3332
use crate::jsapi::AssertSameCompartment;
3433
use crate::jsapi::JS;
3534
use crate::jsapi::{ForOfIterator, ForOfIterator_NonIterableBehavior};
3635
use crate::jsapi::{Heap, JS_DefineElement, JS_GetLatin1StringCharsAndLength};
3736
use crate::jsapi::{JSContext, JSObject, JSString, RootedObject, RootedValue};
3837
use crate::jsapi::{JS_DeprecatedStringHasLatin1Chars, JS_NewUCStringCopyN, JSPROP_ENUMERATE};
3938
use crate::jsapi::{JS_GetTwoByteStringCharsAndLength, NewArrayObject1};
40-
use crate::jsval::{BooleanValue, Int32Value, NullValue, UInt32Value, UndefinedValue};
39+
use crate::jsval::{BooleanValue, DoubleValue, Int32Value, NullValue, UInt32Value, UndefinedValue};
4140
use crate::jsval::{JSVal, ObjectOrNullValue, ObjectValue, StringValue, SymbolValue};
4241
use crate::rooted;
4342
use crate::rust::maybe_wrap_value;
@@ -391,7 +390,7 @@ impl FromJSValConvertible for u32 {
391390
impl ToJSValConvertible for i64 {
392391
#[inline]
393392
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
394-
RUST_JS_NumberValue(*self as f64, &mut *rval);
393+
rval.set(DoubleValue(*self as f64));
395394
}
396395
}
397396

@@ -411,7 +410,7 @@ impl FromJSValConvertible for i64 {
411410
impl ToJSValConvertible for u64 {
412411
#[inline]
413412
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
414-
RUST_JS_NumberValue(*self as f64, &mut *rval);
413+
rval.set(DoubleValue(*self as f64));
415414
}
416415
}
417416

@@ -431,7 +430,7 @@ impl FromJSValConvertible for u64 {
431430
impl ToJSValConvertible for f32 {
432431
#[inline]
433432
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
434-
RUST_JS_NumberValue(*self as f64, &mut *rval);
433+
rval.set(DoubleValue(*self as f64));
435434
}
436435
}
437436

@@ -452,7 +451,7 @@ impl FromJSValConvertible for f32 {
452451
impl ToJSValConvertible for f64 {
453452
#[inline]
454453
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
455-
RUST_JS_NumberValue(*self, &mut *rval);
454+
rval.set(DoubleValue(*self))
456455
}
457456
}
458457

mozjs/src/glue_wrappers.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ wrap!(glue: pub fn RUST_INTERNED_STRING_TO_JSID(cx: *mut JSContext, str_: *mut J
1717
wrap!(glue: pub fn AppendToIdVector(v: MutableHandleIdVector, id: HandleId) -> bool);
1818
wrap!(glue: pub fn JS_GetPromiseResult(promise: HandleObject, dest: MutableHandleValue));
1919
wrap!(glue: pub fn JS_GetScriptPrivate(script: *mut JSScript, dest: MutableHandleValue));
20+
wrap!(glue: pub fn JS_MaybeGetScriptPrivate(obj: *mut JSObject, dest: MutableHandleValue));
2021
wrap!(glue: pub fn JS_GetModulePrivate(module: *mut JSObject, dest: MutableHandleValue));
22+
wrap!(glue: pub fn JS_GetScriptedCallerPrivate(cx: *mut JSContext, dest: MutableHandleValue));
2123
wrap!(glue: pub fn JS_GetRegExpFlags(cx: *mut JSContext, obj: HandleObject, flags: *mut RegExpFlags));
2224
wrap!(glue: pub fn EncodeStringToUTF8(cx: *mut JSContext, str_: HandleString, cb: EncodedStringCallback));
2325
wrap!(glue: pub fn SetDataPropertyDescriptor(desc: MutableHandle<PropertyDescriptor>, value: HandleValue, attrs: u32));

mozjs/src/jsapi_wrappers.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ wrap!(jsapi: pub fn NewPromiseObject(cx: *mut JSContext, executor: HandleObject)
8181
wrap!(jsapi: pub fn IsPromiseObject(obj: HandleObject) -> bool);
8282
wrap!(jsapi: pub fn GetPromiseState(promise: HandleObject) -> PromiseState);
8383
wrap!(jsapi: pub fn GetPromiseID(promise: HandleObject) -> u64);
84-
wrap!(jsapi: pub fn GetPromiseResult(promise: HandleObject) -> Value);
8584
wrap!(jsapi: pub fn GetPromiseIsHandled(promise: HandleObject) -> bool);
8685
wrap!(jsapi: pub fn SetSettledPromiseIsHandled(cx: *mut JSContext, promise: HandleObject) -> bool);
8786
wrap!(jsapi: pub fn SetAnyPromiseIsHandled(cx: *mut JSContext, promise: HandleObject) -> bool);
@@ -114,7 +113,6 @@ wrap!(jsapi: pub fn ClearRegExpStatics(cx: *mut JSContext, obj: HandleObject) ->
114113
wrap!(jsapi: pub fn ExecuteRegExp(cx: *mut JSContext, obj: HandleObject, reobj: HandleObject, chars: *const u16, length: usize, indexp: *mut usize, test: bool, rval: MutableHandle<Value>) -> bool);
115114
wrap!(jsapi: pub fn ExecuteRegExpNoStatics(cx: *mut JSContext, reobj: HandleObject, chars: *const u16, length: usize, indexp: *mut usize, test: bool, rval: MutableHandle<Value>) -> bool);
116115
wrap!(jsapi: pub fn ObjectIsRegExp(cx: *mut JSContext, obj: HandleObject, isRegExp: *mut bool) -> bool);
117-
wrap!(jsapi: pub fn GetRegExpFlags(cx: *mut JSContext, obj: HandleObject) -> RegExpFlags);
118116
wrap!(jsapi: pub fn GetRegExpSource(cx: *mut JSContext, obj: HandleObject) -> *mut JSString);
119117
wrap!(jsapi: pub fn CheckRegExpSyntax(cx: *mut JSContext, chars: *const u16, length: usize, flags: RegExpFlags, error: MutableHandle<Value>) -> bool);
120118
wrap!(jsapi: pub fn GetSavedFrameSource(cx: *mut JSContext, principals: *mut JSPrincipals, savedFrame: HandleObject, sourcep: MutableHandle<*mut JSString>, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult);
@@ -374,3 +372,4 @@ wrap!(jsapi: pub fn JS_GetPropertyDescriptor(cx: *mut JSContext, obj: HandleObje
374372
wrap!(jsapi: pub fn JS_GetUCPropertyDescriptor(cx: *mut JSContext, obj: HandleObject, name: *const u16, namelen: usize, desc: MutableHandle<PropertyDescriptor>, holder: MutableHandleObject, isNone: *mut bool) -> bool);
375373
wrap!(jsapi: pub fn SetPropertyIgnoringNamedGetter(cx: *mut JSContext, obj: HandleObject, id: HandleId, v: HandleValue, receiver: HandleValue, ownDesc: Handle<PropertyDescriptor>, result: *mut ObjectOpResult) -> bool);
376374
wrap!(jsapi: pub fn CreateError(cx: *mut JSContext, type_: JSExnType, stack: HandleObject, fileName: HandleString, lineNumber: u32, columnNumber: u32, report: *mut JSErrorReport, message: HandleString, cause: HandleValue, rval: MutableHandleValue) -> bool);
375+
wrap!(jsapi: pub fn GetExceptionCause(exc: *mut JSObject, dest: MutableHandleValue));

mozjs/src/jsglue.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -591,18 +591,10 @@ bool InvokeHasOwn(const void* handler, JSContext* cx, JS::HandleObject proxy,
591591
id, bp);
592592
}
593593

594-
void RUST_JS_NumberValue(double d, JS::Value* dest) {
595-
*dest = JS_NumberValue(d);
596-
}
597-
598594
const JSJitInfo* RUST_FUNCTION_VALUE_TO_JITINFO(JS::Value v) {
599595
return FUNCTION_VALUE_TO_JITINFO(v);
600596
}
601597

602-
JS::CallArgs CreateCallArgsFromVp(unsigned argc, JS::Value* vp) {
603-
return JS::CallArgsFromVp(argc, vp);
604-
}
605-
606598
bool CallJitGetterOp(const JSJitInfo* info, JSContext* cx,
607599
JS::HandleObject thisObj, void* specializedThis,
608600
unsigned argc, JS::Value* vp) {
@@ -1002,10 +994,18 @@ void JS_GetScriptPrivate(JSScript* script, JS::MutableHandleValue dest) {
1002994
dest.set(JS::GetScriptPrivate(script));
1003995
}
1004996

997+
void JS_MaybeGetScriptPrivate(JSObject* obj, JS::MutableHandleValue dest) {
998+
dest.set(js::MaybeGetScriptPrivate(obj));
999+
}
1000+
10051001
void JS_GetModulePrivate(JSObject* module, JS::MutableHandleValue dest) {
10061002
dest.set(JS::GetModulePrivate(module));
10071003
}
10081004

1005+
void JS_GetScriptedCallerPrivate(JSContext* cx, JS::MutableHandleValue dest) {
1006+
dest.set(JS::GetScriptedCallerPrivate(cx));
1007+
}
1008+
10091009
void JS_GetNaNValue(JSContext* cx, JS::Value* dest) { *dest = JS::NaNValue(); }
10101010

10111011
void JS_GetPositiveInfinityValue(JSContext* cx, JS::Value* dest) {

0 commit comments

Comments
 (0)