Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better documentation #293

Merged
merged 54 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d9a81a9
Added documentation to NumOp, UnaryOp and BitOp
HalidOdat Apr 1, 2020
9b1c508
Added documentation to CompOp
HalidOdat Apr 1, 2020
788f27d
Added documentation to LogOp
HalidOdat Apr 1, 2020
d45e33d
Added documentation to AssignOp
HalidOdat Apr 1, 2020
593955f
fixed NumOp documentation
HalidOdat Apr 1, 2020
919029b
Added root project documentation
HalidOdat Apr 1, 2020
bdb65d6
fixed spelling mistake
HalidOdat Apr 1, 2020
0023116
Update boa/src/syntax/ast/op.rs
HalidOdat Apr 1, 2020
f8012bc
Update boa/src/syntax/ast/op.rs
HalidOdat Apr 1, 2020
b6c83f3
Removed long links
HalidOdat Apr 1, 2020
9985dd9
Update boa/src/syntax/ast/op.rs
HalidOdat Apr 1, 2020
5a76bf5
Update boa/src/syntax/ast/op.rs
HalidOdat Apr 1, 2020
487a719
Update boa/src/syntax/ast/op.rs
HalidOdat Apr 1, 2020
80f7af3
Added some documentation to Keyword
HalidOdat Apr 2, 2020
7b2c722
fixed doc test
HalidOdat Apr 2, 2020
4280c94
Added documentation to Node
HalidOdat Apr 8, 2020
7e3280d
Fixed cargo fmt issues
HalidOdat Apr 8, 2020
125c75a
Added documentation to Keyword
HalidOdat Apr 9, 2020
6c60bc2
Finished documenting Node
HalidOdat Apr 9, 2020
75ef075
Added documentation to MethodDefinitionKind
HalidOdat Apr 9, 2020
be06137
Added documentation to PropertyDefinition
HalidOdat Apr 10, 2020
478330d
Added documentation to Const
HalidOdat Apr 10, 2020
348edbf
Added some documentation to builtins/console
HalidOdat Apr 12, 2020
138f0ca
Added some more documentation to builtins/console
HalidOdat Apr 12, 2020
38d57cb
cargo --doc builds, adding some docs
jasonwilliams Apr 12, 2020
f291549
lexer updates
jasonwilliams Apr 12, 2020
1b47b20
more changes
jasonwilliams Apr 12, 2020
103ab85
more changes
jasonwilliams Apr 12, 2020
bd4e814
doc on vop, op doctest
jasonwilliams Apr 13, 2020
63b02cb
Update boa/src/syntax/lexer/mod.rs
jasonwilliams Apr 12, 2020
7c74b8a
removing akward doc test
jasonwilliams Apr 13, 2020
083412d
doc for check_after_numeric_literal
jasonwilliams Apr 13, 2020
af7ad57
LexerError
jasonwilliams Apr 13, 2020
3e2e241
Added documentation to builtins/json
HalidOdat Apr 14, 2020
b8fe354
Added documentation to builtins/array
HalidOdat Apr 14, 2020
ad546bb
Added documentation to builtins/boolean
HalidOdat Apr 14, 2020
3e5dff6
Added documentation to `BinOp`
HalidOdat Apr 15, 2020
2f801c2
Added some documentation to `punc`
HalidOdat Apr 15, 2020
3742830
Added some documentation to `token`
HalidOdat Apr 15, 2020
fe01fc5
Added some documentation to builtins/string
HalidOdat Apr 15, 2020
5a06339
Added documentation to builtins/number
HalidOdat Apr 15, 2020
15ee257
Added documentation to builtins/math
HalidOdat Apr 15, 2020
da6872a
Added some documentation to builtins/function
HalidOdat Apr 15, 2020
b525f68
Added documentation to RegExp
HalidOdat Apr 25, 2020
70173fa
Added documentation to Error
HalidOdat Apr 25, 2020
e34b192
Added documentation to property
HalidOdat Apr 25, 2020
d3928e0
Added documentation to Symbol
HalidOdat Apr 25, 2020
afb0917
Added some documentation to object
HalidOdat Apr 25, 2020
4a6276f
Added some documentation to value
HalidOdat Apr 25, 2020
cded8d5
Added Development documentation to README.md
HalidOdat Apr 25, 2020
269b063
Documented console methods
HalidOdat Apr 26, 2020
d06d18f
split the json module
HalidOdat Apr 26, 2020
bb7afad
Fixed json issue
HalidOdat Apr 26, 2020
181e96d
Fixed some inconsistencies in node
HalidOdat Apr 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ https://jasonwilliams.github.io/boa/

You can get more verbose errors when running from the command line

## Development documentation

You can check the internal development docs at jasonwilliams.github.io/boa/doc

## Benchmarks

https://jasonwilliams.github.io/boa/dev/bench/
Expand Down
233 changes: 188 additions & 45 deletions boa/src/builtins/array/mod.rs

Large diffs are not rendered by default.

35 changes: 33 additions & 2 deletions boa/src/builtins/boolean/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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),
Expand Down
130 changes: 114 additions & 16 deletions boa/src/builtins/console/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
//! This module implements the global `console` object.
//!
//! The `console` object can be accessed from any global object.
//!
//! The specifics of how it works varies from browser to browser, but there is a de facto set of features that are typically provided.
//!
//! More information:
//! - [MDN documentation][mdn]
//! - [WHATWG `console` specification][spec]
//!
//! [spec]: https://console.spec.whatwg.org/
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Console

#![allow(clippy::print_stdout)]

