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]
profiler = ["measureme", "once_cell"]
# Enable Boa's WHATWG console object implementation.
console = []
[dependencies]
gc = { version = "0.3.6", features = ["derive"] }
serde_json = "1.0.58"

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

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

5
boa/src/builtins/mod.rs

@ -3,6 +3,7 @@
pub mod array;
pub mod bigint;
pub mod boolean;
#[cfg(feature = "console")]
pub mod console;
pub mod date;
pub mod error;
@ -25,7 +26,6 @@ pub(crate) use self::{
array::{array_iterator::ArrayIterator, Array},
bigint::BigInt,
boolean::Boolean,
console::Console,
date::Date,
error::{Error, RangeError, ReferenceError, SyntaxError, TypeError},
function::BuiltInFunctionObject,
@ -68,7 +68,6 @@ pub fn init(context: &mut Context) {
BuiltInObjectObject::init,
Math::init,
Json::init,
Console::init,
Array::init,
BigInt::init,
Boolean::init,
@ -83,6 +82,8 @@ pub fn init(context: &mut Context) {
ReferenceError::init,
TypeError::init,
SyntaxError::init,
#[cfg(feature = "console")]
console::Console::init,
];
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},
iterable::IteratorPrototypes,
symbol::{Symbol, WellKnownSymbols},
Console,
},
class::{Class, ClassBuilder},
exec::Interpreter,
@ -28,6 +27,9 @@ use crate::{
};
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.
#[derive(Debug, Clone)]
pub struct StandardConstructor {
@ -172,6 +174,7 @@ pub struct Context {
symbol_count: u32,
/// console object state.
#[cfg(feature = "console")]
console: Console,
/// Cached well known symbols
@ -193,6 +196,7 @@ impl Default for Context {
realm,
executor,
symbol_count,
#[cfg(feature = "console")]
console: Console::default(),
well_known_symbols,
iterator_prototypes: IteratorPrototypes::default(),
@ -227,11 +231,13 @@ impl Context {
}
/// A helper function for getting a immutable reference to the `console` object.
#[cfg(feature = "console")]
pub(crate) fn console(&self) -> &Console {
&self.console
}
/// A helper function for getting a mutable reference to the `console` object.
#[cfg(feature = "console")]
pub(crate) fn console_mut(&mut self) -> &mut 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(
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 display;
pub(crate) mod display;
mod equality;
mod hash;
mod operations;
@ -35,7 +35,6 @@ mod rcsymbol;
mod r#type;
pub use conversions::*;
pub(crate) use display::display_obj;
pub use display::ValueDisplay;
pub use equality::*;
pub use hash::*;

2
boa_cli/Cargo.toml

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

2
boa_wasm/Cargo.toml

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

Loading…
Cancel
Save