Browse Source

Merge pull request #2544 from svaarala/expr-assignop-fixes

Logical assignment operator trivia
pull/2545/head
Sami Vaarala 1 year ago
committed by GitHub
parent
commit
47eedc5d53
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      releases/releases.yaml
  2. 9
      src-input/duk_js_compiler.c
  3. 5
      tests/ecmascript/expr/test-expr-logicalop-assignment.js

2
releases/releases.yaml

@ -1397,3 +1397,5 @@ duktape_releases:
- "Add support for DJGPP (MSDOS) platform (GH-2472, GH-2473)"
- "Remove .caller and .arguments own properties from both strict and non-strict function objects, and add .caller and .arguments throwers to Function.prototype to match ES2015+ (GH-2482)"
- "Add support for ES2021 digit separator (GH-2537)"
- "Add support for logical assignment operators &&= and ||= (GH-2527)"
- "Fix RangeError in Object.assign for a large number of arguments (GH-2530)"

9
src-input/duk_js_compiler.c

@ -4463,7 +4463,8 @@ binary_logical:
{
duk_regconst_t reg_temp;
duk_int_t pc_jump;
duk_small_uint_t args_truthval = args >> 8;
duk_small_uint_t args_truthval = args & 0x100;
duk_small_uint_t args_assignment = args & 0x200;
duk_small_uint_t args_rbp = args & 0xff;
duk_small_uint_t leftt;
@ -4474,7 +4475,7 @@ binary_logical:
duk_regconst_t reg_obj;
duk_regconst_t rc_key;
if (args_truthval & 2) { // assignment
if (args_assignment) {
leftt = left->t;
if (leftt == DUK_IVAL_VAR) {
DUK_ASSERT(left->x1.t == DUK_ISPEC_VALUE); /* LHS is already side effect free */
@ -4519,12 +4520,12 @@ binary_logical:
duk__ivalue_toforcedreg(comp_ctx, left, reg_temp);
DUK_ASSERT(DUK__ISREG(reg_temp));
duk__emit_bc(comp_ctx,
((args_truthval & 1) ? DUK_OP_IFTRUE_R : DUK_OP_IFFALSE_R),
(args_truthval ? DUK_OP_IFTRUE_R : DUK_OP_IFFALSE_R),
reg_temp); /* skip jump conditionally */
pc_jump = duk__emit_jump_empty(comp_ctx);
duk__expr_toforcedreg(comp_ctx, res, args_rbp /*rbp_flags*/, reg_temp /*forced_reg*/);
if (args_truthval & 2) { // assignment
if (args_assignment) {
if (leftt == DUK_IVAL_VAR) {
if (reg_varbind >= 0) {
duk__emit_a_bc(comp_ctx, DUK_OP_LDREG, reg_varbind, reg_temp);

5
tests/ecmascript/expr/test-expr-logicalop-assignment.js

@ -35,8 +35,6 @@ var b = a ||= testSideEffect(0, '3') || testSideEffect(0, '4') || testSideEffect
print(a); // Should be false, not 0
print(b); // Should be false, not 0
/*===
[object Object]
false
@ -54,7 +52,6 @@ true
testSideEffect(obj, '6').b ||= true;
print(obj.b);
/*===
tse 7
tse 8
@ -64,4 +61,4 @@ tse 10
===*/
testSideEffect(obj, '7').b &&= testSideEffect(obj, '8').b &&= testSideEffect(obj, '9').b = testSideEffect(99, '10');
print(obj.b);
print(obj.b);

Loading…
Cancel
Save