JS_GetScopeChain asserts because of native functions

RESOLVED FIXED

Status

()

Core
JavaScript Engine
RESOLVED FIXED
10 years ago
10 years ago

People

(Reporter: mrbkap, Assigned: mrbkap)

Tracking

({fixed1.8.1.12})

unspecified
x86
Linux
fixed1.8.1.12
Points:
---
Bug Flags:
in-testsuite -

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

10 years ago
Created attachment 271729 [details] [diff] [review]
Proposed fix

Currently, if a user of the C API uses JS_CallFunction to call a native function, and that native function causes JS_GetScopeChain to be called, we will assert. The problem is that native functions inherit the scope chain of their caller, but if there is no caller, then they don't get a scope chain at all. js_GetScopeChain can't deal with this.

My proposed fix is to use the parent of the native function object if there was no scripted caller so we have *some* scopeChain to return in these cases.
Attachment #271729 - Flags: review?(brendan)
Why not remove the assertion and let the result be NULL?

/be
(Assignee)

Comment 2

10 years ago
Because that's ambiguous to the caller -- JS_GetScopeChain can fail. Also, I'm calling it so I can create a new (exception) object based on the current scope chain. If JS_GetScopeChain returns null, then my only other option is JS_GetGlobalObject on the current context, which is badly wrong (as you pointed out to me the other day).
Comment on attachment 271729 [details] [diff] [review]
Proposed fix

Ok then -- boundary condition I should have foreseen.

>         /* If native, use caller varobj and scopeChain for eval. */
>         frame.varobj = fp->varobj;
>         frame.scopeChain = fp->scopeChain;

Blank line here, per prevailing style.

>+        /* But ensure that we have a scope chain. */
>+        if (!frame.scopeChain)
>+            frame.scopeChain = parent;

Otherwise, r=me.

/be
Attachment #271729 - Flags: review?(brendan) → review+
(Assignee)

Comment 4

10 years ago
Created attachment 271737 [details] [diff] [review]
Patch to checkin

I'll check this in when the tree opens.
Attachment #271729 - Attachment is obsolete: true
(Assignee)

Comment 5

10 years ago
Fix checked into trunk.
Status: ASSIGNED → RESOLVED
Last Resolved: 10 years ago
Resolution: --- → FIXED

Updated

10 years ago
Flags: in-testsuite-
(Assignee)

Comment 6

10 years ago
Comment on attachment 271737 [details] [diff] [review]
Patch to checkin

This applies cleanly to the 1.8 branch.
Attachment #271737 - Flags: approval1.8.1.12?
Comment on attachment 271737 [details] [diff] [review]
Patch to checkin

approved for 1.8.1.12, a=dveditz for release-drivers
Attachment #271737 - Flags: approval1.8.1.12? → approval1.8.1.12+
(Assignee)

Comment 8

10 years ago
Fixed on the 1.8 branch.
Keywords: fixed1.8.1.12
You need to log in before you can comment on or make changes to this bug.