private GraceObject mDocument(EvaluationContext ctx) { var ret = sink.SendRPC(0, "document", noArgs); var gfo = ret as GraceForeignObject; if (gfo == null) { return(ret); } int okey = (int)gfo.IdentifyingData; return(new DomObject(okey, sink)); }
private Dom(EvaluationContext ctx) : base("websocket/dom") { var interp = (Interpreter)ctx; sink = interp.RPCSink; var gfo = sink.SendRPC(-1, "init", noArgs) as GraceForeignObject; var win = new DomObject((int)gfo.IdentifyingData, sink); AddMethod("window", new ConstantMethod(win)); //AddMethod("document", new ConstantMethod(new DomObject(1))); AddMethod("document", new DelegateMethod0Ctx(mDocument)); AddMethod("sleep(_)", new DelegateMethod1(mSleep)); AddMethod("run", new DelegateMethod0Ctx(mRun)); AddMethod("yield", new DelegateMethod0Ctx(mYield)); AddMethod("yieldFor(_)", new DelegateMethod1Ctx(mYieldFor)); AddMethod("end", new DelegateMethod0Ctx(mEnd)); AddMethod("ignoreResultOf(_) on(_)", new DelegateMethodReq(mIgnoreResultOf_On)); }
public override GraceObject Request(EvaluationContext ctx, MethodRequest req, GraceObject receiver) { var part = req[0]; var isAssign = false; if (req.Count > 1) { if (req[1].Name == ":=(_)") { part = req[1]; isAssign = true; } } object[] args = new object[part.Arguments.Count]; int i = 0; foreach (var a in part.Arguments) { var d = a as DomObject; var s = a as GraceString; if (d != null) { args[i++] = new int[1] { d.key } } ; else if (s != null) { args[i++] = s.Value; } else { args[i++] = a; } } // Request names include arities, which // the DOM doesn't understand. var name = req.Name; var idx = name.IndexOf('('); if (idx != -1) { name = name.Substring(0, idx); } if (isAssign) { return(sink.SendRPCNoResult(key, name, args)); } if (ignoredMethodResults != null) { if (ignoredMethodResults.Contains(name)) { return(sink.SendRPCNoResult(key, name, args)); } } var ret = sink.SendRPC(key, name, args); var gfo = ret as GraceForeignObject; if (gfo == null) { return(ret); } int okey = (int)gfo.IdentifyingData; return(new DomObject(okey, sink)); }