mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Implement Console.assert.
This commit is contained in:
parent
743dcee0f5
commit
69fb7b0c94
2 changed files with 12 additions and 0 deletions
|
@ -31,6 +31,7 @@ pub trait ConsoleMethods {
|
|||
fn Info(&self, message: DOMString);
|
||||
fn Warn(&self, message: DOMString);
|
||||
fn Error(&self, message: DOMString);
|
||||
fn Assert(&self, condition: bool, message: Option<DOMString>);
|
||||
}
|
||||
|
||||
impl<'a> ConsoleMethods for JSRef<'a, Console> {
|
||||
|
@ -53,6 +54,16 @@ impl<'a> ConsoleMethods for JSRef<'a, Console> {
|
|||
fn Error(&self, message: DOMString) {
|
||||
println!("{:s}", message);
|
||||
}
|
||||
|
||||
fn Assert(&self, condition: bool, message: Option<DOMString>) {
|
||||
if !condition {
|
||||
let message = match message {
|
||||
Some(ref message) => message.as_slice(),
|
||||
None => "no message",
|
||||
};
|
||||
println!("Assertion failed: {:s}", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Reflectable for Console {
|
||||
|
|
|
@ -17,4 +17,5 @@ interface Console {
|
|||
void info(DOMString message);
|
||||
void warn(DOMString message);
|
||||
void error(DOMString message);
|
||||
void assert(boolean condition, optional DOMString message);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue