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

Introduce PropertyKey for field acces, fix #172 (quotes around displayed strings) #373

Merged
merged 26 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
84bedd7
Fix #172, quotes around value in fmt for ValueData::String
RageKnify May 6, 2020
b56dcc2
Merge branch 'master' into quotes_string_value
RageKnify May 11, 2020
93f08f1
Merge branch 'master' into quotes_string_value
RageKnify May 14, 2020
3ae5859
Merge branch 'master' into quotes_string_value
RageKnify May 27, 2020
97bef40
Revert "Fix #172, quotes around value in fmt for ValueData::String"
RageKnify May 28, 2020
54e5c60
Implement DisplayValueData as discussed in #373
RageKnify May 28, 2020
5adb7af
Change DisplayValueData to ValueDisplay, as requested by @HalidOdat
RageKnify May 29, 2020
8df68fe
Merge branch 'master' into quotes_string_value
RageKnify Jun 1, 2020
1c0f3a4
Merge branch 'master' into quotes_string_value
RageKnify Jun 26, 2020
9e44b5c
Change display_obj so that it calls data.display()
RageKnify Jun 26, 2020
830773e
Change log_string_from so that it calls x.display()
RageKnify Jun 26, 2020
a3b4355
Add tests for displaying String values
RageKnify Jun 28, 2020
3d81f49
Ignore display_object test, waiting for #507
RageKnify Jun 29, 2020
5ffbedb
Merge branch 'master' into quotes_string_value
RageKnify Jul 3, 2020
f8ae2b0
Feat: Introduce set_str_field and PropertyKey, discussed on #373
RageKnify Jul 24, 2020
81826cd
Merge branch 'master' into quotes_string_value
RageKnify Jul 24, 2020
9a2c016
Test: Update tests to work with new Value::String formatting
RageKnify Jul 25, 2020
c1726c6
Merge branch 'master' into quotes_string_value
RageKnify Jul 25, 2020
0e897c8
Style: Fix not respecting clippy
RageKnify Jul 25, 2020
50cff2c
Removed `set_str_field`
HalidOdat Jul 26, 2020
d54d908
Fixed `String.prototype.replace` test
HalidOdat Jul 26, 2020
7b68990
Removed debug code
HalidOdat Jul 26, 2020
44b25a7
Merge pull request #1 from boa-dev/remove/set_str_field
RageKnify Jul 26, 2020
638ecb6
Merge branch 'master' into quotes_string_value
RageKnify Jul 26, 2020
cfef90d
Refactor: cleanup #373
RageKnify Jul 26, 2020
ae7fa2b
Refactor: Add documentation and docs as requested in #373
RageKnify Jul 27, 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
36 changes: 34 additions & 2 deletions boa/src/builtins/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ impl Value {
}
}

impl<'vd> Value {
/// Returns a REPL representation of the contained `ValueData`
pub fn display(&'vd self) -> DisplayValueData<'vd> {
self.data().display()
}
}

impl Deref for Value {
type Target = ValueData;

Expand Down Expand Up @@ -763,6 +770,13 @@ impl ValueData {
}
}

impl<'vd> ValueData {
/// Returns a REPL representation of the `ValueData`
fn display(&'vd self) -> DisplayValueData<'vd> {
DisplayValueData::new(self)
}
}

impl Default for ValueData {
fn default() -> Self {
Self::Undefined
Expand Down Expand Up @@ -894,7 +908,7 @@ pub(crate) fn log_string_from(x: &ValueData, print_internals: bool) -> String {
}
}

_ => format!("{}", x),
_ => format!("{}", x.display()),
}
}

Expand Down Expand Up @@ -947,7 +961,7 @@ pub(crate) fn display_obj(v: &ValueData, print_internals: bool) -> String {
format!("{{\n{}\n{}}}", result, closing_indent)
} else {
// Every other type of data is printed as is
format!("{}", data)
format!("{}", data.display())
}
}

Expand Down Expand Up @@ -982,3 +996,21 @@ impl Display for ValueData {
}
}
}

#[derive(Debug, Clone)]
pub struct DisplayValueData<'vd>(pub(crate) &'vd ValueData);
HalidOdat marked this conversation as resolved.
Show resolved Hide resolved

impl<'vd> DisplayValueData<'vd> {
fn new(vd: &'vd ValueData) -> Self {
DisplayValueData(vd)
}
}

impl<'vd> Display for DisplayValueData<'vd> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.0 {
ValueData::String(ref v) => write!(f, "\"{}\"", v),
_ => self.0.fmt(f),
}
}
}
8 changes: 4 additions & 4 deletions boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ pub fn main() -> Result<(), std::io::Error> {
}
} else {
match forward_val(&mut engine, &buffer) {
Ok(v) => print!("{}", v.to_string()),
Err(v) => eprint!("{}", v.to_string()),
Ok(v) => print!("{}", v.display()),
Err(v) => eprint!("{}", v.display()),
}
}
}
Expand All @@ -208,8 +208,8 @@ pub fn main() -> Result<(), std::io::Error> {
}
} else {
match forward_val(&mut engine, buffer.trim_end()) {
Ok(v) => println!("{}", v.to_string()),
Err(v) => eprintln!("{}", v.to_string()),
Ok(v) => println!("{}", v.display()),
Err(v) => eprintln!("{}", v.display()),
}
}

Expand Down