chore; Add some explanatory comments on allow(unused_unsafe) annotations

This commit is contained in:
Christoph Herzog
2023-01-17 00:20:36 +01:00
parent 4c5b773dd7
commit e9edb7e8e6
5 changed files with 15 additions and 0 deletions

View File

@@ -399,6 +399,7 @@ impl Function {
store: &mut impl AsStoreMut, store: &mut impl AsStoreMut,
params: &[Value], params: &[Value],
) -> Result<Box<[Value]>, RuntimeError> { ) -> Result<Box<[Value]>, RuntimeError> {
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
let params: Vec<_> = unsafe { let params: Vec<_> = unsafe {
params params

View File

@@ -92,6 +92,7 @@ impl Memory {
pub(crate) fn new_internal(ty: MemoryType) -> Result<js_sys::WebAssembly::Memory, MemoryError> { pub(crate) fn new_internal(ty: MemoryType) -> Result<js_sys::WebAssembly::Memory, MemoryError> {
let descriptor = js_sys::Object::new(); let descriptor = js_sys::Object::new();
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
unsafe { unsafe {
js_sys::Reflect::set(&descriptor, &"initial".into(), &ty.minimum.0.into()).unwrap(); js_sys::Reflect::set(&descriptor, &"initial".into(), &ty.minimum.0.into()).unwrap();

View File

@@ -171,12 +171,14 @@ impl Imports {
for (ns, exports) in namespaces.into_iter() { for (ns, exports) in namespaces.into_iter() {
let import_namespace = js_sys::Object::new(); let import_namespace = js_sys::Object::new();
for (name, ext) in exports { for (name, ext) in exports {
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
unsafe { unsafe {
js_sys::Reflect::set(&import_namespace, &name.into(), &ext.as_jsvalue(store)) js_sys::Reflect::set(&import_namespace, &name.into(), &ext.as_jsvalue(store))
.expect("Error while setting into the js namespace object"); .expect("Error while setting into the js namespace object");
} }
} }
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
unsafe { unsafe {
js_sys::Reflect::set(&imports, &ns.into(), &import_namespace.into()) js_sys::Reflect::set(&imports, &ns.into(), &import_namespace.into())
@@ -238,6 +240,7 @@ impl Imports {
} }
impl AsJs for Imports { impl AsJs for Imports {
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
fn as_jsvalue(&self, store: &impl AsStoreRef) -> wasm_bindgen::JsValue { fn as_jsvalue(&self, store: &impl AsStoreRef) -> wasm_bindgen::JsValue {
let imports_object = js_sys::Object::new(); let imports_object = js_sys::Object::new();
@@ -245,6 +248,8 @@ impl AsJs for Imports {
let val = unsafe { js_sys::Reflect::get(&imports_object, &namespace.into()).unwrap() }; let val = unsafe { js_sys::Reflect::get(&imports_object, &namespace.into()).unwrap() };
if !val.is_undefined() { if !val.is_undefined() {
// If the namespace is already set // If the namespace is already set
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
unsafe { unsafe {
js_sys::Reflect::set( js_sys::Reflect::set(

View File

@@ -118,6 +118,7 @@ impl Instance {
.map(|export_type| { .map(|export_type| {
let name = export_type.name(); let name = export_type.name();
let extern_type = export_type.ty().clone(); let extern_type = export_type.ty().clone();
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
let js_export = unsafe { let js_export = unsafe {
js_sys::Reflect::get(&instance_exports, &name.into()) js_sys::Reflect::get(&instance_exports, &name.into())

View File

@@ -232,6 +232,7 @@ impl Module {
/// validation of the Module. /// validation of the Module.
pub fn validate(_store: &impl AsStoreRef, binary: &[u8]) -> Result<(), CompileError> { pub fn validate(_store: &impl AsStoreRef, binary: &[u8]) -> Result<(), CompileError> {
let js_bytes = unsafe { Uint8Array::view(binary) }; let js_bytes = unsafe { Uint8Array::view(binary) };
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
unsafe { unsafe {
match WebAssembly::validate(&js_bytes.into()) { match WebAssembly::validate(&js_bytes.into()) {
@@ -267,6 +268,7 @@ impl Module {
let mut import_externs: Vec<Extern> = vec![]; let mut import_externs: Vec<Extern> = vec![];
for import_type in self.imports() { for import_type in self.imports() {
let resolved_import = imports.get_export(import_type.module(), import_type.name()); let resolved_import = imports.get_export(import_type.module(), import_type.name());
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_variables)] #[allow(unused_variables)]
if let wasmer_types::ExternType::Memory(mem_ty) = import_type.ty() { if let wasmer_types::ExternType::Memory(mem_ty) = import_type.ty() {
if resolved_import.is_some() { if resolved_import.is_some() {
@@ -282,6 +284,7 @@ impl Module {
); );
} }
} }
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
unsafe { unsafe {
if let Some(import) = resolved_import { if let Some(import) = resolved_import {
@@ -468,6 +471,7 @@ impl Module {
.iter() .iter()
.enumerate() .enumerate()
.map(move |(i, val)| { .map(move |(i, val)| {
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
unsafe { unsafe {
let module = Reflect::get(val.as_ref(), &"module".into()) let module = Reflect::get(val.as_ref(), &"module".into())
@@ -530,6 +534,7 @@ impl Module {
return Err("The exports length must match the type hints lenght".to_owned()); return Err("The exports length must match the type hints lenght".to_owned());
} }
for (i, val) in exports.iter().enumerate() { for (i, val) in exports.iter().enumerate() {
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
let kind = unsafe { let kind = unsafe {
Reflect::get(val.as_ref(), &"kind".into()) Reflect::get(val.as_ref(), &"kind".into())
@@ -582,6 +587,7 @@ impl Module {
.iter() .iter()
.enumerate() .enumerate()
.map(move |(i, val)| { .map(move |(i, val)| {
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
let field = unsafe { let field = unsafe {
Reflect::get(val.as_ref(), &"name".into()) Reflect::get(val.as_ref(), &"name".into())
@@ -589,6 +595,7 @@ impl Module {
.as_string() .as_string()
.unwrap() .unwrap()
}; };
// Annotation is here to prevent spurious IDE warnings.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
let kind = unsafe { let kind = unsafe {
Reflect::get(val.as_ref(), &"kind".into()) Reflect::get(val.as_ref(), &"kind".into())