DecompileScript() public method

Decompile the script.
Decompile the script.

The canonical source of the script is returned.

public DecompileScript ( System.Script script, int indent ) : string
script System.Script the script to decompile
indent int the number of spaces to indent the result
return string
Example #1
0
			public object Run(Context cx)
			{
				Script script = cx.CompileString(source, "my script", 0, null);
				NUnit.Framework.Assert.AreEqual(source, cx.DecompileScript(script, 4).Trim());
				return null;
			}
Example #2
0
		public override object ExecIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, object[] args)
		{
			if (!f.HasTag(SCRIPT_TAG))
			{
				return base.ExecIdCall(f, cx, scope, thisObj, args);
			}
			int id = f.MethodId();
			switch (id)
			{
				case Id_constructor:
				{
					string source = (args.Length == 0) ? string.Empty : ScriptRuntime.ToString(args[0]);
					Script script = Compile(cx, source);
					Rhino.NativeScript nscript = new Rhino.NativeScript(script);
					ScriptRuntime.SetObjectProtoAndParent(nscript, scope);
					return nscript;
				}

				case Id_toString:
				{
					Rhino.NativeScript real = RealThis(thisObj, f);
					Script realScript = real.script;
					if (realScript == null)
					{
						return string.Empty;
					}
					return cx.DecompileScript(realScript, 0);
				}

				case Id_exec:
				{
					throw Context.ReportRuntimeError1("msg.cant.call.indirect", "exec");
				}

				case Id_compile:
				{
					Rhino.NativeScript real = RealThis(thisObj, f);
					string source = ScriptRuntime.ToString(args, 0);
					real.script = Compile(cx, source);
					return real;
				}
			}
			throw new ArgumentException(id.ToString());
		}