Skip to content

Commit 1381178

Browse files
committed
wrappers2
Signed-off-by: sagudev <[email protected]>
1 parent d8af813 commit 1381178

File tree

4 files changed

+937
-8
lines changed

4 files changed

+937
-8
lines changed

mozjs/src/generate_wrappers.sh

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
gsed=$(type gsed >/dev/null 2>&1 && echo gsed || echo sed)
44
# Detect gfind or find
55
gfind=$(type gfind >/dev/null 2>&1 && echo gfind || echo find)
6-
# This is one big heuristic but seems to work well enough
7-
grep_heur() {
6+
7+
grep_functions() {
88
grep -v "link_name" "$1" | \
99
grep -v '"\]' | \
1010
grep -F -v '/\*\*' | \
@@ -14,8 +14,13 @@ grep_heur() {
1414
grep -v '^\}$' | \
1515
$gsed 's/^ *pub/pub/' | \
1616
$gsed -z 's/\;\n/\n/g' | \
17-
grep 'pub fn' | \
18-
grep Handle | \
17+
grep 'pub fn'
18+
}
19+
20+
# This is one big heuristic but seems to work well enough
21+
grep_heur() {
22+
grep_functions "$1" |
23+
grep -e Handle | \
1924
grep -v roxyHandler | \
2025
grep -v '\bIdVector\b' | # name clash between rust::IdVector and JS::IdVector \
2126
grep -v 'pub fn Unbox' | # this function seems to be platform specific \
@@ -31,16 +36,57 @@ grep_heur() {
3136
grep -v 'MutableHandleObjectVector' # GetDebuggeeGlobals has it
3237
}
3338

34-
# usage find_latest_version_of_file_and_parse $input_file $out_wrapper_module_name
39+
# usage find_latest_version_of_file_and_parse $input_file $out_wrapper_module_name $heur_fn
3540
find_latest_version_of_file_and_parse() {
3641
# clone file and reformat (this is needed for grep_heur to work properly)
3742
# this $(find) only gets last modified file
3843
cp $($gfind target -name "$1" -printf "%T@ %p\n" | sort -n | tail -n 1 | tr ' ' '\n' | tail -n 1) "target/wrap_$1"
3944
rustfmt "target/wrap_$1" --config max_width=1000
4045

4146
# parse reformated file
42-
grep_heur "target/wrap_$1" | $gsed 's/\(.*\)/wrap!('"$2"': \1);/g' > "mozjs/src/$2_wrappers.in.rs"
47+
($3 "target/wrap_$1") | $gsed 's/\(.*\)/wrap!('"$2"': \1);/g' > "mozjs/src/$2$4_wrappers.in.rs"
48+
}
49+
50+
find_latest_version_of_file_and_parse jsapi.rs jsapi grep_heur
51+
find_latest_version_of_file_and_parse gluebindings.rs glue grep_heur
52+
53+
# This is one big heuristic but seems to work well enough
54+
grep_heur2() {
55+
grep_functions "$1" |
56+
grep -e Handle -e JSContext | \
57+
grep -v roxyHandler | \
58+
grep -v '\bIdVector\b' | # name clash between rust::IdVector and JS::IdVector \
59+
grep -v 'pub fn Unbox' | # this function seems to be platform specific \
60+
grep -v 'CopyAsyncStack' | # arch-specific bindgen output
61+
grep -v 'pub fn JS_NewContext' |
62+
grep -v 'pub fn NewMemoryInfo' |
63+
grep -v 'pub fn GetGCContext' |
64+
grep -v 'pub fn SetDebuggerMalloc' |
65+
grep -v 'pub fn GetDebuggerMallocSizeOf' |
66+
grep -v 'pub fn FireOnGarbageCollectionHookRequired' |
67+
grep -v 'pub fn ShouldAvoidSideEffects' |
68+
$gsed 's/root:://g' |
69+
$gsed 's/JS:://g' |
70+
$gsed 's/js:://g' |
71+
$gsed 's/mozilla:://g' |
72+
$gsed 's/\*mut JSContext/\&mut JSContext/g' |
73+
$gsed 's/\*const JSContext/\&JSContext/g' |
74+
grep -F -v '> Handle' | # We are only wrapping handles in args not in results
75+
grep -F -v '...' | # vargs
76+
grep -v 'MutableHandleObjectVector' # GetDebuggeeGlobals has it
77+
}
78+
79+
find_latest_version_of_file_and_parse jsapi.rs jsapi grep_heur2 2
80+
find_latest_version_of_file_and_parse gluebindings.rs glue grep_heur2 2
81+
82+
mark_as_no_gc() {
83+
# Functions with AutoRequireNoGC arg do not trigger GC
84+
sed -i '/\*const AutoRequireNoGC/ s/\&mut JSContext/\&JSContext/' $1
85+
86+
# Functions that also do not trigger GC
87+
for fn in "JS_GetRuntime" "JS_GetParentRuntime"; do
88+
sed -i "/pub fn $fn/ s/\&mut JSContext/\&JSContext/g" $1
89+
done
4390
}
4491

45-
find_latest_version_of_file_and_parse jsapi.rs jsapi
46-
find_latest_version_of_file_and_parse gluebindings.rs glue
92+
mark_as_no_gc mozjs/src/jsapi2_wrappers.in.rs

mozjs/src/glue2_wrappers.in.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
wrap!(glue: pub fn InvokeGetOwnPropertyDescriptor(handler: *const ::std::os::raw::c_void, cx: &mut JSContext, proxy: HandleObject, id: HandleId, desc: MutableHandle<PropertyDescriptor>, isNone: *mut bool) -> bool);
2+
wrap!(glue: pub fn InvokeHasOwn(handler: *const ::std::os::raw::c_void, cx: &mut JSContext, proxy: HandleObject, id: HandleId, bp: *mut bool) -> bool);
3+
wrap!(glue: pub fn CallJitGetterOp(info: *const JSJitInfo, cx: &mut JSContext, thisObj: HandleObject, specializedThis: *mut ::std::os::raw::c_void, argc: ::std::os::raw::c_uint, vp: *mut Value) -> bool);
4+
wrap!(glue: pub fn CallJitSetterOp(info: *const JSJitInfo, cx: &mut JSContext, thisObj: HandleObject, specializedThis: *mut ::std::os::raw::c_void, argc: ::std::os::raw::c_uint, vp: *mut Value) -> bool);
5+
wrap!(glue: pub fn CallJitMethodOp(info: *const JSJitInfo, cx: &mut JSContext, thisObj: HandleObject, specializedThis: *mut ::std::os::raw::c_void, argc: u32, vp: *mut Value) -> bool);
6+
wrap!(glue: pub fn NewCompileOptions(aCx: &mut JSContext, aFile: *const ::std::os::raw::c_char, aLine: ::std::os::raw::c_uint) -> *mut ReadOnlyCompileOptions);
7+
wrap!(glue: pub fn NewProxyObject(aCx: &mut JSContext, aHandler: *const ::std::os::raw::c_void, aPriv: HandleValue, proto: *mut JSObject, aClass: *const JSClass, aLazyProto: bool) -> *mut JSObject);
8+
wrap!(glue: pub fn WrapperNew(aCx: &mut JSContext, aObj: HandleObject, aHandler: *const ::std::os::raw::c_void, aClass: *const JSClass) -> *mut JSObject);
9+
wrap!(glue: pub fn NewWindowProxy(aCx: &mut JSContext, aObj: HandleObject, aHandler: *const ::std::os::raw::c_void) -> *mut JSObject);
10+
wrap!(glue: pub fn RUST_JSID_IS_INT(id: HandleId) -> bool);
11+
wrap!(glue: pub fn int_to_jsid(i: i32, id: MutableHandleId));
12+
wrap!(glue: pub fn RUST_JSID_TO_INT(id: HandleId) -> i32);
13+
wrap!(glue: pub fn RUST_JSID_IS_STRING(id: HandleId) -> bool);
14+
wrap!(glue: pub fn RUST_JSID_TO_STRING(id: HandleId) -> *mut JSString);
15+
wrap!(glue: pub fn RUST_SYMBOL_TO_JSID(sym: *mut Symbol, id: MutableHandleId));
16+
wrap!(glue: pub fn RUST_JSID_IS_VOID(id: HandleId) -> bool);
17+
wrap!(glue: pub fn RUST_INTERNED_STRING_TO_JSID(cx: &mut JSContext, str_: *mut JSString, id: MutableHandleId));
18+
wrap!(glue: pub fn ReportErrorASCII(aCx: &mut JSContext, aError: *const ::std::os::raw::c_char));
19+
wrap!(glue: pub fn ReportErrorUTF8(aCx: &mut JSContext, aError: *const ::std::os::raw::c_char));
20+
wrap!(glue: pub fn UnwrapObjectDynamic(obj: *mut JSObject, cx: &mut JSContext, stopAtWindowProxy: bool) -> *mut JSObject);
21+
wrap!(glue: pub fn CreateRootedIdVector(cx: &mut JSContext) -> *mut PersistentRootedIdVector);
22+
wrap!(glue: pub fn AppendToIdVector(v: MutableHandleIdVector, id: HandleId) -> bool);
23+
wrap!(glue: pub fn CreateRootedObjectVector(aCx: &mut JSContext) -> *mut PersistentRootedObjectVector);
24+
wrap!(glue: pub fn CollectServoSizes(cx: &mut JSContext, sizes: *mut ServoSizes, gs: GetSize) -> bool);
25+
wrap!(glue: pub fn JS_GetPromiseResult(promise: HandleObject, dest: MutableHandleValue));
26+
wrap!(glue: pub fn JS_GetScriptPrivate(script: *mut JSScript, dest: MutableHandleValue));
27+
wrap!(glue: pub fn JS_MaybeGetScriptPrivate(obj: *mut JSObject, dest: MutableHandleValue));
28+
wrap!(glue: pub fn JS_GetModulePrivate(module: *mut JSObject, dest: MutableHandleValue));
29+
wrap!(glue: pub fn JS_GetScriptedCallerPrivate(cx: &mut JSContext, dest: MutableHandleValue));
30+
wrap!(glue: pub fn JS_GetNaNValue(cx: &mut JSContext, dest: *mut Value));
31+
wrap!(glue: pub fn JS_GetPositiveInfinityValue(cx: &mut JSContext, dest: *mut Value));
32+
wrap!(glue: pub fn JS_GetEmptyStringValue(cx: &mut JSContext, dest: *mut Value));
33+
wrap!(glue: pub fn JS_GetRegExpFlags(cx: &mut JSContext, obj: HandleObject, flags: *mut RegExpFlags));
34+
wrap!(glue: pub fn EncodeStringToUTF8(cx: &mut JSContext, str_: HandleString, cb: EncodedStringCallback));
35+
wrap!(glue: pub fn SetUpEventLoopDispatch(cx: &mut JSContext, callback: RustDispatchToEventLoopCallback, closure: *mut ::std::os::raw::c_void));
36+
wrap!(glue: pub fn DispatchableRun(cx: &mut JSContext, ptr: *mut DispatchablePointer, mb: Dispatchable_MaybeShuttingDown));
37+
wrap!(glue: pub fn DescribeScriptedCaller(cx: &mut JSContext, buffer: *mut ::std::os::raw::c_char, buflen: usize, line: *mut u32, col: *mut u32) -> bool);
38+
wrap!(glue: pub fn SetDataPropertyDescriptor(desc: MutableHandle<PropertyDescriptor>, value: HandleValue, attrs: u32));
39+
wrap!(glue: pub fn SetAccessorPropertyDescriptor(desc: MutableHandle<PropertyDescriptor>, getter: HandleObject, setter: HandleObject, attrs: u32));
40+
wrap!(glue: pub fn DumpJSStack(cx: &mut JSContext, showArgs: bool, showLocals: bool, showThisProps: bool));
41+
wrap!(glue: pub fn StackGCVectorValueLength(vec: Handle<StackGCVector<Value, TempAllocPolicy>>) -> u32);
42+
wrap!(glue: pub fn StackGCVectorStringLength(vec: Handle<StackGCVector<*mut JSString, TempAllocPolicy>>) -> u32);
43+
wrap!(glue: pub fn StackGCVectorValueAtIndex(vec: Handle<StackGCVector<Value, TempAllocPolicy>>, index: u32) -> *const Value);
44+
wrap!(glue: pub fn StackGCVectorStringAtIndex(vec: Handle<StackGCVector<*mut JSString, TempAllocPolicy>>, index: u32) -> *const *mut JSString);

0 commit comments

Comments
 (0)