Closed Bug 494637 Opened 15 years ago Closed 12 years ago

inconsistent parent for null and flat closures

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 659577

People

(Reporter: igor, Unassigned)

References

Details

Currently js_Interpter, when creating null and flat closures, uses fp->scopeChain as their parent. This means that null closure may or may not get a Call or Block on their parent chain depending on the current runtime situation. For example, the following examples prints [object global], null because for the second invocation of f the null closure will have the Call object on its scope chain:

function f(x)
{
    if (x)
        x("1");
    return function() {}
}

print(f().__parent__);
print(f(eval).__parent__);

At the very least the parent chain should be similar for both cases. I suggest to use always callee's parent when creating null or flat closures. Besides the consistency, it will also avoid rooting Call or Block objects that may created during closure's parent execution or debugging.
__parent__ has been removed.
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
Tom, this isn't about __parent__, that was just used to demo the inconsistency.

/be
Status: RESOLVED → REOPENED
Resolution: INVALID → ---
Status: REOPENED → NEW
So, the comment 0 code would look like this nowadays:

function f(x)
{
    if (x)
        x("1");
    return function() {}
}

print(parent(f()));
print(parent(f(eval)));

But this now prints [object global] twice, because indirect eval is global eval (no Call object is created during the second call to f).

Igor's point about the debugger or some equivalent way of forcing Call object creation selectively and unpredictably at runtime stands.

Looks like I'm going to fix this for bug 592202.

/be
Depends on: 592202
No longer depends on: 592202
Depends on: 592202
(In reply to comment #3)
> Looks like I'm going to fix this for bug 592202.

Fixed?
Not fixed.

/be
Bug 659577 provides deterministic scope chain depth; debugger gets a faux-scope-chain of proxies that doesn't mutate fp->scopeChain ever.
Status: NEW → RESOLVED
Closed: 14 years ago12 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.