Browse Source

Feature `console` crate feature (#800)

* Put console object in a feature flag

* Add documentation for crate features

* fix typo
pull/806/head
Halid Odat 4 years ago committed by GitHub
parent
commit
39b4ead8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      boa/Cargo.toml
  2. 2
      boa/src/builtins/console/mod.rs
  3. 5
      boa/src/builtins/mod.rs
  4. 8
      boa/src/context.rs
  5. 10
      boa/src/lib.rs
  6. 3
      boa/src/value/mod.rs
  7. 2
      boa_cli/Cargo.toml
  8. 2
      boa_wasm/Cargo.toml

3
boa/Cargo.toml

@ -13,6 +13,9 @@ edition = "2018"
[features] [features]
profiler = ["measureme", "once_cell"] profiler = ["measureme", "once_cell"]
# Enable Boa's WHATWG console object implementation.
console = []
[dependencies] [dependencies]
gc = { version = "0.3.6", features = ["derive"] } gc = { version = "0.3.6", features = ["derive"] }
serde_json = "1.0.58" serde_json = "1.0.58"

2
boa/src/builtins/console/mod.rs

@ -20,7 +20,7 @@ use crate::{
builtins::BuiltIn, builtins::BuiltIn,
object::ObjectInitializer, object::ObjectInitializer,
property::Attribute, property::Attribute,
value::{display_obj, RcString, Value}, value::{display::display_obj, RcString, Value},
BoaProfiler, Context, Result, BoaProfiler, Context, Result,
}; };
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;

5
boa/src/builtins/mod.rs

@ -3,6 +3,7 @@
pub mod array; pub mod array;
pub mod bigint; pub mod bigint;
pub mod boolean; pub mod boolean;
#[cfg(feature = "console")]
pub mod console; pub mod console;
pub mod date; pub mod date;
pub mod error; pub mod error;
@ -25,7 +26,6 @@ pub(crate) use self::{
array::{array_iterator::ArrayIterator, Array}, array::{array_iterator::ArrayIterator, Array},
bigint::BigInt, bigint::BigInt,
boolean::Boolean, boolean::Boolean,
console::Console,
date::Date, date::Date,
error::{Error, RangeError, ReferenceError, SyntaxError, TypeError}, error::{Error, RangeError, ReferenceError, SyntaxError, TypeError},
function::BuiltInFunctionObject, function::BuiltInFunctionObject,
@ -68,7 +68,6 @@ pub fn init(context: &mut Context) {
BuiltInObjectObject::init, BuiltInObjectObject::init,
Math::init, Math::init,
Json::init, Json::init,
Console::init,
Array::init, Array::init,
BigInt::init, BigInt::init,
Boolean::init, Boolean::init,
@ -83,6 +82,8 @@ pub fn init(context: &mut Context) {
ReferenceError::init, ReferenceError::init,
TypeError::init, TypeError::init,
SyntaxError::init, SyntaxError::init,
#[cfg(feature = "console")]
console::Console::init,
]; ];
let global_object = if let Value::Object(global) = context.global_object() { let global_object = if let Value::Object(global) = context.global_object() {

8
boa/src/context.rs

@ -6,7 +6,6 @@ use crate::{
function::{Function, FunctionFlags, NativeFunction}, function::{Function, FunctionFlags, NativeFunction},
iterable::IteratorPrototypes, iterable::IteratorPrototypes,
symbol::{Symbol, WellKnownSymbols}, symbol::{Symbol, WellKnownSymbols},
Console,
}, },
class::{Class, ClassBuilder}, class::{Class, ClassBuilder},
exec::Interpreter, exec::Interpreter,
@ -28,6 +27,9 @@ use crate::{
}; };
use std::result::Result as StdResult; use std::result::Result as StdResult;
#[cfg(feature = "console")]
use crate::builtins::console::Console;
/// Store a builtin constructor (such as `Object`) and its corresponding prototype. /// Store a builtin constructor (such as `Object`) and its corresponding prototype.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct StandardConstructor { pub struct StandardConstructor {
@ -172,6 +174,7 @@ pub struct Context {
symbol_count: u32, symbol_count: u32,
/// console object state. /// console object state.
#[cfg(feature = "console")]
console: Console, console: Console,
/// Cached well known symbols /// Cached well known symbols
@ -193,6 +196,7 @@ impl Default for Context {
realm, realm,
executor, executor,
symbol_count, symbol_count,
#[cfg(feature = "console")]
console: Console::default(), console: Console::default(),
well_known_symbols, well_known_symbols,
iterator_prototypes: IteratorPrototypes::default(), iterator_prototypes: IteratorPrototypes::default(),
@ -227,11 +231,13 @@ impl Context {
} }
/// A helper function for getting a immutable reference to the `console` object. /// A helper function for getting a immutable reference to the `console` object.
#[cfg(feature = "console")]
pub(crate) fn console(&self) -> &Console { pub(crate) fn console(&self) -> &Console {
&self.console &self.console
} }
/// A helper function for getting a mutable reference to the `console` object. /// A helper function for getting a mutable reference to the `console` object.
#[cfg(feature = "console")]
pub(crate) fn console_mut(&mut self) -> &mut Console { pub(crate) fn console_mut(&mut self) -> &mut Console {
&mut self.console &mut self.console
} }

10
boa/src/lib.rs

@ -1,4 +1,12 @@
//! This is an experimental Javascript lexer, parser and compiler written in Rust. Currently, it has support for some of the language. /*!
This is an experimental Javascript lexer, parser and compiler written in Rust. Currently, it has support for some of the language.
# Crate Features
- **serde** - Enables serialization and deserialization of the AST (Abstract Syntax Tree).
- **console** - Enables `boa`s WHATWG `console` object implementation.
- **profiler** - Enables profiling with measureme (this is mostly internal).
**/
#![doc( #![doc(
html_logo_url = "https://raw.githubusercontent.com/jasonwilliams/boa/master/assets/logo.svg", html_logo_url = "https://raw.githubusercontent.com/jasonwilliams/boa/master/assets/logo.svg",

3
boa/src/value/mod.rs

@ -25,7 +25,7 @@ use std::{
}; };
mod conversions; mod conversions;
mod display; pub(crate) mod display;
mod equality; mod equality;
mod hash; mod hash;
mod operations; mod operations;
@ -35,7 +35,6 @@ mod rcsymbol;
mod r#type; mod r#type;
pub use conversions::*; pub use conversions::*;
pub(crate) use display::display_obj;
pub use display::ValueDisplay; pub use display::ValueDisplay;
pub use equality::*; pub use equality::*;
pub use hash::*; pub use hash::*;

2
boa_cli/Cargo.toml

@ -11,7 +11,7 @@ exclude = ["../.vscode/*", "../Dockerfile", "../Makefile", "../.editorConfig"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
Boa = { path = "../boa", features = ["serde"] } Boa = { path = "../boa", features = ["serde", "console"] }
rustyline = "6.3.0" rustyline = "6.3.0"
rustyline-derive = "0.3.1" rustyline-derive = "0.3.1"
structopt = "0.3.18" structopt = "0.3.18"

2
boa_wasm/Cargo.toml

@ -11,7 +11,7 @@ exclude = ["../.vscode/*", "../Dockerfile", "../Makefile", "../.editorConfig"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
Boa = { path = "../boa" } Boa = { path = "../boa", features = ["console"] }
wasm-bindgen = "0.2.68" wasm-bindgen = "0.2.68"
[lib] [lib]

Loading…
Cancel
Save