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.
Why not remove the assertion and let the result be NULL? /be
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
Created attachment 271737 [details] [diff] [review] Patch to checkin I'll check this in when the tree opens.
Fix checked into trunk.
Comment on attachment 271737 [details] [diff] [review] Patch to checkin This applies cleanly to the 1.8 branch.
Comment on attachment 271737 [details] [diff] [review] Patch to checkin approved for 18.104.22.168, a=dveditz for release-drivers
Fixed on the 1.8 branch.