Note that there are some explanatory texts on larger screens.

plurals
  1. POFind and report Javascript compilation errors in XULRunner using nsIScriptContext or the SpiderMonkey API
    text
    copied!<p>I have an experimental version of wxWebConnect (embedding XULRunner in wxWidgets) at <a href="https://github.com/jonmmorgan/wxwebconnect/" rel="nofollow">https://github.com/jonmmorgan/wxwebconnect/</a>. It offers a method</p> <pre><code>wxString wxWebControl::ExecuteScriptWithResult(const wxString&amp; js_code) </code></pre> <p>which executes the Javascript string using nsIScriptContext::EvaluateStringWithValue, converts the value to a string with JS_ValueToString, and then returns the string.</p> <p>However, I found with the current implementation that if the Javascript string is syntactically invalid (e.g. WebControl.ExecuteScriptWithResult('{a:2')) then the program would crash when trying to convert the result to a string. I discovered the aIsUndefined parameter, which I can use to determine whether script execution succeeded or not and prevent the crash. However, this doesn't help me find what the actual error was, and I think it would be good to report that (like Firebug tells me "SyntaxError: missing } in compound statement"). As far as I can see, even using something like nsIScriptContext::CompileScript will just tell me whether the compilation succeeded or not, and doesn't give me a way to get at the actual syntax error.</p> <p>Following <a href="http://chadaustin.me/2009/02/evaluating-javascript-in-an-embedded-xulrunnergecko-window/" rel="nofollow">http://chadaustin.me/2009/02/evaluating-javascript-in-an-embedded-xulrunnergecko-window/</a>, I tried using JS_GetPendingException, but it never seems to return true. Even when I run webcontrol.ExecuteScriptWithResult("throw new Error('a');") it still doesn't have a pending exception, but does say the result is undefined.</p> <p>Is there any other good way to get a compilation or execution error from nsIScriptContext or the SpiderMonkey API? Any idea why JS_GetPendingException doesn't seem to do this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload