Skip to content

Conversation

@rtakacs
Copy link
Contributor

@rtakacs rtakacs commented Nov 27, 2018

The explicit boolean type conversion (introduced by #2575) desn't work
with TizenRT if custom boolean representation is used. Of course,
TizenRT gives an opportunity to use the C99 standard boolean (that works
well if that is set).

I've replaced all the explicit boolean type conversions with double
negations that helps to work JerryScript well with custom boolean types.

(Note: this patch fixes 14 tests on TizenRT.)

@LaszloLango LaszloLango added the bug Undesired behaviour label Nov 27, 2018
@akosthekiss
Copy link
Member

@rtakacs What is the compilation error message on TizenRT? What type of x can cause (bool) x to fail but !!x to pass??

@zherczeg
Copy link
Member

As far as I understand TizenRT has a built-in "bool emulation" layer for whatever reason. In this layer bool is defined as uint8_t, and (bool)(a & b) is the last 8 bit of the result operation. Obviously this is not the same as the logical value of (a & b).

exponent + frac_digits,
&exponent,
ecma_number_is_zero (this_num));
!!ecma_number_is_zero (this_num));
Copy link
Member

Choose a reason for hiding this comment

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

Here, ecma_number_is_zero returns bool and ecma_builtin_number_prototype_helper_round expects bool. I cannot think of any scenario with whatever bool redefinition where !! would be necessary. So, is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, that's indeed unnecessary change.

@akosthekiss
Copy link
Member

@zherczeg Yikes! Thanks for the background.

@rtakacs
Copy link
Contributor Author

rtakacs commented Nov 27, 2018

@akosthekiss There is no compilation error message. The explicit conversation has runtime side effect that appears on some tests.

@rtakacs rtakacs force-pushed the logical-bool-conversion branch from 2bacad7 to dee2879 Compare November 27, 2018 13:34
@zherczeg
Copy link
Member

(I like != 0 more than !! although not a strict requirement)

Btw the TizenRT implementation:
https://github.com/Samsung/TizenRT/blob/master/os/include/stdbool.h

Copy link
Contributor

@galpeter galpeter left a comment

Choose a reason for hiding this comment

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

lgtm

@akosthekiss
Copy link
Member

I kind of tend to agree with @zherczeg. != 0 is something we use throughout the code base, but I cannot recall to have seen !! in JerryScript before. (I'll double check in some minutes.)

@akosthekiss
Copy link
Member

  • !! is only used in the definitions of JERRY_LIKELY, JERRY_UNLIKELY, and JERRY_STATIC_ASSERT_GLUE; and at a single assertion in jerry_debugger_receive.
  • bool.*!= 0 is used 3 times in "real" code, always in scenarios like & CBC_CODE_FLAGS_STRICT_MODE) != 0

I think we should follow the existing pattern (!= 0).

PS: Self revision, however: 3 times is not "throughout the code base".

@LaszloLango
Copy link
Contributor

@akosthekiss !! is used in the current code base in a few place (JERRY_STATIC_ASSERT, JERRY_LiKELY, JERRY_UNLIKELY, etc.). I don't have strong preferences, !! and !=0 are both good to me, although !! is shorter so it is a bit better to my eyes.

The explicit boolean type conversion (introduced by jerryscript-project#2575) desn't work
with TizenRT if custom boolean representation is used. Of course,
TizenRT gives an opportunity to use the C99 standard boolean (that works
well if that is set).

I've replaced all the explicit boolean type conversions with double
negations that helps to work JerryScript well with custom boolean types.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.uszeged@partner.samsung.com
@rtakacs rtakacs force-pushed the logical-bool-conversion branch from dee2879 to 4f109c6 Compare November 28, 2018 08:57
@rtakacs
Copy link
Contributor Author

rtakacs commented Nov 28, 2018

@LaszloLango @akosthekiss @zherczeg Thank you for your opinion. I've changed !! to != 0.

Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@galpeter galpeter left a comment

Choose a reason for hiding this comment

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

still lgtm ;)

Copy link
Contributor

@LaszloLango LaszloLango left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@akosthekiss akosthekiss left a comment

Choose a reason for hiding this comment

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

LGTM

@zherczeg zherczeg merged commit 5151f91 into jerryscript-project:master Nov 28, 2018
@rtakacs rtakacs deleted the logical-bool-conversion branch January 18, 2019 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Undesired behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants