Open Bug 1780916 Opened 3 years ago Updated 8 months ago

String in String output differnet error message

Categories

(Core :: JavaScript Engine, enhancement, P2)

Firefox 102
enhancement

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.

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
Status: UNCONFIRMED → NEW
Ever confirmed: true

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.

Severity: -- → N/A
Priority: -- → P2
You need to log in before you can comment on or make changes to this bug.