How to use vmCtx method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

state.rs.5893bb9.js

Source:state.rs.5893bb9.js Github

copy

Full Screen

1var data = {lines:[2{"lineNum":" 1","line":"//! The state module is used to track state of a running web assembly instances so that"},3{"lineNum":" 2","line":"//! state could read or updated at runtime. Use cases include generating stack traces, switching"},4{"lineNum":" 3","line":"//! generated code from one tier to another, or serializing state of a running instace."},5{"lineNum":" 4","line":""},6{"lineNum":" 5","line":"use crate::backend::Backend;"},7{"lineNum":" 6","line":"use std::collections::BTreeMap;"},8{"lineNum":" 7","line":"use std::ops::Bound::{Included, Unbounded};"},9{"lineNum":" 8","line":""},10{"lineNum":" 9","line":"/// An index to a register"},11{"lineNum":" 10","line":"#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]","class":"lineNoCov","hits":"0","possible_hits":"4",},12{"lineNum":" 11","line":"pub struct RegisterIndex(pub usize);"},13{"lineNum":" 12","line":""},14{"lineNum":" 13","line":"/// A kind of wasm or constant value"},15{"lineNum":" 14","line":"#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]","class":"lineNoCov","hits":"0","possible_hits":"7",},16{"lineNum":" 15","line":"pub enum WasmAbstractValue {"},17{"lineNum":" 16","line":" /// A wasm runtime value"},18{"lineNum":" 17","line":" Runtime,"},19{"lineNum":" 18","line":" /// A wasm constant value"},20{"lineNum":" 19","line":" Const(u64),","class":"lineNoCov","hits":"0","possible_hits":"3",},21{"lineNum":" 20","line":"}"},22{"lineNum":" 21","line":""},23{"lineNum":" 22","line":"/// A container for the state of a running wasm instance."},24{"lineNum":" 23","line":"#[derive(Clone, Debug)]","class":"lineNoCov","hits":"0","possible_hits":"6",},25{"lineNum":" 24","line":"pub struct MachineState {"},26{"lineNum":" 25","line":" /// Stack values."},27{"lineNum":" 26","line":" pub stack_values: Vec<MachineValue>,","class":"lineNoCov","hits":"0","possible_hits":"2",},28{"lineNum":" 27","line":" /// Register values."},29{"lineNum":" 28","line":" pub register_values: Vec<MachineValue>,","class":"lineNoCov","hits":"0","possible_hits":"2",},30{"lineNum":" 29","line":" /// Previous frame."},31{"lineNum":" 30","line":" pub prev_frame: BTreeMap<usize, MachineValue>,","class":"lineNoCov","hits":"0","possible_hits":"2",},32{"lineNum":" 31","line":" /// Wasm stack."},33{"lineNum":" 32","line":" pub wasm_stack: Vec<WasmAbstractValue>,","class":"lineNoCov","hits":"0","possible_hits":"2",},34{"lineNum":" 33","line":" /// Private depth of the wasm stack."},35{"lineNum":" 34","line":" pub wasm_stack_private_depth: usize,","class":"lineNoCov","hits":"0","possible_hits":"2",},36{"lineNum":" 35","line":" /// Wasm instruction offset."},37{"lineNum":" 36","line":" pub wasm_inst_offset: usize,","class":"lineNoCov","hits":"0","possible_hits":"2",},38{"lineNum":" 37","line":"}"},39{"lineNum":" 38","line":""},40{"lineNum":" 39","line":"/// A diff of two `MachineState`s."},41{"lineNum":" 40","line":"#[derive(Clone, Debug, Default)]","class":"lineNoCov","hits":"0","possible_hits":"7",},42{"lineNum":" 41","line":"pub struct MachineStateDiff {"},43{"lineNum":" 42","line":" /// Last."},44{"lineNum":" 43","line":" pub last: Option<usize>,","class":"lineNoCov","hits":"0","possible_hits":"2",},45{"lineNum":" 44","line":" /// Stack push."},46{"lineNum":" 45","line":" pub stack_push: Vec<MachineValue>,","class":"lineNoCov","hits":"0","possible_hits":"2",},47{"lineNum":" 46","line":" /// Stack pop."},48{"lineNum":" 47","line":" pub stack_pop: usize,","class":"lineNoCov","hits":"0","possible_hits":"2",},49{"lineNum":" 48","line":""},50{"lineNum":" 49","line":" /// Register diff."},51{"lineNum":" 50","line":" pub reg_diff: Vec<(RegisterIndex, MachineValue)>,","class":"lineNoCov","hits":"0","possible_hits":"2",},52{"lineNum":" 51","line":""},53{"lineNum":" 52","line":" /// Previous frame diff."},54{"lineNum":" 53","line":" pub prev_frame_diff: BTreeMap<usize, Option<MachineValue>>, // None for removal","class":"lineNoCov","hits":"0","possible_hits":"2",},55{"lineNum":" 54","line":""},56{"lineNum":" 55","line":" /// Wasm stack push."},57{"lineNum":" 56","line":" pub wasm_stack_push: Vec<WasmAbstractValue>,","class":"lineNoCov","hits":"0","possible_hits":"2",},58{"lineNum":" 57","line":" /// Wasm stack pop."},59{"lineNum":" 58","line":" pub wasm_stack_pop: usize,","class":"lineNoCov","hits":"0","possible_hits":"2",},60{"lineNum":" 59","line":" /// Private depth of the wasm stack."},61{"lineNum":" 60","line":" pub wasm_stack_private_depth: usize, // absolute value; not a diff.","class":"lineNoCov","hits":"0","possible_hits":"2",},62{"lineNum":" 61","line":" /// Wasm instruction offset."},63{"lineNum":" 62","line":" pub wasm_inst_offset: usize, // absolute value; not a diff.","class":"lineNoCov","hits":"0","possible_hits":"2",},64{"lineNum":" 63","line":"}"},65{"lineNum":" 64","line":""},66{"lineNum":" 65","line":"/// A kind of machine value."},67{"lineNum":" 66","line":"#[derive(Clone, Debug, Eq, PartialEq, Hash)]","class":"lineNoCov","hits":"0","possible_hits":"16",},68{"lineNum":" 67","line":"pub enum MachineValue {"},69{"lineNum":" 68","line":" /// Undefined."},70{"lineNum":" 69","line":" Undefined,"},71{"lineNum":" 70","line":" /// Vmctx."},72{"lineNum":" 71","line":" Vmctx,"},73{"lineNum":" 72","line":" /// Vmctx Deref."},74{"lineNum":" 73","line":" VmctxDeref(Vec<usize>),","class":"lineNoCov","hits":"0","possible_hits":"2",},75{"lineNum":" 74","line":" /// Preserve Register."},76{"lineNum":" 75","line":" PreserveRegister(RegisterIndex),","class":"lineNoCov","hits":"0","possible_hits":"2",},77{"lineNum":" 76","line":" /// Copy Stack BP Relative."},78{"lineNum":" 77","line":" CopyStackBPRelative(i32), // relative to Base Pointer, in byte offset","class":"lineNoCov","hits":"0","possible_hits":"2",},79{"lineNum":" 78","line":" /// Explicit Shadow."},80{"lineNum":" 79","line":" ExplicitShadow, // indicates that all values above this are above the shadow region"},81{"lineNum":" 80","line":" /// Wasm Stack."},82{"lineNum":" 81","line":" WasmStack(usize),","class":"lineNoCov","hits":"0","possible_hits":"2",},83{"lineNum":" 82","line":" /// Wasm Local."},84{"lineNum":" 83","line":" WasmLocal(usize),","class":"lineNoCov","hits":"0","possible_hits":"2",},85{"lineNum":" 84","line":" /// Two Halves."},86{"lineNum":" 85","line":" TwoHalves(Box<(MachineValue, MachineValue)>), // 32-bit values. TODO: optimize: add another type for inner \"half\" value to avoid boxing?","class":"lineNoCov","hits":"0","possible_hits":"2",},87{"lineNum":" 86","line":"}"},88{"lineNum":" 87","line":""},89{"lineNum":" 88","line":"/// A map of function states."},90{"lineNum":" 89","line":"#[derive(Clone, Debug)]","class":"lineNoCov","hits":"0","possible_hits":"7",},91{"lineNum":" 90","line":"pub struct FunctionStateMap {"},92{"lineNum":" 91","line":" /// Initial."},93{"lineNum":" 92","line":" pub initial: MachineState,","class":"lineNoCov","hits":"0","possible_hits":"2",},94{"lineNum":" 93","line":" /// Local Function Id."},95{"lineNum":" 94","line":" pub local_function_id: usize,","class":"lineNoCov","hits":"0","possible_hits":"2",},96{"lineNum":" 95","line":" /// Locals."},97{"lineNum":" 96","line":" pub locals: Vec<WasmAbstractValue>,","class":"lineNoCov","hits":"0","possible_hits":"2",},98{"lineNum":" 97","line":" /// Shadow size."},99{"lineNum":" 98","line":" pub shadow_size: usize, // for single-pass backend, 32 bytes on x86-64","class":"lineNoCov","hits":"0","possible_hits":"2",},100{"lineNum":" 99","line":" /// Diffs."},101{"lineNum":" 100","line":" pub diffs: Vec<MachineStateDiff>,","class":"lineNoCov","hits":"0","possible_hits":"2",},102{"lineNum":" 101","line":" /// Wasm Function Header target offset."},103{"lineNum":" 102","line":" pub wasm_function_header_target_offset: Option<SuspendOffset>,","class":"lineNoCov","hits":"0","possible_hits":"2",},104{"lineNum":" 103","line":" /// Wasm offset to target offset"},105{"lineNum":" 104","line":" pub wasm_offset_to_target_offset: BTreeMap<usize, SuspendOffset>,","class":"lineNoCov","hits":"0","possible_hits":"2",},106{"lineNum":" 105","line":" /// Loop offsets."},107{"lineNum":" 106","line":" pub loop_offsets: BTreeMap<usize, OffsetInfo>, /* suspend_offset -> info */","class":"lineNoCov","hits":"0","possible_hits":"2",},108{"lineNum":" 107","line":" /// Call offsets."},109{"lineNum":" 108","line":" pub call_offsets: BTreeMap<usize, OffsetInfo>, /* suspend_offset -> info */","class":"lineNoCov","hits":"0","possible_hits":"2",},110{"lineNum":" 109","line":" /// Trappable offsets."},111{"lineNum":" 110","line":" pub trappable_offsets: BTreeMap<usize, OffsetInfo>, /* suspend_offset -> info */","class":"lineNoCov","hits":"0","possible_hits":"2",},112{"lineNum":" 111","line":"}"},113{"lineNum":" 112","line":""},114{"lineNum":" 113","line":"/// A kind of suspend offset."},115{"lineNum":" 114","line":"#[derive(Clone, Copy, Debug)]","class":"lineNoCov","hits":"0","possible_hits":"2",},116{"lineNum":" 115","line":"pub enum SuspendOffset {"},117{"lineNum":" 116","line":" /// A loop."},118{"lineNum":" 117","line":" Loop(usize),"},119{"lineNum":" 118","line":" /// A call."},120{"lineNum":" 119","line":" Call(usize),"},121{"lineNum":" 120","line":" /// A trappable."},122{"lineNum":" 121","line":" Trappable(usize),"},123{"lineNum":" 122","line":"}"},124{"lineNum":" 123","line":""},125{"lineNum":" 124","line":"/// Info for an offset."},126{"lineNum":" 125","line":"#[derive(Clone, Debug)]","class":"lineNoCov","hits":"0","possible_hits":"2",},127{"lineNum":" 126","line":"pub struct OffsetInfo {"},128{"lineNum":" 127","line":" /// End offset."},129{"lineNum":" 128","line":" pub end_offset: usize, // excluded bound","class":"lineNoCov","hits":"0","possible_hits":"2",},130{"lineNum":" 129","line":" /// Diff Id."},131{"lineNum":" 130","line":" pub diff_id: usize,","class":"lineNoCov","hits":"0","possible_hits":"2",},132{"lineNum":" 131","line":" /// Activate offset."},133{"lineNum":" 132","line":" pub activate_offset: usize,","class":"lineNoCov","hits":"0","possible_hits":"2",},134{"lineNum":" 133","line":"}"},135{"lineNum":" 134","line":""},136{"lineNum":" 135","line":"/// A map of module state."},137{"lineNum":" 136","line":"#[derive(Clone, Debug)]","class":"lineNoCov","hits":"0","possible_hits":"3",},138{"lineNum":" 137","line":"pub struct ModuleStateMap {"},139{"lineNum":" 138","line":" /// Local functions."},140{"lineNum":" 139","line":" pub local_functions: BTreeMap<usize, FunctionStateMap>,","class":"lineNoCov","hits":"0","possible_hits":"2",},141{"lineNum":" 140","line":" /// Total size."},142{"lineNum":" 141","line":" pub total_size: usize,","class":"lineNoCov","hits":"0","possible_hits":"2",},143{"lineNum":" 142","line":"}"},144{"lineNum":" 143","line":""},145{"lineNum":" 144","line":"/// State dump of a wasm function."},146{"lineNum":" 145","line":"#[derive(Clone, Debug, Serialize, Deserialize)]"},147{"lineNum":" 146","line":"pub struct WasmFunctionStateDump {"},148{"lineNum":" 147","line":" /// Local function id."},149{"lineNum":" 148","line":" pub local_function_id: usize,"},150{"lineNum":" 149","line":" /// Wasm instruction offset."},151{"lineNum":" 150","line":" pub wasm_inst_offset: usize,"},152{"lineNum":" 151","line":" /// Stack."},153{"lineNum":" 152","line":" pub stack: Vec<Option<u64>>,"},154{"lineNum":" 153","line":" /// Locals."},155{"lineNum":" 154","line":" pub locals: Vec<Option<u64>>,"},156{"lineNum":" 155","line":"}"},157{"lineNum":" 156","line":""},158{"lineNum":" 157","line":"/// An image of the execution state."},159{"lineNum":" 158","line":"#[derive(Clone, Debug, Serialize, Deserialize)]"},160{"lineNum":" 159","line":"pub struct ExecutionStateImage {"},161{"lineNum":" 160","line":" /// Frames."},162{"lineNum":" 161","line":" pub frames: Vec<WasmFunctionStateDump>,"},163{"lineNum":" 162","line":"}"},164{"lineNum":" 163","line":""},165{"lineNum":" 164","line":"/// Represents an image of an `Instance` including its memory, globals, and execution state."},166{"lineNum":" 165","line":"#[derive(Debug, Clone, Serialize, Deserialize)]"},167{"lineNum":" 166","line":"pub struct InstanceImage {"},168{"lineNum":" 167","line":" /// Memory for this `InstanceImage`"},169{"lineNum":" 168","line":" pub memory: Option<Vec<u8>>,"},170{"lineNum":" 169","line":" /// Stored globals for this `InstanceImage`"},171{"lineNum":" 170","line":" pub globals: Vec<u128>,"},172{"lineNum":" 171","line":" /// `ExecutionStateImage` for this `InstanceImage`"},173{"lineNum":" 172","line":" pub execution_state: ExecutionStateImage,"},174{"lineNum":" 173","line":"}"},175{"lineNum":" 174","line":""},176{"lineNum":" 175","line":"/// A `CodeVersion` is a container for a unit of generated code for a module."},177{"lineNum":" 176","line":"#[derive(Debug, Clone)]"},178{"lineNum":" 177","line":"pub struct CodeVersion {"},179{"lineNum":" 178","line":" /// Indicates if this code version is the baseline version."},180{"lineNum":" 179","line":" pub baseline: bool,"},181{"lineNum":" 180","line":""},182{"lineNum":" 181","line":" /// `ModuleStateMap` for this code version."},183{"lineNum":" 182","line":" pub msm: ModuleStateMap,"},184{"lineNum":" 183","line":""},185{"lineNum":" 184","line":" /// A pointer to the machine code for this module."},186{"lineNum":" 185","line":" pub base: usize,"},187{"lineNum":" 186","line":""},188{"lineNum":" 187","line":" /// The backend used to compile this module."},189{"lineNum":" 188","line":" pub backend: Backend,"},190{"lineNum":" 189","line":"}"},191{"lineNum":" 190","line":""},192{"lineNum":" 191","line":"impl ModuleStateMap {"},193{"lineNum":" 192","line":" /// Looks up an ip from self using the given ip, base, and offset table provider."},194{"lineNum":" 193","line":" pub fn lookup_ip<F: FnOnce(&FunctionStateMap) -> &BTreeMap<usize, OffsetInfo>>("},195{"lineNum":" 194","line":" &self,"},196{"lineNum":" 195","line":" ip: usize,"},197{"lineNum":" 196","line":" base: usize,"},198{"lineNum":" 197","line":" offset_table_provider: F,"},199{"lineNum":" 198","line":" ) -> Option<(&FunctionStateMap, MachineState)> {"},200{"lineNum":" 199","line":" if ip < base || ip - base >= self.total_size {"},201{"lineNum":" 200","line":" None"},202{"lineNum":" 201","line":" } else {"},203{"lineNum":" 202","line":" let (_, fsm) = self"},204{"lineNum":" 203","line":" .local_functions"},205{"lineNum":" 204","line":" .range((Unbounded, Included(&(ip - base))))"},206{"lineNum":" 205","line":" .last()"},207{"lineNum":" 206","line":" .unwrap();"},208{"lineNum":" 207","line":""},209{"lineNum":" 208","line":" match offset_table_provider(fsm)"},210{"lineNum":" 209","line":" .range((Unbounded, Included(&(ip - base))))"},211{"lineNum":" 210","line":" .last()"},212{"lineNum":" 211","line":" {"},213{"lineNum":" 212","line":" Some((_, x)) => {"},214{"lineNum":" 213","line":" if ip - base >= x.end_offset {"},215{"lineNum":" 214","line":" None"},216{"lineNum":" 215","line":" } else if x.diff_id < fsm.diffs.len() {"},217{"lineNum":" 216","line":" Some((fsm, fsm.diffs[x.diff_id].build_state(fsm)))"},218{"lineNum":" 217","line":" } else {"},219{"lineNum":" 218","line":" None"},220{"lineNum":" 219","line":" }"},221{"lineNum":" 220","line":" }"},222{"lineNum":" 221","line":" None => None,"},223{"lineNum":" 222","line":" }"},224{"lineNum":" 223","line":" }"},225{"lineNum":" 224","line":" }"},226{"lineNum":" 225","line":" /// Looks up a call ip from self using the given ip and base values."},227{"lineNum":" 226","line":" pub fn lookup_call_ip("},228{"lineNum":" 227","line":" &self,"},229{"lineNum":" 228","line":" ip: usize,"},230{"lineNum":" 229","line":" base: usize,"},231{"lineNum":" 230","line":" ) -> Option<(&FunctionStateMap, MachineState)> {"},232{"lineNum":" 231","line":" self.lookup_ip(ip, base, |fsm| &fsm.call_offsets)"},233{"lineNum":" 232","line":" }"},234{"lineNum":" 233","line":""},235{"lineNum":" 234","line":" /// Looks up a trappable ip from self using the given ip and base values."},236{"lineNum":" 235","line":" pub fn lookup_trappable_ip("},237{"lineNum":" 236","line":" &self,"},238{"lineNum":" 237","line":" ip: usize,"},239{"lineNum":" 238","line":" base: usize,"},240{"lineNum":" 239","line":" ) -> Option<(&FunctionStateMap, MachineState)> {"},241{"lineNum":" 240","line":" self.lookup_ip(ip, base, |fsm| &fsm.trappable_offsets)"},242{"lineNum":" 241","line":" }"},243{"lineNum":" 242","line":""},244{"lineNum":" 243","line":" /// Looks up a loop ip from self using the given ip and base values."},245{"lineNum":" 244","line":" pub fn lookup_loop_ip("},246{"lineNum":" 245","line":" &self,"},247{"lineNum":" 246","line":" ip: usize,"},248{"lineNum":" 247","line":" base: usize,"},249{"lineNum":" 248","line":" ) -> Option<(&FunctionStateMap, MachineState)> {"},250{"lineNum":" 249","line":" self.lookup_ip(ip, base, |fsm| &fsm.loop_offsets)"},251{"lineNum":" 250","line":" }"},252{"lineNum":" 251","line":"}"},253{"lineNum":" 252","line":""},254{"lineNum":" 253","line":"impl FunctionStateMap {"},255{"lineNum":" 254","line":" /// Creates a new `FunctionStateMap` with the given parameters."},256{"lineNum":" 255","line":" pub fn new(","class":"lineNoCov","hits":"0","possible_hits":"2",},257{"lineNum":" 256","line":" initial: MachineState,"},258{"lineNum":" 257","line":" local_function_id: usize,"},259{"lineNum":" 258","line":" shadow_size: usize,"},260{"lineNum":" 259","line":" locals: Vec<WasmAbstractValue>,"},261{"lineNum":" 260","line":" ) -> FunctionStateMap {"},262{"lineNum":" 261","line":" FunctionStateMap {","class":"lineNoCov","hits":"0","possible_hits":"1",},263{"lineNum":" 262","line":" initial,","class":"lineNoCov","hits":"0","possible_hits":"1",},264{"lineNum":" 263","line":" local_function_id,","class":"lineNoCov","hits":"0","possible_hits":"1",},265{"lineNum":" 264","line":" shadow_size,","class":"lineNoCov","hits":"0","possible_hits":"1",},266{"lineNum":" 265","line":" locals,","class":"lineNoCov","hits":"0","possible_hits":"1",},267{"lineNum":" 266","line":" diffs: vec![],","class":"lineNoCov","hits":"0","possible_hits":"1",},268{"lineNum":" 267","line":" wasm_function_header_target_offset: None,","class":"lineNoCov","hits":"0","possible_hits":"1",},269{"lineNum":" 268","line":" wasm_offset_to_target_offset: BTreeMap::new(),","class":"lineNoCov","hits":"0","possible_hits":"1",},270{"lineNum":" 269","line":" loop_offsets: BTreeMap::new(),","class":"lineNoCov","hits":"0","possible_hits":"1",},271{"lineNum":" 270","line":" call_offsets: BTreeMap::new(),","class":"lineNoCov","hits":"0","possible_hits":"1",},272{"lineNum":" 271","line":" trappable_offsets: BTreeMap::new(),","class":"lineNoCov","hits":"0","possible_hits":"1",},273{"lineNum":" 272","line":" }","class":"lineNoCov","hits":"0","possible_hits":"5",},274{"lineNum":" 273","line":" }","class":"lineNoCov","hits":"0","possible_hits":"1",},275{"lineNum":" 274","line":"}"},276{"lineNum":" 275","line":""},277{"lineNum":" 276","line":"impl MachineState {"},278{"lineNum":" 277","line":" /// Creates a `MachineStateDiff` from self and the given `&MachineState`."},279{"lineNum":" 278","line":" pub fn diff(&self, old: &MachineState) -> MachineStateDiff {"},280{"lineNum":" 279","line":" let first_diff_stack_depth: usize = self"},281{"lineNum":" 280","line":" .stack_values"},282{"lineNum":" 281","line":" .iter()"},283{"lineNum":" 282","line":" .zip(old.stack_values.iter())"},284{"lineNum":" 283","line":" .enumerate()"},285{"lineNum":" 284","line":" .find(|&(_, (a, b))| a != b)"},286{"lineNum":" 285","line":" .map(|x| x.0)"},287{"lineNum":" 286","line":" .unwrap_or(old.stack_values.len().min(self.stack_values.len()));"},288{"lineNum":" 287","line":" assert_eq!(self.register_values.len(), old.register_values.len());"},289{"lineNum":" 288","line":" let reg_diff: Vec<_> = self"},290{"lineNum":" 289","line":" .register_values"},291{"lineNum":" 290","line":" .iter()"},292{"lineNum":" 291","line":" .zip(old.register_values.iter())"},293{"lineNum":" 292","line":" .enumerate()"},294{"lineNum":" 293","line":" .filter(|&(_, (a, b))| a != b)"},295{"lineNum":" 294","line":" .map(|(i, (a, _))| (RegisterIndex(i), a.clone()))"},296{"lineNum":" 295","line":" .collect();"},297{"lineNum":" 296","line":" let prev_frame_diff: BTreeMap<usize, Option<MachineValue>> = self"},298{"lineNum":" 297","line":" .prev_frame"},299{"lineNum":" 298","line":" .iter()"},300{"lineNum":" 299","line":" .filter(|(k, v)| {"},301{"lineNum":" 300","line":" if let Some(ref old_v) = old.prev_frame.get(k) {"},302{"lineNum":" 301","line":" v != old_v"},303{"lineNum":" 302","line":" } else {"},304{"lineNum":" 303","line":" true"},305{"lineNum":" 304","line":" }"},306{"lineNum":" 305","line":" })"},307{"lineNum":" 306","line":" .map(|(&k, v)| (k, Some(v.clone())))"},308{"lineNum":" 307","line":" .chain("},309{"lineNum":" 308","line":" old.prev_frame"},310{"lineNum":" 309","line":" .iter()"},311{"lineNum":" 310","line":" .filter(|(k, _)| self.prev_frame.get(k).is_none())"},312{"lineNum":" 311","line":" .map(|(&k, _)| (k, None)),"},313{"lineNum":" 312","line":" )"},314{"lineNum":" 313","line":" .collect();"},315{"lineNum":" 314","line":" let first_diff_wasm_stack_depth: usize = self"},316{"lineNum":" 315","line":" .wasm_stack"},317{"lineNum":" 316","line":" .iter()"},318{"lineNum":" 317","line":" .zip(old.wasm_stack.iter())"},319{"lineNum":" 318","line":" .enumerate()"},320{"lineNum":" 319","line":" .find(|&(_, (a, b))| a != b)"},321{"lineNum":" 320","line":" .map(|x| x.0)"},322{"lineNum":" 321","line":" .unwrap_or(old.wasm_stack.len().min(self.wasm_stack.len()));"},323{"lineNum":" 322","line":" MachineStateDiff {"},324{"lineNum":" 323","line":" last: None,"},325{"lineNum":" 324","line":" stack_push: self.stack_values[first_diff_stack_depth..].to_vec(),"},326{"lineNum":" 325","line":" stack_pop: old.stack_values.len() - first_diff_stack_depth,"},327{"lineNum":" 326","line":" reg_diff,"},328{"lineNum":" 327","line":""},329{"lineNum":" 328","line":" prev_frame_diff,"},330{"lineNum":" 329","line":""},331{"lineNum":" 330","line":" wasm_stack_push: self.wasm_stack[first_diff_wasm_stack_depth..].to_vec(),"},332{"lineNum":" 331","line":" wasm_stack_pop: old.wasm_stack.len() - first_diff_wasm_stack_depth,"},333{"lineNum":" 332","line":" wasm_stack_private_depth: self.wasm_stack_private_depth,"},334{"lineNum":" 333","line":""},335{"lineNum":" 334","line":" wasm_inst_offset: self.wasm_inst_offset,"},336{"lineNum":" 335","line":" }"},337{"lineNum":" 336","line":" }"},338{"lineNum":" 337","line":"}"},339{"lineNum":" 338","line":""},340{"lineNum":" 339","line":"impl MachineStateDiff {"},341{"lineNum":" 340","line":" /// Creates a `MachineState` from the given `&FunctionStateMap`."},342{"lineNum":" 341","line":" pub fn build_state(&self, m: &FunctionStateMap) -> MachineState {"},343{"lineNum":" 342","line":" let mut chain: Vec<&MachineStateDiff> = vec![];"},344{"lineNum":" 343","line":" chain.push(self);"},345{"lineNum":" 344","line":" let mut current = self.last;"},346{"lineNum":" 345","line":" while let Some(x) = current {"},347{"lineNum":" 346","line":" let that = &m.diffs[x];"},348{"lineNum":" 347","line":" current = that.last;"},349{"lineNum":" 348","line":" chain.push(that);"},350{"lineNum":" 349","line":" }"},351{"lineNum":" 350","line":" chain.reverse();"},352{"lineNum":" 351","line":" let mut state = m.initial.clone();"},353{"lineNum":" 352","line":" for x in chain {"},354{"lineNum":" 353","line":" for _ in 0..x.stack_pop {"},355{"lineNum":" 354","line":" state.stack_values.pop().unwrap();"},356{"lineNum":" 355","line":" }"},357{"lineNum":" 356","line":" for v in &x.stack_push {"},358{"lineNum":" 357","line":" state.stack_values.push(v.clone());"},359{"lineNum":" 358","line":" }"},360{"lineNum":" 359","line":" for &(index, ref v) in &x.reg_diff {"},361{"lineNum":" 360","line":" state.register_values[index.0] = v.clone();"},362{"lineNum":" 361","line":" }"},363{"lineNum":" 362","line":" for (index, ref v) in &x.prev_frame_diff {"},364{"lineNum":" 363","line":" if let Some(ref x) = v {"},365{"lineNum":" 364","line":" state.prev_frame.insert(*index, x.clone());"},366{"lineNum":" 365","line":" } else {"},367{"lineNum":" 366","line":" state.prev_frame.remove(index).unwrap();"},368{"lineNum":" 367","line":" }"},369{"lineNum":" 368","line":" }"},370{"lineNum":" 369","line":" for _ in 0..x.wasm_stack_pop {"},371{"lineNum":" 370","line":" state.wasm_stack.pop().unwrap();"},372{"lineNum":" 371","line":" }"},373{"lineNum":" 372","line":" for v in &x.wasm_stack_push {"},374{"lineNum":" 373","line":" state.wasm_stack.push(*v);"},375{"lineNum":" 374","line":" }"},376{"lineNum":" 375","line":" }"},377{"lineNum":" 376","line":" state.wasm_stack_private_depth = self.wasm_stack_private_depth;"},378{"lineNum":" 377","line":" state.wasm_inst_offset = self.wasm_inst_offset;"},379{"lineNum":" 378","line":" state"},380{"lineNum":" 379","line":" }"},381{"lineNum":" 380","line":"}"},382{"lineNum":" 381","line":""},383{"lineNum":" 382","line":"impl ExecutionStateImage {"},384{"lineNum":" 383","line":" /// Prints a backtrace if the `WASMER_BACKTRACE` environment variable is 1."},385{"lineNum":" 384","line":" pub fn print_backtrace_if_needed(&self) {"},386{"lineNum":" 385","line":" use std::env;"},387{"lineNum":" 386","line":""},388{"lineNum":" 387","line":" if let Ok(x) = env::var(\"WASMER_BACKTRACE\") {"},389{"lineNum":" 388","line":" if x == \"1\" {"},390{"lineNum":" 389","line":" eprintln!(\"{}\", self.output());"},391{"lineNum":" 390","line":" return;"},392{"lineNum":" 391","line":" }"},393{"lineNum":" 392","line":" }"},394{"lineNum":" 393","line":""},395{"lineNum":" 394","line":" eprintln!(\"Run with `WASMER_BACKTRACE=1` environment variable to display a backtrace.\");"},396{"lineNum":" 395","line":" }"},397{"lineNum":" 396","line":""},398{"lineNum":" 397","line":" /// Converts self into a `String`, used for display purposes."},399{"lineNum":" 398","line":" pub fn output(&self) -> String {"},400{"lineNum":" 399","line":" fn join_strings(x: impl Iterator<Item = String>, sep: &str) -> String {"},401{"lineNum":" 400","line":" let mut ret = String::new();"},402{"lineNum":" 401","line":" let mut first = true;"},403{"lineNum":" 402","line":""},404{"lineNum":" 403","line":" for s in x {"},405{"lineNum":" 404","line":" if first {"},406{"lineNum":" 405","line":" first = false;"},407{"lineNum":" 406","line":" } else {"},408{"lineNum":" 407","line":" ret += sep;"},409{"lineNum":" 408","line":" }"},410{"lineNum":" 409","line":" ret += &s;"},411{"lineNum":" 410","line":" }"},412{"lineNum":" 411","line":""},413{"lineNum":" 412","line":" ret"},414{"lineNum":" 413","line":" }"},415{"lineNum":" 414","line":""},416{"lineNum":" 415","line":" fn format_optional_u64_sequence(x: &[Option<u64>]) -> String {"},417{"lineNum":" 416","line":" if x.len() == 0 {"},418{"lineNum":" 417","line":" \"(empty)\".into()"},419{"lineNum":" 418","line":" } else {"},420{"lineNum":" 419","line":" join_strings("},421{"lineNum":" 420","line":" x.iter().enumerate().map(|(i, x)| {"},422{"lineNum":" 421","line":" format!("},423{"lineNum":" 422","line":" \"[{}] = {}\","},424{"lineNum":" 423","line":" i,"},425{"lineNum":" 424","line":" x.map(|x| format!(\"{}\", x))"},426{"lineNum":" 425","line":" .unwrap_or_else(|| \"?\".to_string())"},427{"lineNum":" 426","line":" )"},428{"lineNum":" 427","line":" }),"},429{"lineNum":" 428","line":" \", \","},430{"lineNum":" 429","line":" )"},431{"lineNum":" 430","line":" }"},432{"lineNum":" 431","line":" }"},433{"lineNum":" 432","line":""},434{"lineNum":" 433","line":" let mut ret = String::new();"},435{"lineNum":" 434","line":""},436{"lineNum":" 435","line":" if self.frames.len() == 0 {"},437{"lineNum":" 436","line":" ret += &\"Unknown fault address, cannot read stack.\";"},438{"lineNum":" 437","line":" ret += \"\\n\";"},439{"lineNum":" 438","line":" } else {"},440{"lineNum":" 439","line":" ret += &\"Backtrace:\";"},441{"lineNum":" 440","line":" ret += \"\\n\";"},442{"lineNum":" 441","line":" for (i, f) in self.frames.iter().enumerate() {"},443{"lineNum":" 442","line":" ret += &format!(\"* Frame {} @ Local function {}\", i, f.local_function_id);"},444{"lineNum":" 443","line":" ret += \"\\n\";"},445{"lineNum":" 444","line":" ret += &format!(\" {} {}\\n\", \"Offset:\", format!(\"{}\", f.wasm_inst_offset),);"},446{"lineNum":" 445","line":" ret += &format!("},447{"lineNum":" 446","line":" \" {} {}\\n\","},448{"lineNum":" 447","line":" \"Locals:\","},449{"lineNum":" 448","line":" format_optional_u64_sequence(&f.locals)"},450{"lineNum":" 449","line":" );"},451{"lineNum":" 450","line":" ret += &format!("},452{"lineNum":" 451","line":" \" {} {}\\n\\n\","},453{"lineNum":" 452","line":" \"Stack:\","},454{"lineNum":" 453","line":" format_optional_u64_sequence(&f.stack)"},455{"lineNum":" 454","line":" );"},456{"lineNum":" 455","line":" }"},457{"lineNum":" 456","line":" }"},458{"lineNum":" 457","line":""},459{"lineNum":" 458","line":" ret"},460{"lineNum":" 459","line":" }"},461{"lineNum":" 460","line":"}"},462{"lineNum":" 461","line":""},463{"lineNum":" 462","line":"impl InstanceImage {"},464{"lineNum":" 463","line":" /// Converts a slice of bytes into an `Option<InstanceImage>`"},465{"lineNum":" 464","line":" pub fn from_bytes(input: &[u8]) -> Option<InstanceImage> {"},466{"lineNum":" 465","line":" use bincode::deserialize;"},467{"lineNum":" 466","line":" match deserialize(input) {"},468{"lineNum":" 467","line":" Ok(x) => Some(x),"},469{"lineNum":" 468","line":" Err(_) => None,"},470{"lineNum":" 469","line":" }"},471{"lineNum":" 470","line":" }"},472{"lineNum":" 471","line":""},473{"lineNum":" 472","line":" /// Converts self into a vector of bytes."},474{"lineNum":" 473","line":" pub fn to_bytes(&self) -> Vec<u8> {"},475{"lineNum":" 474","line":" use bincode::serialize;"},476{"lineNum":" 475","line":" serialize(self).unwrap()"},477{"lineNum":" 476","line":" }"},478{"lineNum":" 477","line":"}"},479{"lineNum":" 478","line":""},480{"lineNum":" 479","line":"/// Declarations for x86-64 registers."},481{"lineNum":" 480","line":"#[cfg(unix)]"},482{"lineNum":" 481","line":"pub mod x64_decl {"},483{"lineNum":" 482","line":" use super::*;"},484{"lineNum":" 483","line":""},485{"lineNum":" 484","line":" /// General-purpose registers."},486{"lineNum":" 485","line":" #[repr(u8)]"},487{"lineNum":" 486","line":" #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]","class":"lineNoCov","hits":"0","possible_hits":"2",},488{"lineNum":" 487","line":" pub enum GPR {"},489{"lineNum":" 488","line":" /// RAX register"},490{"lineNum":" 489","line":" RAX,"},491{"lineNum":" 490","line":" /// RCX register"},492{"lineNum":" 491","line":" RCX,"},493{"lineNum":" 492","line":" /// RDX register"},494{"lineNum":" 493","line":" RDX,"},495{"lineNum":" 494","line":" /// RBX register"},496{"lineNum":" 495","line":" RBX,"},497{"lineNum":" 496","line":" /// RSP register"},498{"lineNum":" 497","line":" RSP,"},499{"lineNum":" 498","line":" /// RBP register"},500{"lineNum":" 499","line":" RBP,"},501{"lineNum":" 500","line":" /// RSI register"},502{"lineNum":" 501","line":" RSI,"},503{"lineNum":" 502","line":" /// RDI register"},504{"lineNum":" 503","line":" RDI,"},505{"lineNum":" 504","line":" /// R8 register"},506{"lineNum":" 505","line":" R8,"},507{"lineNum":" 506","line":" /// R9 register"},508{"lineNum":" 507","line":" R9,"},509{"lineNum":" 508","line":" /// R10 register"},510{"lineNum":" 509","line":" R10,"},511{"lineNum":" 510","line":" /// R11 register"},512{"lineNum":" 511","line":" R11,"},513{"lineNum":" 512","line":" /// R12 register"},514{"lineNum":" 513","line":" R12,"},515{"lineNum":" 514","line":" /// R13 register"},516{"lineNum":" 515","line":" R13,"},517{"lineNum":" 516","line":" /// R14 register"},518{"lineNum":" 517","line":" R14,"},519{"lineNum":" 518","line":" /// R15 register"},520{"lineNum":" 519","line":" R15,"},521{"lineNum":" 520","line":" }"},522{"lineNum":" 521","line":""},523{"lineNum":" 522","line":" /// XMM registers."},524{"lineNum":" 523","line":" #[repr(u8)]"},525{"lineNum":" 524","line":" #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]","class":"lineNoCov","hits":"0","possible_hits":"2",},526{"lineNum":" 525","line":" pub enum XMM {"},527{"lineNum":" 526","line":" /// XMM register 0"},528{"lineNum":" 527","line":" XMM0,"},529{"lineNum":" 528","line":" /// XMM register 1"},530{"lineNum":" 529","line":" XMM1,"},531{"lineNum":" 530","line":" /// XMM register 2"},532{"lineNum":" 531","line":" XMM2,"},533{"lineNum":" 532","line":" /// XMM register 3"},534{"lineNum":" 533","line":" XMM3,"},535{"lineNum":" 534","line":" /// XMM register 4"},536{"lineNum":" 535","line":" XMM4,"},537{"lineNum":" 536","line":" /// XMM register 5"},538{"lineNum":" 537","line":" XMM5,"},539{"lineNum":" 538","line":" /// XMM register 6"},540{"lineNum":" 539","line":" XMM6,"},541{"lineNum":" 540","line":" /// XMM register 7"},542{"lineNum":" 541","line":" XMM7,"},543{"lineNum":" 542","line":" /// XMM register 8"},544{"lineNum":" 543","line":" XMM8,"},545{"lineNum":" 544","line":" /// XMM register 9"},546{"lineNum":" 545","line":" XMM9,"},547{"lineNum":" 546","line":" /// XMM register 10"},548{"lineNum":" 547","line":" XMM10,"},549{"lineNum":" 548","line":" /// XMM register 11"},550{"lineNum":" 549","line":" XMM11,"},551{"lineNum":" 550","line":" /// XMM register 12"},552{"lineNum":" 551","line":" XMM12,"},553{"lineNum":" 552","line":" /// XMM register 13"},554{"lineNum":" 553","line":" XMM13,"},555{"lineNum":" 554","line":" /// XMM register 14"},556{"lineNum":" 555","line":" XMM14,"},557{"lineNum":" 556","line":" /// XMM register 15"},558{"lineNum":" 557","line":" XMM15,"},559{"lineNum":" 558","line":" }"},560{"lineNum":" 559","line":""},561{"lineNum":" 560","line":" /// A machine register under the x86-64 architecture."},562{"lineNum":" 561","line":" #[derive(Copy, Clone, Debug, Eq, PartialEq)]","class":"lineNoCov","hits":"0","possible_hits":"3",},563{"lineNum":" 562","line":" pub enum X64Register {"},564{"lineNum":" 563","line":" /// General-purpose registers."},565{"lineNum":" 564","line":" GPR(GPR),","class":"lineNoCov","hits":"0","possible_hits":"1",},566{"lineNum":" 565","line":" /// XMM (floating point/SIMD) registers."},567{"lineNum":" 566","line":" XMM(XMM),","class":"lineNoCov","hits":"0","possible_hits":"1",},568{"lineNum":" 567","line":" }"},569{"lineNum":" 568","line":""},570{"lineNum":" 569","line":" impl X64Register {"},571{"lineNum":" 570","line":" /// Returns the index of the register."},572{"lineNum":" 571","line":" pub fn to_index(&self) -> RegisterIndex {","class":"lineNoCov","hits":"0","possible_hits":"1",},573{"lineNum":" 572","line":" match *self {","class":"lineNoCov","hits":"0","possible_hits":"2",},574{"lineNum":" 573","line":" X64Register::GPR(x) => RegisterIndex(x as usize),","class":"lineNoCov","hits":"0","possible_hits":"2",},575{"lineNum":" 574","line":" X64Register::XMM(x) => RegisterIndex(x as usize + 16),","class":"lineNoCov","hits":"0","possible_hits":"3",},576{"lineNum":" 575","line":" }"},577{"lineNum":" 576","line":" }","class":"lineNoCov","hits":"0","possible_hits":"1",},578{"lineNum":" 577","line":""},579{"lineNum":" 578","line":" /// Converts a DWARD regnum to X64Register."},580{"lineNum":" 579","line":" pub fn from_dwarf_regnum(x: u16) -> Option<X64Register> {","class":"lineNoCov","hits":"0","possible_hits":"1",},581{"lineNum":" 580","line":" Some(match x {","class":"lineNoCov","hits":"0","possible_hits":"25",},582{"lineNum":" 581","line":" 0 => X64Register::GPR(GPR::RAX),","class":"lineNoCov","hits":"0","possible_hits":"2",},583{"lineNum":" 582","line":" 1 => X64Register::GPR(GPR::RDX),","class":"lineNoCov","hits":"0","possible_hits":"1",},584{"lineNum":" 583","line":" 2 => X64Register::GPR(GPR::RCX),","class":"lineNoCov","hits":"0","possible_hits":"1",},585{"lineNum":" 584","line":" 3 => X64Register::GPR(GPR::RBX),","class":"lineNoCov","hits":"0","possible_hits":"1",},586{"lineNum":" 585","line":" 4 => X64Register::GPR(GPR::RSI),","class":"lineNoCov","hits":"0","possible_hits":"1",},587{"lineNum":" 586","line":" 5 => X64Register::GPR(GPR::RDI),","class":"lineNoCov","hits":"0","possible_hits":"1",},588{"lineNum":" 587","line":" 6 => X64Register::GPR(GPR::RBP),","class":"lineNoCov","hits":"0","possible_hits":"1",},589{"lineNum":" 588","line":" 7 => X64Register::GPR(GPR::RSP),","class":"lineNoCov","hits":"0","possible_hits":"1",},590{"lineNum":" 589","line":" 8 => X64Register::GPR(GPR::R8),","class":"lineNoCov","hits":"0","possible_hits":"1",},591{"lineNum":" 590","line":" 9 => X64Register::GPR(GPR::R9),","class":"lineNoCov","hits":"0","possible_hits":"1",},592{"lineNum":" 591","line":" 10 => X64Register::GPR(GPR::R10),","class":"lineNoCov","hits":"0","possible_hits":"1",},593{"lineNum":" 592","line":" 11 => X64Register::GPR(GPR::R11),","class":"lineNoCov","hits":"0","possible_hits":"1",},594{"lineNum":" 593","line":" 12 => X64Register::GPR(GPR::R12),","class":"lineNoCov","hits":"0","possible_hits":"1",},595{"lineNum":" 594","line":" 13 => X64Register::GPR(GPR::R13),","class":"lineNoCov","hits":"0","possible_hits":"1",},596{"lineNum":" 595","line":" 14 => X64Register::GPR(GPR::R14),","class":"lineNoCov","hits":"0","possible_hits":"1",},597{"lineNum":" 596","line":" 15 => X64Register::GPR(GPR::R15),","class":"lineNoCov","hits":"0","possible_hits":"1",},598{"lineNum":" 597","line":""},599{"lineNum":" 598","line":" 17 => X64Register::XMM(XMM::XMM0),","class":"lineNoCov","hits":"0","possible_hits":"1",},600{"lineNum":" 599","line":" 18 => X64Register::XMM(XMM::XMM1),","class":"lineNoCov","hits":"0","possible_hits":"1",},601{"lineNum":" 600","line":" 19 => X64Register::XMM(XMM::XMM2),","class":"lineNoCov","hits":"0","possible_hits":"1",},602{"lineNum":" 601","line":" 20 => X64Register::XMM(XMM::XMM3),","class":"lineNoCov","hits":"0","possible_hits":"1",},603{"lineNum":" 602","line":" 21 => X64Register::XMM(XMM::XMM4),","class":"lineNoCov","hits":"0","possible_hits":"1",},604{"lineNum":" 603","line":" 22 => X64Register::XMM(XMM::XMM5),","class":"lineNoCov","hits":"0","possible_hits":"1",},605{"lineNum":" 604","line":" 23 => X64Register::XMM(XMM::XMM6),","class":"lineNoCov","hits":"0","possible_hits":"1",},606{"lineNum":" 605","line":" 24 => X64Register::XMM(XMM::XMM7),","class":"lineNoCov","hits":"0","possible_hits":"1",},607{"lineNum":" 606","line":" _ => return None,","class":"lineNoCov","hits":"0","possible_hits":"1",},608{"lineNum":" 607","line":" })"},609{"lineNum":" 608","line":" }","class":"lineNoCov","hits":"0","possible_hits":"3",},610{"lineNum":" 609","line":" }"},611{"lineNum":" 610","line":"}"},612{"lineNum":" 611","line":""},613{"lineNum":" 612","line":"#[cfg(unix)]"},614{"lineNum":" 613","line":"pub mod x64 {"},615{"lineNum":" 614","line":" //! The x64 state module contains functions to generate state and code for x64 targets."},616{"lineNum":" 615","line":" pub use super::x64_decl::*;"},617{"lineNum":" 616","line":" use super::*;"},618{"lineNum":" 617","line":" use crate::codegen::BreakpointMap;"},619{"lineNum":" 618","line":" use crate::fault::{"},620{"lineNum":" 619","line":" catch_unsafe_unwind, get_boundary_register_preservation, run_on_alternative_stack,"},621{"lineNum":" 620","line":" };"},622{"lineNum":" 621","line":" use crate::structures::TypedIndex;"},623{"lineNum":" 622","line":" use crate::types::LocalGlobalIndex;"},624{"lineNum":" 623","line":" use crate::vm::Ctx;"},625{"lineNum":" 624","line":" use std::any::Any;"},626{"lineNum":" 625","line":""},627{"lineNum":" 626","line":" unsafe fn compute_vmctx_deref(vmctx: *const Ctx, seq: &[usize]) -> u64 {"},628{"lineNum":" 627","line":" let mut ptr = &vmctx as *const *const Ctx as *const u8;"},629{"lineNum":" 628","line":" for x in seq {"},630{"lineNum":" 629","line":" ptr = (*(ptr as *const *const u8)).offset(*x as isize);"},631{"lineNum":" 630","line":" }"},632{"lineNum":" 631","line":" ptr as usize as u64"},633{"lineNum":" 632","line":" }"},634{"lineNum":" 633","line":""},635{"lineNum":" 634","line":" /// Create a new `MachineState` with default values."},636{"lineNum":" 635","line":" pub fn new_machine_state() -> MachineState {","class":"lineNoCov","hits":"0","possible_hits":"2",},637{"lineNum":" 636","line":" MachineState {","class":"lineNoCov","hits":"0","possible_hits":"1",},638{"lineNum":" 637","line":" stack_values: vec![],","class":"lineNoCov","hits":"0","possible_hits":"1",},639{"lineNum":" 638","line":" register_values: vec![MachineValue::Undefined; 16 + 8],","class":"lineNoCov","hits":"0","possible_hits":"3",},640{"lineNum":" 639","line":" prev_frame: BTreeMap::new(),","class":"lineNoCov","hits":"0","possible_hits":"1",},641{"lineNum":" 640","line":" wasm_stack: vec![],","class":"lineNoCov","hits":"0","possible_hits":"1",},642{"lineNum":" 641","line":" wasm_stack_private_depth: 0,"},643{"lineNum":" 642","line":" wasm_inst_offset: ::std::usize::MAX,"},644{"lineNum":" 643","line":" }","class":"lineNoCov","hits":"0","possible_hits":"3",},645{"lineNum":" 644","line":" }","class":"lineNoCov","hits":"0","possible_hits":"1",},646{"lineNum":" 645","line":""},647{"lineNum":" 646","line":" /// Invokes a call return on the stack for the given module state map, code base, instance"},648{"lineNum":" 647","line":" /// image and context."},649{"lineNum":" 648","line":" #[warn(unused_variables)]"},650{"lineNum":" 649","line":" pub unsafe fn invoke_call_return_on_stack("},651{"lineNum":" 650","line":" msm: &ModuleStateMap,"},652{"lineNum":" 651","line":" code_base: usize,"},653{"lineNum":" 652","line":" image: InstanceImage,"},654{"lineNum":" 653","line":" vmctx: &mut Ctx,"},655{"lineNum":" 654","line":" breakpoints: Option<BreakpointMap>,"},656{"lineNum":" 655","line":" ) -> Result<u64, Box<dyn Any>> {"},657{"lineNum":" 656","line":" let mut stack: Vec<u64> = vec![0; 1048576 * 8 / 8]; // 8MB stack"},658{"lineNum":" 657","line":" let mut stack_offset: usize = stack.len();"},659{"lineNum":" 658","line":""},660{"lineNum":" 659","line":" stack_offset -= 3; // placeholder for call return"},661{"lineNum":" 660","line":""},662{"lineNum":" 661","line":" let mut last_stack_offset: u64 = 0; // rbp"},663{"lineNum":" 662","line":""},664{"lineNum":" 663","line":" let mut known_registers: [Option<u64>; 32] = [None; 32];"},665{"lineNum":" 664","line":""},666{"lineNum":" 665","line":" let local_functions_vec: Vec<&FunctionStateMap> ="},667{"lineNum":" 666","line":" msm.local_functions.iter().map(|(_, v)| v).collect();"},668{"lineNum":" 667","line":""},669{"lineNum":" 668","line":" // Bottom to top"},670{"lineNum":" 669","line":" for f in image.execution_state.frames.iter().rev() {"},671{"lineNum":" 670","line":" let fsm = local_functions_vec[f.local_function_id];"},672{"lineNum":" 671","line":" let suspend_offset = if f.wasm_inst_offset == ::std::usize::MAX {"},673{"lineNum":" 672","line":" fsm.wasm_function_header_target_offset"},674{"lineNum":" 673","line":" } else {"},675{"lineNum":" 674","line":" fsm.wasm_offset_to_target_offset"},676{"lineNum":" 675","line":" .get(&f.wasm_inst_offset)"},677{"lineNum":" 676","line":" .map(|x| *x)"},678{"lineNum":" 677","line":" }"},679{"lineNum":" 678","line":" .expect(\"instruction is not a critical point\");"},680{"lineNum":" 679","line":""},681{"lineNum":" 680","line":" let (activate_offset, diff_id) = match suspend_offset {"},682{"lineNum":" 681","line":" SuspendOffset::Loop(x) => fsm.loop_offsets.get(&x),"},683{"lineNum":" 682","line":" SuspendOffset::Call(x) => fsm.call_offsets.get(&x),"},684{"lineNum":" 683","line":" SuspendOffset::Trappable(x) => fsm.trappable_offsets.get(&x),"},685{"lineNum":" 684","line":" }"},686{"lineNum":" 685","line":" .map(|x| (x.activate_offset, x.diff_id))"},687{"lineNum":" 686","line":" .expect(\"offset cannot be found in table\");"},688{"lineNum":" 687","line":""},689{"lineNum":" 688","line":" let diff = &fsm.diffs[diff_id];"},690{"lineNum":" 689","line":" let state = diff.build_state(fsm);"},691{"lineNum":" 690","line":""},692{"lineNum":" 691","line":" stack_offset -= 1;"},693{"lineNum":" 692","line":" stack[stack_offset] = stack.as_ptr().offset(last_stack_offset as isize) as usize as u64; // push rbp"},694{"lineNum":" 693","line":" last_stack_offset = stack_offset as _;"},695{"lineNum":" 694","line":""},696{"lineNum":" 695","line":" let mut got_explicit_shadow = false;"},697{"lineNum":" 696","line":""},698{"lineNum":" 697","line":" for v in state.stack_values.iter() {"},699{"lineNum":" 698","line":" match *v {"},700{"lineNum":" 699","line":" MachineValue::Undefined => stack_offset -= 1,"},701{"lineNum":" 700","line":" MachineValue::Vmctx => {"},702{"lineNum":" 701","line":" stack_offset -= 1;"},703{"lineNum":" 702","line":" stack[stack_offset] = vmctx as *mut Ctx as usize as u64;"},704{"lineNum":" 703","line":" }"},705{"lineNum":" 704","line":" MachineValue::VmctxDeref(ref seq) => {"},706{"lineNum":" 705","line":" stack_offset -= 1;"},707{"lineNum":" 706","line":" stack[stack_offset] = compute_vmctx_deref(vmctx as *const Ctx, seq);"},708{"lineNum":" 707","line":" }"},709{"lineNum":" 708","line":" MachineValue::PreserveRegister(index) => {"},710{"lineNum":" 709","line":" stack_offset -= 1;"},711{"lineNum":" 710","line":" stack[stack_offset] = known_registers[index.0].unwrap_or(0);"},712{"lineNum":" 711","line":" }"},713{"lineNum":" 712","line":" MachineValue::CopyStackBPRelative(byte_offset) => {"},714{"lineNum":" 713","line":" assert!(byte_offset % 8 == 0);"},715{"lineNum":" 714","line":" let target_offset = (byte_offset / 8) as isize;"},716{"lineNum":" 715","line":" let v = stack[(last_stack_offset as isize + target_offset) as usize];"},717{"lineNum":" 716","line":" stack_offset -= 1;"},718{"lineNum":" 717","line":" stack[stack_offset] = v;"},719{"lineNum":" 718","line":" }"},720{"lineNum":" 719","line":" MachineValue::ExplicitShadow => {"},721{"lineNum":" 720","line":" assert!(fsm.shadow_size % 8 == 0);"},722{"lineNum":" 721","line":" stack_offset -= fsm.shadow_size / 8;"},723{"lineNum":" 722","line":" got_explicit_shadow = true;"},724{"lineNum":" 723","line":" }"},725{"lineNum":" 724","line":" MachineValue::WasmStack(x) => {"},726{"lineNum":" 725","line":" stack_offset -= 1;"},727{"lineNum":" 726","line":" match state.wasm_stack[x] {"},728{"lineNum":" 727","line":" WasmAbstractValue::Const(x) => {"},729{"lineNum":" 728","line":" stack[stack_offset] = x;"},730{"lineNum":" 729","line":" }"},731{"lineNum":" 730","line":" WasmAbstractValue::Runtime => {"},732{"lineNum":" 731","line":" stack[stack_offset] = f.stack[x].unwrap();"},733{"lineNum":" 732","line":" }"},734{"lineNum":" 733","line":" }"},735{"lineNum":" 734","line":" }"},736{"lineNum":" 735","line":" MachineValue::WasmLocal(x) => {"},737{"lineNum":" 736","line":" stack_offset -= 1;"},738{"lineNum":" 737","line":" match fsm.locals[x] {"},739{"lineNum":" 738","line":" WasmAbstractValue::Const(x) => {"},740{"lineNum":" 739","line":" stack[stack_offset] = x;"},741{"lineNum":" 740","line":" }"},742{"lineNum":" 741","line":" WasmAbstractValue::Runtime => {"},743{"lineNum":" 742","line":" stack[stack_offset] = f.locals[x].unwrap();"},744{"lineNum":" 743","line":" }"},745{"lineNum":" 744","line":" }"},746{"lineNum":" 745","line":" }"},747{"lineNum":" 746","line":" MachineValue::TwoHalves(ref inner) => {"},748{"lineNum":" 747","line":" stack_offset -= 1;"},749{"lineNum":" 748","line":" // TODO: Cleanup"},750{"lineNum":" 749","line":" match inner.0 {"},751{"lineNum":" 750","line":" MachineValue::WasmStack(x) => match state.wasm_stack[x] {"},752{"lineNum":" 751","line":" WasmAbstractValue::Const(x) => {"},753{"lineNum":" 752","line":" assert!(x <= std::u32::MAX as u64);"},754{"lineNum":" 753","line":" stack[stack_offset] |= x;"},755{"lineNum":" 754","line":" }"},756{"lineNum":" 755","line":" WasmAbstractValue::Runtime => {"},757{"lineNum":" 756","line":" let v = f.stack[x].unwrap();"},758{"lineNum":" 757","line":" assert!(v <= std::u32::MAX as u64);"},759{"lineNum":" 758","line":" stack[stack_offset] |= v;"},760{"lineNum":" 759","line":" }"},761{"lineNum":" 760","line":" },"},762{"lineNum":" 761","line":" MachineValue::WasmLocal(x) => match fsm.locals[x] {"},763{"lineNum":" 762","line":" WasmAbstractValue::Const(x) => {"},764{"lineNum":" 763","line":" assert!(x <= std::u32::MAX as u64);"},765{"lineNum":" 764","line":" stack[stack_offset] |= x;"},766{"lineNum":" 765","line":" }"},767{"lineNum":" 766","line":" WasmAbstractValue::Runtime => {"},768{"lineNum":" 767","line":" let v = f.locals[x].unwrap();"},769{"lineNum":" 768","line":" assert!(v <= std::u32::MAX as u64);"},770{"lineNum":" 769","line":" stack[stack_offset] |= v;"},771{"lineNum":" 770","line":" }"},772{"lineNum":" 771","line":" },"},773{"lineNum":" 772","line":" MachineValue::VmctxDeref(ref seq) => {"},774{"lineNum":" 773","line":" stack[stack_offset] |="},775{"lineNum":" 774","line":" compute_vmctx_deref(vmctx as *const Ctx, seq)"},776{"lineNum":" 775","line":" & (std::u32::MAX as u64);"},777{"lineNum":" 776","line":" }"},778{"lineNum":" 777","line":" MachineValue::Undefined => {}"},779{"lineNum":" 778","line":" _ => unimplemented!(\"TwoHalves.0\"),"},780{"lineNum":" 779","line":" }"},781{"lineNum":" 780","line":" match inner.1 {"},782{"lineNum":" 781","line":" MachineValue::WasmStack(x) => match state.wasm_stack[x] {"},783{"lineNum":" 782","line":" WasmAbstractValue::Const(x) => {"},784{"lineNum":" 783","line":" assert!(x <= std::u32::MAX as u64);"},785{"lineNum":" 784","line":" stack[stack_offset] |= x << 32;"},786{"lineNum":" 785","line":" }"},787{"lineNum":" 786","line":" WasmAbstractValue::Runtime => {"},788{"lineNum":" 787","line":" let v = f.stack[x].unwrap();"},789{"lineNum":" 788","line":" assert!(v <= std::u32::MAX as u64);"},790{"lineNum":" 789","line":" stack[stack_offset] |= v << 32;"},791{"lineNum":" 790","line":" }"},792{"lineNum":" 791","line":" },"},793{"lineNum":" 792","line":" MachineValue::WasmLocal(x) => match fsm.locals[x] {"},794{"lineNum":" 793","line":" WasmAbstractValue::Const(x) => {"},795{"lineNum":" 794","line":" assert!(x <= std::u32::MAX as u64);"},796{"lineNum":" 795","line":" stack[stack_offset] |= x << 32;"},797{"lineNum":" 796","line":" }"},798{"lineNum":" 797","line":" WasmAbstractValue::Runtime => {"},799{"lineNum":" 798","line":" let v = f.locals[x].unwrap();"},800{"lineNum":" 799","line":" assert!(v <= std::u32::MAX as u64);"},801{"lineNum":" 800","line":" stack[stack_offset] |= v << 32;"},802{"lineNum":" 801","line":" }"},803{"lineNum":" 802","line":" },"},804{"lineNum":" 803","line":" MachineValue::VmctxDeref(ref seq) => {"},805{"lineNum":" 804","line":" stack[stack_offset] |="},806{"lineNum":" 805","line":" (compute_vmctx_deref(vmctx as *const Ctx, seq)"},807{"lineNum":" 806","line":" & (std::u32::MAX as u64))"},808{"lineNum":" 807","line":" << 32;"},809{"lineNum":" 808","line":" }"},810{"lineNum":" 809","line":" MachineValue::Undefined => {}"},811{"lineNum":" 810","line":" _ => unimplemented!(\"TwoHalves.1\"),"},812{"lineNum":" 811","line":" }"},813{"lineNum":" 812","line":" }"},814{"lineNum":" 813","line":" }"},815{"lineNum":" 814","line":" }"},816{"lineNum":" 815","line":" if !got_explicit_shadow {"},817{"lineNum":" 816","line":" assert!(fsm.shadow_size % 8 == 0);"},818{"lineNum":" 817","line":" stack_offset -= fsm.shadow_size / 8;"},819{"lineNum":" 818","line":" }"},820{"lineNum":" 819","line":" for (i, v) in state.register_values.iter().enumerate() {"},821{"lineNum":" 820","line":" match *v {"},822{"lineNum":" 821","line":" MachineValue::Undefined => {}"},823{"lineNum":" 822","line":" MachineValue::Vmctx => {"},824{"lineNum":" 823","line":" known_registers[i] = Some(vmctx as *mut Ctx as usize as u64);"},825{"lineNum":" 824","line":" }"},826{"lineNum":" 825","line":" MachineValue::VmctxDeref(ref seq) => {"},827{"lineNum":" 826","line":" known_registers[i] = Some(compute_vmctx_deref(vmctx as *const Ctx, seq));"},828{"lineNum":" 827","line":" }"},829{"lineNum":" 828","line":" MachineValue::WasmStack(x) => match state.wasm_stack[x] {"},830{"lineNum":" 829","line":" WasmAbstractValue::Const(x) => {"},831{"lineNum":" 830","line":" known_registers[i] = Some(x);"},832{"lineNum":" 831","line":" }"},833{"lineNum":" 832","line":" WasmAbstractValue::Runtime => {"},834{"lineNum":" 833","line":" known_registers[i] = Some(f.stack[x].unwrap());"},835{"lineNum":" 834","line":" }"},836{"lineNum":" 835","line":" },"},837{"lineNum":" 836","line":" MachineValue::WasmLocal(x) => match fsm.locals[x] {"},838{"lineNum":" 837","line":" WasmAbstractValue::Const(x) => {"},839{"lineNum":" 838","line":" known_registers[i] = Some(x);"},840{"lineNum":" 839","line":" }"},841{"lineNum":" 840","line":" WasmAbstractValue::Runtime => {"},842{"lineNum":" 841","line":" known_registers[i] = Some(f.locals[x].unwrap());"},843{"lineNum":" 842","line":" }"},844{"lineNum":" 843","line":" },"},845{"lineNum":" 844","line":" _ => unreachable!(),"},846{"lineNum":" 845","line":" }"},847{"lineNum":" 846","line":" }"},848{"lineNum":" 847","line":""},849{"lineNum":" 848","line":" // no need to check 16-byte alignment here because it\'s possible that we\'re not at a call entry."},850{"lineNum":" 849","line":""},851{"lineNum":" 850","line":" stack_offset -= 1;"},852{"lineNum":" 851","line":" stack[stack_offset] = (code_base + activate_offset) as u64; // return address"},853{"lineNum":" 852","line":" }"},854{"lineNum":" 853","line":""},855{"lineNum":" 854","line":" stack_offset -= 1;"},856{"lineNum":" 855","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::R15).to_index().0].unwrap_or(0);"},857{"lineNum":" 856","line":""},858{"lineNum":" 857","line":" stack_offset -= 1;"},859{"lineNum":" 858","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::R14).to_index().0].unwrap_or(0);"},860{"lineNum":" 859","line":""},861{"lineNum":" 860","line":" stack_offset -= 1;"},862{"lineNum":" 861","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::R13).to_index().0].unwrap_or(0);"},863{"lineNum":" 862","line":""},864{"lineNum":" 863","line":" stack_offset -= 1;"},865{"lineNum":" 864","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::R12).to_index().0].unwrap_or(0);"},866{"lineNum":" 865","line":""},867{"lineNum":" 866","line":" stack_offset -= 1;"},868{"lineNum":" 867","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::R11).to_index().0].unwrap_or(0);"},869{"lineNum":" 868","line":""},870{"lineNum":" 869","line":" stack_offset -= 1;"},871{"lineNum":" 870","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::R10).to_index().0].unwrap_or(0);"},872{"lineNum":" 871","line":""},873{"lineNum":" 872","line":" stack_offset -= 1;"},874{"lineNum":" 873","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::R9).to_index().0].unwrap_or(0);"},875{"lineNum":" 874","line":""},876{"lineNum":" 875","line":" stack_offset -= 1;"},877{"lineNum":" 876","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::R8).to_index().0].unwrap_or(0);"},878{"lineNum":" 877","line":""},879{"lineNum":" 878","line":" stack_offset -= 1;"},880{"lineNum":" 879","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::RSI).to_index().0].unwrap_or(0);"},881{"lineNum":" 880","line":""},882{"lineNum":" 881","line":" stack_offset -= 1;"},883{"lineNum":" 882","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::RDI).to_index().0].unwrap_or(0);"},884{"lineNum":" 883","line":""},885{"lineNum":" 884","line":" stack_offset -= 1;"},886{"lineNum":" 885","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::RDX).to_index().0].unwrap_or(0);"},887{"lineNum":" 886","line":""},888{"lineNum":" 887","line":" stack_offset -= 1;"},889{"lineNum":" 888","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::RCX).to_index().0].unwrap_or(0);"},890{"lineNum":" 889","line":""},891{"lineNum":" 890","line":" stack_offset -= 1;"},892{"lineNum":" 891","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::RBX).to_index().0].unwrap_or(0);"},893{"lineNum":" 892","line":""},894{"lineNum":" 893","line":" stack_offset -= 1;"},895{"lineNum":" 894","line":" stack[stack_offset] = known_registers[X64Register::GPR(GPR::RAX).to_index().0].unwrap_or(0);"},896{"lineNum":" 895","line":""},897{"lineNum":" 896","line":" stack_offset -= 1;"},898{"lineNum":" 897","line":" stack[stack_offset] = stack.as_ptr().offset(last_stack_offset as isize) as usize as u64; // rbp"},899{"lineNum":" 898","line":""},900{"lineNum":" 899","line":" stack_offset -= 1;"},901{"lineNum":" 900","line":" stack[stack_offset] ="},902{"lineNum":" 901","line":" known_registers[X64Register::XMM(XMM::XMM15).to_index().0].unwrap_or(0);"},903{"lineNum":" 902","line":""},904{"lineNum":" 903","line":" stack_offset -= 1;"},905{"lineNum":" 904","line":" stack[stack_offset] ="},906{"lineNum":" 905","line":" known_registers[X64Register::XMM(XMM::XMM14).to_index().0].unwrap_or(0);"},907{"lineNum":" 906","line":""},908{"lineNum":" 907","line":" stack_offset -= 1;"},909{"lineNum":" 908","line":" stack[stack_offset] ="},910{"lineNum":" 909","line":" known_registers[X64Register::XMM(XMM::XMM13).to_index().0].unwrap_or(0);"},911{"lineNum":" 910","line":""},912{"lineNum":" 911","line":" stack_offset -= 1;"},913{"lineNum":" 912","line":" stack[stack_offset] ="},914{"lineNum":" 913","line":" known_registers[X64Register::XMM(XMM::XMM12).to_index().0].unwrap_or(0);"},915{"lineNum":" 914","line":""},916{"lineNum":" 915","line":" stack_offset -= 1;"},917{"lineNum":" 916","line":" stack[stack_offset] ="},918{"lineNum":" 917","line":" known_registers[X64Register::XMM(XMM::XMM11).to_index().0].unwrap_or(0);"},919{"lineNum":" 918","line":""},920{"lineNum":" 919","line":" stack_offset -= 1;"},921{"lineNum":" 920","line":" stack[stack_offset] ="},922{"lineNum":" 921","line":" known_registers[X64Register::XMM(XMM::XMM10).to_index().0].unwrap_or(0);"},923{"lineNum":" 922","line":""},924{"lineNum":" 923","line":" stack_offset -= 1;"},925{"lineNum":" 924","line":" stack[stack_offset] ="},926{"lineNum":" 925","line":" known_registers[X64Register::XMM(XMM::XMM9).to_index().0].unwrap_or(0);"},927{"lineNum":" 926","line":""},928{"lineNum":" 927","line":" stack_offset -= 1;"},929{"lineNum":" 928","line":" stack[stack_offset] ="},930{"lineNum":" 929","line":" known_registers[X64Register::XMM(XMM::XMM8).to_index().0].unwrap_or(0);"},931{"lineNum":" 930","line":" stack_offset -= 1;"},932{"lineNum":" 931","line":" stack[stack_offset] ="},933{"lineNum":" 932","line":" known_registers[X64Register::XMM(XMM::XMM7).to_index().0].unwrap_or(0);"},934{"lineNum":" 933","line":""},935{"lineNum":" 934","line":" stack_offset -= 1;"},936{"lineNum":" 935","line":" stack[stack_offset] ="},937{"lineNum":" 936","line":" known_registers[X64Register::XMM(XMM::XMM6).to_index().0].unwrap_or(0);"},938{"lineNum":" 937","line":""},939{"lineNum":" 938","line":" stack_offset -= 1;"},940{"lineNum":" 939","line":" stack[stack_offset] ="},941{"lineNum":" 940","line":" known_registers[X64Register::XMM(XMM::XMM5).to_index().0].unwrap_or(0);"},942{"lineNum":" 941","line":""},943{"lineNum":" 942","line":" stack_offset -= 1;"},944{"lineNum":" 943","line":" stack[stack_offset] ="},945{"lineNum":" 944","line":" known_registers[X64Register::XMM(XMM::XMM4).to_index().0].unwrap_or(0);"},946{"lineNum":" 945","line":""},947{"lineNum":" 946","line":" stack_offset -= 1;"},948{"lineNum":" 947","line":" stack[stack_offset] ="},949{"lineNum":" 948","line":" known_registers[X64Register::XMM(XMM::XMM3).to_index().0].unwrap_or(0);"},950{"lineNum":" 949","line":""},951{"lineNum":" 950","line":" stack_offset -= 1;"},952{"lineNum":" 951","line":" stack[stack_offset] ="},953{"lineNum":" 952","line":" known_registers[X64Register::XMM(XMM::XMM2).to_index().0].unwrap_or(0);"},954{"lineNum":" 953","line":""},955{"lineNum":" 954","line":" stack_offset -= 1;"},956{"lineNum":" 955","line":" stack[stack_offset] ="},957{"lineNum":" 956","line":" known_registers[X64Register::XMM(XMM::XMM1).to_index().0].unwrap_or(0);"},958{"lineNum":" 957","line":""},959{"lineNum":" 958","line":" stack_offset -= 1;"},960{"lineNum":" 959","line":" stack[stack_offset] ="},961{"lineNum":" 960","line":" known_registers[X64Register::XMM(XMM::XMM0).to_index().0].unwrap_or(0);"},962{"lineNum":" 961","line":""},963{"lineNum":" 962","line":" if let Some(ref memory) = image.memory {"},964{"lineNum":" 963","line":" assert!(vmctx.internal.memory_bound <= memory.len());"},965{"lineNum":" 964","line":""},966{"lineNum":" 965","line":" if vmctx.internal.memory_bound < memory.len() {"},967{"lineNum":" 966","line":" let grow: unsafe extern \"C\" fn(ctx: &mut Ctx, memory_index: usize, delta: usize) ="},968{"lineNum":" 967","line":" ::std::mem::transmute((*vmctx.internal.intrinsics).memory_grow);"},969{"lineNum":" 968","line":" grow("},970{"lineNum":" 969","line":" vmctx,"},971{"lineNum":" 970","line":" 0,"},972{"lineNum":" 971","line":" (memory.len() - vmctx.internal.memory_bound) / 65536,"},973{"lineNum":" 972","line":" );"},974{"lineNum":" 973","line":" assert_eq!(vmctx.internal.memory_bound, memory.len());"},975{"lineNum":" 974","line":" }"},976{"lineNum":" 975","line":""},977{"lineNum":" 976","line":" std::slice::from_raw_parts_mut(vmctx.internal.memory_base, vmctx.internal.memory_bound)"},978{"lineNum":" 977","line":" .copy_from_slice(memory);"},979{"lineNum":" 978","line":" }"},980{"lineNum":" 979","line":""},981{"lineNum":" 980","line":" let globals_len = (*vmctx.module).info.globals.len();"},982{"lineNum":" 981","line":" for i in 0..globals_len {"},983{"lineNum":" 982","line":" (*(*vmctx.local_backing).globals[LocalGlobalIndex::new(i)].vm_local_global()).data ="},984{"lineNum":" 983","line":" image.globals[i];"},985{"lineNum":" 984","line":" }"},986{"lineNum":" 985","line":""},987{"lineNum":" 986","line":" drop(image); // free up host memory"},988{"lineNum":" 987","line":""},989{"lineNum":" 988","line":" catch_unsafe_unwind("},990{"lineNum":" 989","line":" || {"},991{"lineNum":" 990","line":" run_on_alternative_stack("},992{"lineNum":" 991","line":" stack.as_mut_ptr().offset(stack.len() as isize),"},993{"lineNum":" 992","line":" stack.as_mut_ptr().offset(stack_offset as isize),"},994{"lineNum":" 993","line":" )"},995{"lineNum":" 994","line":" },"},996{"lineNum":" 995","line":" breakpoints,"},997{"lineNum":" 996","line":" )"},998{"lineNum":" 997","line":" }"},999{"lineNum":" 998","line":""},1000{"lineNum":" 999","line":" /// Builds an `InstanceImage` for the given `Ctx` and `ExecutionStateImage`."},1001{"lineNum":" 1000","line":" pub fn build_instance_image("},1002{"lineNum":" 1001","line":" vmctx: &mut Ctx,"},1003{"lineNum":" 1002","line":" execution_state: ExecutionStateImage,"},1004{"lineNum":" 1003","line":" ) -> InstanceImage {"},1005{"lineNum":" 1004","line":" unsafe {"},1006{"lineNum":" 1005","line":" let memory = if vmctx.internal.memory_base.is_null() {"},1007{"lineNum":" 1006","line":" None"},1008{"lineNum":" 1007","line":" } else {"},1009{"lineNum":" 1008","line":" Some("},1010{"lineNum":" 1009","line":" std::slice::from_raw_parts("},1011{"lineNum":" 1010","line":" vmctx.internal.memory_base,"},1012{"lineNum":" 1011","line":" vmctx.internal.memory_bound,"},1013{"lineNum":" 1012","line":" )"},1014{"lineNum":" 1013","line":" .to_vec(),"},1015{"lineNum":" 1014","line":" )"},1016{"lineNum":" 1015","line":" };"},1017{"lineNum":" 1016","line":""},1018{"lineNum":" 1017","line":" // FIXME: Imported globals"},1019{"lineNum":" 1018","line":" let globals_len = (*vmctx.module).info.globals.len();"},1020{"lineNum":" 1019","line":" let globals: Vec<u128> = (0..globals_len)"},1021{"lineNum":" 1020","line":" .map(|i| {"},1022{"lineNum":" 1021","line":" (*vmctx.local_backing).globals[LocalGlobalIndex::new(i)]"},1023{"lineNum":" 1022","line":" .get()"},1024{"lineNum":" 1023","line":" .to_u128()"},1025{"lineNum":" 1024","line":" })"},1026{"lineNum":" 1025","line":" .collect();"},1027{"lineNum":" 1026","line":""},1028{"lineNum":" 1027","line":" InstanceImage {"},1029{"lineNum":" 1028","line":" memory: memory,"},1030{"lineNum":" 1029","line":" globals: globals,"},1031{"lineNum":" 1030","line":" execution_state: execution_state,"},1032{"lineNum":" 1031","line":" }"},1033{"lineNum":" 1032","line":" }"},1034{"lineNum":" 1033","line":" }"},1035{"lineNum":" 1034","line":""},1036{"lineNum":" 1035","line":" /// Returns a `ExecutionStateImage` for the given versions, stack, initial registers and"},1037{"lineNum":" 1036","line":" /// initial address."},1038{"lineNum":" 1037","line":" #[warn(unused_variables)]"},1039{"lineNum":" 1038","line":" pub unsafe fn read_stack<\'a, I: Iterator<Item = &\'a CodeVersion>, F: Fn() -> I + \'a>("},1040{"lineNum":" 1039","line":" versions: F,"},1041{"lineNum":" 1040","line":" mut stack: *const u64,"},1042{"lineNum":" 1041","line":" initially_known_registers: [Option<u64>; 32],"},1043{"lineNum":" 1042","line":" mut initial_address: Option<u64>,"},1044{"lineNum":" 1043","line":" max_depth: Option<usize>,"},1045{"lineNum":" 1044","line":" ) -> ExecutionStateImage {"},1046{"lineNum":" 1045","line":" let mut known_registers: [Option<u64>; 32] = initially_known_registers;"},1047{"lineNum":" 1046","line":" let mut results: Vec<WasmFunctionStateDump> = vec![];"},1048{"lineNum":" 1047","line":" let mut was_baseline = true;"},1049{"lineNum":" 1048","line":""},1050{"lineNum":" 1049","line":" for depth in 0.. {"},1051{"lineNum":" 1050","line":" if let Some(max_depth) = max_depth {"},1052{"lineNum":" 1051","line":" if depth >= max_depth {"},1053{"lineNum":" 1052","line":" return ExecutionStateImage { frames: results };"},1054{"lineNum":" 1053","line":" }"},1055{"lineNum":" 1054","line":" }"},1056{"lineNum":" 1055","line":""},1057{"lineNum":" 1056","line":" let ret_addr = initial_address.take().unwrap_or_else(|| {"},1058{"lineNum":" 1057","line":" let x = *stack;"},1059{"lineNum":" 1058","line":" stack = stack.offset(1);"},1060{"lineNum":" 1059","line":" x"},1061{"lineNum":" 1060","line":" });"},1062{"lineNum":" 1061","line":""},1063{"lineNum":" 1062","line":" let mut fsm_state: Option<(&FunctionStateMap, MachineState)> = None;"},1064{"lineNum":" 1063","line":" let mut is_baseline: Option<bool> = None;"},1065{"lineNum":" 1064","line":""},1066{"lineNum":" 1065","line":" for version in versions() {"},1067{"lineNum":" 1066","line":" //println!(\"Lookup IP: {:x}\", ret_addr);"},1068{"lineNum":" 1067","line":" match version"},1069{"lineNum":" 1068","line":" .msm"},1070{"lineNum":" 1069","line":" .lookup_call_ip(ret_addr as usize, version.base)"},1071{"lineNum":" 1070","line":" .or_else(|| {"},1072{"lineNum":" 1071","line":" version"},1073{"lineNum":" 1072","line":" .msm"},1074{"lineNum":" 1073","line":" .lookup_trappable_ip(ret_addr as usize, version.base)"},1075{"lineNum":" 1074","line":" })"},1076{"lineNum":" 1075","line":" .or_else(|| version.msm.lookup_loop_ip(ret_addr as usize, version.base))"},1077{"lineNum":" 1076","line":" {"},1078{"lineNum":" 1077","line":" Some(x) => {"},1079{"lineNum":" 1078","line":" fsm_state = Some(x);"},1080{"lineNum":" 1079","line":" is_baseline = Some(version.baseline);"},1081{"lineNum":" 1080","line":" break;"},1082{"lineNum":" 1081","line":" }"},1083{"lineNum":" 1082","line":" None => {}"},1084{"lineNum":" 1083","line":" };"},1085{"lineNum":" 1084","line":" }"},1086{"lineNum":" 1085","line":""},1087{"lineNum":" 1086","line":" let (fsm, state) = if let Some(x) = fsm_state {"},1088{"lineNum":" 1087","line":" x"},1089{"lineNum":" 1088","line":" } else {"},1090{"lineNum":" 1089","line":" return ExecutionStateImage { frames: results };"},1091{"lineNum":" 1090","line":" };"},1092{"lineNum":" 1091","line":""},1093{"lineNum":" 1092","line":" {"},1094{"lineNum":" 1093","line":" let is_baseline = is_baseline.unwrap();"},1095{"lineNum":" 1094","line":""},1096{"lineNum":" 1095","line":" // Are we unwinding through an optimized/baseline boundary?"},1097{"lineNum":" 1096","line":" if is_baseline && !was_baseline {"},1098{"lineNum":" 1097","line":" let callee_saved = &*get_boundary_register_preservation();"},1099{"lineNum":" 1098","line":" known_registers[X64Register::GPR(GPR::R15).to_index().0] ="},1100{"lineNum":" 1099","line":" Some(callee_saved.r15);"},1101{"lineNum":" 1100","line":" known_registers[X64Register::GPR(GPR::R14).to_index().0] ="},1102{"lineNum":" 1101","line":" Some(callee_saved.r14);"},1103{"lineNum":" 1102","line":" known_registers[X64Register::GPR(GPR::R13).to_index().0] ="},1104{"lineNum":" 1103","line":" Some(callee_saved.r13);"},1105{"lineNum":" 1104","line":" known_registers[X64Register::GPR(GPR::R12).to_index().0] ="},1106{"lineNum":" 1105","line":" Some(callee_saved.r12);"},1107{"lineNum":" 1106","line":" known_registers[X64Register::GPR(GPR::RBX).to_index().0] ="},1108{"lineNum":" 1107","line":" Some(callee_saved.rbx);"},1109{"lineNum":" 1108","line":" }"},1110{"lineNum":" 1109","line":""},1111{"lineNum":" 1110","line":" was_baseline = is_baseline;"},1112{"lineNum":" 1111","line":" }"},1113{"lineNum":" 1112","line":""},1114{"lineNum":" 1113","line":" let mut wasm_stack: Vec<Option<u64>> = state"},1115{"lineNum":" 1114","line":" .wasm_stack"},1116{"lineNum":" 1115","line":" .iter()"},1117{"lineNum":" 1116","line":" .map(|x| match *x {"},1118{"lineNum":" 1117","line":" WasmAbstractValue::Const(x) => Some(x),"},1119{"lineNum":" 1118","line":" WasmAbstractValue::Runtime => None,"},1120{"lineNum":" 1119","line":" })"},1121{"lineNum":" 1120","line":" .collect();"},1122{"lineNum":" 1121","line":" let mut wasm_locals: Vec<Option<u64>> = fsm"},1123{"lineNum":" 1122","line":" .locals"},1124{"lineNum":" 1123","line":" .iter()"},1125{"lineNum":" 1124","line":" .map(|x| match *x {"},1126{"lineNum":" 1125","line":" WasmAbstractValue::Const(x) => Some(x),"},1127{"lineNum":" 1126","line":" WasmAbstractValue::Runtime => None,"},1128{"lineNum":" 1127","line":" })"},1129{"lineNum":" 1128","line":" .collect();"},1130{"lineNum":" 1129","line":""},1131{"lineNum":" 1130","line":" // This must be before the next loop because that modifies `known_registers`."},1132{"lineNum":" 1131","line":" for (i, v) in state.register_values.iter().enumerate() {"},1133{"lineNum":" 1132","line":" match *v {"},1134{"lineNum":" 1133","line":" MachineValue::Undefined => {}"},1135{"lineNum":" 1134","line":" MachineValue::Vmctx => {}"},1136{"lineNum":" 1135","line":" MachineValue::VmctxDeref(_) => {}"},1137{"lineNum":" 1136","line":" MachineValue::WasmStack(idx) => {"},1138{"lineNum":" 1137","line":" if let Some(v) = known_registers[i] {"},1139{"lineNum":" 1138","line":" wasm_stack[idx] = Some(v);"},1140{"lineNum":" 1139","line":" } else {"},1141{"lineNum":" 1140","line":" eprintln!("},1142{"lineNum":" 1141","line":" \"BUG: Register {} for WebAssembly stack slot {} has unknown value.\","},1143{"lineNum":" 1142","line":" i, idx"},1144{"lineNum":" 1143","line":" );"},1145{"lineNum":" 1144","line":" }"},1146{"lineNum":" 1145","line":" }"},1147{"lineNum":" 1146","line":" MachineValue::WasmLocal(idx) => {"},1148{"lineNum":" 1147","line":" if let Some(v) = known_registers[i] {"},1149{"lineNum":" 1148","line":" wasm_locals[idx] = Some(v);"},1150{"lineNum":" 1149","line":" }"},1151{"lineNum":" 1150","line":" }"},1152{"lineNum":" 1151","line":" _ => unreachable!(),"},1153{"lineNum":" 1152","line":" }"},1154{"lineNum":" 1153","line":" }"},1155{"lineNum":" 1154","line":""},1156{"lineNum":" 1155","line":" let mut found_shadow = false;"},1157{"lineNum":" 1156","line":" for v in state.stack_values.iter() {"},1158{"lineNum":" 1157","line":" match *v {"},1159{"lineNum":" 1158","line":" MachineValue::ExplicitShadow => {"},1160{"lineNum":" 1159","line":" found_shadow = true;"},1161{"lineNum":" 1160","line":" break;"},1162{"lineNum":" 1161","line":" }"},1163{"lineNum":" 1162","line":" _ => {}"},1164{"lineNum":" 1163","line":" }"},1165{"lineNum":" 1164","line":" }"},1166{"lineNum":" 1165","line":" if !found_shadow {"},1167{"lineNum":" 1166","line":" stack = stack.offset((fsm.shadow_size / 8) as isize);"},1168{"lineNum":" 1167","line":" }"},1169{"lineNum":" 1168","line":""},1170{"lineNum":" 1169","line":" for v in state.stack_values.iter().rev() {"},1171{"lineNum":" 1170","line":" match *v {"},1172{"lineNum":" 1171","line":" MachineValue::ExplicitShadow => {"},1173{"lineNum":" 1172","line":" stack = stack.offset((fsm.shadow_size / 8) as isize);"},1174{"lineNum":" 1173","line":" }"},1175{"lineNum":" 1174","line":" MachineValue::Undefined => {"},1176{"lineNum":" 1175","line":" stack = stack.offset(1);"},1177{"lineNum":" 1176","line":" }"},1178{"lineNum":" 1177","line":" MachineValue::Vmctx => {"},1179{"lineNum":" 1178","line":" stack = stack.offset(1);"},1180{"lineNum":" 1179","line":" }"},1181{"lineNum":" 1180","line":" MachineValue::VmctxDeref(_) => {"},1182{"lineNum":" 1181","line":" stack = stack.offset(1);"},1183{"lineNum":" 1182","line":" }"},1184{"lineNum":" 1183","line":" MachineValue::PreserveRegister(idx) => {"},1185{"lineNum":" 1184","line":" known_registers[idx.0] = Some(*stack);"},1186{"lineNum":" 1185","line":" stack = stack.offset(1);"},1187{"lineNum":" 1186","line":" }"},1188{"lineNum":" 1187","line":" MachineValue::CopyStackBPRelative(_) => {"},1189{"lineNum":" 1188","line":" stack = stack.offset(1);"},1190{"lineNum":" 1189","line":" }"},1191{"lineNum":" 1190","line":" MachineValue::WasmStack(idx) => {"},1192{"lineNum":" 1191","line":" wasm_stack[idx] = Some(*stack);"},1193{"lineNum":" 1192","line":" stack = stack.offset(1);"},1194{"lineNum":" 1193","line":" }"},1195{"lineNum":" 1194","line":" MachineValue::WasmLocal(idx) => {"},1196{"lineNum":" 1195","line":" wasm_locals[idx] = Some(*stack);"},1197{"lineNum":" 1196","line":" stack = stack.offset(1);"},1198{"lineNum":" 1197","line":" }"},1199{"lineNum":" 1198","line":" MachineValue::TwoHalves(ref inner) => {"},1200{"lineNum":" 1199","line":" let v = *stack;"},1201{"lineNum":" 1200","line":" stack = stack.offset(1);"},1202{"lineNum":" 1201","line":" match inner.0 {"},1203{"lineNum":" 1202","line":" MachineValue::WasmStack(idx) => {"},1204{"lineNum":" 1203","line":" wasm_stack[idx] = Some(v & 0xffffffffu64);"},1205{"lineNum":" 1204","line":" }"},1206{"lineNum":" 1205","line":" MachineValue::WasmLocal(idx) => {"},1207{"lineNum":" 1206","line":" wasm_locals[idx] = Some(v & 0xffffffffu64);"},1208{"lineNum":" 1207","line":" }"},1209{"lineNum":" 1208","line":" MachineValue::VmctxDeref(_) => {}"},1210{"lineNum":" 1209","line":" MachineValue::Undefined => {}"},1211{"lineNum":" 1210","line":" _ => unimplemented!(\"TwoHalves.0 (read)\"),"},1212{"lineNum":" 1211","line":" }"},1213{"lineNum":" 1212","line":" match inner.1 {"},1214{"lineNum":" 1213","line":" MachineValue::WasmStack(idx) => {"},1215{"lineNum":" 1214","line":" wasm_stack[idx] = Some(v >> 32);"},1216{"lineNum":" 1215","line":" }"},1217{"lineNum":" 1216","line":" MachineValue::WasmLocal(idx) => {"},1218{"lineNum":" 1217","line":" wasm_locals[idx] = Some(v >> 32);"},1219{"lineNum":" 1218","line":" }"},1220{"lineNum":" 1219","line":" MachineValue::VmctxDeref(_) => {}"},1221{"lineNum":" 1220","line":" MachineValue::Undefined => {}"},1222{"lineNum":" 1221","line":" _ => unimplemented!(\"TwoHalves.1 (read)\"),"},1223{"lineNum":" 1222","line":" }"},1224{"lineNum":" 1223","line":" }"},1225{"lineNum":" 1224","line":" }"},1226{"lineNum":" 1225","line":" }"},1227{"lineNum":" 1226","line":""},1228{"lineNum":" 1227","line":" for (offset, v) in state.prev_frame.iter() {"},1229{"lineNum":" 1228","line":" let offset = (*offset + 2) as isize; // (saved_rbp, return_address)"},1230{"lineNum":" 1229","line":" match *v {"},1231{"lineNum":" 1230","line":" MachineValue::WasmStack(idx) => {"},1232{"lineNum":" 1231","line":" wasm_stack[idx] = Some(*stack.offset(offset));"},1233{"lineNum":" 1232","line":" }"},1234{"lineNum":" 1233","line":" MachineValue::WasmLocal(idx) => {"},1235{"lineNum":" 1234","line":" wasm_locals[idx] = Some(*stack.offset(offset));"},1236{"lineNum":" 1235","line":" }"},1237{"lineNum":" 1236","line":" _ => unreachable!(\"values in prev frame can only be stack/local\"),"},1238{"lineNum":" 1237","line":" }"},1239{"lineNum":" 1238","line":" }"},1240{"lineNum":" 1239","line":" stack = stack.offset(1); // saved_rbp"},1241{"lineNum":" 1240","line":""},1242{"lineNum":" 1241","line":" wasm_stack.truncate("},1243{"lineNum":" 1242","line":" wasm_stack"},1244{"lineNum":" 1243","line":" .len()"},1245{"lineNum":" 1244","line":" .checked_sub(state.wasm_stack_private_depth)"},1246{"lineNum":" 1245","line":" .unwrap(),"},1247{"lineNum":" 1246","line":" );"},1248{"lineNum":" 1247","line":""},1249{"lineNum":" 1248","line":" let wfs = WasmFunctionStateDump {"},1250{"lineNum":" 1249","line":" local_function_id: fsm.local_function_id,"},1251{"lineNum":" 1250","line":" wasm_inst_offset: state.wasm_inst_offset,"},1252{"lineNum":" 1251","line":" stack: wasm_stack,"},1253{"lineNum":" 1252","line":" locals: wasm_locals,"},1254{"lineNum":" 1253","line":" };"},1255{"lineNum":" 1254","line":" //println!(\"WFS = {:?}\", wfs);"},1256{"lineNum":" 1255","line":" results.push(wfs);"},1257{"lineNum":" 1256","line":" }"},1258{"lineNum":" 1257","line":""},1259{"lineNum":" 1258","line":" unreachable!();"},1260{"lineNum":" 1259","line":" }"},1261{"lineNum":" 1260","line":"}"},1262]};1263var percent_low = 25;var percent_high = 75;1264var header = { "command" : "compile_debug", "date" : "2019-11-28 11:37:30", "instrumented" : 106, "covered" : 0,};...

