mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
script: Include constructors and static methods in generated DOM traits (#33665)
* Add all constructors, special operations, and static methods to generated DOM interface traits. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Move all constructors and static methods defined in bare impl blocks inside FooMethods trait impls. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Add missing doc links. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
946fa9cdee
commit
7d931e673a
133 changed files with 1479 additions and 1438 deletions
|
@ -14,6 +14,7 @@ use js::rust::wrappers::{
|
|||
};
|
||||
use js::rust::{describe_scripted_caller, HandleValue, IdVector};
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::ConsoleBinding::consoleMethods;
|
||||
use crate::dom::bindings::conversions::jsstring_to_str;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
|
@ -53,6 +54,11 @@ impl Console {
|
|||
chan.send(devtools_message).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// Directly logs a DOMString, without processing the message
|
||||
pub fn internal_warn(global: &GlobalScope, message: DOMString) {
|
||||
console_message(global, message, LogLevel::Warn)
|
||||
}
|
||||
}
|
||||
|
||||
// In order to avoid interleaving the stdout output of the Console API methods
|
||||
|
@ -221,45 +227,40 @@ fn console_message(global: &GlobalScope, message: DOMString, level: LogLevel) {
|
|||
})
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
impl Console {
|
||||
impl consoleMethods for Console {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console/log
|
||||
pub fn Log(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
fn Log(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
console_messages(global, messages, LogLevel::Log)
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console/clear
|
||||
pub fn Clear(global: &GlobalScope) {
|
||||
fn Clear(global: &GlobalScope) {
|
||||
let message: Vec<HandleValue> = Vec::new();
|
||||
console_messages(global, message, LogLevel::Clear)
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console
|
||||
pub fn Debug(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
fn Debug(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
console_messages(global, messages, LogLevel::Debug)
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console/info
|
||||
pub fn Info(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
fn Info(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
console_messages(global, messages, LogLevel::Info)
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console/warn
|
||||
pub fn Warn(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
fn Warn(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
console_messages(global, messages, LogLevel::Warn)
|
||||
}
|
||||
// Directly logs a DOMString, without processing the message
|
||||
pub fn internal_warn(global: &GlobalScope, message: DOMString) {
|
||||
console_message(global, message, LogLevel::Warn)
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console/error
|
||||
pub fn Error(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
fn Error(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
console_messages(global, messages, LogLevel::Error)
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console/assert
|
||||
pub fn Assert(_cx: JSContext, global: &GlobalScope, condition: bool, message: HandleValue) {
|
||||
fn Assert(_cx: JSContext, global: &GlobalScope, condition: bool, message: HandleValue) {
|
||||
if !condition {
|
||||
let message = if message.is_undefined() {
|
||||
DOMString::from("no message")
|
||||
|
@ -272,7 +273,7 @@ impl Console {
|
|||
}
|
||||
|
||||
// https://console.spec.whatwg.org/#time
|
||||
pub fn Time(global: &GlobalScope, label: DOMString) {
|
||||
fn Time(global: &GlobalScope, label: DOMString) {
|
||||
if let Ok(()) = global.time(label.clone()) {
|
||||
let message = DOMString::from(format!("{label}: timer started"));
|
||||
console_message(global, message, LogLevel::Log);
|
||||
|
@ -280,7 +281,7 @@ impl Console {
|
|||
}
|
||||
|
||||
// https://console.spec.whatwg.org/#timelog
|
||||
pub fn TimeLog(_cx: JSContext, global: &GlobalScope, label: DOMString, data: Vec<HandleValue>) {
|
||||
fn TimeLog(_cx: JSContext, global: &GlobalScope, label: DOMString, data: Vec<HandleValue>) {
|
||||
if let Ok(delta) = global.time_log(&label) {
|
||||
let message = DOMString::from(format!(
|
||||
"{label}: {delta}ms {}",
|
||||
|
@ -291,7 +292,7 @@ impl Console {
|
|||
}
|
||||
|
||||
// https://console.spec.whatwg.org/#timeend
|
||||
pub fn TimeEnd(global: &GlobalScope, label: DOMString) {
|
||||
fn TimeEnd(global: &GlobalScope, label: DOMString) {
|
||||
if let Ok(delta) = global.time_end(&label) {
|
||||
let message = DOMString::from(format!("{label}: {delta}ms"));
|
||||
console_message(global, message, LogLevel::Log);
|
||||
|
@ -299,29 +300,29 @@ impl Console {
|
|||
}
|
||||
|
||||
// https://console.spec.whatwg.org/#group
|
||||
pub fn Group(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
fn Group(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
global.push_console_group(stringify_handle_values(messages));
|
||||
}
|
||||
|
||||
// https://console.spec.whatwg.org/#groupcollapsed
|
||||
pub fn GroupCollapsed(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
fn GroupCollapsed(_cx: JSContext, global: &GlobalScope, messages: Vec<HandleValue>) {
|
||||
global.push_console_group(stringify_handle_values(messages));
|
||||
}
|
||||
|
||||
// https://console.spec.whatwg.org/#groupend
|
||||
pub fn GroupEnd(global: &GlobalScope) {
|
||||
fn GroupEnd(global: &GlobalScope) {
|
||||
global.pop_console_group();
|
||||
}
|
||||
|
||||
/// <https://console.spec.whatwg.org/#count>
|
||||
pub fn Count(global: &GlobalScope, label: DOMString) {
|
||||
fn Count(global: &GlobalScope, label: DOMString) {
|
||||
let count = global.increment_console_count(&label);
|
||||
let message = DOMString::from(format!("{label}: {count}"));
|
||||
console_message(global, message, LogLevel::Log);
|
||||
}
|
||||
|
||||
/// <https://console.spec.whatwg.org/#countreset>
|
||||
pub fn CountReset(global: &GlobalScope, label: DOMString) {
|
||||
fn CountReset(global: &GlobalScope, label: DOMString) {
|
||||
if global.reset_console_count(&label).is_err() {
|
||||
Self::internal_warn(
|
||||
global,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue