mozilla / rhino

Rhino is an open-source implementation of JavaScript written entirely in Java
https://rhino.github.io
Other
4.18k stars 851 forks source link

Default Parameters + Destructuring - Pending items #1641

Open 0xe opened 1 month ago

0xe commented 1 month ago

Address items pending from https://github.com/mozilla/rhino/pull/1640

function a() {}; (function() { 
            for (let {x = a()} = {}; ; ) { 
                return 3; 
            }
        })()
function f([x = 1, y = 2] = {x: 3, y: 4}) {
 return x + y;
 }

This should throw a TypeError as [Symbol.iterator] is not implemented for that object on the rhs, instead uses defaults to return 3.

function f([x = 1, y = 2] = {x: 3, y: 4, 
                              [Symbol.iterator]: function*() { 
                                yield 3; 
                                yield 4; 
                              }}) {
                                return x + y;
                              }

And this should work because we call into iterator to get the default values. Instead we throw a NPE currently.

p-bakker commented 1 month ago

@0xe any chance you'll be picking up this one not that the previous part has been merged?

0xe commented 1 month ago

@0xe any chance you'll be picking up this one not that the previous part has been merged?

Yep. I'm planning on starting with destructuring with defaults in for loops.

0xe commented 4 weeks ago

Looking to add support for destructuring with defaults in for loops, I found some problems in how default values were transformed. I've created a PR to fix those first: https://github.com/mozilla/rhino/pull/1708.