Contributing to Web APIs
May 1, 2018 ยท View on GitHub
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Contributing to Web APIs
-
When implementing properties and methods, follow the HTML spec
-
A helpful resource for translating types from the HTML spec to Rust can be found in the
TypedArray objectstable here -
Try to stay as close as possible to the original JS name while maintaining Rust naming conventions
-
-
You can run
stdweb's tests withcargo web test --features web_testThis will run them under headless Chromium
-
For concrete Javascript types, define a struct as an
instance_ofthe concrete Js typeeg:
#[derive(Clone, Debug, Eq, PartialEq, ReferenceType)] #[reference(instance_of = "CanvasGradient")] pub struct CanvasGradient(Reference); -
Make sure to document the struct according to the documentation in MDN and provide a link
eg:
/// The CanvasGradient struct represents an opaque object describing a gradient. /// It is returned by the methods CanvasRenderingContext2D.createLinearGradient() or /// CanvasRenderingContext2D.createRadialGradient(). /// /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/CanvasGradient)Remember these are Rust docs so certain keywords such as
DOMStringandInterfaceneed to be "translated" into Rust equivalentseg:
`DOMString` -> `String`/`Enum` (whichever is more appropriate) `Interface` -> `trait`Also add a comment linking the actual HTML spec for that particular object
eg:
// https://html.spec.whatwg.org/#canvasgradient -
For functions that can't be overloaded properly with traits, define multiple functions with a suffix to specify their use
Try to find one "general" or "basic" function that can take the original non-suffixed name
-
You can export structs and enums by adding them to lib.rs