SpiderMonkey JS_EvaluateUCScriptForPrincipals doesn't clear exceptions after compile error, needs to call LAST_FRAME_CHECKS

RESOLVED DUPLICATE of bug 451732

Status

()

Core
JavaScript Engine
RESOLVED DUPLICATE of bug 451732
8 years ago
8 years ago

People

(Reporter: Gwurk, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

8 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4
Build Identifier: 

This page http://developer.mozilla.org/En/SpiderMonkey/JSAPI_User_Guide#Automatic_handling_of_uncaught_exceptions claims that JS_EvaluateScript should clear any pending exceptions before it returns. However, it doesn't clear the exception if it is caused by compilation errors (e.g., syntax errors).

In the implementation of JS_EvaluateUCScriptForPrincipals() in jsapi.c, you do:

  script = js_CompileScript(cx, obj, principals, TCF_COMPILE_N_GO,
                            chars, length, NULL, filename, lineno);
  if (!script)
      return JS_FALSE;
  ok = js_Execute(cx, obj, script, NULL, 0, rval);
  LAST_FRAME_CHECKS(cx, ok);
  JS_DestroyScript(cx, script);
  return ok;

You need to do the LAST_FRAME_CHECKS if js_CompileScript() fails as well.

Reproducible: Always

Steps to Reproduce:
#include <assert.h>
#include "jsapi.h"

int main() {
  JSRuntime* rt = JS_NewRuntime(10000);
  JSContext* cx = JS_NewContext(rt, 8192);

  JSObject* obj =  JS_NewObject(cx, NULL, NULL, NULL);
  jsval rval;
  static const char script[] = "!@#$ syntax error";
  JS_EvaluateScript(cx, obj, script, sizeof(script) - 1, "src", 0, &rval);
  // JS_EvaluateScript should clear syntax error exceptions but doesn't:
  assert(!JS_IsExceptionPending(cx));

  // if you take out the assert, running another script that throws will
  // also fail if you build SpiderMonkey with the DEBUG macro defined:
  static const char script2[] = "throw 123;";
  JS_EvaluateScript(cx, obj, script2, sizeof(script2) - 1, "src", 0, &rval);

  JS_DestroyContext(cx);
  JS_DestroyRuntime(rt);
  return 0;
}
Couple of things here, 20-20 hindsight but I hope helpful for next time:

* Search all (open and closed) bugs, in this case for LAST_FRAME_CHECKS.

* Check the latest http://hg.mozilla.org/mozilla-central/js/src for fixes. For the bleeding edge, try http://hg.mozilla.org/tracemonkey/js/src.

/be
Status: UNCONFIRMED → RESOLVED
Last Resolved: 8 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 451732
You need to log in before you can comment on or make changes to this bug.