Skip to content
This repository was archived by the owner on Nov 12, 2022. It is now read-only.

Commit 2fe69f2

Browse files
author
Alan Jeffrey
committed
Put wrappers around functions that return JS::Values
1 parent e54b8af commit 2fe69f2

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

src/glue.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ extern "C" {
233233
aHandler: *const ::libc::c_void)
234234
-> *mut JSObject;
235235
pub fn GetWindowProxyClass() -> *const Class;
236-
pub fn GetProxyReservedSlot(obj: *mut JSObject, slot: u32) -> JS::Value;
236+
pub fn GetProxyReservedSlot(obj: *mut JSObject, slot: u32, dest: *mut JS::Value);
237237
pub fn GetProxyPrivate(obj: *mut JSObject) -> Value;
238238
pub fn SetProxyReservedSlot(obj: *mut JSObject, slot: u32, val: *const JS::Value);
239239
pub fn SetProxyPrivate(obj: *mut JSObject, expando: *const JS::Value);
@@ -339,4 +339,12 @@ extern "C" {
339339
pub fn GetLengthOfJSStructuredCloneData(data: *mut JSStructuredCloneData) -> usize;
340340
pub fn CopyJSStructuredCloneData(src: *const JSStructuredCloneData, dest: *mut u8);
341341
pub fn WriteBytesToJSStructuredCloneData(src: *const u8, len: usize, dest: *mut JSStructuredCloneData);
342+
pub fn JS_ComputeThis (cx: *mut JSContext , vp: *mut JS::Value, dest: *mut JS::Value);
343+
pub fn JS_GetModuleHostDefinedField (module: *mut JSObject, dest: *mut JS::Value);
344+
pub fn JS_GetPromiseResult (promise: JS::HandleObject, dest: *mut JS::Value);
345+
pub fn JS_THIS (cx: *mut JSContext , vp: *mut JS::Value, dest: *mut JS::Value);
346+
pub fn JS_GetNaNValue (cx: *mut JSContext, dest: *mut JS::Value);
347+
pub fn JS_GetPositiveInfinityValue (cx: *mut JSContext, dest: *mut JS::Value);
348+
pub fn JS_GetEmptyStringValue (cx: *mut JSContext, dest: *mut JS::Value);
349+
pub fn JS_GetReservedSlot (obj: *mut JSObject , index: u32, dest: *mut JS::Value);
342350
}

src/jsglue.cpp

+51-3
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,10 @@ GetWindowProxyClass()
574574
return &WindowProxyClass;
575575
}
576576

577-
JS::Value
578-
GetProxyReservedSlot(JSObject* obj, uint32_t slot)
577+
void
578+
GetProxyReservedSlot(JSObject* obj, uint32_t slot, JS::Value* dest)
579579
{
580-
return js::GetProxyReservedSlot(obj, slot);
580+
*dest = js::GetProxyReservedSlot(obj, slot);
581581
}
582582

583583
void
@@ -952,4 +952,52 @@ WriteBytesToJSStructuredCloneData(const uint8_t* src, size_t len, JSStructuredCl
952952
return dest->WriteBytes(reinterpret_cast<const char*>(src), len);
953953
}
954954

955+
// MSVC uses a different calling conventions for functions
956+
// that return non-POD values. Unfortunately, this includes anything
957+
// with a constructor, such as JS::Value, so we can't call these
958+
// from Rust. These wrapper functions are only here to
959+
// ensure the calling convention is right.
960+
// https://docs.microsoft.com/en-us/cpp/build/return-values-cpp
961+
// https://mozilla.logbot.info/jsapi/20180622#c14918658
962+
963+
void
964+
JS_ComputeThis(JSContext* cx, JS::Value* vp, JS::Value* dest) {
965+
*dest = JS::detail::ComputeThis(cx, vp);
966+
}
967+
968+
void
969+
JS_GetModuleHostDefinedField(JSObject* module, JS::Value* dest) {
970+
*dest = JS::GetModuleHostDefinedField(module);
971+
}
972+
973+
void
974+
JS_GetPromiseResult(JS::HandleObject promise, JS::Value* dest) {
975+
*dest = JS::GetPromiseResult(promise);
976+
}
977+
978+
void
979+
JS_THIS(JSContext* cx, JS::Value* vp, JS::Value* dest) {
980+
*dest = JS_THIS(cx, vp);
981+
}
982+
983+
void
984+
JS_GetNaNValue(JSContext* cx, JS::Value* dest) {
985+
*dest = JS_GetNaNValue(cx);
986+
}
987+
988+
void
989+
JS_GetPositiveInfinityValue(JSContext* cx, JS::Value* dest) {
990+
*dest = JS_GetPositiveInfinityValue(cx);
991+
}
992+
993+
void
994+
JS_GetEmptyStringValue(JSContext* cx, JS::Value* dest) {
995+
*dest = JS_GetEmptyStringValue(cx);
996+
}
997+
998+
void
999+
JS_GetReservedSlot(JSObject* obj, uint32_t index, JS::Value* dest) {
1000+
*dest = JS_GetReservedSlot(obj, index);
1001+
}
1002+
9551003
} // extern "C"

0 commit comments

Comments
 (0)