From ad546bb84d23ba1ec5039d45877779d15886758a Mon Sep 17 00:00:00 2001 From: HalidOdat Date: Tue, 14 Apr 2020 15:26:56 +0200 Subject: [PATCH] Added documentation to builtins/boolean --- boa/src/builtins/boolean/mod.rs | 35 +++++++++++++++++++++++++++++++-- boa/src/builtins/mod.rs | 1 - 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/boa/src/builtins/boolean/mod.rs b/boa/src/builtins/boolean/mod.rs index 604125a81c..38b4b7e1ba 100644 --- a/boa/src/builtins/boolean/mod.rs +++ b/boa/src/builtins/boolean/mod.rs @@ -1,3 +1,14 @@ +//! This module implements the global `Boolean` object. +//! +//! The Boolean object is an object wrapper for a boolean value. +//! +//! More information: +//! - [ECMAScript reference][spec] +//! - [MDN documentation][mdn] +//! +//! [spec]: https://tc39.es/ecma262/#sec-boolean-object +//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean + #[cfg(test)] mod tests; @@ -35,13 +46,27 @@ pub fn call_boolean(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultVal } } -/// https://tc39.es/ecma262/#sec-boolean.prototype.tostring +/// The `toString()` method returns a string representing the specified `Boolean` object. +/// +/// More information: +/// - [ECMAScript reference][spec] +/// - [MDN documentation][mdn] +/// +/// [spec]: https://tc39.es/ecma262/#sec-boolean-object +/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/toString pub fn to_string(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue { let b = this_boolean_value(this); Ok(to_value(b.to_string())) } -/// https://tc39.es/ecma262/#sec-boolean.prototype.valueof +/// The valueOf() method returns the primitive value of a `Boolean` object. +/// +/// More information: +/// - [ECMAScript reference][spec] +/// - [MDN documentation][mdn] +/// +/// [spec]: https://tc39.es/ecma262/#sec-boolean.prototype.valueof +/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf pub fn value_of(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue { Ok(this_boolean_value(this)) } @@ -79,6 +104,12 @@ pub fn to_boolean(value: &Value) -> Value { } } +/// An Utility function used to get the internal BooleanData. +/// +/// More information: +/// - [ECMAScript reference][spec] +/// +/// [spec]: https://tc39.es/ecma262/#sec-thisbooleanvalue pub fn this_boolean_value(value: &Value) -> Value { match *value.deref().borrow() { ValueData::Boolean(v) => to_value(v), diff --git a/boa/src/builtins/mod.rs b/boa/src/builtins/mod.rs index 3e3ca7d974..84126aee92 100644 --- a/boa/src/builtins/mod.rs +++ b/boa/src/builtins/mod.rs @@ -14,7 +14,6 @@ macro_rules! make_builtin_fn { } pub mod array; -/// The global `Boolean` object pub mod boolean; pub mod console; /// The global `Error` object