1999-06-09 07:10:30 +04:00
|
|
|
class JSName extends ExpressionNode {
|
|
|
|
|
|
|
|
JSName(JSIdentifier anID, int aScope)
|
|
|
|
{
|
|
|
|
id = anID;
|
|
|
|
scope = aScope; // this is the scope that the name was used in
|
|
|
|
}
|
|
|
|
|
|
|
|
String print(String indent)
|
|
|
|
{
|
|
|
|
return indent + "JSName : " + id.s + ", scope : " + scope + "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
JSReference evalLHS(Environment theEnv)
|
|
|
|
{
|
1999-06-15 04:57:05 +04:00
|
|
|
JSScope scope = theEnv.scope;
|
|
|
|
while (scope != null) {
|
|
|
|
if (scope.hasProp(theEnv, id))
|
|
|
|
return new JSReference(scope, id);
|
|
|
|
else
|
|
|
|
scope = scope.parent;
|
|
|
|
}
|
|
|
|
return new JSReference(theEnv.globalScope, id);
|
1999-06-09 07:10:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JSValue eval(Environment theEnv)
|
|
|
|
{
|
1999-06-15 04:57:05 +04:00
|
|
|
JSScope scope = theEnv.scope;
|
|
|
|
while (scope != null) {
|
|
|
|
if (scope.hasProp(theEnv, id))
|
|
|
|
return scope.getProp(theEnv, id);
|
|
|
|
else
|
|
|
|
scope = scope.parent;
|
|
|
|
}
|
|
|
|
throw new JSException(new JSString(id.s + " undefined"));
|
1999-06-09 07:10:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JSIdentifier id;
|
|
|
|
int scope;
|
|
|
|
|
|
|
|
}
|