Full Screen

Full Screen

typed_func.rs.f08adfad.js

Source:typed_func.rs.f08adfad.js Github

copy

Full Screen

1var data = {lines:[2{"lineNum":" 1","line":"//! The typed func module implements a way of representing a wasm function"},3{"lineNum":" 2","line":"//! with the correct types from rust. Function calls using a typed func have a low overhead."},4{"lineNum":" 3","line":"use crate::{"},5{"lineNum":" 4","line":" error::RuntimeError,"},6{"lineNum":" 5","line":" export::{Context, Export, FuncPointer},"},7{"lineNum":" 6","line":" import::IsExport,"},8{"lineNum":" 7","line":" types::{FuncSig, NativeWasmType, Type, WasmExternType},"},9{"lineNum":" 8","line":" vm,"},10{"lineNum":" 9","line":"};"},11{"lineNum":" 10","line":"use std::{"},12{"lineNum":" 11","line":" any::Any,"},13{"lineNum":" 12","line":" convert::Infallible,"},14{"lineNum":" 13","line":" ffi::c_void,"},15{"lineNum":" 14","line":" fmt,"},16{"lineNum":" 15","line":" marker::PhantomData,"},17{"lineNum":" 16","line":" mem, panic,"},18{"lineNum":" 17","line":" ptr::{self, NonNull},"},19{"lineNum":" 18","line":" sync::Arc,"},20{"lineNum":" 19","line":"};"},21{"lineNum":" 20","line":""},22{"lineNum":" 21","line":"/// Wasm trap info."},23{"lineNum":" 22","line":"#[repr(C)]"},24{"lineNum":" 23","line":"pub enum WasmTrapInfo {"},25{"lineNum":" 24","line":" /// Unreachable trap."},26{"lineNum":" 25","line":" Unreachable = 0,"},27{"lineNum":" 26","line":" /// Call indirect incorrect signature trap."},28{"lineNum":" 27","line":" IncorrectCallIndirectSignature = 1,"},29{"lineNum":" 28","line":" /// Memory out of bounds trap."},30{"lineNum":" 29","line":" MemoryOutOfBounds = 2,"},31{"lineNum":" 30","line":" /// Call indirect out of bounds trap."},32{"lineNum":" 31","line":" CallIndirectOOB = 3,"},33{"lineNum":" 32","line":" /// Illegal arithmetic trap."},34{"lineNum":" 33","line":" IllegalArithmetic = 4,"},35{"lineNum":" 34","line":" /// Misaligned atomic access trap."},36{"lineNum":" 35","line":" MisalignedAtomicAccess = 5,"},37{"lineNum":" 36","line":" /// Unknown trap."},38{"lineNum":" 37","line":" Unknown,"},39{"lineNum":" 38","line":"}"},40{"lineNum":" 39","line":""},41{"lineNum":" 40","line":"impl fmt::Display for WasmTrapInfo {"},42{"lineNum":" 41","line":" fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {"},43{"lineNum":" 42","line":" write!("},44{"lineNum":" 43","line":" f,"},45{"lineNum":" 44","line":" \"{}\","},46{"lineNum":" 45","line":" match self {"},47{"lineNum":" 46","line":" WasmTrapInfo::Unreachable => \"unreachable\","},48{"lineNum":" 47","line":" WasmTrapInfo::IncorrectCallIndirectSignature => {"},49{"lineNum":" 48","line":" \"incorrect `call_indirect` signature\""},50{"lineNum":" 49","line":" }"},51{"lineNum":" 50","line":" WasmTrapInfo::MemoryOutOfBounds => \"memory out-of-bounds access\","},52{"lineNum":" 51","line":" WasmTrapInfo::CallIndirectOOB => \"`call_indirect` out-of-bounds\","},53{"lineNum":" 52","line":" WasmTrapInfo::IllegalArithmetic => \"illegal arithmetic operation\","},54{"lineNum":" 53","line":" WasmTrapInfo::MisalignedAtomicAccess => \"misaligned atomic access\","},55{"lineNum":" 54","line":" WasmTrapInfo::Unknown => \"unknown\","},56{"lineNum":" 55","line":" }"},57{"lineNum":" 56","line":" )"},58{"lineNum":" 57","line":" }"},59{"lineNum":" 58","line":"}"},60{"lineNum":" 59","line":""},61{"lineNum":" 60","line":"/// This is just an empty trait to constrict that types that"},62{"lineNum":" 61","line":"/// can be put into the third/fourth (depending if you include lifetimes)"},63{"lineNum":" 62","line":"/// of the `Func` struct."},64{"lineNum":" 63","line":"pub trait Kind {}"},65{"lineNum":" 64","line":""},66{"lineNum":" 65","line":"/// Aliases to an extern \"C\" type used as a trampoline to a function."},67{"lineNum":" 66","line":"pub type Trampoline = unsafe extern \"C\" fn("},68{"lineNum":" 67","line":" vmctx: *mut vm::Ctx,"},69{"lineNum":" 68","line":" func: NonNull<vm::Func>,"},70{"lineNum":" 69","line":" args: *const u64,"},71{"lineNum":" 70","line":" rets: *mut u64,"},72{"lineNum":" 71","line":");"},73{"lineNum":" 72","line":""},74{"lineNum":" 73","line":"/// Aliases to an extern \"C\" type used to invoke a function."},75{"lineNum":" 74","line":"pub type Invoke = unsafe extern \"C\" fn("},76{"lineNum":" 75","line":" trampoline: Trampoline,"},77{"lineNum":" 76","line":" vmctx: *mut vm::Ctx,"},78{"lineNum":" 77","line":" func: NonNull<vm::Func>,"},79{"lineNum":" 78","line":" args: *const u64,"},80{"lineNum":" 79","line":" rets: *mut u64,"},81{"lineNum":" 80","line":" trap_info: *mut WasmTrapInfo,"},82{"lineNum":" 81","line":" user_error: *mut Option<Box<dyn Any>>,"},83{"lineNum":" 82","line":" extra: Option<NonNull<c_void>>,"},84{"lineNum":" 83","line":") -> bool;"},85{"lineNum":" 84","line":""},86{"lineNum":" 85","line":"/// TODO(lachlan): Naming TBD."},87{"lineNum":" 86","line":"/// This contains the trampoline and invoke functions for a specific signature,"},88{"lineNum":" 87","line":"/// as well as the environment that the invoke function may or may not require."},89{"lineNum":" 88","line":"#[derive(Copy, Clone)]"},90{"lineNum":" 89","line":"pub struct Wasm {"},91{"lineNum":" 90","line":" pub(crate) trampoline: Trampoline,"},92{"lineNum":" 91","line":" pub(crate) invoke: Invoke,"},93{"lineNum":" 92","line":" pub(crate) invoke_env: Option<NonNull<c_void>>,"},94{"lineNum":" 93","line":"}"},95{"lineNum":" 94","line":""},96{"lineNum":" 95","line":"impl Wasm {"},97{"lineNum":" 96","line":" /// Create new `Wasm` from given parts."},98{"lineNum":" 97","line":" pub unsafe fn from_raw_parts(","class":"lineNoCov","hits":"0","possible_hits":"1",},99{"lineNum":" 98","line":" trampoline: Trampoline,"},100{"lineNum":" 99","line":" invoke: Invoke,"},101{"lineNum":" 100","line":" invoke_env: Option<NonNull<c_void>>,"},102{"lineNum":" 101","line":" ) -> Self {"},103{"lineNum":" 102","line":" Self {","class":"lineNoCov","hits":"0","possible_hits":"1",},104{"lineNum":" 103","line":" trampoline,","class":"lineNoCov","hits":"0","possible_hits":"1",},105{"lineNum":" 104","line":" invoke,","class":"lineNoCov","hits":"0","possible_hits":"1",},106{"lineNum":" 105","line":" invoke_env,","class":"lineNoCov","hits":"0","possible_hits":"1",},107{"lineNum":" 106","line":" }"},108{"lineNum":" 107","line":" }","class":"lineNoCov","hits":"0","possible_hits":"2",},109{"lineNum":" 108","line":"}"},110{"lineNum":" 109","line":""},111{"lineNum":" 110","line":"/// This type, as part of the `Func` type signature, represents a function that is created"},112{"lineNum":" 111","line":"/// by the host."},113{"lineNum":" 112","line":"pub struct Host(());"},114{"lineNum":" 113","line":""},115{"lineNum":" 114","line":"impl Kind for Wasm {}"},116{"lineNum":" 115","line":"impl Kind for Host {}"},117{"lineNum":" 116","line":""},118{"lineNum":" 117","line":"/// Represents a list of WebAssembly values."},119{"lineNum":" 118","line":"pub trait WasmTypeList {"},120{"lineNum":" 119","line":" /// CStruct type."},121{"lineNum":" 120","line":" type CStruct;"},122{"lineNum":" 121","line":""},123{"lineNum":" 122","line":" /// Array of return values."},124{"lineNum":" 123","line":" type RetArray: AsMut<[u64]>;"},125{"lineNum":" 124","line":""},126{"lineNum":" 125","line":" /// Construct `Self` based on an array of returned values."},127{"lineNum":" 126","line":" fn from_ret_array(array: Self::RetArray) -> Self;"},128{"lineNum":" 127","line":""},129{"lineNum":" 128","line":" /// Generates an empty array that will hold the returned values of"},130{"lineNum":" 129","line":" /// the WebAssembly function."},131{"lineNum":" 130","line":" fn empty_ret_array() -> Self::RetArray;"},132{"lineNum":" 131","line":""},133{"lineNum":" 132","line":" /// Transforms C values into Rust values."},134{"lineNum":" 133","line":" fn from_c_struct(c_struct: Self::CStruct) -> Self;"},135{"lineNum":" 134","line":""},136{"lineNum":" 135","line":" /// Transforms Rust values into C values."},137{"lineNum":" 136","line":" fn into_c_struct(self) -> Self::CStruct;"},138{"lineNum":" 137","line":""},139{"lineNum":" 138","line":" /// Get types of the current values."},140{"lineNum":" 139","line":" fn types() -> &\'static [Type];"},141{"lineNum":" 140","line":""},142{"lineNum":" 141","line":" /// This method is used to distribute the values onto a function,"},143{"lineNum":" 142","line":" /// e.g. `(1, 2).call(func, …)`. This form is unlikely to be used"},144{"lineNum":" 143","line":" /// directly in the code, see the `Func:call` implementation."},145{"lineNum":" 144","line":" unsafe fn call<Rets>("},146{"lineNum":" 145","line":" self,"},147{"lineNum":" 146","line":" f: NonNull<vm::Func>,"},148{"lineNum":" 147","line":" wasm: Wasm,"},149{"lineNum":" 148","line":" ctx: *mut vm::Ctx,"},150{"lineNum":" 149","line":" ) -> Result<Rets, RuntimeError>"},151{"lineNum":" 150","line":" where"},152{"lineNum":" 151","line":" Rets: WasmTypeList;"},153{"lineNum":" 152","line":"}"},154{"lineNum":" 153","line":""},155{"lineNum":" 154","line":"/// Empty trait to specify the kind of `ExternalFunction`: With or"},156{"lineNum":" 155","line":"/// without a `vm::Ctx` argument. See the `ExplicitVmCtx` and the"},157{"lineNum":" 156","line":"/// `ImplicitVmCtx` structures."},158{"lineNum":" 157","line":"///"},159{"lineNum":" 158","line":"/// This type is never aimed to be used by a user. It is used by the"},160{"lineNum":" 159","line":"/// trait system to automatically generate an appropriate `wrap`"},161{"lineNum":" 160","line":"/// function."},162{"lineNum":" 161","line":"pub trait ExternalFunctionKind {}"},163{"lineNum":" 162","line":""},164{"lineNum":" 163","line":"/// This empty structure indicates that an external function must"},165{"lineNum":" 164","line":"/// contain an explicit `vm::Ctx` argument (at first position)."},166{"lineNum":" 165","line":"///"},167{"lineNum":" 166","line":"/// ```rs,ignore"},168{"lineNum":" 167","line":"/// fn add_one(_: mut &vm::Ctx, x: i32) -> i32 {"},169{"lineNum":" 168","line":"/// x + 1"},170{"lineNum":" 169","line":"/// }"},171{"lineNum":" 170","line":"/// ```"},172{"lineNum":" 171","line":"pub struct ExplicitVmCtx {}"},173{"lineNum":" 172","line":""},174{"lineNum":" 173","line":"/// This empty structure indicates that an external function has no"},175{"lineNum":" 174","line":"/// `vm::Ctx` argument (at first position). Its signature is:"},176{"lineNum":" 175","line":"///"},177{"lineNum":" 176","line":"/// ```rs,ignore"},178{"lineNum":" 177","line":"/// fn add_one(x: i32) -> i32 {"},179{"lineNum":" 178","line":"/// x + 1"},180{"lineNum":" 179","line":"/// }"},181{"lineNum":" 180","line":"/// ```"},182{"lineNum":" 181","line":"pub struct ImplicitVmCtx {}"},183{"lineNum":" 182","line":""},184{"lineNum":" 183","line":"impl ExternalFunctionKind for ExplicitVmCtx {}"},185{"lineNum":" 184","line":"impl ExternalFunctionKind for ImplicitVmCtx {}"},186{"lineNum":" 185","line":""},187{"lineNum":" 186","line":"/// Represents a function that can be converted to a `vm::Func`"},188{"lineNum":" 187","line":"/// (function pointer) that can be called within WebAssembly."},189{"lineNum":" 188","line":"pub trait ExternalFunction<Kind, Args, Rets>"},190{"lineNum":" 189","line":"where"},191{"lineNum":" 190","line":" Kind: ExternalFunctionKind,"},192{"lineNum":" 191","line":" Args: WasmTypeList,"},193{"lineNum":" 192","line":" Rets: WasmTypeList,"},194{"lineNum":" 193","line":"{"},195{"lineNum":" 194","line":" /// Conver to function pointer."},196{"lineNum":" 195","line":" fn to_raw(self) -> (NonNull<vm::Func>, Option<NonNull<vm::FuncEnv>>);"},197{"lineNum":" 196","line":"}"},198{"lineNum":" 197","line":""},199{"lineNum":" 198","line":"/// Represents a TrapEarly type."},200{"lineNum":" 199","line":"pub trait TrapEarly<Rets>"},201{"lineNum":" 200","line":"where"},202{"lineNum":" 201","line":" Rets: WasmTypeList,"},203{"lineNum":" 202","line":"{"},204{"lineNum":" 203","line":" /// The error type for this trait."},205{"lineNum":" 204","line":" type Error: \'static;"},206{"lineNum":" 205","line":" /// Get returns or error result."},207{"lineNum":" 206","line":" fn report(self) -> Result<Rets, Self::Error>;"},208{"lineNum":" 207","line":"}"},209{"lineNum":" 208","line":""},210{"lineNum":" 209","line":"impl<Rets> TrapEarly<Rets> for Rets"},211{"lineNum":" 210","line":"where"},212{"lineNum":" 211","line":" Rets: WasmTypeList,"},213{"lineNum":" 212","line":"{"},214{"lineNum":" 213","line":" type Error = Infallible;"},215{"lineNum":" 214","line":" fn report(self) -> Result<Rets, Infallible> {"},216{"lineNum":" 215","line":" Ok(self)"},217{"lineNum":" 216","line":" }"},218{"lineNum":" 217","line":"}"},219{"lineNum":" 218","line":""},220{"lineNum":" 219","line":"impl<Rets, E> TrapEarly<Rets> for Result<Rets, E>"},221{"lineNum":" 220","line":"where"},222{"lineNum":" 221","line":" Rets: WasmTypeList,"},223{"lineNum":" 222","line":" E: \'static,"},224{"lineNum":" 223","line":"{"},225{"lineNum":" 224","line":" type Error = E;"},226{"lineNum":" 225","line":" fn report(self) -> Result<Rets, E> {"},227{"lineNum":" 226","line":" self"},228{"lineNum":" 227","line":" }"},229{"lineNum":" 228","line":"}"},230{"lineNum":" 229","line":""},231{"lineNum":" 230","line":"/// Represents a function that can be used by WebAssembly."},232{"lineNum":" 231","line":"pub struct Func<\'a, Args = (), Rets = (), Inner: Kind = Wasm> {"},233{"lineNum":" 232","line":" inner: Inner,"},234{"lineNum":" 233","line":" func: NonNull<vm::Func>,"},235{"lineNum":" 234","line":" func_env: Option<NonNull<vm::FuncEnv>>,"},236{"lineNum":" 235","line":" vmctx: *mut vm::Ctx,"},237{"lineNum":" 236","line":" _phantom: PhantomData<(&\'a (), Args, Rets)>,"},238{"lineNum":" 237","line":"}"},239{"lineNum":" 238","line":""},240{"lineNum":" 239","line":"unsafe impl<\'a, Args, Rets> Send for Func<\'a, Args, Rets, Wasm> {}"},241{"lineNum":" 240","line":"unsafe impl<\'a, Args, Rets> Send for Func<\'a, Args, Rets, Host> {}"},242{"lineNum":" 241","line":""},243{"lineNum":" 242","line":"impl<\'a, Args, Rets> Func<\'a, Args, Rets, Wasm>"},244{"lineNum":" 243","line":"where"},245{"lineNum":" 244","line":" Args: WasmTypeList,"},246{"lineNum":" 245","line":" Rets: WasmTypeList,"},247{"lineNum":" 246","line":"{"},248{"lineNum":" 247","line":" pub(crate) unsafe fn from_raw_parts("},249{"lineNum":" 248","line":" inner: Wasm,"},250{"lineNum":" 249","line":" func: NonNull<vm::Func>,"},251{"lineNum":" 250","line":" func_env: Option<NonNull<vm::FuncEnv>>,"},252{"lineNum":" 251","line":" vmctx: *mut vm::Ctx,"},253{"lineNum":" 252","line":" ) -> Func<\'a, Args, Rets, Wasm> {"},254{"lineNum":" 253","line":" Func {"},255{"lineNum":" 254","line":" inner,"},256{"lineNum":" 255","line":" func,"},257{"lineNum":" 256","line":" func_env,"},258{"lineNum":" 257","line":" vmctx,"},259{"lineNum":" 258","line":" _phantom: PhantomData,"},260{"lineNum":" 259","line":" }"},261{"lineNum":" 260","line":" }"},262{"lineNum":" 261","line":""},263{"lineNum":" 262","line":" /// Get the underlying func pointer."},264{"lineNum":" 263","line":" pub fn get_vm_func(&self) -> NonNull<vm::Func> {"},265{"lineNum":" 264","line":" self.func"},266{"lineNum":" 265","line":" }"},267{"lineNum":" 266","line":"}"},268{"lineNum":" 267","line":""},269{"lineNum":" 268","line":"impl<\'a, Args, Rets> Func<\'a, Args, Rets, Host>"},270{"lineNum":" 269","line":"where"},271{"lineNum":" 270","line":" Args: WasmTypeList,"},272{"lineNum":" 271","line":" Rets: WasmTypeList,"},273{"lineNum":" 272","line":"{"},274{"lineNum":" 273","line":" /// Creates a new `Func`."},275{"lineNum":" 274","line":" pub fn new<F, Kind>(func: F) -> Func<\'a, Args, Rets, Host>"},276{"lineNum":" 275","line":" where"},277{"lineNum":" 276","line":" Kind: ExternalFunctionKind,"},278{"lineNum":" 277","line":" F: ExternalFunction<Kind, Args, Rets>,"},279{"lineNum":" 278","line":" {"},280{"lineNum":" 279","line":" let (func, func_env) = func.to_raw();"},281{"lineNum":" 280","line":""},282{"lineNum":" 281","line":" Func {"},283{"lineNum":" 282","line":" inner: Host(()),"},284{"lineNum":" 283","line":" func,"},285{"lineNum":" 284","line":" func_env,"},286{"lineNum":" 285","line":" vmctx: ptr::null_mut(),"},287{"lineNum":" 286","line":" _phantom: PhantomData,"},288{"lineNum":" 287","line":" }"},289{"lineNum":" 288","line":" }"},290{"lineNum":" 289","line":"}"},291{"lineNum":" 290","line":""},292{"lineNum":" 291","line":"impl<\'a, Args, Rets, Inner> Func<\'a, Args, Rets, Inner>"},293{"lineNum":" 292","line":"where"},294{"lineNum":" 293","line":" Args: WasmTypeList,"},295{"lineNum":" 294","line":" Rets: WasmTypeList,"},296{"lineNum":" 295","line":" Inner: Kind,"},297{"lineNum":" 296","line":"{"},298{"lineNum":" 297","line":" /// Returns the types of the function inputs."},299{"lineNum":" 298","line":" pub fn params(&self) -> &\'static [Type] {"},300{"lineNum":" 299","line":" Args::types()"},301{"lineNum":" 300","line":" }"},302{"lineNum":" 301","line":""},303{"lineNum":" 302","line":" /// Returns the types of the function outputs."},304{"lineNum":" 303","line":" pub fn returns(&self) -> &\'static [Type] {"},305{"lineNum":" 304","line":" Rets::types()"},306{"lineNum":" 305","line":" }"},307{"lineNum":" 306","line":"}"},308{"lineNum":" 307","line":""},309{"lineNum":" 308","line":"impl WasmTypeList for Infallible {"},310{"lineNum":" 309","line":" type CStruct = Infallible;"},311{"lineNum":" 310","line":" type RetArray = [u64; 0];"},312{"lineNum":" 311","line":""},313{"lineNum":" 312","line":" fn from_ret_array(_: Self::RetArray) -> Self {"},314{"lineNum":" 313","line":" unreachable!()"},315{"lineNum":" 314","line":" }"},316{"lineNum":" 315","line":""},317{"lineNum":" 316","line":" fn empty_ret_array() -> Self::RetArray {"},318{"lineNum":" 317","line":" unreachable!()"},319{"lineNum":" 318","line":" }"},320{"lineNum":" 319","line":""},321{"lineNum":" 320","line":" fn from_c_struct(_: Self::CStruct) -> Self {"},322{"lineNum":" 321","line":" unreachable!()"},323{"lineNum":" 322","line":" }"},324{"lineNum":" 323","line":""},325{"lineNum":" 324","line":" fn into_c_struct(self) -> Self::CStruct {"},326{"lineNum":" 325","line":" unreachable!()"},327{"lineNum":" 326","line":" }"},328{"lineNum":" 327","line":""},329{"lineNum":" 328","line":" fn types() -> &\'static [Type] {"},330{"lineNum":" 329","line":" &[]"},331{"lineNum":" 330","line":" }"},332{"lineNum":" 331","line":""},333{"lineNum":" 332","line":" #[allow(non_snake_case)]"},334{"lineNum":" 333","line":" unsafe fn call<Rets>("},335{"lineNum":" 334","line":" self,"},336{"lineNum":" 335","line":" _: NonNull<vm::Func>,"},337{"lineNum":" 336","line":" _: Wasm,"},338{"lineNum":" 337","line":" _: *mut vm::Ctx,"},339{"lineNum":" 338","line":" ) -> Result<Rets, RuntimeError>"},340{"lineNum":" 339","line":" where"},341{"lineNum":" 340","line":" Rets: WasmTypeList,"},342{"lineNum":" 341","line":" {"},343{"lineNum":" 342","line":" unreachable!()"},344{"lineNum":" 343","line":" }"},345{"lineNum":" 344","line":"}"},346{"lineNum":" 345","line":""},347{"lineNum":" 346","line":"macro_rules! impl_traits {"},348{"lineNum":" 347","line":" ( [$repr:ident] $struct_name:ident, $( $x:ident ),* ) => {"},349{"lineNum":" 348","line":" /// Struct for typed funcs."},350{"lineNum":" 349","line":" #[repr($repr)]"},351{"lineNum":" 350","line":" pub struct $struct_name< $( $x ),* > ( $( <$x as WasmExternType>::Native ),* )"},352{"lineNum":" 351","line":" where"},353{"lineNum":" 352","line":" $( $x: WasmExternType ),*;"},354{"lineNum":" 353","line":""},355{"lineNum":" 354","line":" impl< $( $x ),* > WasmTypeList for ( $( $x ),* )"},356{"lineNum":" 355","line":" where"},357{"lineNum":" 356","line":" $( $x: WasmExternType ),*"},358{"lineNum":" 357","line":" {"},359{"lineNum":" 358","line":" type CStruct = $struct_name<$( $x ),*>;"},360{"lineNum":" 359","line":""},361{"lineNum":" 360","line":" type RetArray = [u64; count_idents!( $( $x ),* )];"},362{"lineNum":" 361","line":""},363{"lineNum":" 362","line":" fn from_ret_array(array: Self::RetArray) -> Self {"},364{"lineNum":" 363","line":" #[allow(non_snake_case)]"},365{"lineNum":" 364","line":" let [ $( $x ),* ] = array;"},366{"lineNum":" 365","line":""},367{"lineNum":" 366","line":" ( $( WasmExternType::from_native(NativeWasmType::from_binary($x)) ),* )"},368{"lineNum":" 367","line":" }"},369{"lineNum":" 368","line":""},370{"lineNum":" 369","line":" fn empty_ret_array() -> Self::RetArray {"},371{"lineNum":" 370","line":" [0; count_idents!( $( $x ),* )]"},372{"lineNum":" 371","line":" }"},373{"lineNum":" 372","line":""},374{"lineNum":" 373","line":" fn from_c_struct(c_struct: Self::CStruct) -> Self {"},375{"lineNum":" 374","line":" #[allow(non_snake_case)]"},376{"lineNum":" 375","line":" let $struct_name ( $( $x ),* ) = c_struct;"},377{"lineNum":" 376","line":""},378{"lineNum":" 377","line":" ( $( WasmExternType::from_native($x) ),* )"},379{"lineNum":" 378","line":" }"},380{"lineNum":" 379","line":""},381{"lineNum":" 380","line":" #[allow(unused_parens, non_snake_case)]"},382{"lineNum":" 381","line":" fn into_c_struct(self) -> Self::CStruct {"},383{"lineNum":" 382","line":" let ( $( $x ),* ) = self;"},384{"lineNum":" 383","line":""},385{"lineNum":" 384","line":" $struct_name ( $( WasmExternType::to_native($x) ),* )"},386{"lineNum":" 385","line":" }"},387{"lineNum":" 386","line":""},388{"lineNum":" 387","line":" fn types() -> &\'static [Type] {"},389{"lineNum":" 388","line":" &[$( $x::Native::TYPE ),*]"},390{"lineNum":" 389","line":" }"},391{"lineNum":" 390","line":""},392{"lineNum":" 391","line":" #[allow(unused_parens, non_snake_case)]"},393{"lineNum":" 392","line":" unsafe fn call<Rets>("},394{"lineNum":" 393","line":" self,"},395{"lineNum":" 394","line":" f: NonNull<vm::Func>,"},396{"lineNum":" 395","line":" wasm: Wasm,"},397{"lineNum":" 396","line":" ctx: *mut vm::Ctx,"},398{"lineNum":" 397","line":" ) -> Result<Rets, RuntimeError>"},399{"lineNum":" 398","line":" where"},400{"lineNum":" 399","line":" Rets: WasmTypeList"},401{"lineNum":" 400","line":" {"},402{"lineNum":" 401","line":" let ( $( $x ),* ) = self;"},403{"lineNum":" 402","line":" let args = [ $( $x.to_native().to_binary()),* ];"},404{"lineNum":" 403","line":" let mut rets = Rets::empty_ret_array();"},405{"lineNum":" 404","line":" let mut trap = WasmTrapInfo::Unknown;"},406{"lineNum":" 405","line":" let mut user_error = None;"},407{"lineNum":" 406","line":""},408{"lineNum":" 407","line":" if (wasm.invoke)("},409{"lineNum":" 408","line":" wasm.trampoline,"},410{"lineNum":" 409","line":" ctx,"},411{"lineNum":" 410","line":" f,"},412{"lineNum":" 411","line":" args.as_ptr(),"},413{"lineNum":" 412","line":" rets.as_mut().as_mut_ptr(),"},414{"lineNum":" 413","line":" &mut trap,"},415{"lineNum":" 414","line":" &mut user_error,"},416{"lineNum":" 415","line":" wasm.invoke_env"},417{"lineNum":" 416","line":" ) {"},418{"lineNum":" 417","line":" Ok(Rets::from_ret_array(rets))"},419{"lineNum":" 418","line":" } else {"},420{"lineNum":" 419","line":" if let Some(data) = user_error {"},421{"lineNum":" 420","line":" Err(RuntimeError::Error { data })"},422{"lineNum":" 421","line":" } else {"},423{"lineNum":" 422","line":" Err(RuntimeError::Trap { msg: trap.to_string().into() })"},424{"lineNum":" 423","line":" }"},425{"lineNum":" 424","line":" }"},426{"lineNum":" 425","line":" }"},427{"lineNum":" 426","line":" }"},428{"lineNum":" 427","line":""},429{"lineNum":" 428","line":" impl< $( $x, )* Rets, Trap, FN > ExternalFunction<ExplicitVmCtx, ( $( $x ),* ), Rets> for FN"},430{"lineNum":" 429","line":" where"},431{"lineNum":" 430","line":" $( $x: WasmExternType, )*"},432{"lineNum":" 431","line":" Rets: WasmTypeList,"},433{"lineNum":" 432","line":" Trap: TrapEarly<Rets>,"},434{"lineNum":" 433","line":" FN: Fn(&mut vm::Ctx $( , $x )*) -> Trap + \'static,"},435{"lineNum":" 434","line":" {"},436{"lineNum":" 435","line":" #[allow(non_snake_case)]"},437{"lineNum":" 436","line":" fn to_raw(self) -> (NonNull<vm::Func>, Option<NonNull<vm::FuncEnv>>) {"},438{"lineNum":" 437","line":" // The `wrap` function is a wrapper around the"},439{"lineNum":" 438","line":" // imported function. It manages the argument passed"},440{"lineNum":" 439","line":" // to the imported function (in this case, the"},441{"lineNum":" 440","line":" // `vmctx` along with the regular WebAssembly"},442{"lineNum":" 441","line":" // arguments), and it manages the trapping."},443{"lineNum":" 442","line":" //"},444{"lineNum":" 443","line":" // It is also required for the LLVM backend to be"},445{"lineNum":" 444","line":" // able to unwind through this function."},446{"lineNum":" 445","line":" #[cfg_attr(nightly, unwind(allowed))]"},447{"lineNum":" 446","line":" extern fn wrap<$( $x, )* Rets, Trap, FN>("},448{"lineNum":" 447","line":" vmctx: &vm::Ctx $( , $x: <$x as WasmExternType>::Native )*"},449{"lineNum":" 448","line":" ) -> Rets::CStruct"},450{"lineNum":" 449","line":" where"},451{"lineNum":" 450","line":" $( $x: WasmExternType, )*"},452{"lineNum":" 451","line":" Rets: WasmTypeList,"},453{"lineNum":" 452","line":" Trap: TrapEarly<Rets>,"},454{"lineNum":" 453","line":" FN: Fn(&mut vm::Ctx, $( $x, )*) -> Trap,"},455{"lineNum":" 454","line":" {"},456{"lineNum":" 455","line":" // Get the pointer to this `wrap` function."},457{"lineNum":" 456","line":" let self_pointer = wrap::<$( $x, )* Rets, Trap, FN> as *const vm::Func;"},458{"lineNum":" 457","line":""},459{"lineNum":" 458","line":" // Get the collection of imported functions."},460{"lineNum":" 459","line":" let vm_imported_functions = unsafe { &(*vmctx.import_backing).vm_functions };"},461{"lineNum":" 460","line":""},462{"lineNum":" 461","line":" // Retrieve the `vm::FuncCtx`."},463{"lineNum":" 462","line":" let mut func_ctx: NonNull<vm::FuncCtx> = vm_imported_functions"},464{"lineNum":" 463","line":" .iter()"},465{"lineNum":" 464","line":" .find_map(|(_, imported_func)| {"},466{"lineNum":" 465","line":" if imported_func.func == self_pointer {"},467{"lineNum":" 466","line":" Some(imported_func.func_ctx)"},468{"lineNum":" 467","line":" } else {"},469{"lineNum":" 468","line":" None"},470{"lineNum":" 469","line":" }"},471{"lineNum":" 470","line":" })"},472{"lineNum":" 471","line":" .expect(\"Import backing is not well-formed, cannot find `func_ctx`.\");"},473{"lineNum":" 472","line":" let func_ctx = unsafe { func_ctx.as_mut() };"},474{"lineNum":" 473","line":""},475{"lineNum":" 474","line":" // Extract `vm::Ctx` from `vm::FuncCtx`. The"},476{"lineNum":" 475","line":" // pointer is always non-null."},477{"lineNum":" 476","line":" let vmctx = unsafe { func_ctx.vmctx.as_mut() };"},478{"lineNum":" 477","line":""},479{"lineNum":" 478","line":" // Extract `vm::FuncEnv` from `vm::FuncCtx`."},480{"lineNum":" 479","line":" let func_env = func_ctx.func_env;"},481{"lineNum":" 480","line":""},482{"lineNum":" 481","line":" let func: &FN = match func_env {"},483{"lineNum":" 482","line":" // The imported function is a regular"},484{"lineNum":" 483","line":" // function, a closure without a captured"},485{"lineNum":" 484","line":" // environment, or a closure with a captured"},486{"lineNum":" 485","line":" // environment."},487{"lineNum":" 486","line":" Some(func_env) => unsafe {"},488{"lineNum":" 487","line":" let func: NonNull<FN> = func_env.cast();"},489{"lineNum":" 488","line":""},490{"lineNum":" 489","line":" &*func.as_ptr()"},491{"lineNum":" 490","line":" },"},492{"lineNum":" 491","line":""},493{"lineNum":" 492","line":" // This branch is supposed to be unreachable."},494{"lineNum":" 493","line":" None => unreachable!()"},495{"lineNum":" 494","line":" };"},496{"lineNum":" 495","line":""},497{"lineNum":" 496","line":" // Catch unwind in case of errors."},498{"lineNum":" 497","line":" let err = match panic::catch_unwind("},499{"lineNum":" 498","line":" panic::AssertUnwindSafe("},500{"lineNum":" 499","line":" || {"},501{"lineNum":" 500","line":" func(vmctx $( , WasmExternType::from_native($x) )* ).report()"},502{"lineNum":" 501","line":" // ^^^^^ The imported function"},503{"lineNum":" 502","line":" // expects `vm::Ctx` as first"},504{"lineNum":" 503","line":" // argument; provide it."},505{"lineNum":" 504","line":" }"},506{"lineNum":" 505","line":" )"},507{"lineNum":" 506","line":" ) {"},508{"lineNum":" 507","line":" Ok(Ok(returns)) => return returns.into_c_struct(),"},509{"lineNum":" 508","line":" Ok(Err(err)) => {"},510{"lineNum":" 509","line":" let b: Box<_> = err.into();"},511{"lineNum":" 510","line":" b as Box<dyn Any>"},512{"lineNum":" 511","line":" },"},513{"lineNum":" 512","line":" Err(err) => err,"},514{"lineNum":" 513","line":" };"},515{"lineNum":" 514","line":""},516{"lineNum":" 515","line":" // At this point, there is an error that needs to"},517{"lineNum":" 516","line":" // be trapped."},518{"lineNum":" 517","line":" unsafe {"},519{"lineNum":" 518","line":" (&*vmctx.module).runnable_module.do_early_trap(err)"},520{"lineNum":" 519","line":" }"},521{"lineNum":" 520","line":" }"},522{"lineNum":" 521","line":""},523{"lineNum":" 522","line":" // Extract the captured environment of the imported"},524{"lineNum":" 523","line":" // function if any."},525{"lineNum":" 524","line":" let func_env: Option<NonNull<vm::FuncEnv>> ="},526{"lineNum":" 525","line":" // `FN` is a function pointer, or a closure"},527{"lineNum":" 526","line":" // _without_ a captured environment."},528{"lineNum":" 527","line":" if mem::size_of::<Self>() == 0 {"},529{"lineNum":" 528","line":" NonNull::new(&self as *const _ as *mut vm::FuncEnv)"},530{"lineNum":" 529","line":" }"},531{"lineNum":" 530","line":" // `FN` is a closure _with_ a captured"},532{"lineNum":" 531","line":" // environment."},533{"lineNum":" 532","line":" else {"},534{"lineNum":" 533","line":" NonNull::new(Box::into_raw(Box::new(self))).map(NonNull::cast)"},535{"lineNum":" 534","line":" };"},536{"lineNum":" 535","line":""},537{"lineNum":" 536","line":" ("},538{"lineNum":" 537","line":" NonNull::new(wrap::<$( $x, )* Rets, Trap, Self> as *mut vm::Func).unwrap(),"},539{"lineNum":" 538","line":" func_env"},540{"lineNum":" 539","line":" )"},541{"lineNum":" 540","line":" }"},542{"lineNum":" 541","line":" }"},543{"lineNum":" 542","line":""},544{"lineNum":" 543","line":" impl< $( $x, )* Rets, Trap, FN > ExternalFunction<ImplicitVmCtx, ( $( $x ),* ), Rets> for FN"},545{"lineNum":" 544","line":" where"},546{"lineNum":" 545","line":" $( $x: WasmExternType, )*"},547{"lineNum":" 546","line":" Rets: WasmTypeList,"},548{"lineNum":" 547","line":" Trap: TrapEarly<Rets>,"},549{"lineNum":" 548","line":" FN: Fn($( $x, )*) -> Trap + \'static,"},550{"lineNum":" 549","line":" {"},551{"lineNum":" 550","line":" #[allow(non_snake_case)]"},552{"lineNum":" 551","line":" fn to_raw(self) -> (NonNull<vm::Func>, Option<NonNull<vm::FuncEnv>>) {"},553{"lineNum":" 552","line":" // The `wrap` function is a wrapper around the"},554{"lineNum":" 553","line":" // imported function. It manages the argument passed"},555{"lineNum":" 554","line":" // to the imported function (in this case, only the"},556{"lineNum":" 555","line":" // regular WebAssembly arguments), and it manages the"},557{"lineNum":" 556","line":" // trapping."},558{"lineNum":" 557","line":" //"},559{"lineNum":" 558","line":" // It is also required for the LLVM backend to be"},560{"lineNum":" 559","line":" // able to unwind through this function."},561{"lineNum":" 560","line":" #[cfg_attr(nightly, unwind(allowed))]"},562{"lineNum":" 561","line":" extern fn wrap<$( $x, )* Rets, Trap, FN>("},563{"lineNum":" 562","line":" vmctx: &vm::Ctx $( , $x: <$x as WasmExternType>::Native )*"},564{"lineNum":" 563","line":" ) -> Rets::CStruct"},565{"lineNum":" 564","line":" where"},566{"lineNum":" 565","line":" $( $x: WasmExternType, )*"},567{"lineNum":" 566","line":" Rets: WasmTypeList,"},568{"lineNum":" 567","line":" Trap: TrapEarly<Rets>,"},569{"lineNum":" 568","line":" FN: Fn($( $x, )*) -> Trap,"},570{"lineNum":" 569","line":" {"},571{"lineNum":" 570","line":" // Get the pointer to this `wrap` function."},572{"lineNum":" 571","line":" let self_pointer = wrap::<$( $x, )* Rets, Trap, FN> as *const vm::Func;"},573{"lineNum":" 572","line":""},574{"lineNum":" 573","line":" // Get the collection of imported functions."},575{"lineNum":" 574","line":" let vm_imported_functions = unsafe { &(*vmctx.import_backing).vm_functions };"},576{"lineNum":" 575","line":""},577{"lineNum":" 576","line":" // Retrieve the `vm::FuncCtx`."},578{"lineNum":" 577","line":" let mut func_ctx: NonNull<vm::FuncCtx> = vm_imported_functions"},579{"lineNum":" 578","line":" .iter()"},580{"lineNum":" 579","line":" .find_map(|(_, imported_func)| {"},581{"lineNum":" 580","line":" if imported_func.func == self_pointer {"},582{"lineNum":" 581","line":" Some(imported_func.func_ctx)"},583{"lineNum":" 582","line":" } else {"},584{"lineNum":" 583","line":" None"},585{"lineNum":" 584","line":" }"},586{"lineNum":" 585","line":" })"},587{"lineNum":" 586","line":" .expect(\"Import backing is not well-formed, cannot find `func_ctx`.\");"},588{"lineNum":" 587","line":" let func_ctx = unsafe { func_ctx.as_mut() };"},589{"lineNum":" 588","line":""},590{"lineNum":" 589","line":" // Extract `vm::Ctx` from `vm::FuncCtx`. The"},591{"lineNum":" 590","line":" // pointer is always non-null."},592{"lineNum":" 591","line":" let vmctx = unsafe { func_ctx.vmctx.as_mut() };"},593{"lineNum":" 592","line":""},594{"lineNum":" 593","line":" // Extract `vm::FuncEnv` from `vm::FuncCtx`."},595{"lineNum":" 594","line":" let func_env = func_ctx.func_env;"},596{"lineNum":" 595","line":""},597{"lineNum":" 596","line":" let func: &FN = match func_env {"},598{"lineNum":" 597","line":" // The imported function is a regular"},599{"lineNum":" 598","line":" // function, a closure without a captured"},600{"lineNum":" 599","line":" // environment, or a closure with a captured"},601{"lineNum":" 600","line":" // environment."},602{"lineNum":" 601","line":" Some(func_env) => unsafe {"},603{"lineNum":" 602","line":" let func: NonNull<FN> = func_env.cast();"},604{"lineNum":" 603","line":""},605{"lineNum":" 604","line":" &*func.as_ptr()"},606{"lineNum":" 605","line":" },"},607{"lineNum":" 606","line":""},608{"lineNum":" 607","line":" // This branch is supposed to be unreachable."},609{"lineNum":" 608","line":" None => unreachable!()"},610{"lineNum":" 609","line":" };"},611{"lineNum":" 610","line":""},612{"lineNum":" 611","line":" // Catch unwind in case of errors."},613{"lineNum":" 612","line":" let err = match panic::catch_unwind("},614{"lineNum":" 613","line":" panic::AssertUnwindSafe("},615{"lineNum":" 614","line":" || {"},616{"lineNum":" 615","line":" func($( WasmExternType::from_native($x), )* ).report()"},617{"lineNum":" 616","line":" }"},618{"lineNum":" 617","line":" )"},619{"lineNum":" 618","line":" ) {"},620{"lineNum":" 619","line":" Ok(Ok(returns)) => return returns.into_c_struct(),"},621{"lineNum":" 620","line":" Ok(Err(err)) => {"},622{"lineNum":" 621","line":" let b: Box<_> = err.into();"},623{"lineNum":" 622","line":" b as Box<dyn Any>"},624{"lineNum":" 623","line":" },"},625{"lineNum":" 624","line":" Err(err) => err,"},626{"lineNum":" 625","line":" };"},627{"lineNum":" 626","line":""},628{"lineNum":" 627","line":" // At this point, there is an error that needs to"},629{"lineNum":" 628","line":" // be trapped."},630{"lineNum":" 629","line":" unsafe {"},631{"lineNum":" 630","line":" (&*vmctx.module).runnable_module.do_early_trap(err)"},632{"lineNum":" 631","line":" }"},633{"lineNum":" 632","line":" }"},634{"lineNum":" 633","line":""},635{"lineNum":" 634","line":" // Extract the captured environment of the imported"},636{"lineNum":" 635","line":" // function if any."},637{"lineNum":" 636","line":" let func_env: Option<NonNull<vm::FuncEnv>> ="},638{"lineNum":" 637","line":" // `FN` is a function pointer, or a closure"},639{"lineNum":" 638","line":" // _without_ a captured environment."},640{"lineNum":" 639","line":" if mem::size_of::<Self>() == 0 {"},641{"lineNum":" 640","line":" NonNull::new(&self as *const _ as *mut vm::FuncEnv)"},642{"lineNum":" 641","line":" }"},643{"lineNum":" 642","line":" // `FN` is a closure _with_ a captured"},644{"lineNum":" 643","line":" // environment."},645{"lineNum":" 644","line":" else {"},646{"lineNum":" 645","line":" NonNull::new(Box::into_raw(Box::new(self))).map(NonNull::cast)"},647{"lineNum":" 646","line":" };"},648{"lineNum":" 647","line":""},649{"lineNum":" 648","line":" ("},650{"lineNum":" 649","line":" NonNull::new(wrap::<$( $x, )* Rets, Trap, Self> as *mut vm::Func).unwrap(),"},651{"lineNum":" 650","line":" func_env"},652{"lineNum":" 651","line":" )"},653{"lineNum":" 652","line":" }"},654{"lineNum":" 653","line":" }"},655{"lineNum":" 654","line":""},656{"lineNum":" 655","line":" impl<\'a $( , $x )*, Rets> Func<\'a, ( $( $x ),* ), Rets, Wasm>"},657{"lineNum":" 656","line":" where"},658{"lineNum":" 657","line":" $( $x: WasmExternType, )*"},659{"lineNum":" 658","line":" Rets: WasmTypeList,"},660{"lineNum":" 659","line":" {"},661{"lineNum":" 660","line":" /// Call the typed func and return results."},662{"lineNum":" 661","line":" #[allow(non_snake_case)]"},663{"lineNum":" 662","line":" pub fn call(&self, $( $x: $x, )* ) -> Result<Rets, RuntimeError> {"},664{"lineNum":" 663","line":" #[allow(unused_parens)]"},665{"lineNum":" 664","line":" unsafe {"},666{"lineNum":" 665","line":" <( $( $x ),* ) as WasmTypeList>::call("},667{"lineNum":" 666","line":" ( $( $x ),* ),"},668{"lineNum":" 667","line":" self.func,"},669{"lineNum":" 668","line":" self.inner,"},670{"lineNum":" 669","line":" self.vmctx"},671{"lineNum":" 670","line":" )"},672{"lineNum":" 671","line":" }"},673{"lineNum":" 672","line":" }"},674{"lineNum":" 673","line":" }"},675{"lineNum":" 674","line":" };"},676{"lineNum":" 675","line":"}"},677{"lineNum":" 676","line":""},678{"lineNum":" 677","line":"macro_rules! count_idents {"},679{"lineNum":" 678","line":" ( $($idents:ident),* ) => {{"},680{"lineNum":" 679","line":" #[allow(dead_code, non_camel_case_types)]"},681{"lineNum":" 680","line":" enum Idents { $($idents,)* __CountIdentsLast }"},682{"lineNum":" 681","line":" const COUNT: usize = Idents::__CountIdentsLast as usize;"},683{"lineNum":" 682","line":" COUNT"},684{"lineNum":" 683","line":" }};"},685{"lineNum":" 684","line":"}"},686{"lineNum":" 685","line":""},687{"lineNum":" 686","line":"impl_traits!([C] S0,);"},688{"lineNum":" 687","line":"impl_traits!([transparent] S1, A);"},689{"lineNum":" 688","line":"impl_traits!([C] S2, A, B);"},690{"lineNum":" 689","line":"impl_traits!([C] S3, A, B, C);"},691{"lineNum":" 690","line":"impl_traits!([C] S4, A, B, C, D);"},692{"lineNum":" 691","line":"impl_traits!([C] S5, A, B, C, D, E);"},693{"lineNum":" 692","line":"impl_traits!([C] S6, A, B, C, D, E, F);"},694{"lineNum":" 693","line":"impl_traits!([C] S7, A, B, C, D, E, F, G);"},695{"lineNum":" 694","line":"impl_traits!([C] S8, A, B, C, D, E, F, G, H);"},696{"lineNum":" 695","line":"impl_traits!([C] S9, A, B, C, D, E, F, G, H, I);"},697{"lineNum":" 696","line":"impl_traits!([C] S10, A, B, C, D, E, F, G, H, I, J);"},698{"lineNum":" 697","line":"impl_traits!([C] S11, A, B, C, D, E, F, G, H, I, J, K);"},699{"lineNum":" 698","line":"impl_traits!([C] S12, A, B, C, D, E, F, G, H, I, J, K, L);"},700{"lineNum":" 699","line":""},701{"lineNum":" 700","line":"impl<\'a, Args, Rets, Inner> IsExport for Func<\'a, Args, Rets, Inner>"},702{"lineNum":" 701","line":"where"},703{"lineNum":" 702","line":" Args: WasmTypeList,"},704{"lineNum":" 703","line":" Rets: WasmTypeList,"},705{"lineNum":" 704","line":" Inner: Kind,"},706{"lineNum":" 705","line":"{"},707{"lineNum":" 706","line":" fn to_export(&self) -> Export {"},708{"lineNum":" 707","line":" let func = unsafe { FuncPointer::new(self.func.as_ptr()) };"},709{"lineNum":" 708","line":" let ctx = match self.func_env {"},710{"lineNum":" 709","line":" func_env @ Some(_) => Context::ExternalWithEnv(self.vmctx, func_env),"},711{"lineNum":" 710","line":" None => Context::Internal,"},712{"lineNum":" 711","line":" };"},713{"lineNum":" 712","line":" let signature = Arc::new(FuncSig::new(Args::types(), Rets::types()));"},714{"lineNum":" 713","line":""},715{"lineNum":" 714","line":" Export::Function {"},716{"lineNum":" 715","line":" func,"},717{"lineNum":" 716","line":" ctx,"},718{"lineNum":" 717","line":" signature,"},719{"lineNum":" 718","line":" }"},720{"lineNum":" 719","line":" }"},721{"lineNum":" 720","line":"}"},722{"lineNum":" 721","line":""},723{"lineNum":" 722","line":"#[cfg(test)]"},724{"lineNum":" 723","line":"mod tests {"},725{"lineNum":" 724","line":" use super::*;"},726{"lineNum":" 725","line":""},727{"lineNum":" 726","line":" macro_rules! test_func_arity_n {"},728{"lineNum":" 727","line":" ($test_name:ident, $($x:ident),*) => {"},729{"lineNum":" 728","line":" #[test]"},730{"lineNum":" 729","line":" fn $test_name() {"},731{"lineNum":" 730","line":" use crate::vm;"},732{"lineNum":" 731","line":""},733{"lineNum":" 732","line":" fn with_vmctx(_: &mut vm::Ctx, $($x: i32),*) -> i32 {"},734{"lineNum":" 733","line":" vec![$($x),*].iter().sum()"},735{"lineNum":" 734","line":" }"},736{"lineNum":" 735","line":""},737{"lineNum":" 736","line":" fn without_vmctx($($x: i32),*) -> i32 {"},738{"lineNum":" 737","line":" vec![$($x),*].iter().sum()"},739{"lineNum":" 738","line":" }"},740{"lineNum":" 739","line":""},741{"lineNum":" 740","line":" let _ = Func::new(with_vmctx);"},742{"lineNum":" 741","line":" let _ = Func::new(without_vmctx);"},743{"lineNum":" 742","line":" let _ = Func::new(|_: &mut vm::Ctx, $($x: i32),*| -> i32 {"},744{"lineNum":" 743","line":" vec![$($x),*].iter().sum()"},745{"lineNum":" 744","line":" });"},746{"lineNum":" 745","line":" let _ = Func::new(|$($x: i32),*| -> i32 {"},747{"lineNum":" 746","line":" vec![$($x),*].iter().sum()"},748{"lineNum":" 747","line":" });"},749{"lineNum":" 748","line":" }"},750{"lineNum":" 749","line":" }"},751{"lineNum":" 750","line":" }"},752{"lineNum":" 751","line":""},753{"lineNum":" 752","line":" #[test]"},754{"lineNum":" 753","line":" fn test_func_arity_0() {"},755{"lineNum":" 754","line":" fn foo(_: &mut vm::Ctx) -> i32 {"},756{"lineNum":" 755","line":" 0"},757{"lineNum":" 756","line":" }"},758{"lineNum":" 757","line":""},759{"lineNum":" 758","line":" fn bar() -> i32 {"},760{"lineNum":" 759","line":" 0"},761{"lineNum":" 760","line":" }"},762{"lineNum":" 761","line":""},763{"lineNum":" 762","line":" let _ = Func::new(foo);"},764{"lineNum":" 763","line":" let _ = Func::new(bar);"},765{"lineNum":" 764","line":" let _ = Func::new(|_: &mut vm::Ctx| -> i32 { 0 });"},766{"lineNum":" 765","line":" let _ = Func::new(|| -> i32 { 0 });"},767{"lineNum":" 766","line":" }"},768{"lineNum":" 767","line":""},769{"lineNum":" 768","line":" test_func_arity_n!(test_func_arity_1, a);"},770{"lineNum":" 769","line":" test_func_arity_n!(test_func_arity_2, a, b);"},771{"lineNum":" 770","line":" test_func_arity_n!(test_func_arity_3, a, b, c);"},772{"lineNum":" 771","line":" test_func_arity_n!(test_func_arity_4, a, b, c, d);"},773{"lineNum":" 772","line":" test_func_arity_n!(test_func_arity_5, a, b, c, d, e);"},774{"lineNum":" 773","line":" test_func_arity_n!(test_func_arity_6, a, b, c, d, e, f);"},775{"lineNum":" 774","line":" test_func_arity_n!(test_func_arity_7, a, b, c, d, e, f, g);"},776{"lineNum":" 775","line":" test_func_arity_n!(test_func_arity_8, a, b, c, d, e, f, g, h);"},777{"lineNum":" 776","line":" test_func_arity_n!(test_func_arity_9, a, b, c, d, e, f, g, h, i);"},778{"lineNum":" 777","line":" test_func_arity_n!(test_func_arity_10, a, b, c, d, e, f, g, h, i, j);"},779{"lineNum":" 778","line":" test_func_arity_n!(test_func_arity_11, a, b, c, d, e, f, g, h, i, j, k);"},780{"lineNum":" 779","line":" test_func_arity_n!(test_func_arity_12, a, b, c, d, e, f, g, h, i, j, k, l);"},781{"lineNum":" 780","line":""},782{"lineNum":" 781","line":" #[test]"},783{"lineNum":" 782","line":" fn test_call() {"},784{"lineNum":" 783","line":" fn foo(_ctx: &mut vm::Ctx, a: i32, b: i32) -> (i32, i32) {"},785{"lineNum":" 784","line":" (a, b)"},786{"lineNum":" 785","line":" }"},787{"lineNum":" 786","line":""},788{"lineNum":" 787","line":" let _f = Func::new(foo);"},789{"lineNum":" 788","line":" }"},790{"lineNum":" 789","line":""},791{"lineNum":" 790","line":" #[test]"},792{"lineNum":" 791","line":" fn test_imports() {"},793{"lineNum":" 792","line":" use crate::{func, imports};"},794{"lineNum":" 793","line":""},795{"lineNum":" 794","line":" fn foo(_ctx: &mut vm::Ctx, a: i32) -> i32 {"},796{"lineNum":" 795","line":" a"},797{"lineNum":" 796","line":" }"},798{"lineNum":" 797","line":""},799{"lineNum":" 798","line":" let _import_object = imports! {"},800{"lineNum":" 799","line":" \"env\" => {"},801{"lineNum":" 800","line":" \"foo\" => func!(foo),"},802{"lineNum":" 801","line":" },"},803{"lineNum":" 802","line":" };"},804{"lineNum":" 803","line":" }"},805{"lineNum":" 804","line":"}"},806]};807var percent_low = 25;var percent_high = 75;808var header = { "command" : "compile_debug", "date" : "2019-11-28 11:37:30", "instrumented" : 6, "covered" : 0,};...

