253003: re-ordering script compile, r=brendan

This commit is contained in:
crowder%fiverocks.com 2007-01-29 04:40:34 +00:00
Родитель 5da9812eba
Коммит 3a74a63ab4
1 изменённых файлов: 15 добавлений и 14 удалений

Просмотреть файл

@ -160,10 +160,10 @@ static JSBool
script_compile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
JSScript *oldscript, *script;
JSStackFrame *fp, *caller;
JSString *str;
JSObject *scopeobj;
JSScript *oldscript, *script;
JSStackFrame *fp, *caller;
const char *file;
uintN line;
JSPrincipals *principals;
@ -176,6 +176,19 @@ script_compile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
if (argc == 0)
goto out;
/* Otherwise, the first arg is the script source to compile. */
str = js_ValueToString(cx, argv[0]);
if (!str)
return JS_FALSE;
argv[0] = STRING_TO_JSVAL(str);
scopeobj = NULL;
if (argc >= 2) {
if (!js_ValueToObject(cx, argv[1], &scopeobj))
return JS_FALSE;
argv[1] = OBJECT_TO_JSVAL(scopeobj);
}
/* XXX thread safety was completely neglected in this function... */
oldscript = (JSScript *) JS_GetPrivate(cx, obj);
if (oldscript) {
@ -188,23 +201,11 @@ script_compile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
}
}
/* Otherwise, the first arg is the script source to compile. */
str = js_ValueToString(cx, argv[0]);
if (!str)
return JS_FALSE;
argv[0] = STRING_TO_JSVAL(str);
/* Compile using the caller's scope chain, which js_Invoke passes to fp. */
fp = cx->fp;
caller = JS_GetScriptedCaller(cx, fp);
JS_ASSERT(!caller || fp->scopeChain == caller->scopeChain);
scopeobj = NULL;
if (argc >= 2) {
if (!js_ValueToObject(cx, argv[1], &scopeobj))
return JS_FALSE;
argv[1] = OBJECT_TO_JSVAL(scopeobj);
}
if (caller) {
if (!scopeobj) {
scopeobj = js_GetScopeChain(cx, caller);