Hi Eric It works but *it cant handle line number correctly* After some search I figure out how to find correct line number Here is a sample: http://www.hungryfools.com/2008/03/i-was-really-determined-to-figure-out.html
jsd.errorHook = { onError: function(message, fileName, *lineNo*, pos, flags,
errnum, exc){ /* xxx handle the error here xxx */ }};
Using @mozilla.org/js/jsd/debugger-service;1 gives lots of powerful tools,
but I cant find any documentation about how to use it
I have one more problem:
*Can anybody help me how to add breakpoints to my script*
I think with it I can pause my script without any CPU usage, and it will
help me a lot
Any suggestion would be appropriated
P.S: for testing JSD here is an working example :-)
------------------
<?xml version="1.0"?>
<!DOCTYPE window SYSTEM "chrome://chatzilla/locale/chatzilla.dtd">
<?xul-overlay href="chrome://global/content/globalOverlay.xul"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul
"
id="main-window" orient="vertical" onclose="onClose();">
<script>
<![CDATA[
dump ("Debugging starts\n");
var scriptHook = {
onScriptCreated: function scripthook (script) { },
onScriptDestroyed: function scripthook (script) { }
};
var errorHook = {
onError: function(message, fileName, lineNo, pos, flags, errnum,
exc){
dump( "message: " + message + "\n");
}
};
var enumerateScripts = {
enumerateScript: function (scripts) {
dump('this line doesnt shown!');
}
};
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
const JSD_CTRID = "@mozilla.org/js/jsd/debugger-service;1";
const jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var jsds =
Components.classes[JSD_CTRID].getService(jsdIDebuggerService);
jsds.scriptHook = scriptHook;
jsds.errorHook = errorHook;
jsds.enumerateScripts = enumerateScripts;
jsds.on();
function onClose () {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
jsds.off();
}
function onKeyPress (e) {
if (e.keyCode == 13)
doEval();
}
function doEval() {
var ex;
try {
var rv = eval(document.getElementById("input-box").value);
document.getElementById("output-box").value = rv;
} catch (ex) {
document.getElementById("output-box").value =
"Caught exception: " + String(ex);
}
finally
{
document.getElementById("input-box").value = "";
}
}
]]>
</script>
<textbox id="input-box" style="width:100%" multiline="true"/>
<button label = "Execute" oncommand="doEval();" />
<textbox id="output-box" style="width:100%" readonly="true"/>
</window>
------------------
On Fri, Mar 13, 2009 at 12:27 AM, Eric Jung <[email protected]> wrote:
>
>
> On Thu, Mar 12, 2009 at 5:11 AM, joe ertaba <[email protected]> wrote:
>
>> I want to use *eval *to run JavaScript commands dynamically
>>
>> It works fine but I cant figure out *error line number* with it.
>>
>> it seems that it is possible to improve error handling using @
>> mozilla.org/js/jsd/debugger-service;1
>>
>> Can any body help how to use this to execute js dynamically also handling
>> errors, an example would be appreciated [?]
>>
>>
> You can get a line number with the Exception.stack and Error.stack
> properties For example:
>
> try {
> ...
> ...
> }
> catch (e) {
> dump(e + "\n" + e.stack + "\n");
> }
>
> or
>
> try {
> var foo = "123";
> alert(foo);
> throw new Error("hi mom!"); // forces catch block to be invoked
> }
> catch(e) {
> dump(e + "\n" + e.stack + "\n");
> }
>
>
>
> _______________________________________________
> Project_owners mailing list
> [email protected]
> https://www.mozdev.org/mailman/listinfo/project_owners
>
>
<<329.png>>
_______________________________________________ Project_owners mailing list [email protected] https://www.mozdev.org/mailman/listinfo/project_owners
