mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 16:46:26 +00:00
35 lines
903 B
Java
35 lines
903 B
Java
|
|
import java.util.Vector;
|
|
|
|
class NativeFunction extends JSObject {
|
|
|
|
NativeFunction(ControlNode aBody)
|
|
{
|
|
super("Function");
|
|
body = aBody;
|
|
}
|
|
|
|
JSValue call(Environment theEnv, JSValue rV)
|
|
{
|
|
|
|
JSScope args = new JSScope("Arguments");
|
|
theEnv.enterNewScope(args);
|
|
|
|
for (int i = 0; i < parameters.size(); i++) {
|
|
if (rV instanceof JSValueList)
|
|
args.putProp(theEnv, (JSString)(parameters.elementAt(i)), (JSValue) ( ((JSValueList)rV).contents.elementAt(i)) );
|
|
else
|
|
args.putProp(theEnv, (JSString)(parameters.elementAt(i)), rV );
|
|
}
|
|
|
|
ControlNode c = body;
|
|
while (c != null) c = c.eval(theEnv);
|
|
|
|
theEnv.leaveScope();
|
|
return theEnv.resultValue;
|
|
}
|
|
|
|
ControlNode body;
|
|
Vector parameters = new Vector();
|
|
|
|
} |