Closed Bug 784197 Opened 12 years ago Closed 7 years ago

Default arguments sometimes don't get overridden.

Categories

(Core :: JavaScript Engine, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: espadrine, Unassigned)

Details

(Whiteboard: [js:p3])

I have been using the following code for a month in a patch I write:

    …
    dump('matching ' + matchProp + '\n');
    let props = getMatchedProps(obj, {matchProp:matchProp});
    …
    
    function getMatchedProps(aObj, aOptions = {matchProp: ""})
    {
      dump('got aOptions ' + JSON.stringify(aOptions) + '\n');
      // Argument defaults.
      aOptions.matchProp = aOptions.matchProp || "";
      …
    }

Very rarely, I get the following (example) output:

> matching foo
> got aOptions {"matchProp":""}

99% of the time (and, in this example, a split second before the output I pasted above), I do get the following, correct, output:

> matching fo
> got aOptions {"matchProp":"fo"}

As I understand it, there is a tiny edge case that isn't covered.

Worth noting: when this happens, the default argument for that function will stop getting overridden several times in a row, for around fifty times.
Whiteboard: [js:p3]
Assignee: general → nobody
Tentatively marking as WFM given that the default arguments code changed quite a lot in the last five years.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.