Skip to content

Conversation

ledsun
Copy link
Contributor

@ledsun ledsun commented Jul 24, 2023

This is a pull request where I switched from implementing the to_b method to implementing JS::True, as pointed out in #247.

The following use cases are assumed:

if searchParams.has('phrase') == JS::True
  ...
end

It is used to correctly determine the boolean value returned from a JavaScript function in a Ruby if expression.

To treat the return value of a JavaScript function as a condition of a Ruby if expression, do the following
if searchParams.has('phrase') == JS::True`.
assert_equal 'null', JS::Null.to_s
assert_equal 'undefined', JS::Undefined.to_s
assert_equal 'true', JS::True.to_s
assert_equal 'false', JS::False.to_s
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I use JS::Object with assert_equal as the argument, I get the following error:

JS::Error: TypeError: Cannot read properties of null (reading 'encoding')

To avoid the error, I compare with a string.

@kateinoigakukun kateinoigakukun merged commit 9ba83fe into ruby:main Jul 24, 2023
@ledsun ledsun deleted the add_true_and_false_constants branch August 11, 2023 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants