From 77e3687daa855887b0a4c194617c130385242ecd Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Mon, 15 May 2000 06:06:12 +0000 Subject: [PATCH] Comment the need for rooted JS_NewScriptObject; whitespace/comment cleanup. --- js/src/jsapi.h | 16 ++++++++++++++++ js/src/jscntxt.c | 10 +++++----- js/src/jsfile.c | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 4fca3025554..97f3cafce3c 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -953,6 +953,22 @@ JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj, const char *filename, FILE *fh, JSPrincipals *principals); +/* + * NB: you must use JS_NewScriptObject and root a pointer to its return value + * in order to keep a JSScript and its atoms safe from garbage collection after + * creating the script via JS_Compile* and before a JS_ExecuteScript* call. + * E.g., and without error checks: + * + * JSScript *script = JS_CompileFile(cx, global, filename); + * JSObject *scrobj = JS_NewScriptObject(cx, script); + * JS_AddNamedRoot(cx, &scrobj, "scrobj"); + * do { + * jsval result; + * JS_ExecuteScript(cx, global, script, &result); + * JS_GC(); + * } while (!JSVAL_IS_BOOLEAN(result) || JSVAL_TO_BOOLEAN(result)); + * JS_RemoveRoot(cx, &scrobj); + */ extern JS_PUBLIC_API(JSObject *) JS_NewScriptObject(JSContext *cx, JSScript *script); diff --git a/js/src/jscntxt.c b/js/src/jscntxt.c index d9df4a5d19c..94ba8629367 100644 --- a/js/src/jscntxt.c +++ b/js/src/jscntxt.c @@ -193,13 +193,13 @@ js_DestroyContext(JSContext *cx, JSGCMode gcmode) if (last) { /* Always force, so we wait for any racing GC to finish. */ js_ForceGC(cx); - js_FreeAtomState(cx, &rt->atomState); + js_FreeAtomState(cx, &rt->atomState); /* Take the runtime down now that it has no contexts. */ - JS_LOCK_RUNTIME(rt); - rt->state = JSRTS_DOWN; - JS_NOTIFY_ALL_CONDVAR(rt->stateChange); - JS_UNLOCK_RUNTIME(rt); + JS_LOCK_RUNTIME(rt); + rt->state = JSRTS_DOWN; + JS_NOTIFY_ALL_CONDVAR(rt->stateChange); + JS_UNLOCK_RUNTIME(rt); } else { if (gcmode == JS_FORCE_GC) js_ForceGC(cx); diff --git a/js/src/jsfile.c b/js/src/jsfile.c index 9478d2b1a6b..b12b7a0b76c 100644 --- a/js/src/jsfile.c +++ b/js/src/jsfile.c @@ -1685,7 +1685,7 @@ file_readln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) endofline = JS_TRUE; goto loop; } - if (data2!='\n') { /* we read one char to far. buffer it. */ + if (data2!='\n') { /* We read one char too far. Buffer it. */ file->charBuffer = data2; file->charBufferUsed = JS_TRUE; }