Trait greenwasm_spectest::ScriptHandler [−][src]
pub trait ScriptHandler { fn reset(&mut self); fn action_invoke(
&mut self,
module: Option<String>,
field: String,
args: Vec<Value>
) -> InvokationResult; fn action_get(&mut self, module: Option<String>, field: String) -> Value; fn module(&mut self, bytes: Vec<u8>, name: Option<String>); fn assert_malformed(&mut self, bytes: Vec<u8>); fn assert_invalid(&mut self, bytes: Vec<u8>); fn assert_uninstantiable(&mut self, bytes: Vec<u8>); fn assert_exhaustion(&mut self, action: Action); fn register(&mut self, name: Option<String>, as_name: String); fn action(&mut self, action: Action) -> Vec<Value> { ... } fn assert_return(&mut self, action: Action, expected: Vec<Value>) { ... } fn assert_trap(&mut self, action: Action) { ... } fn assert_unlinkable(&mut self, bytes: Vec<u8>) { ... } fn assert_return_canonical_nan(&mut self, action: Action) { ... } fn assert_return_arithmetic_nan(&mut self, action: Action) { ... } }
Handles the different script commands of the *.wast
format.
Required Methods
fn reset(&mut self)
Reset all state of the handler, specifically clearing all loaded modules and assuming a new script file.
fn action_invoke(
&mut self,
module: Option<String>,
field: String,
args: Vec<Value>
) -> InvokationResult
&mut self,
module: Option<String>,
field: String,
args: Vec<Value>
) -> InvokationResult
Handles an invoke
action.
Should call a exported function with name field
and arguments
args
from a loaded module.
Targets either the last loaded module if module
is None, or
the module registered with the given name otherwise.
fn action_get(&mut self, module: Option<String>, field: String) -> Value
Handles an get
action.
Should get a exported global with name field
from a loaded module.
Targets either the last loaded module if module
is None, or
the module registered with the given name otherwise.
fn module(&mut self, bytes: Vec<u8>, name: Option<String>)
Handles a module load.
The webassembly module is passed in its binary format in
the bytes
argument.
If name
is Some
, it should be registered under that name.
In any case it should count as the least recently loaded module.
fn assert_malformed(&mut self, bytes: Vec<u8>)
Handles an assert_malformed
.
The webassembly module is passed in its binary format in
the bytes
argument.
Should panic if the module can be successfully decoded.
fn assert_invalid(&mut self, bytes: Vec<u8>)
Handles an assert_malformed
.
The webassembly module is passed in its binary format in
the bytes
argument.
Should panic if the module can be successfully decoded.
fn assert_uninstantiable(&mut self, bytes: Vec<u8>)
Handles an assert_uninstantiable
.
The webassembly module is passed in its binary format in
the bytes
argument.
Should panic if the module can be successfully instantiated.
fn assert_exhaustion(&mut self, action: Action)
Handles an assert_trap
.
Should panic if the result of handling the action
does not exhaust the stack, or refers to an global.
fn register(&mut self, name: Option<String>, as_name: String)
Register a loaded module under the name as_name
.
If name
is Some
, it should be registered under that name.
In any case it should count as the least recently loaded module.
Provided Methods
fn action(&mut self, action: Action) -> Vec<Value>
Handles an action
.
The default implementation dispatches to action_get
or action_invoke
, gathers the result in an vector, and panics
if a function call trapped or exhausted the stack.
fn assert_return(&mut self, action: Action, expected: Vec<Value>)
Handles an assert_return
.
Per default panics if the result of handling the action
does not result in the expected
values.
Floating point values should, and per default are,
compared according to their bit-pattern, and not their normal
PartialEq
semantic. See the NanCompare
wrapper type.
fn assert_trap(&mut self, action: Action)
Handles an assert_trap
.
Per default panics if the result of handling the action
does not trap, or refers to an global.
fn assert_unlinkable(&mut self, bytes: Vec<u8>)
Handles an assert_unlinkable
.
The webassembly module is passed in its binary format in
the bytes
argument.
Should panic if the module can be successfully linked.
This seems to be a legacy script command, and per default
just invokes assert_uninstantiable
.
fn assert_return_canonical_nan(&mut self, action: Action)
Handles an assert_return_canonical_nan
.
Per default panics if the result of handling the action
does not result in single canonical NaN floating point value.
Any canonical NaN is also a arithmetic NaN.
Floating point values should, and per default are,
compared according to their bit-pattern, and not their normal
PartialEq
semantic. See the NanCompare
wrapper type.
fn assert_return_arithmetic_nan(&mut self, action: Action)
Handles an assert_return_arithmetic_nan
.
Per default panics if the result of handling the action
does not result in single arithmetic NaN floating point value.
Any canonical NaN is also a arithmetic NaN.
Floating point values should, and per default are,
compared according to their bit-pattern, and not their normal
PartialEq
semantic. See the NanCompare
wrapper type.