String in String output differnet error message
Categories
(Core :: JavaScript Engine, enhancement, P2)
Tracking
()
People
(Reporter: 845043157, Unassigned)
References
(Blocks 1 open bug)
Details
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0
Steps to reproduce:
run the program:
'str1' in 'str2';
Actual results:
TypeError: cannot use ‘in’ operator to search for “str1” in ”str2”;
Expected results:
TypeError:right-hand side of ‘in’ should be an object,got string
The same error outputs different error messages:
1 in 'str';
TypeError:right-hand side of ‘in’ should be an object,got string
true in 'str';
TypeError:right-hand side of ‘in’ should be an object,got string
'str' in 1;
TypeError:right-hand side of ‘in’ should be an object,got number
'str' in true;
TypeError:right-hand side of ‘in’ should be an object,got boolean
Only String in String output different error message.I think the wrong error message only explains why the error happened but not explains how to slove it.May be the following is better.
Comment 1•3 years ago
•
|
||
Thank you for reporting.
It makes sense, the error should explain how to solve.
Then, I have a question, how do you hit the issue?
If the expectation there is that in
to perform search, then better error message should say how the string search can be performed.
So, something like:
'str1' in 'str2'
cannot use `in` operator to search string. use "str2".includes("str1")` instead
Updated•3 years ago
|
I summarize the error message as 'v1 in v2;' and then use ramdom variable to replace v1 and v2.When v1 and v2 are all String,it output an unexpected error message and then my program will throw it.
Updated•3 years ago
|
Description
•