public override object ExecIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, object[] args)
{
if (!f.HasTag(GENERATOR_TAG))
{
return base.ExecIdCall(f, cx, scope, thisObj, args);
}
int id = f.MethodId();
if (!(thisObj is NativeGenerator))
{
throw IncompatibleCallError(f);
}
NativeGenerator generator = (NativeGenerator)thisObj;
switch (id)
{
case Id_close:
{
// need to run any pending finally clauses
return generator.Resume(cx, scope, GENERATOR_CLOSE, new NativeGenerator.GeneratorClosedException());
}
case Id_next:
{
// arguments to next() are ignored
generator.firstTime = false;
return generator.Resume(cx, scope, GENERATOR_SEND, Undefined.instance);
}
case Id_send:
{
object arg = args.Length > 0 ? args[0] : Undefined.instance;
if (generator.firstTime && !arg.Equals(Undefined.instance))
{
throw ScriptRuntime.TypeError0("msg.send.newborn");
}
return generator.Resume(cx, scope, GENERATOR_SEND, arg);
}
case Id_throw:
{
return generator.Resume(cx, scope, GENERATOR_THROW, args.Length > 0 ? args[0] : Undefined.instance);
}
case Id___iterator__:
{
return thisObj;
}
default:
{
throw new ArgumentException(id.ToString());
}
}
}