Full Screen

Full Screen

trampolines.rs.9bf9ed0.js

Source:trampolines.rs.9bf9ed0.js Github

copy

Full Screen

1var data = {lines:[2{"lineNum":" 1","line":"use crate::intrinsics::Intrinsics;"},3{"lineNum":" 2","line":"use inkwell::{"},4{"lineNum":" 3","line":" builder::Builder,"},5{"lineNum":" 4","line":" context::Context,"},6{"lineNum":" 5","line":" module::{Linkage, Module},"},7{"lineNum":" 6","line":" types::{BasicType, FunctionType},"},8{"lineNum":" 7","line":" values::FunctionValue,"},9{"lineNum":" 8","line":" AddressSpace,"},10{"lineNum":" 9","line":"};"},11{"lineNum":" 10","line":"use wasmer_runtime_core::{"},12{"lineNum":" 11","line":" module::ModuleInfo,"},13{"lineNum":" 12","line":" structures::{SliceMap, TypedIndex},"},14{"lineNum":" 13","line":" types::{FuncSig, SigIndex, Type},"},15{"lineNum":" 14","line":"};"},16{"lineNum":" 15","line":""},17{"lineNum":" 16","line":"pub fn generate_trampolines<\'ctx>(","class":"linePartCov","hits":"1","order":"530","possible_hits":"2",},18{"lineNum":" 17","line":" info: &ModuleInfo,"},19{"lineNum":" 18","line":" signatures: &SliceMap<SigIndex, FunctionType<\'ctx>>,"},20{"lineNum":" 19","line":" module: &Module<\'ctx>,"},21{"lineNum":" 20","line":" context: &\'ctx Context,"},22{"lineNum":" 21","line":" builder: &Builder<\'ctx>,"},23{"lineNum":" 22","line":" intrinsics: &Intrinsics<\'ctx>,"},24{"lineNum":" 23","line":") -> Result<(), String> {"},25{"lineNum":" 24","line":" for (sig_index, sig) in info.signatures.iter() {","class":"linePartCov","hits":"2","order":"531","possible_hits":"4",},26{"lineNum":" 25","line":" let func_type = signatures[sig_index];","class":"lineNoCov","hits":"0","possible_hits":"1",},27{"lineNum":" 26","line":""},28{"lineNum":" 27","line":" let trampoline_sig = intrinsics.void_ty.fn_type(","class":"lineNoCov","hits":"0","possible_hits":"2",},29{"lineNum":" 28","line":" &[","class":"lineNoCov","hits":"0","possible_hits":"1",},30{"lineNum":" 29","line":" intrinsics.ctx_ptr_ty.as_basic_type_enum(), // vmctx ptr","class":"lineNoCov","hits":"0","possible_hits":"1",},31{"lineNum":" 30","line":" func_type","class":"lineNoCov","hits":"0","possible_hits":"1",},32{"lineNum":" 31","line":" .ptr_type(AddressSpace::Generic)","class":"lineNoCov","hits":"0","possible_hits":"1",},33{"lineNum":" 32","line":" .as_basic_type_enum(), // func ptr"},34{"lineNum":" 33","line":" intrinsics.i64_ptr_ty.as_basic_type_enum(), // args ptr","class":"lineNoCov","hits":"0","possible_hits":"1",},35{"lineNum":" 34","line":" intrinsics.i64_ptr_ty.as_basic_type_enum(), // returns ptr","class":"lineNoCov","hits":"0","possible_hits":"1",},36{"lineNum":" 35","line":" ],"},37{"lineNum":" 36","line":" false,"},38{"lineNum":" 37","line":" );"},39{"lineNum":" 38","line":""},40{"lineNum":" 39","line":" let trampoline_func = module.add_function(","class":"lineNoCov","hits":"0","possible_hits":"3",},41{"lineNum":" 40","line":" &format!(\"trmp{}\", sig_index.index()),","class":"lineNoCov","hits":"0","possible_hits":"1",},42{"lineNum":" 41","line":" trampoline_sig,","class":"lineNoCov","hits":"0","possible_hits":"1",},43{"lineNum":" 42","line":" Some(Linkage::External),","class":"lineNoCov","hits":"0","possible_hits":"1",},44{"lineNum":" 43","line":" );","class":"lineNoCov","hits":"0","possible_hits":"2",},45{"lineNum":" 44","line":""},46{"lineNum":" 45","line":" generate_trampoline(trampoline_func, sig, context, builder, intrinsics)?;","class":"lineNoCov","hits":"0","possible_hits":"3",},47{"lineNum":" 46","line":" }"},48{"lineNum":" 47","line":" Ok(())","class":"lineCov","hits":"1","order":"532","possible_hits":"1",},49{"lineNum":" 48","line":"}","class":"lineCov","hits":"2","order":"533","possible_hits":"2",},50{"lineNum":" 49","line":""},51{"lineNum":" 50","line":"fn generate_trampoline<\'ctx>(","class":"lineNoCov","hits":"0","possible_hits":"2",},52{"lineNum":" 51","line":" trampoline_func: FunctionValue,"},53{"lineNum":" 52","line":" func_sig: &FuncSig,"},54{"lineNum":" 53","line":" context: &\'ctx Context,"},55{"lineNum":" 54","line":" builder: &Builder<\'ctx>,"},56{"lineNum":" 55","line":" intrinsics: &Intrinsics<\'ctx>,"},57{"lineNum":" 56","line":") -> Result<(), String> {"},58{"lineNum":" 57","line":" let entry_block = context.append_basic_block(trampoline_func, \"entry\");","class":"lineNoCov","hits":"0","possible_hits":"1",},59{"lineNum":" 58","line":" builder.position_at_end(&entry_block);","class":"lineNoCov","hits":"0","possible_hits":"1",},60{"lineNum":" 59","line":""},61{"lineNum":" 60","line":" let (vmctx_ptr, func_ptr, args_ptr, returns_ptr) = match trampoline_func.get_params().as_slice()","class":"lineNoCov","hits":"0","possible_hits":"2",},62{"lineNum":" 61","line":" {"},63{"lineNum":" 62","line":" &[vmctx_ptr, func_ptr, args_ptr, returns_ptr] => (","class":"lineNoCov","hits":"0","possible_hits":"3",},64{"lineNum":" 63","line":" vmctx_ptr,","class":"lineNoCov","hits":"0","possible_hits":"1",},65{"lineNum":" 64","line":" func_ptr.into_pointer_value(),","class":"lineNoCov","hits":"0","possible_hits":"1",},66{"lineNum":" 65","line":" args_ptr.into_pointer_value(),","class":"lineNoCov","hits":"0","possible_hits":"1",},67{"lineNum":" 66","line":" returns_ptr.into_pointer_value(),","class":"lineNoCov","hits":"0","possible_hits":"1",},68{"lineNum":" 67","line":" ),"},69{"lineNum":" 68","line":" _ => return Err(\"trampoline function unimplemented\".to_string()),","class":"lineNoCov","hits":"0","possible_hits":"3",},70{"lineNum":" 69","line":" };","class":"lineNoCov","hits":"0","possible_hits":"3",},71{"lineNum":" 70","line":""},72{"lineNum":" 71","line":" let cast_ptr_ty = |wasmer_ty| match wasmer_ty {","class":"lineNoCov","hits":"0","possible_hits":"4",},73{"lineNum":" 72","line":" Type::I32 | Type::F32 => intrinsics.i32_ptr_ty,","class":"lineNoCov","hits":"0","possible_hits":"2",},74{"lineNum":" 73","line":" Type::I64 | Type::F64 => intrinsics.i64_ptr_ty,","class":"lineNoCov","hits":"0","possible_hits":"1",},75{"lineNum":" 74","line":" Type::V128 => intrinsics.i128_ptr_ty,","class":"lineNoCov","hits":"0","possible_hits":"1",},76{"lineNum":" 75","line":" };","class":"lineNoCov","hits":"0","possible_hits":"2",},77{"lineNum":" 76","line":""},78{"lineNum":" 77","line":" let mut args_vec = Vec::with_capacity(func_sig.params().len() + 1);","class":"lineNoCov","hits":"0","possible_hits":"2",},79{"lineNum":" 78","line":" args_vec.push(vmctx_ptr);","class":"lineNoCov","hits":"0","possible_hits":"1",},80{"lineNum":" 79","line":""},81{"lineNum":" 80","line":" let mut i = 0;","class":"lineNoCov","hits":"0","possible_hits":"1",},82{"lineNum":" 81","line":" for param_ty in func_sig.params().iter() {","class":"lineNoCov","hits":"0","possible_hits":"4",},83{"lineNum":" 82","line":" let index = intrinsics.i32_ty.const_int(i as _, false);","class":"lineNoCov","hits":"0","possible_hits":"1",},84{"lineNum":" 83","line":" let item_pointer = unsafe { builder.build_in_bounds_gep(args_ptr, &[index], \"arg_ptr\") };","class":"lineNoCov","hits":"0","possible_hits":"1",},85{"lineNum":" 84","line":""},86{"lineNum":" 85","line":" let casted_pointer_type = cast_ptr_ty(*param_ty);","class":"lineNoCov","hits":"0","possible_hits":"1",},87{"lineNum":" 86","line":""},88{"lineNum":" 87","line":" let typed_item_pointer ="},89{"lineNum":" 88","line":" builder.build_pointer_cast(item_pointer, casted_pointer_type, \"typed_arg_pointer\");","class":"lineNoCov","hits":"0","possible_hits":"1",},90{"lineNum":" 89","line":""},91{"lineNum":" 90","line":" let arg = builder.build_load(typed_item_pointer, \"arg\");","class":"lineNoCov","hits":"0","possible_hits":"1",},92{"lineNum":" 91","line":" args_vec.push(arg);","class":"lineNoCov","hits":"0","possible_hits":"1",},93{"lineNum":" 92","line":" i = i + 1;","class":"lineNoCov","hits":"0","possible_hits":"2",},94{"lineNum":" 93","line":" if *param_ty == Type::V128 {","class":"lineNoCov","hits":"0","possible_hits":"1",},95{"lineNum":" 94","line":" i = i + 1;","class":"lineNoCov","hits":"0","possible_hits":"3",},96{"lineNum":" 95","line":" }"},97{"lineNum":" 96","line":" }"},98{"lineNum":" 97","line":""},99{"lineNum":" 98","line":" let call_site = builder.build_call(func_ptr, &args_vec, \"call\");","class":"lineNoCov","hits":"0","possible_hits":"2",},100{"lineNum":" 99","line":""},101{"lineNum":" 100","line":" match func_sig.returns() {","class":"lineNoCov","hits":"0","possible_hits":"2",},102{"lineNum":" 101","line":" &[] => {}","class":"lineNoCov","hits":"0","possible_hits":"1",},103{"lineNum":" 102","line":" &[one_ret] => {","class":"lineNoCov","hits":"0","possible_hits":"2",},104{"lineNum":" 103","line":" let ret_ptr_type = cast_ptr_ty(one_ret);","class":"lineNoCov","hits":"0","possible_hits":"2",},105{"lineNum":" 104","line":""},106{"lineNum":" 105","line":" let typed_ret_ptr ="},107{"lineNum":" 106","line":" builder.build_pointer_cast(returns_ptr, ret_ptr_type, \"typed_ret_ptr\");","class":"lineNoCov","hits":"0","possible_hits":"1",},108{"lineNum":" 107","line":" builder.build_store(","class":"lineNoCov","hits":"0","possible_hits":"2",},109{"lineNum":" 108","line":" typed_ret_ptr,","class":"lineNoCov","hits":"0","possible_hits":"1",},110{"lineNum":" 109","line":" call_site.try_as_basic_value().left().unwrap(),","class":"lineNoCov","hits":"0","possible_hits":"1",},111{"lineNum":" 110","line":" );"},112{"lineNum":" 111","line":" }"},113{"lineNum":" 112","line":" _ => {"},114{"lineNum":" 113","line":" return Err(\"trampoline function multi-value returns unimplemented\".to_string());","class":"lineNoCov","hits":"0","possible_hits":"3",},115{"lineNum":" 114","line":" }"},116{"lineNum":" 115","line":" }"},117{"lineNum":" 116","line":""},118{"lineNum":" 117","line":" builder.build_return(None);","class":"lineNoCov","hits":"0","possible_hits":"1",},119{"lineNum":" 118","line":" Ok(())","class":"lineNoCov","hits":"0","possible_hits":"1",},120{"lineNum":" 119","line":"}","class":"lineNoCov","hits":"0","possible_hits":"4",},121]};122var percent_low = 25;var percent_high = 75;123var header = { "command" : "compile_debug", "date" : "2019-11-28 11:37:30", "instrumented" : 60, "covered" : 4,};...

