MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / instantiate

Method instantiate

crates/fuzzing/src/oracles/diff_v8.rs:48–78  ·  view source on GitHub ↗
(&mut self, wasm: &[u8])

Source from the content-addressed store, hash-verified

46 }
47
48 fn instantiate(&mut self, wasm: &[u8]) -> Result<Box<dyn DiffInstance>> {
49 // Setup a new `Context` in which we'll be creating this instance and
50 // executing code.
51 let mut isolate = self.isolate.borrow_mut();
52 let isolate = &mut **isolate;
53 let mut scope = v8::HandleScope::new(isolate);
54 let context = v8::Context::new(&mut scope, Default::default());
55 let global = context.global(&mut scope);
56 let mut scope = v8::ContextScope::new(&mut scope, context);
57
58 // Move the `wasm` into JS and then invoke `new WebAssembly.Module`.
59 let buf = v8::ArrayBuffer::new_backing_store_from_boxed_slice(wasm.into());
60 let buf = v8::SharedRef::from(buf);
61 let name = v8::String::new(&mut scope, "WASM_BINARY").unwrap();
62 let buf = v8::ArrayBuffer::with_backing_store(&mut scope, &buf);
63 global.set(&mut scope, name.into(), buf.into());
64 let module = eval(&mut scope, "new WebAssembly.Module(WASM_BINARY)").unwrap();
65 let name = v8::String::new(&mut scope, "WASM_MODULE").unwrap();
66 global.set(&mut scope, name.into(), module);
67
68 // Using our `WASM_MODULE` run instantiation. Note that it's guaranteed
69 // that nothing is imported into differentially-executed modules so
70 // this is expected to only take the module argument.
71 let instance = eval(&mut scope, "new WebAssembly.Instance(WASM_MODULE)")?;
72
73 Ok(Box::new(V8Instance {
74 isolate: self.isolate.clone(),
75 context: v8::Global::new(&mut scope, context),
76 instance: v8::Global::new(&mut scope, instance),
77 }))
78 }
79
80 fn assert_error_match(&self, err: &Error, wasmtime: &Trap) {
81 let v8 = err.to_string();

Callers 15

instantiate_with_dummyFunction · 0.45
gc_opsFunction · 0.45
exception_opsFunction · 0.45
gc_accessFunction · 0.45
smoke_test_engineFunction · 0.45
check_stacksFunction · 0.45
instantiateFunction · 0.45

Calls 8

fromFunction · 0.85
evalFunction · 0.85
OkFunction · 0.85
globalMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
setMethod · 0.45
cloneMethod · 0.45

Tested by 15

instantiateFunction · 0.36
func_callFunction · 0.36
func_typedFunction · 0.36
call_exported_funcFunction · 0.36
instance_get_exportFunction · 0.36
instance_exportsFunction · 0.36
instance_get_funcFunction · 0.36