Is it safe for a JSScript* to remove itself (or rather, the JSObject*
that is wrapping it) as a root from its JSContext, while it is
executing? (Assuming the script will no longer be used after it completes).
E.g.:
a: JS_ExecuteScript(... foo ...)
b: (call to native function)
c: JS_RemoveRoot(... foo ...)
This is useful in case you want to expose a Quit function to JS, for
instance, or something similar. After reading some source comments, I am
vaguely under the impression that JS_ExecuteScript temporarily protects
the script from GC, so it should be possible in theory. Is that the case?
Thanks a ton!
Al.
Yes, this is safe.
The garbage collector won't collect a script that's executing.
-j
Wait--I think this is unsafe after all! Sorry for the wrong answer.
It seems like it would be a two-line change to SpiderMonkey to make
this safe, though (in js_TraceScript, also trace script->object if
it's non-null).
-j
No worries :).
> It seems like it would be a two-line change to SpiderMonkey to make
> this safe, though (in js_TraceScript, also trace script->object if
> it's non-null).
>
> -j
Ah, I see. Any chance of these changes being committed? I think it'd be
a good property to have. I would try to do it myself, but I'm not all
that comfortable with the engine source yet, so I'd probably mess
something up :P.
Thanks again,
Al.