Closed Bug 321021 Opened 19 years ago Closed 19 years ago

Unable to get exceptions from JS_EvaluateScript and friends

Categories

(Core :: JavaScript Engine, defect)

PowerPC
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: clkao, Assigned: shaver)

Details

Attachments

(2 files, 2 obsolete files)

User-Agent:       Mozilla/5.0 (Macintosh; U; PPC Mac OS X; zh-tw) AppleWebKit/416.12 (KHTML, like Gecko) Safari/416.13
Build Identifier: 

One should be able to use JS_IsExceptionPending() to check if the context contains uncaught exceptions after JS_EvaluateScript is called.  However, the uncaught exceptions are reported as error by the LAST_FRAME_CHECKS macro.  Being reported as error means the embedder has no way accessing the raw exception object.  Attached is an example.


Reproducible: Always

Steps to Reproduce:
Compile the test script and run.  Expected to see "returning false 1", rahter than "returning false 0"
Attached file test case
Yeah, this sucks, and we think it's biting others as well.

I proposed adding a context option to suppress LAST_FRAME_CHECKS' exception-to-error conversion.

Anyone want to throw another option on the table?
Yeah, JSOPTION_DONT_REPORT_UNCAUGHT, unless someone has a better idea.  Shaver, you want to field this one?

/be
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: testcase-
My other idea was to have LAST_FRAME_CHECKS still call the error reporter (if set?) but leave the exception state intact.  I don't like that idea as much as JSOPTION_DONT_REPORT_UNCAUGHT, though the double semantic negative in that name gives me mild pause.
Assignee: general → shaver
This does it for me.  I added

    JS_SetOptions(cx, JSOPTION_DONT_REPORT_UNCAUGHT);

after the JS_SetGlobalObject call in the aforementioned testcase.
Attachment #206743 - Flags: superreview?(brendan)
Attachment #206743 - Flags: review?(mrbkap)
Comment on attachment 206743 [details] [diff] [review]
Add JSOPTION_DONT_REPORT_UNCAUGHT

API compatibility always seems to make things uglier. I should remember to use this instead of a fake fp in evalInSandbox!
Attachment #206743 - Flags: review?(mrbkap) → review+
Comment on attachment 206743 [details] [diff] [review]
Add JSOPTION_DONT_REPORT_UNCAUGHT

>Index: jsapi.c
>===================================================================
>RCS file: /cvsroot/mozilla/js/src/jsapi.c,v
>retrieving revision 3.229
>diff -u -p -r3.229 jsapi.c
>--- jsapi.c	5 Dec 2005 21:35:15 -0000	3.229
>+++ jsapi.c	24 Dec 2005 01:30:59 -0000
>@@ -3646,7 +3646,7 @@ JS_CompileUCScript(JSContext *cx, JSObje
> #if JS_HAS_EXCEPTIONS
> # define LAST_FRAME_EXCEPTION_CHECK(cx,result)                                \
>     JS_BEGIN_MACRO                                                            \
>-        if (!(result))                                                        \
>+        if (!(result) && (!(cx)->options & JSOPTION_DONT_REPORT_UNCAUGHT))    \

Oops, you meant

        if (!(result) && !((cx)->options & JSOPTION_DONT_REPORT_UNCAUGHT))

>+#define JSOPTION_DONT_REPORT_UNCAUGHT \
>+                                JS_BIT(8)       /* prevent exceptions left
>+                                                   uncaught, when returning from
>+                                                   the outermost frame or API
>+                                                   call, from being converted
>+                                                   to an error report */

Couple of English nits:
- Use plural consistently: "prevent exceptions... from being converted into error reports".
- Transpose the dependent clause: "When returning from the outermost API call, prevent ...".

/be
Attachment #206743 - Flags: superreview?(brendan) → superreview-
I am so getting "transpose the deponent clause" on a T-shirt.
Attachment #206743 - Attachment is obsolete: true
Attachment #206745 - Flags: superreview?(brendan)
Attachment #206745 - Flags: review?(mrbkap)
Comment on attachment 206745 [details] [diff] [review]
deponents and negations transposed, nouns enpluralificated

Your jsapi.c changes seem unchanged from above.
Attachment #206745 - Flags: review?(mrbkap) → review-
Thanks.
Attachment #206745 - Attachment is obsolete: true
Attachment #206746 - Flags: superreview?(brendan)
Attachment #206746 - Flags: review?(mrbkap)
Attachment #206745 - Flags: superreview?(brendan)
Comment on attachment 206746 [details] [diff] [review]
you have no idea how late it is here, in my brain

I could guess, but I'll give you the benefit of the doubt.
Attachment #206746 - Flags: review?(mrbkap) → review+
Comment on attachment 206746 [details] [diff] [review]
you have no idea how late it is here, in my brain

The double "prevent" in the jsapi.h comment is fixed my tree, natch.
Comment on attachment 206746 [details] [diff] [review]
you have no idea how late it is here, in my brain

sr=me with undoubled "prevent".

/be
Attachment #206746 - Flags: superreview?(brendan) → superreview+
shaver, you gonna check this in soon?

/be
Fixed.
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: