| 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(); |