-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Corrected impl of typeof #396
Conversation
Does this code look alright? I ask because I'm encountering the following bizarre compile error and I'm wondering if there's an alternative route I can pursue: error: internal compiler error: src/librustc/ty/steal.rs:34: attempted to read from stolen value
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:875:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.43.0 (4fb7144ed 2020-04-20) running on x86_64-apple-darwin
note: compiler flags: -C debuginfo=2 -C incremental --crate-type cdylib --crate-type lib
note: some of the compiler flags provided by cargo are hidden
thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
left: `LLVMing`,
right: `Codegenning`', <::std::macros::panic macros>:5:6
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.43.0 (4fb7144ed 2020-04-20) running on x86_64-apple-darwin
note: compiler flags: -C debuginfo=2 -C incremental --crate-type cdylib --crate-type lib
note: some of the compiler flags provided by cargo are hidden
error: aborting due to previous error
error: could not compile `Boa`. |
That is in fact a bug inside the Rust compiler. You should report it, as the error says. You could also try to upgrade to the latest stable version, to see if they solved the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! thanks for the contribution. After some discussion in #359, it seems that it's best if we implement this as a unary expression and remove the Node
, then move the exec
part to the unary expression execution.
We should also add tests to this.
Yeah sorry about that its my fault i was under the impression it was a Node expression and not a unary one. |
c502fc6
to
08760f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice indeed! This is almost ready to be merged, just give a look to my comments :)
boa/src/exec/mod.rs
Outdated
"object" | ||
} | ||
} | ||
}), | ||
_ => unimplemented!(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that we already implemented all variants, so this is unreachable :D
_ => unimplemented!(), |
08760f2
to
a74de30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ready to be merged from my side :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me too. Check my comment it's mostly for my understanding.
boa/src/exec/mod.rs
Outdated
UnaryOp::TypeOf => Value::from(match v_a.data() { | ||
ValueData::Undefined => "undefined", | ||
ValueData::Symbol(_) => "symbol", | ||
ValueData::Null => "object", | ||
ValueData::Boolean(_) => "boolean", | ||
ValueData::Rational(_) | ValueData::Integer(_) => "number", | ||
ValueData::String(_) => "string", | ||
ValueData::Object(ref o) => { | ||
if o.deref().borrow().is_callable() { | ||
"function" | ||
} else { | ||
"object" | ||
} | ||
} | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we do this here when we can just call value.get_type()
which returns a &'static str
, it seems like were duplicating code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i mentioned in the original issue that we don't need both jasonwilliams#359 (comment)
a74de30
to
93b5270
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's best to keep the get_type
function in value and just call it from exec. there are a lot of places were get_type
is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as @HalidOdat said maybe we can just call get_type() from UnaryOf::TypeOf
93b5270
to
ca1de5c
Compare
ca1de5c
to
8ede26a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, it seems it's almost ready, just one test failing. Could you check why? I also added a small comment to see if we can improve testing coverage and documentation for null comparison.
boa/src/builtins/value/operations.rs
Outdated
//Null has to be handled specially because "typeof null" returns object and if we managed | ||
//this without a special case we would compare self and other as if they were actually | ||
//objects which unfortunately fails | ||
if self.is_null() { | ||
return true; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test for this, and a link to the spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't boa/src/builtins/value/tests.rs:58 already a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Perfect, thanks :)
8ede26a
to
55b4610
Compare
I'm having difficulty replicating the errors in CI on my local development environments (Windows and Mac OSX). I'm not entirely sure where to proceed from here so I would love to have some suggestions! |
Looks like you've found a regression introduced by my "implement this" change I will look at this. |
Thanks! |
Lets see if https://github.com/jasonwilliams/boa/pull/407 passes and ill merge that, String wasn't defaulting to empty when being called as The fact that you made a test for this is great as we may not have captured that before. |
Removed Node::TypeOf, implemented UnaryOp::TypeOf, and added tests
55b4610
to
b92dac2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks perfect! Thanks for the contribution @restitutororbis :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good to go for me as well :)
Corrected impl of typeof to follow specification by using relevant
AST node directly instead of using UnaryOp
This Pull Request fixes #359.
It changes the following: