Permalink
Browse files

2006-06-14 Michael Hutchinson <m.j.hutchinson@gmail.com>

	* AspNetEdit.JSCall/CommandManager.cs: Null input checking to avoid 
	segfaults, general cleanup.


svn path=/trunk/aspeditor/; revision=61694
  • Loading branch information...
1 parent 5eee502 commit 4283773631673866e84c8fe391c615544dad7528 @mhutch mhutch committed Jun 14, 2006
Showing with 30 additions and 19 deletions.
  1. +25 −19 src/jscall/AspNetEdit.JSCall/CommandManager.cs
  2. +5 −0 src/jscall/ChangeLog
@@ -48,14 +48,15 @@ public class CommandManager
static extern int ExecuteScript (IntPtr embed,
[MarshalAs(UnmanagedType.LPWStr)] string script);
- private Hashtable functions;
+ private Hashtable functions = new Hashtable ();
private WebControl webControl;
- public CommandManager (WebControl w)
- {
- functions = new Hashtable();
-
- webControl = w;
+ public CommandManager (WebControl control)
+ {
+ if (control == null)
+ throw new ArgumentNullException ("The Command Manager must be bound to a WebControl instance.", "control");
+
+ webControl = control;
webControl.TitleChange += new EventHandler (webControl_ECMAStatus);
}
@@ -66,7 +67,7 @@ private void webControl_ECMAStatus (object sender, EventArgs e)
string[] call = webControl.Title.Split ((char)234);
if (call.Length < 2)
- throw new Exception ("Too few parameters in call from JavaScript");
+ throw new Exception ("Too few parameters in call from JavaScript.");
string function = call[1];
string returnTo = call[2];
@@ -75,7 +76,7 @@ private void webControl_ECMAStatus (object sender, EventArgs e)
System.Array.Copy (call, 3, args, 0, (call.Length - 3));
if (!functions.Contains (function))
- throw new Exception ("Unknown function name called from JavaScript");
+ throw new Exception ("Unknown function name called from JavaScript.");
ClrCall clrCall = (ClrCall) functions[function];
@@ -93,6 +94,9 @@ private void webControl_ECMAStatus (object sender, EventArgs e)
public void JSEval (string script)
{
+ if ((script == null) || (script.Length < 1))
+ throw new ArgumentNullException ("A null or empty script cannot be executed.", "script");
+
int result = ExecuteScript (webControl.Handle, script);
string err;
@@ -126,19 +130,21 @@ public void JSEval (string script)
}
public void JSCall (string function, string returnTo, params string[] args)
- {
- string argsOut = String.Empty;
-
- if (args != null)
- {
+ {
+ if ((function==null) || (function.Length < 1))
+ throw new ArgumentException ("A function name must be specified.", "function");
+
+ if (returnTo == null) returnTo = string.Empty;
+
+ string argsOut = String.Empty;
+
+ if (args != null) {
argsOut += args[0];
- for (int i = 1; i <= args.Length - 1; i++)
- {
+ for (int i = 1; i <= args.Length - 1; i++) {
argsOut += (char)234 + args[i];
}
- }
+ }
- if (returnTo == null) returnTo = string.Empty;
int result = PlaceFunctionCall (webControl.Handle, function, returnTo, argsOut);
string err;
@@ -200,7 +206,7 @@ public void RegisterJSHandler (string name, ClrCall handler)
}
else
{
- throw new Exception ("A handler with this name already exists");
+ throw new Exception ("A handler with this name already exists.");
}
}
@@ -213,7 +219,7 @@ public void UnregisterJSHandler (string name)
}
else
{
- throw new IndexOutOfRangeException ("A function with this name has not been registered");
+ throw new IndexOutOfRangeException ("A function with this name has not been registered.");
}
}
View
@@ -1,3 +1,8 @@
+2006-06-14 Michael Hutchinson <m.j.hutchinson@gmail.com>
+
+ * AspNetEdit.JSCall/CommandManager.cs: Null input checking to avoid
+ segfaults, general cleanup.
+
2006-06-14 Chris Howie <cdhowie@nerdshack.com>
* jscallglue/jscallglue.cpp,

0 comments on commit 4283773

Please sign in to comment.