-
-
Notifications
You must be signed in to change notification settings - Fork 400
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
Context::to_ordinary_primitive
panics when passed a function
#776
Comments
Oh, also this doesn't panic in release mode -- it just does the wrong thing.
It's getting down here somehow: Lines 412 to 413 in 87d9e9c
Which I'm not sure why... the function should have a |
@Razican and @Lan2u you were the ones who took care of #435 / #441 , looking at the codebase I don't think An object can still be identified as a function cince its |
I think it can be removed, there is no such thing as a "function" type in JavaScript, they are callable objects. |
I did just check in chrome, and: function x() {}
typeof x Does return |
can't we check if its an object with |
Should be incidentally fixed by #777, as |
@vgel this has been fixed, right? |
Yes, I just tested on |
Description
Trying to convert a function object (such as
function test() {}
) to a primitive (such as via theNumber
constructor) panics, because of a mismatch of assumptions betweenValue::to_primitive
andContext::ordinary_to_primitive
.To Reproduce
Context
Value::to_primitive
checks if its own variant isObject
, and if so passes the value over toContext::ordinary_to_primitive
:boa/boa/src/value/mod.rs
Lines 595 to 609 in 3e60d2c
But
Context::to_ordinary_primitive
checks ifget_type()
returnsType::Object
:boa/boa/src/context.rs
Lines 377 to 383 in 87d9e9c
These two don't match up, because
Value::get_type
checks if the object is callable, and if so returnsfunction
:boa/boa/src/value/type.rs
Lines 49 to 54 in 59d328e
I believe the correct thing to do by the standard here is to treat functions the same as objects. https://tc39.es/ecma262/#sec-ordinarytoprimitive says Type of O should be Object, and in that section it only lists the Object type. Function as a type only comes up in https://tc39.es/ecma262/#sec-typeof-operator .
Build environment (please complete the following information):
Linux marina 5.4.0-7634-generic #38~1592497129~20.04~9a1ea2e-Ubuntu SMP Fri Jun 19 22:43:37 UTC x86_64 x86_64 x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered: