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

Remove direct conversion from &str to JsValue/PropertyKey. #3319

Merged
merged 5 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ chrome_profiler.json
# e2e test
playwright-report
test-results

# dhat
dhat-*.json
perf.data*
50 changes: 50 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ lto = "fat"
# Makes sure that all code is compiled together, for LTO
codegen-units = 1

[profile.release-dbg]
inherits = "release"
debug = true

# The test profile, used for `cargo test`.
[profile.test]
# Enables thin local LTO and some optimizations.
Expand Down
2 changes: 2 additions & 0 deletions boa_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ colored.workspace = true
regex.workspace = true
phf = { workspace = true, features = ["macros"] }
pollster.workspace = true
dhat = { version = "0.3.2", optional = true }

[features]
default = ["boa_engine/annex-b", "boa_engine/experimental", "boa_engine/intl"]
dhat = ["dep:dhat"]

[target.x86_64-unknown-linux-gnu.dependencies]
jemallocator.workspace = true
Expand Down
31 changes: 23 additions & 8 deletions boa_cli/src/debug/function.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use boa_engine::{
js_string,
object::ObjectInitializer,
vm::flowgraph::{Direction, Graph},
Context, JsArgs, JsNativeError, JsObject, JsResult, JsValue, NativeFunction,
Expand Down Expand Up @@ -67,8 +68,10 @@ fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> Js
let mut direction = Direction::LeftToRight;
if let Some(arguments) = args.get(1) {
if let Some(arguments) = arguments.as_object() {
format = flowgraph_parse_format_option(&arguments.get("format", context)?)?;
direction = flowgraph_parse_direction_option(&arguments.get("direction", context)?)?;
format = flowgraph_parse_format_option(&arguments.get(js_string!("format"), context)?)?;
direction = flowgraph_parse_direction_option(
&arguments.get(js_string!("direction"), context)?,
)?;
} else if value.is_string() {
format = flowgraph_parse_format_option(value)?;
} else {
Expand Down Expand Up @@ -97,7 +100,7 @@ fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> Js
FlowgraphFormat::Mermaid => graph.to_mermaid_format(),
};

Ok(JsValue::new(result))
Ok(JsValue::new(js_string!(result)))
}

fn bytecode(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
Expand All @@ -122,7 +125,7 @@ fn bytecode(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResul
JsNativeError::typ().with_message("native functions do not have bytecode")
})?;

Ok(code.to_interned_string(context.interner()).into())
Ok(js_string!(code.to_interned_string(context.interner())).into())
}

fn set_trace_flag_in_function_object(object: &JsObject, value: bool) -> JsResult<()> {
Expand Down Expand Up @@ -176,9 +179,21 @@ fn traceable(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsV

pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
ObjectInitializer::new(context)
.function(NativeFunction::from_fn_ptr(flowgraph), "flowgraph", 1)
.function(NativeFunction::from_fn_ptr(bytecode), "bytecode", 1)
.function(NativeFunction::from_fn_ptr(trace), "trace", 1)
.function(NativeFunction::from_fn_ptr(traceable), "traceable", 2)
.function(
NativeFunction::from_fn_ptr(flowgraph),
js_string!("flowgraph"),
1,
)
.function(
NativeFunction::from_fn_ptr(bytecode),
js_string!("bytecode"),
1,
)
.function(NativeFunction::from_fn_ptr(trace), js_string!("trace"), 1)
.function(
NativeFunction::from_fn_ptr(traceable),
js_string!("traceable"),
2,
)
.build()
}
10 changes: 8 additions & 2 deletions boa_cli/src/debug/gc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use boa_engine::{object::ObjectInitializer, Context, JsObject, JsResult, JsValue, NativeFunction};
use boa_engine::{
js_string, object::ObjectInitializer, Context, JsObject, JsResult, JsValue, NativeFunction,
};

/// Trigger garbage collection.
fn collect(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
Expand All @@ -8,6 +10,10 @@ fn collect(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue>

pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
ObjectInitializer::new(context)
.function(NativeFunction::from_fn_ptr(collect), "collect", 0)
.function(
NativeFunction::from_fn_ptr(collect),
js_string!("collect"),
0,
)
.build()
}
5 changes: 3 additions & 2 deletions boa_cli/src/debug/limits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use boa_engine::{
js_string,
object::{FunctionObjectBuilder, ObjectInitializer},
property::Attribute,
Context, JsArgs, JsNativeError, JsObject, JsResult, JsValue, NativeFunction,
Expand Down Expand Up @@ -55,13 +56,13 @@ pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
.build();
ObjectInitializer::new(context)
.accessor(
"loop",
js_string!("loop"),
Some(get_loop),
Some(set_loop),
Attribute::WRITABLE | Attribute::CONFIGURABLE | Attribute::NON_ENUMERABLE,
)
.accessor(
"recursion",
js_string!("recursion"),
Some(get_recursion),
Some(set_recursion),
Attribute::WRITABLE | Attribute::CONFIGURABLE | Attribute::NON_ENUMERABLE,
Expand Down
18 changes: 9 additions & 9 deletions boa_cli/src/debug/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Allow lint so it, doesn't warn about `JsResult<>` unneeded return on functions.
#![allow(clippy::unnecessary_wraps)]

use boa_engine::{object::ObjectInitializer, property::Attribute, Context, JsObject};
use boa_engine::{js_string, object::ObjectInitializer, property::Attribute, Context, JsObject};

mod function;
mod gc;
Expand All @@ -22,37 +22,37 @@ fn create_boa_object(context: &mut Context<'_>) -> JsObject {

ObjectInitializer::new(context)
.property(
"function",
js_string!("function"),
function_module,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.property(
"object",
js_string!("object"),
object_module,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.property(
"shape",
js_string!("shape"),
shape_module,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.property(
"optimizer",
js_string!("optimizer"),
optimizer_module,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.property(
"gc",
js_string!("gc"),
gc_module,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.property(
"realm",
js_string!("realm"),
realm_module,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.property(
"limits",
js_string!("limits"),
limits_module,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
Expand All @@ -63,7 +63,7 @@ pub(crate) fn init_boa_debug_object(context: &mut Context<'_>) {
let boa_object = create_boa_object(context);
context
.register_global_property(
"$boa",
js_string!("$boa"),
boa_object,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
Expand Down
7 changes: 4 additions & 3 deletions boa_cli/src/debug/object.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use boa_engine::{
object::ObjectInitializer, Context, JsNativeError, JsObject, JsResult, JsValue, NativeFunction,
js_string, object::ObjectInitializer, Context, JsNativeError, JsObject, JsResult, JsValue,
NativeFunction,
};

/// Returns objects pointer in memory.
Expand All @@ -17,11 +18,11 @@ fn id(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
};

let ptr: *const _ = object.as_ref();
Ok(format!("0x{:X}", ptr as usize).into())
Ok(js_string!(format!("0x{:X}", ptr as usize)).into())
}

pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
ObjectInitializer::new(context)
.function(NativeFunction::from_fn_ptr(id), "id", 1)
.function(NativeFunction::from_fn_ptr(id), js_string!("id"), 1)
.build()
}
5 changes: 3 additions & 2 deletions boa_cli/src/debug/optimizer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use boa_engine::{
js_string,
object::{FunctionObjectBuilder, ObjectInitializer},
optimizer::OptimizerOptions,
property::Attribute,
Expand Down Expand Up @@ -71,13 +72,13 @@ pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
.build();
ObjectInitializer::new(context)
.accessor(
"constantFolding",
js_string!("constantFolding"),
Some(get_constant_folding),
Some(set_constant_folding),
Attribute::WRITABLE | Attribute::CONFIGURABLE | Attribute::NON_ENUMERABLE,
)
.accessor(
"statistics",
js_string!("statistics"),
Some(get_statistics),
Some(set_statistics),
Attribute::WRITABLE | Attribute::CONFIGURABLE | Attribute::NON_ENUMERABLE,
Expand Down
6 changes: 4 additions & 2 deletions boa_cli/src/debug/realm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use boa_engine::{object::ObjectInitializer, Context, JsObject, JsResult, JsValue, NativeFunction};
use boa_engine::{
js_string, object::ObjectInitializer, Context, JsObject, JsResult, JsValue, NativeFunction,
};

/// Creates a new ECMAScript Realm and returns the global object of the realm.
fn create(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
Expand All @@ -9,6 +11,6 @@ fn create(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue>

pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
ObjectInitializer::new(context)
.function(NativeFunction::from_fn_ptr(create), "create", 0)
.function(NativeFunction::from_fn_ptr(create), js_string!("create"), 0)
.build()
}
8 changes: 4 additions & 4 deletions boa_cli/src/debug/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn id(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
let object = get_object(args, 0)?;
let object = object.borrow();
let shape = object.shape();
Ok(format!("0x{:X}", shape.to_addr_usize()).into())
Ok(js_string!(format!("0x{:X}", shape.to_addr_usize())).into())
}

/// Returns object's shape type.
Expand Down Expand Up @@ -62,8 +62,8 @@ fn same(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue>

pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
ObjectInitializer::new(context)
.function(NativeFunction::from_fn_ptr(id), "id", 1)
.function(NativeFunction::from_fn_ptr(r#type), "type", 1)
.function(NativeFunction::from_fn_ptr(same), "same", 2)
.function(NativeFunction::from_fn_ptr(id), js_string!("id"), 1)
.function(NativeFunction::from_fn_ptr(r#type), js_string!("type"), 1)
.function(NativeFunction::from_fn_ptr(same), js_string!("same"), 2)
.build()
}
Loading