Full Screen

Full Screen

main.js

Source:main.js Github

copy

Full Screen

1function googleSuccess() {2 'use strict';3 console.log('m here');4 // List of markers to display on map5 var markers = [6 {7 placeName: 'San Francisco Zoo',8 icon: 'img/koala.png',9 latLng: {10 lat: 37.732873,11 lng: -122.50297212 },13 photos: [14 'img/sf-zoo-1.jpg',15 'img/sf-zoo-2.jpg',16 'img/sf-zoo-3.jpg'17 ]18 },19 {20 placeName: 'Mission Dolores Park',21 icon: 'img/park.png',22 latLng: {23 lat: 37.759718,24 lng: -122.42705825 },26 photos: [27 'img/dolores-park-1.jpg',28 'img/dolores-park-2.jpg',29 'img/dolores-park-3.jpg'30 ]31 },32 {33 placeName: 'Japanese Tea Garden',34 icon: 'img/garden.png',35 latLng: {36 lat: 37.769752,37 lng: -122.46979938 },39 photos: [40 'img/japanese-garden-1.jpg',41 'img/japanese-garden-2.jpg',42 'img/japanese-garden-3.jpg'43 ]44 },45 {46 placeName: 'Baker Beach',47 icon: 'img/beach.png',48 latLng: {49 lat: 37.793562,50 lng: -122.48357851 },52 photos: [53 'img/baker-beach-1.jpg',54 'img/baker-beach-2.jpg',55 'img/baker-beach-3.jpg'56 ]57 },58 {59 placeName: 'Fort Point',60 icon: 'img/fort.png',61 latLng: {62 lat: 37.810594,63 lng: -122.47696464 },65 photos: [66 'img/fort-point-1.jpg',67 'img/fort-point-2.jpg',68 'img/fort-point-3.jpg'69 ]70 },71 {72 placeName: 'Coit Tower',73 icon: 'img/tower.png',74 latLng: {75 lat: 37.802396,76 lng: -122.40578977 },78 photos: [79 'img/coit-tower-1.jpg',80 'img/coit-tower-2.jpg',81 'img/coit-tower-3.jpg'82 ]83 }84 ];85 /**86 * Helper function to check if element has certain class87 */88 function hasClass(element, className) {89 return (' ' + element.className + ' ').indexOf(' ' + className + ' ') > -1;90 }91 /**92 * Represents a single map marker93 */94 var Marker = function (latLng, placeName, icon, map) {95 return new google.maps.Marker({96 position: latLng,97 map: map,98 icon: icon,99 title: placeName100 });101 };102 /**103 * Append a button to the infowindow for the random yes or no answer104 */105 var appendYesOrNo = function(marker) {106 // Get the info window currently displayed.107 var infowindow = document.getElementById('info');108 // Attach a button to call YesOrNo API109 var div = document.createElement('div');110 div.id = 'answer';111 var btn = document.createElement('button');112 btn.id = 'questionBtn';113 var t = document.createTextNode('Do you think I should go?');114 btn.appendChild(t);115 btn.onclick = (function(){return yesOrNo(marker)});116 div.appendChild(btn);117 infowindow.appendChild(div);118 };119 /**120 * Use yesno api to retrieve a random yes or no answer with a gif121 */122 var yesOrNo = function(marker) {123 var xhttp = new XMLHttpRequest();124 var yesOrNoApiUrl = 'http://yesno.wtf/api/'125 xhttp.onreadystatechange = function() {126 if (xhttp.readyState == 4 && xhttp.status == 200) {127 var responseJson = JSON.parse(xhttp.responseText);128 var oImg=document.createElement('img');129 var btn = document.getElementById('questionBtn');130 oImg.setAttribute('src', responseJson.image);131 btn.style.display = 'none';132 document.getElementById('answer').appendChild(oImg);133 // Change center of map for marker to be at the bottom,134 // to display full info window135 var map = marker.getMap();136 var markerPos = marker.getPosition();137 var getSouthWest = map.getBounds().getSouthWest();138 var mapCenter = map.getCenter();139 var markerPosSWDiff = markerPos.lat() - getSouthWest.lat();140 var newLat = mapCenter.lat() + (markerPosSWDiff/2);141 map.setCenter({lat: newLat, lng: mapCenter.lng()});142 } else if (xhttp.readyState == 4 && xhttp.status != 200) {143 document.getElementById('error').innerHTML = 'Something went wrong. Ask me later!';144 }145 };146 xhttp.open('GET', yesOrNoApiUrl, true);147 xhttp.send();148 };149 /**150 * Use Foursquare api to get the place id then use it to get tips151 */152 function getFoursquareTips(marker) {153 var xhttp = new XMLHttpRequest();154 var getPlaceUrl = 'https://api.foursquare.com/v2/venues/search?'+155 'll=' + marker.position.lat() + ',' + marker.position.lng() +156 '&limit=1&radius=100&'+157 'oauth_token=MA1GR4J2VETXZPIGSPCMSS1A4WGKLVFFG41IVZMQY54KXIP2&'+158 'v=20140806';159 xhttp.onreadystatechange = function() {160 if (xhttp.readyState == 4 && xhttp.status == 200) {161 var responseJson = JSON.parse(xhttp.responseText);162 getTips(responseJson.response.venues[0].id);163 } else if (xhttp.readyState == 4 && xhttp.status != 200) {164 document.getElementById('error').innerHTML = 'Sorry. We\'re unable to find info about the place!';165 }166 };167 xhttp.open('GET', getPlaceUrl, true);168 xhttp.send();169 };170 /**171 * Use Foursquare api to get tips for the place giving the place id172 */173 function getTips(placeId) {174 var xhttp = new XMLHttpRequest();175 var getTipsUrl = 'https://api.foursquare.com/v2/venues/'+176 placeId + '/tips?'+177 'oauth_token=MA1GR4J2VETXZPIGSPCMSS1A4WGKLVFFG41IVZMQY54KXIP2&v=20140806'+178 '&sort=popular&limit=3';179 xhttp.onreadystatechange = function() {180 if (xhttp.readyState == 4 && xhttp.status == 200) {181 var responseJson = JSON.parse(xhttp.responseText);182 var text = document.createTextNode(responseJson.response.tips.items[0].text);183 var tipsDiv = document.getElementById('tips');184 tipsDiv.appendChild(text);185 } else if (xhttp.readyState == 4 && xhttp.status != 200) {186 document.getElementById('error').innerHTML = 'Sorry. We\'re unable to find any tips!';187 }188 };189 xhttp.open('GET', getTipsUrl, true);190 xhttp.send();191 };192 /**193 * The ViewModel for our neighborhood App194 */195 var ViewModel = function (markers) {196 // Refer to the context of ViewModel197 var vmCtx = this;198 this.currentPlaceImages = ko.observableArray([]);199 // Define center of map and map options200 var myLatlng = new google.maps.LatLng(37.765733, -122.454162);201 var mapOptions = {202 zoom: 12,203 center: myLatlng,204 mapTypeId: google.maps.MapTypeId.ROADMAP205 };206 // Load map in map div207 this.map = new google.maps.Map(document.getElementById('map'),208 mapOptions);209 // Create one infowindow to be used by all marker, instead of creating one210 // for every marker, to avoid visual clutter and have only one window open211 // at any given time212 this.infowindow = new google.maps.InfoWindow();213 /**214 * Executes when a marker or its corresponding name in the list is clicked215 */216 this.highlightMarker = function(marker) {217 var self = vmCtx;218 // Check if name list is shown, hide it.219 // This hides the fullscreen list of places names when it's on mobile220 var nameList = document.getElementById('list-menu');221 if(hasClass(nameList, 'activated')) {222 nameList.className = '';223 }224 var content = '<div id="info"><h1>' + marker.title + '</h1>'+225 '<div id="tips"></div><div id="error"></div>'+'</div>';226 vmCtx.infowindow.setContent(content);227 vmCtx.infowindow.open(marker.get('map'), marker);228 vmCtx.map.setZoom(12);229 vmCtx.pounceMarker(marker);230 vmCtx.addPhotos(marker);231 getFoursquareTips(marker);232 appendYesOrNo(marker);233 };234 /**235 * Triggers marker pounce animation236 */237 this.pounceMarker = function(marker) {238 // Trigger animation239 marker.setAnimation(google.maps.Animation.BOUNCE);240 // Stop animation241 vmCtx.stopAnimation(marker);242 // Set center of map to the current marker position243 vmCtx.map.panTo(marker.getPosition());244 };245 /**246 * Stop marker pounce animation247 */248 this.stopAnimation = function(marker) {249 setTimeout(function () {250 marker.setAnimation(null);251 }, 1000);252 };253 /**254 * Add current marker's place photos to currentPlaceImages observable array255 */256 this.addPhotos = function(marker) {257 var len = marker.photos.length,258 photos = marker.photos;259 // Clear pictures of past marker260 vmCtx.currentPlaceImages.removeAll();261 // Add the new marker photos262 for(var i = 0; i < len; ++i) {263 vmCtx.currentPlaceImages.push(photos[i]);264 }265 };266 /**267 * Map array of passed markers to an observableArray of Marker objects268 */269 this.markers = ko.observableArray(markers.map(function (marker) {270 var photos = marker.photos;271 var marker = new Marker(marker.latLng, marker.placeName, marker.icon, vmCtx.map);272 marker.photos = photos;273 google.maps.event.addListener(marker, 'click', function() {274 vmCtx.highlightMarker(marker);275 });276 return marker;277 }));278 // Keep track of visible markers279 this.visibleMarkers = this.markers;280 // Show List of names281 this.activateList = function() {282 var element = document.getElementById('list-menu');283 console.log(element.style);284 if(!element.style.display) {285 element.className = 'activated';286 }287 }288 // Value of search query289 this.query = ko.observable('');290 /**291 * Search markers for a name that matches the search query and292 * add the matched markers to the visibleMarkers observable array293 */294 this.runQuery = ko.computed(function() {295 this.visibleMarkers = ko.computed(function() {296 var query = this.query()297 // Filter array elements based on place name, hide the markers that are not a match298 // and save results in visibleMarkers observable array299 return this.markers().filter(function (marker) {300 if(marker.title.toLowerCase().indexOf(query.toLowerCase()) >= 0) {301 marker.setVisible(true);302 return marker;303 } else {304 marker.setVisible(false);305 }306 });307 }, this);308 }, this);309 };310 // Bind a new instance of our view model to the page311 var viewModel = new ViewModel(markers || []);312 ko.applyBindings(viewModel);313 console.log(viewModel);314}315function googleError(){316 var app = document.getElementById('app');317 app.innerHTML = '<div class="error">'+ '<p>Unfortunately we\'re unable to load the map. '+318 'Here\'s some cute cats instead! </p>' +319 '<img src="img/cutecat.jpg"></div>';...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1#!/usr/bin/env node2const fs = require('fs');3const path = require('path');4const { promisify } = require('util');5const vm = require('vm');6const commonmark = require('commonmark');7const cheerio = require('cheerio');8// utils9const readFile = promisify(fs.readFile);10const writeFile = promisify(fs.writeFile);11function parseContent(content) {12 let readingKey = true;13 let readingValue = false;14 let key, value;15 let mark = 0;16 const parsed = {};17 for (let i = 0; i < content.length; i++) {18 switch (content[i]) {19 case '=':20 if (readingKey) {21 readingKey = false;22 key = content.substr(mark, i-mark);23 mark = i+1;24 readingValue = true;25 }26 break;27 case '\n':28 if (readingKey) {29 parsed.content = content.substr(mark);30 i = content.length;31 break;32 }33 readingValue = false;34 value = content.substr(mark, i-mark);35 parsed[key] = value;36 mark = i+1;37 readingKey = true;38 break;39 }40 }41 var reader = new commonmark.Parser();42 var writer = new commonmark.HtmlRenderer();43 parsed.content = writer.render(reader.parse(parsed.content));44 return parsed;45}46const contentCache = {};47function contentFromFile(dirPath, relPath) {48 const absPath = path.join(dirPath, relPath);49 let parsed;50 if (contentCache[absPath]) {51 parsed = contentCache[absPath];52 } else {53 parsed = parseContent(fs.readFileSync(absPath, 'utf8'));54 contentCache[absPath] = parsed;55 }56 const extIdx = relPath.lastIndexOf('.');57 parsed.fileName = extIdx < 0 ? path.basename(relPath) : path.basename(relPath.substr(0, extIdx));58 parsed.baseFileName = extIdx < 0 ? relPath : relPath.substr(0, extIdx);59 parsed.relPath = relPath;60 return parsed;61}62class Contents extends Array {63 constructor() {64 super(...arguments);65 }66 mostRecent(n=0, by='date') {67 if (n <= 0 || n === undefined) {68 n = this.length;69 }70 return this71 .map(d => {72 if (d[by]) {73 return d;74 }75 d[by] = new Date() + "";76 return d;77 })78 .sort((left, right) => {79 const ld = new Date(left[by]);80 const rd = new Date(right[by]);81 if (ld < rd) {82 return 1;83 } else if (ld > rd) {84 return -1;85 }86 return 0;87 })88 .slice(0, n);89 }90}91function contentFromDirectory(baseDir, relPath) {92 const dirPath = path.join(baseDir, relPath);93 return new Contents(...fs.readdirSync(dirPath).map(filePath => {94 return contentFromFile(baseDir, path.join(relPath, filePath));95 }));96}97class Queue {98 constructor() {99 this.q = new Array();100 }101 enqueue(elem) {102 this.q.unshift(elem);103 }104 dequeue() {105 return this.q.pop();106 }107 isEmpty() {108 return this.q.length === 0;109 }110}111function mkdirRSync(mkpath) {112 if (mkpath.length === 0) {113 return;114 }115 const lof = mkpath.lastIndexOf(path.sep);116 if (lof != -1) {117 mkdirRSync(mkpath.substr(0, lof))118 }119 if (!fs.existsSync(mkpath)) {120 fs.mkdirSync(mkpath);121 }122}123class Compiler {124 constructor(srcDir, vmCtx, compileQueue) {125 this.srcDir = srcDir;126 this.cwd = '';127 this.vmCtx = vmCtx;128 this.compileQueue = compileQueue;129 this.cache = {};130 // extend ctx131 this.vmCtx.compile = this.compile.bind(this);132 this.vmCtx.compileDyn = this.compileDyn.bind(this);133 this.vmCtx.include = this.include.bind(this);134 }135 compileDyn(filePath) {136 return this.compile(filePath, {dynamic: true})137 }138 include(includePath, opt) {139 const filePath = path.join(this.srcDir, includePath);140 const stat = fs.statSync(filePath);141 if (stat.isDirectory()) {142 const dirPath = filePath;143 return fs.readdirSync(dirPath).filter(fileInDirPath => {144 if (opt.excludeExt) {145 let ext = fileInDirPath.startsWith(".") ? fileInDirPath : path.extname(fileInDirPath);146 ext = ext.slice(1).toLowerCase();147 const shouldInclude = opt.excludeExt.filter(excludeExt => {148 return excludeExt.toLowerCase() === ext;149 }).length == 0;150 return shouldInclude;151 }152 return true;153 }).map(fileInDirPath => {154 const filePath = path.join(includePath, fileInDirPath);155 this.include(path.join(filePath));156 return filePath;157 }).flat();158 }159 this.compileQueue.enqueue([this.cwd, includePath]);160 return includePath;161 }162 compile(filePath, opts={}) {163 const absPath = path.join(this.cwd, filePath);164 if (this.cache[absPath]) {165 return this.cache[absPath];166 }167 let result;168 switch (path.extname(filePath).toLowerCase()) {169 case '.md': {170 const content = contentFromFile(this.cwd, filePath);171 if (!content.template) {172 throw new Error("content missing template; cannot compile");173 }174 const templateFile = path.join(this.srcDir, content.template);175 const data = cheerio.load(fs.readFileSync(templateFile, 'utf8'), {_useHtmlParser2: true});176 const localCtx = vm.createContext({ ...this.vmCtx });177 localCtx.content = content;178 data('script[compile]').each((idx, s) => {179 const result = vm.runInContext(`{${cheerio(s).html()}}`, localCtx);180 cheerio(s).replaceWith(result);181 });182 filePath = content.out ?183 path.join(path.dirname(filePath), content.out) :184 filePath.substr(0, filePath.lastIndexOf('.')) + ".html";185 result = [data.html(), filePath];186 break;187 };188 case '.html': {189 const data = cheerio.load(fs.readFileSync(absPath, 'utf8'), {_useHtmlParser2: true});190 const localCtx = vm.createContext({ ...this.vmCtx });191 localCtx.$ = data;192 data('script[compile]').each((idx, s) => {193 const result = vm.runInContext(`{${cheerio(s).html()}}`, localCtx);194 cheerio(s).replaceWith(result);195 });196 data('a[compile-ref]').each((idx, t) => {197 if (!this.compileQueue) {198 return;199 }200 const ref = cheerio(t).attr('compile-ref');201 cheerio(t).removeAttr('compile-ref');202 if (!this.cache[path.join(this.cwd, ref)]) {203 this.compileQueue.enqueue([this.cwd, ref]); 204 }205 })206 data('link[compile-ref][rel="stylesheet"]').each((idx, t) => {207 if (!this.compileQueue) {208 return;209 }210 const ref = cheerio(t).attr('href');211 cheerio(t).removeAttr('compile-ref');212 if (!this.cache[path.join(this.cwd, ref)]) {213 this.compileQueue.enqueue([this.cwd, ref]); 214 }215 })216 data('img[compile-ref]').each((idx, t) => {217 if (!this.compileQueue) {218 return;219 }220 const src = cheerio(t).attr('src');221 cheerio(t).removeAttr('compile-ref');222 if (!this.cache[path.join(this.cwd, src)]) {223 this.compileQueue.enqueue([this.cwd, src]);224 }225 })226 result = data.html();227 break;228 };229 case '.css':230 case '.png':231 case '.jpg': {232 result = fs.readFileSync(absPath, 'binary');233 break;234 };235 default:236 throw new Error("do not know how to compile " + filePath);237 }238 if (!opts.dynamic) {239 this.cache[absPath] = result;240 }241 return result;242 }243}244// main245(async () => {246 if (!process.argv[2]) {247 console.error("project directory required");248 return;249 }250 const rootDir = process.argv[2];251 const rootStat = fs.statSync(rootDir);252 if (!rootStat.isDirectory()) {253 console.error("project directory required");254 return;255 }256 const configStr = await readFile(path.join(process.argv[2], 'config.json'), 'utf8')257 const config = JSON.parse(configStr);258 const srcDir = path.join(rootDir, 'src');259 const ctx = {260 'buildInfo': {261 'date': new Date(),262 },263 '$': cheerio,264 'content': from => {265 const filePath = path.join(srcDir, from);266 const stat = fs.statSync(filePath);267 if (stat.isDirectory()) {268 return contentFromDirectory(srcDir, from);269 }270 return contentFromFile(srcDir, from);271 },272 'console': console,273 'config': config,274 'tween': (arr, value) => {275 const arrCopy = arr.slice();276 const origLen = arrCopy.length;277 const newLen = (origLen*2)-1;278 for (let i = 0; i < newLen-1; i+=2) {279 arrCopy.splice(i+1, 0, value);280 }281 return arrCopy;282 }283 };284 try {285 ctx.buildInfo.revision = require('child_process')286 .execSync(`cd ${process.argv[2]}; git rev-parse --short HEAD`)287 .toString().trim()288 } catch (ignored) {}289 vm.createContext(ctx);290 const indexRelPath = config.src || "index.html";291 const compileQueue = new Queue();292 compileQueue.enqueue([srcDir, indexRelPath]);293 const compiler = new Compiler(srcDir, ctx, compileQueue);294 while (!compileQueue.isEmpty()) {295 let [baseDir, relPath] = compileQueue.dequeue();296 compiler.cwd = baseDir;297 try {298 ctx.path = path.join('/', relPath);299 let file = compiler.compile(relPath);300 if (config.out) {301 const outDir = path.join(rootDir, config.out);302 if (file instanceof Array) {303 relPath = file[1];304 file = file[0];305 }306 const outPath = path.join(outDir, relPath);307 mkdirRSync(path.dirname(outPath));308 await writeFile(outPath, file, {encoding: 'binary'})309 console.info("updated", outPath);310 }311 } catch (err) {312 console.error("error compiling", err)313 process.exit(1);314 }315 }...

Full Screen

Full Screen

script-searcher.js

Source:script-searcher.js Github

copy

Full Screen

1'use strict';2const vm = require('vm');3const DEBUG = true;4const getScriptUrl = function(embededPage) {5 if (typeof embededPage !== 'string') throw new Error('Invalid argument: argument must be type of "string"');6 const match = Array.from(embededPage.matchAll(/<script\s+src\s*=\s*"(?<path>[-a-zA-Z0-9@:%._\/\+~#=]+)\/base.js"/g));7 if (match.length === 0) throw new Error('Script */base.js does not exists');8 return match[0].groups.path + '/base.js';9};10const Searcher = function(script) {11 const _getDecipherCode = function() {12 /*13 source from youtube-dl: _parse_sig_js(self, jscode);14 */15 const commonPtrn = [16 /\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?<funcName>[a-zA-Z0-9$]+)\(/,17 /\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?<funcName>[a-zA-Z0-9$]+)\(/,18 /(?:\b|[^a-zA-Z0-9$])(?<funcName>[a-zA-Z0-9$]{2})\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)/,19 /(?<funcName>[a-zA-Z0-9$]+)\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)/20 ];21 let entryFunc = null;22 commonPtrn.some((r) => {23 const match = script.match(r);24 if (!match) return false;25 entryFunc = match.groups.funcName;26 return true27 })28 if (!entryFunc) throw new Error('Cannot find entry function for decryption');29 const entryFuncCode = _getVarDefinition(entryFunc);30 printLog(`varName: ${entryFunc}, def: ${entryFuncCode}`);31 let funcList = [entryFuncCode];32 let maxAllowedTry = 100;33 let vmCtx = {};34 vm.createContext(vmCtx);35 vm.runInContext(entryFuncCode, vmCtx);36 do {37 try {38 --maxAllowedTry;39 printLog('eval entry function: ' + maxAllowedTry);40 vm.runInContext(`${entryFunc}('_dummy_string_')`, vmCtx);41 break;42 } catch (e) {43 if (e.name === 'ReferenceError') {44 const fname = _getUndefinedVarName(e.message);45 const fcode = _getVarDefinition(fname);46 printLog(`varName: ${fname}, def: ${fcode}`);47 vm.runInContext(fcode, vmCtx);48 funcList.push(fcode);49 } else {50 printLog(`Unknown error: ${e}`);51 throw e;52 }53 }54 } while (maxAllowedTry > 0)55 if (maxAllowedTry === 0) throw new Error('Cannot obtain decrypt function within 100 tries');56 return {57 entry: entryFunc,58 code: funcList.join('\n')59 };60 }61 const _getUndefinedVarName = function(errMsg) {62 printLog(`getUndefinedVarName: ${errMsg}`)63 const match = errMsg.match(/^(?<varName>\w+) is not defined$/);64 if (!match) throw new Error(`Unexpected error: ${errMsg}`);65 else printLog(match.groups.varName);66 return match.groups.varName;67 }68 const _getVarDefinition = function(varName) {69 // accept var definition in following style:70 // (var|let|const|) varName=(*|function(*))71 // special checking: varName cannot follow any character other than [,;\s]72 // assume var definition ends with ';' and no string literals included73 const dec = script.match(new RegExp(`(?:\\b(?:var|let|const)\\s+)?(?:[,;\\s]+|^)${varName}\\s*=\\s*(?<f>function\\s*\\([^)]*\\))?`));74 if (!dec) throw new Error(`Cannot find variable ${varName}`);75 const sIdx = dec.index + dec[0].length;76 let eIdx = 0;77 if (!dec.groups.f) {78 // non-function definition79 let c = script[sIdx];80 if (c === '{' || c === '[' || c === '(') {81 eIdx = _balanceSymbol(sIdx);82 } else {83 eIdx = sIdx;84 do {85 c = script[++eIdx];86 }87 while (c !== ';')88 }89 } else {90 // function definition91 eIdx = _balanceSymbol(sIdx);92 }93 return dec[0] + script.substring(sIdx, eIdx);94 }95 const _balanceSymbol = function(startIdx) {96 // find end index of symbol that balances code starts with start index97 // assume no string literals in code98 let idx = startIdx;99 let stack = [];100 while (idx < script.length) {101 const c = script[idx];102 ++idx;103 switch (c) {104 case '{':105 case '(':106 case '[':107 stack.push(c);108 break;109 case '}':110 if (stack.length > 0 && stack[stack.length-1] === '{') {111 stack.pop();112 } else throw new Error('Inbalanced bracket "}"');113 break;114 case ')':115 if (stack.length > 0 && stack[stack.length-1] === '(') {116 stack.pop();117 } else throw new Error('Inbalanced bracket ")"');118 break;119 case ']':120 if (stack.length > 0 && stack[stack.length-1] === '[') {121 stack.pop();122 } else throw new Error('Inbalanced bracket "]"');123 break;124 }125 if (stack.length === 0) break;126 }127 if (stack.length !== 0) throw new Error('Inbalanced brackets');128 return idx;129 }130 this.decipherCode = _getDecipherCode();131};132const Decrypter = function(decipherCode) {133 let vmCtx = {};134 vm.createContext(vmCtx);135 vm.runInContext(decipherCode.code, vmCtx);136 const decipher = vm.runInContext(decipherCode.entry, vmCtx);137 this.getDecryptedUrl = function(cipher) {138 // cipher contains 3 url parameters: s(encrypted signature), sp(param to be added to result url), url139 const params = cipher.split('&');140 let paramMap = {};141 params.forEach((pair) => {142 let kV = pair.split('=');143 if (kV.length == 2) {144 paramMap[kV[0]] = kV[1];145 }146 });147 if (!paramMap.s) throw new Error('Missing "s" parameter in signatureCipher');148 if (!paramMap.sp) throw new Error('Missing "sp" parameter in signatureCipher');149 if (!paramMap.url) throw new Error('Missing "url" parameter in signatureCipher');150 const signature = decipher(decodeURIComponent(paramMap.s));151 return decodeURIComponent(paramMap.url) + '&' + paramMap.sp + '=' + signature +152 '&ratebypass=yes';153 };154};155const printLog = function(message) {156 if (DEBUG) console.log(message);157}...

Full Screen

Full Screen

execute-child.js

Source:execute-child.js Github

copy

Full Screen

...26 const vmCtx = vm.runInNewContext(fullScript, {}, {timeout});27 // run the driver script, giving user access to the driver object, a fake28 // console logger, and a promise library29 log.info('Running driver script in Node vm');30 let result = await vmCtx(driver, consoleFns, B);31 log.info('Ensuring driver script result is appropriate type for return');32 result = coerceScriptResult(result);33 return {result, logs};34}35/**36 * Embed a user-generated script inside a method which takes only the37 * predetermined objects we specify38 *39 * @param {string} script - the javascript to execute40 *41 * @return {string} - the full script to execute42 */43function buildScript (script) {44 return `(async function execute (driver, console, Promise) {...

Full Screen

Full Screen

checkLeaks.js

Source:checkLeaks.js Github

copy

Full Screen

1/*2 print what symbols a script makes in the top-level scope3 use this to check for unprefixed names4 also try running your program with --use_strict to find undeclared globals5 */6var vm = require('vm');7var fs = require('fs');8var what = 'nonhs';9var script;10var wrap = false;11var opts = [];12var nonOpts = [];13for(var i=2;i<process.argv.length;i++) {14 var a = process.argv[i];15 if(a.substring(0,2) == '--') opts.push(a); else nonOpts.push(a);16}17if(nonOpts.length === 1) script = getScript(nonOpts[0]); else usage();18opts.forEach(function(opt) {19 if(opt === '--wrap') wrap = true;20 else if(opt === '--all') what = 'all';21 else if(opt === '--public') what = 'public';22 else usage();23});24function getScript(name) {25 return fs.readFileSync(name);26}27function usage() {28 console.log(['usage', process.argv[0], process.argv[1],'[option]','script.js'].join(' '));29 console.log(['\n options'30 ,'--wrap: wrap script in function'31 ,'--all: print all names, not just those not prefixed with h$'32 ,'--public: print all public names (that do not start with h$$)'].join('\n '));33 process.exit(1);34}35/*36 give our script a process object, but process.exit shouldn't37 really exit the process, just stop the scheduler38 */39var ctxProcess = copy(process);40ctxProcess.exit = function(exitCode) {41 this.disableTimeout = true;42}43var ctxSetTimeout = function() {44 if(!ctxProcess.disableTimeout)45 return setTimeout.apply(this, arguments);46}47ctxProcess.stdin = null;48ctxProcess.disableTimeout = false;49var ctx = { global: global50 , process: ctxProcess51 , console: console52 , require: require53 , setTimeout: ctxSetTimeout54 , clearTimeout: clearTimeout55 , setInterval: setInterval56 , clearInterval: clearInterval57 , setImmediate: setImmediate58 , clearImmediate: clearImmediate59 , Buffer: Buffer60 , ArrayBuffer: ArrayBuffer61 , DataView: DataView62 , Int8Array: Int8Array63 , Uint8Array: Uint8Array64 , Uint8ClampedArray: Uint8ClampedArray65 , Int16Array: Int16Array66 , Uint16Array: Uint16Array67 , Int32Array: Int32Array68 , Uint32Array: Uint32Array69 , Float32Array: Float32Array70 , Float64Array: Float64Array71 };72function copy(o) {73 var q = {};74 for(var p in o) q[p] = o[p];75 return q;76}77var ctxBefore = copy(ctx);78console.log('*** starting script');79var vmCtx = vm.createContext(ctx);80if(wrap) script = '(function() {\n' + script + '})();'81vm.runInContext(script, vmCtx, '<script>');82reportGlobals(ctxBefore, vmCtx);83function reportGlobals(b, c) {84 console.log('*** script run, collected properties:');85 for(var p in c) {86 if(c.hasOwnProperty(p) && !b.hasOwnProperty(p)) {87 if(what === 'all' ||88 (what === 'public' && p.substring(0,3) !== 'h$$') ||89 (what === 'nonhs' && p.substring(0,2) !== 'h$'))90 console.log(' - ' + p);91 }92 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const vmCtx = await driver.vmCtx();2const vmCtx = await driver.vmCtx();3const vmCtx = await driver.vmCtx();4const vmCtx = await driver.vmCtx();5const vmCtx = await driver.vmCtx();6const vmCtx = await driver.vmCtx();7const vmCtx = await driver.vmCtx();8const vmCtx = await driver.vmCtx();9const vmCtx = await driver.vmCtx();10const vmCtx = await driver.vmCtx();11const vmCtx = await driver.vmCtx();12const vmCtx = await driver.vmCtx();

Full Screen

Using AI Code Generation

copy

Full Screen

1const vmCtx = driver.vmCtx;2const vm = vmCtx.vm;3const ctx = vmCtx.ctx;4const vmCtx = driver.vmCtx;5const vm = vmCtx.vm;6const ctx = vmCtx.ctx;7const vmCtx = driver.vmCtx;8const vm = vmCtx.vm;9const ctx = vmCtx.ctx;10const vmCtx = driver.vmCtx;11const vm = vmCtx.vm;12const ctx = vmCtx.ctx;13const vmCtx = driver.vmCtx;14const vm = vmCtx.vm;15const ctx = vmCtx.ctx;16const vmCtx = driver.vmCtx;17const vm = vmCtx.vm;18const ctx = vmCtx.ctx;19const vmCtx = driver.vmCtx;20const vm = vmCtx.vm;21const ctx = vmCtx.ctx;22const vmCtx = driver.vmCtx;23const vm = vmCtx.vm;24const ctx = vmCtx.ctx;25const vmCtx = driver.vmCtx;26const vm = vmCtx.vm;27const ctx = vmCtx.ctx;28const vmCtx = driver.vmCtx;29const vm = vmCtx.vm;30const ctx = vmCtx.ctx;31const vmCtx = driver.vmCtx;32const vm = vmCtx.vm;33const ctx = vmCtx.ctx;34const vmCtx = driver.vmCtx;35const vm = vmCtx.vm;36const ctx = vmCtx.ctx;37const vmCtx = driver.vmCtx;38const vm = vmCtx.vm;39const ctx = vmCtx.ctx;40const vmCtx = driver.vmCtx;41const vm = vmCtx.vm;42const ctx = vmCtx.ctx;43const vmCtx = driver.vmCtx;

Full Screen

Using AI Code Generation

copy

Full Screen

1const vmCtx = await this.driver.vmCtx;2console.log(vmCtx);3const vmCtx = await this.driver.vmCtx;4console.log(vmCtx);5const vmCtx = await this.driver.vmCtx;6console.log(vmCtx);7const vmCtx = await this.driver.vmCtx;8console.log(vmCtx);9const vmCtx = await this.driver.vmCtx;10console.log(vmCtx);11const vmCtx = await this.driver.vmCtx;12console.log(vmCtx);13const vmCtx = await this.driver.vmCtx;14console.log(vmCtx);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { BaseDriver } = require('appium-base-driver');2const { vmCtx } = BaseDriver;3const { BaseDriver } = require('appium-base-driver');4const { vmCtx } = BaseDriver;5const { BaseDriver } = require('appium-base-driver');6const { vmCtx } = BaseDriver;7const { BaseDriver } = require('appium-base-driver');8const { vmCtx } = BaseDriver;9const { BaseDriver } = require('appium-base-driver');10const { vmCtx } = BaseDriver;11const { BaseDriver } = require('appium-base-driver');12const { vmCtx } = BaseDriver;13const { BaseDriver } = require('appium-base-driver');14const { vmCtx } = BaseDriver;15const { BaseDriver } = require('appium-base-driver');16const { vmCtx } = BaseDriver;17const { BaseDriver } = require('appium-base-driver');18const { vmCtx } = BaseDriver;19const { BaseDriver } = require('appium-base-driver');20const { vmCtx } = BaseDriver;21const { BaseDriver } = require('appium-base-driver');22const { vmCtx } = BaseDriver;23const { BaseDriver } = require('appium-base-driver');24const { vmCtx } = BaseDriver;25const { BaseDriver } = require('appium-base-driver');26const { vmCtx } = BaseDriver;

Full Screen

Using AI Code Generation

copy

Full Screen

1const vmCtx = this.opts.vmCtx;2const vmCtx = this.opts.vmCtx;3const vmCtx = this.opts.vmCtx;4const vmCtx = this.opts.vmCtx;5const vmCtx = this.opts.vmCtx;6vmCtx.call('get', '

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test', () => {2 it('should open the app', async () => {3 await driver.vmCtx();4 });5});6describe('Test', () => {7 it('should open the app', async () => {8 await driver.vmCtx();9 });10});11describe('Test', () => {12 it('should open the app', async () => {13 await driver.vmCtx();14 });15});16describe('Test', () => {17 it('should open the app', async () => {18 await driver.vmCtx();19 });20});21describe('Test', () => {22 it('should open the app', async () => {23 await driver.vmCtx();24 });25});26describe('Test', () => {27 it('should open the app', async () => {28 await driver.vmCtx();29 });30});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Base Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful