public static Callable GetValueFunctionAndThis(object value, Context cx)
{
if (!(value is Callable))
{
throw NotFunctionError(value);
}
Callable f = (Callable)value;
Scriptable thisObj = null;
if (f is Scriptable)
{
thisObj = ((Scriptable)f).GetParentScope();
}
if (thisObj == null)
{
if (cx.topCallScope == null)
{
throw new InvalidOperationException();
}
thisObj = cx.topCallScope;
}
if (thisObj.GetParentScope() != null)
{
if (thisObj is NativeWith)
{
}
else
{
// functions defined inside with should have with target
// as their thisObj
if (thisObj is NativeCall)
{
// nested functions should have top scope as their thisObj
thisObj = ScriptableObject.GetTopLevelScope(thisObj);
}
}
}
StoreScriptable(cx, thisObj);
return f;
}