mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-17 15:01:23 +00:00
Tweak some logic in JsValue::drop
While technically correct the current implementation sort of made it only roundaboutedly so. Tweak the logic a bit and the associated comment to ensure that stack values are never dropped and the global constants are all skipped.
This commit is contained in:
12
src/lib.rs
12
src/lib.rs
@ -534,10 +534,14 @@ impl Drop for JsValue {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
// if the first bit is set then this is a stack value, so we for
|
// The first bit indicates whether this is a stack value or not.
|
||||||
// sure need to drop it. Otherwise if this is one of the special
|
// Stack values should never be dropped (they're always in
|
||||||
// reserved values there's no need to drop it.
|
// `ManuallyDrop`)
|
||||||
if (self.idx & 1) == 1 || self.idx >= JSIDX_RESERVED {
|
debug_assert!(self.idx & 1 == 0);
|
||||||
|
|
||||||
|
// We don't want to drop the first few elements as they're all
|
||||||
|
// reserved, but everything else is safe to drop.
|
||||||
|
if self.idx >= JSIDX_RESERVED {
|
||||||
__wbindgen_object_drop_ref(self.idx);
|
__wbindgen_object_drop_ref(self.idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user