Skip to content

Commit

Permalink
Make deprecated functions only compile in test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Sep 6, 2020
1 parent f20fa24 commit 5ca5991
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions boa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
clippy::let_unit_value,
missing_doc_code_examples
)]
// Remove me when we remove `forward_val`, `froward` and `exec`
//
// This is added because it generates to many warnings,
// beause these functions are used in almost every test.
#![cfg_attr(any(test), allow(deprecated))]

pub mod builtins;
pub mod class;
Expand All @@ -51,11 +46,7 @@ mod context;

use std::result::Result as StdResult;

pub(crate) use crate::{
exec::Executable,
profiler::BoaProfiler,
syntax::{ast::node::StatementList, Parser},
};
pub(crate) use crate::{exec::Executable, profiler::BoaProfiler};
pub use gc::{custom_trace, unsafe_empty_trace, Finalize, Trace};

// Export things to root level
Expand All @@ -65,6 +56,10 @@ pub use crate::{builtins::value::Value, context::Context};
#[must_use]
pub type Result<T> = StdResult<T, Value>;

#[cfg(test)]
use crate::syntax::{ast::node::StatementList, Parser};

#[cfg(test)]
fn parser_expr(src: &str) -> StdResult<StatementList, String> {
Parser::new(src.as_bytes())
.parse_all()
Expand All @@ -73,8 +68,8 @@ fn parser_expr(src: &str) -> StdResult<StatementList, String> {

/// Execute the code using an existing Context
/// The str is consumed and the state of the Context is changed
#[deprecated(note = "Please use Context::eval() instead")]
pub fn forward(engine: &mut Context, src: &str) -> String {
#[cfg(test)]
pub(crate) fn forward(engine: &mut Context, src: &str) -> String {
// Setup executor
let expr = match parser_expr(src) {
Ok(res) => res,
Expand All @@ -91,8 +86,8 @@ pub fn forward(engine: &mut Context, src: &str) -> String {
/// Similar to `forward`, except the current value is returned instad of the string
/// If the interpreter fails parsing an error value is returned instead (error object)
#[allow(clippy::unit_arg, clippy::drop_copy)]
#[deprecated(note = "Please use Context::eval() instead")]
pub fn forward_val(engine: &mut Context, src: &str) -> Result<Value> {
#[cfg(test)]
pub(crate) fn forward_val(engine: &mut Context, src: &str) -> Result<Value> {
let main_timer = BoaProfiler::global().start_event("Main", "Main");
// Setup executor
let result = match parser_expr(src) {
Expand All @@ -111,8 +106,8 @@ pub fn forward_val(engine: &mut Context, src: &str) -> Result<Value> {
}

/// Create a clean Context and execute the code
#[deprecated(note = "Please use Context::eval() instead")]
pub fn exec(src: &str) -> String {
#[cfg(test)]
pub(crate) fn exec(src: &str) -> String {
match Context::new().eval(src) {
Ok(value) => value.display().to_string(),
Err(error) => error.display().to_string(),
Expand Down

0 comments on commit 5ca5991

Please sign in to comment.