#[cfg(test)]
Expand All @@ -14,6 +27,7 @@ use crate::{
use gc::Gc;
use std::{collections::HashMap, time::SystemTime};

/// This is the internal console object state.
#[derive(Debug, Default)]
pub struct ConsoleState {
count_map: HashMap<String, u32>,
Expand All @@ -33,6 +47,7 @@ impl ConsoleState {

impl InternalState for ConsoleState {}

/// This represents the different types of log messages.
#[derive(Debug)]
pub enum LogMessage {
Log(String),
Expand All @@ -41,12 +56,14 @@ pub enum LogMessage {
Error(String),
}

/// Helper function that returns the argument at a specified index.
fn get_arg_at_index<T: FromValue + Default>(args: &[Value], index: usize) -> Option<T> {
args.get(index)
.cloned()
.map(|s| from_value::<T>(s).expect("Convert error"))
}

/// Helper function for logging messages.
pub fn logger(msg: LogMessage, console_state: &ConsoleState) {
let indent = 2 * console_state.groups.len();

Expand All @@ -60,6 +77,7 @@ pub fn logger(msg: LogMessage, console_state: &ConsoleState) {
}
}

/// This represents the `console` formatter.
pub fn formatter(data: &[Value]) -> String {
let target = get_arg_at_index::<String>(data, 0).unwrap_or_default();
match data.len() {
Expand Down Expand Up @@ -125,7 +143,12 @@ pub fn formatter(data: &[Value]) -> String {
/// Prints a JavaScript value to the standard error if first argument evaluates to `false` or there
/// were no arguments.
///
/// More information: <https://console.spec.whatwg.org/#assert>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#assert
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/assert
pub fn assert(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let assertion = get_arg_at_index::<bool>(args, 0).unwrap_or_default();

Expand Down Expand Up @@ -153,7 +176,12 @@ pub fn assert(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue
///
/// Removes all groups and clears console if possible.
///
/// More information: <https://console.spec.whatwg.org/#clear>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#clear
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/clear
pub fn clear(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_mut(|state: &mut ConsoleState| {
state.groups.clear();
Expand All @@ -166,7 +194,12 @@ pub fn clear(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// Prints a JavaScript values with "debug" logLevel.
///
/// More information: <https://console.spec.whatwg.org/#debug>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#debug
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/debug
pub fn debug(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined))
Expand All @@ -176,7 +209,12 @@ pub fn debug(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// Prints a JavaScript values with "error" logLevel.
///
/// More information: <https://console.spec.whatwg.org/#error>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#error
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/error
pub fn error(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Error(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined))
Expand All @@ -186,7 +224,12 @@ pub fn error(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// Prints a JavaScript values with "info" logLevel.
///
/// More information: <https://console.spec.whatwg.org/#info>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#info
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/info
pub fn info(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Info(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined))
Expand All @@ -196,7 +239,12 @@ pub fn info(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// Prints a JavaScript values with "log" logLevel.
///
/// More information: <https://console.spec.whatwg.org/#log>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#log
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/log
pub fn log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined))
Expand All @@ -206,7 +254,12 @@ pub fn log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// Prints a stack trace with "trace" logLevel, optionally labelled by data.
///
/// More information: <https://console.spec.whatwg.org/#trace>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#trace
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/trace
pub fn trace(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
if !args.is_empty() {
this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state));
Expand All @@ -227,7 +280,12 @@ pub fn trace(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// Prints a JavaScript values with "warn" logLevel.
///
/// More information: <https://console.spec.whatwg.org/#warn>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#warn
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/warn
pub fn warn(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Warn(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined))
Expand All @@ -237,7 +295,12 @@ pub fn warn(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// Prints number of times the function was called with that particular label.
///
/// More information: <https://console.spec.whatwg.org/#count>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#count
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/count
pub fn count(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());

Expand All @@ -256,7 +319,12 @@ pub fn count(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// Resets the counter for label.
///
/// More information: <https://console.spec.whatwg.org/#countreset>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#countreset
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/countReset
pub fn count_reset(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());

Expand All @@ -281,7 +349,12 @@ fn system_time_in_ms() -> u128 {
///
/// Starts the timer for given label.
///
/// More information: <https://console.spec.whatwg.org/#time>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#time
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/time
pub fn time(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());

Expand All @@ -304,7 +377,12 @@ pub fn time(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// Prints elapsed time for timer with given label.
///
/// More information: <https://console.spec.whatwg.org/#timelog>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#timelog
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/timeLog
pub fn time_log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());

Expand All @@ -331,7 +409,12 @@ pub fn time_log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValu
///
/// Removes the timer with given label.
///
/// More information: <https://console.spec.whatwg.org/#timeend>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#timeend
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/timeEnd
pub fn time_end(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());

Expand All @@ -357,7 +440,12 @@ pub fn time_end(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValu
///
/// Adds new group with name from formatted data to stack.
///
/// More information: <https://console.spec.whatwg.org/#group>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#group
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/group
pub fn group(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let group_label = formatter(args);

Expand All @@ -373,7 +461,12 @@ pub fn group(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
///
/// Removes the last group from the stack.
///
/// More information: <https://console.spec.whatwg.org/#groupend>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#groupend
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/groupEnd
pub fn group_end(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_mut(|state: &mut ConsoleState| {
state.groups.pop();
Expand All @@ -386,7 +479,12 @@ pub fn group_end(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue
///
/// Prints info about item
///
/// More information: <https://console.spec.whatwg.org/#dir>
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#dir
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/dir
pub fn dir(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_mut(|state: &mut ConsoleState| {
logger(
Expand Down
Loading