From e5bf3349f66288ef79e5ab7e83d2cbe7d6363272 Mon Sep 17 00:00:00 2001 From: "mlm%netscape.com" Date: Fri, 25 Sep 1998 22:08:28 +0000 Subject: [PATCH] Branch landing: Multithreading libmocha in mozilla. - Add JS_BeginRequest and JS_EndRequest calls - Add context parameters to some functions --- modules/libpref/src/prefapi.c | 34 ++++++++++++++++++++++++++++----- modules/libpref/src/prefapi.cpp | 34 ++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/modules/libpref/src/prefapi.c b/modules/libpref/src/prefapi.c index 0fcf0715b6f4..36b8d64c8c1c 100644 --- a/modules/libpref/src/prefapi.c +++ b/modules/libpref/src/prefapi.c @@ -367,19 +367,30 @@ PREF_Init(char *filename) return 0; } - JS_SetVersion(m_mochaContext, JSVERSION_1_2); + JS_BeginRequest(m_mochaContext); m_GlobalConfigObject = JS_NewObject(m_mochaContext, &global_class, NULL, NULL); - if (!m_GlobalConfigObject) + if (!m_GlobalConfigObject) { + JS_EndRequest(m_mochaContext); return 0; + } - if (!JS_InitStandardClasses(m_mochaContext, m_GlobalConfigObject)) + /* MLM - need a global object for set version call now. */ + JS_SetGlobalObject(m_mochaContext, m_GlobalConfigObject); + + JS_SetVersion(m_mochaContext, JSVERSION_1_2); + + if (!JS_InitStandardClasses(m_mochaContext, + m_GlobalConfigObject)) { + JS_EndRequest(m_mochaContext); return 0; + } JS_SetBranchCallback(m_mochaContext, pref_BranchCallback); JS_SetErrorReporter(m_mochaContext, NULL); - m_mochaPrefObject = JS_DefineObject(m_mochaContext, m_GlobalConfigObject, + m_mochaPrefObject = JS_DefineObject(m_mochaContext, + m_GlobalConfigObject, "PrefConfig", &autoconf_class, NULL, @@ -389,12 +400,14 @@ PREF_Init(char *filename) if (!JS_DefineProperties(m_mochaContext, m_mochaPrefObject, autoconf_props)) { + JS_EndRequest(m_mochaContext); return 0; } if (!JS_DefineFunctions(m_mochaContext, m_mochaPrefObject, autoconf_methods)) { + JS_EndRequest(m_mochaContext); return 0; } @@ -403,6 +416,8 @@ PREF_Init(char *filename) #if !defined(XP_WIN) && !defined(XP_OS2) ok = pref_InitInitialObjects(); #endif + } else { + JS_BeginRequest(m_mochaContext); } if (ok && filename) { @@ -411,6 +426,7 @@ PREF_Init(char *filename) else if (!ok) { m_ErrorOpeningUserPrefs = TRUE; } + JS_EndRequest(m_mochaContext); return ok; } @@ -420,8 +436,10 @@ PREF_GetConfigContext(JSContext **js_context) if (!js_context) return FALSE; *js_context = NULL; - if (m_mochaContext) + if (m_mochaContext) { *js_context = m_mochaContext; + JS_SetContextThread(m_mochaContext); + } return TRUE; } @@ -504,6 +522,7 @@ PREF_EvaluateConfigScript(const char * js_buffer, size_t length, if (!m_mochaContext || !scope) return JS_FALSE; + JS_BeginRequest(m_mochaContext); errReporter = JS_SetErrorReporter(m_mochaContext, pref_ErrorReporter); m_CallbacksEnabled = bCallbacks; @@ -513,6 +532,7 @@ PREF_EvaluateConfigScript(const char * js_buffer, size_t length, m_CallbacksEnabled = TRUE; /* ?? want to enable after reading user/lock file */ JS_SetErrorReporter(m_mochaContext, errReporter); + JS_EndRequest(m_mochaContext); return ok; } @@ -536,9 +556,11 @@ PREF_QuietEvaluateJSBuffer(const char * js_buffer, size_t length) if (!m_mochaContext || !m_mochaPrefObject) return PREF_NOT_INITIALIZED; + JS_BeginRequest(m_mochaContext); ok = JS_EvaluateScript(m_mochaContext, m_mochaPrefObject, js_buffer, length, NULL, 0, &result); + JS_EndRequest(m_mochaContext); /* Hey, this really returns a JSBool */ return ok; } @@ -552,8 +574,10 @@ PREF_QuietEvaluateJSBufferWithGlobalScope(const char * js_buffer, size_t length) if (!m_mochaContext || !m_GlobalConfigObject) return PREF_NOT_INITIALIZED; + JS_BeginRequest(m_mochaContext); ok = JS_EvaluateScript(m_mochaContext, m_GlobalConfigObject, js_buffer, length, NULL, 0, &result); + JS_EndRequest(m_mochaContext); /* Hey, this really returns a JSBool */ return ok; diff --git a/modules/libpref/src/prefapi.cpp b/modules/libpref/src/prefapi.cpp index 0fcf0715b6f4..36b8d64c8c1c 100644 --- a/modules/libpref/src/prefapi.cpp +++ b/modules/libpref/src/prefapi.cpp @@ -367,19 +367,30 @@ PREF_Init(char *filename) return 0; } - JS_SetVersion(m_mochaContext, JSVERSION_1_2); + JS_BeginRequest(m_mochaContext); m_GlobalConfigObject = JS_NewObject(m_mochaContext, &global_class, NULL, NULL); - if (!m_GlobalConfigObject) + if (!m_GlobalConfigObject) { + JS_EndRequest(m_mochaContext); return 0; + } - if (!JS_InitStandardClasses(m_mochaContext, m_GlobalConfigObject)) + /* MLM - need a global object for set version call now. */ + JS_SetGlobalObject(m_mochaContext, m_GlobalConfigObject); + + JS_SetVersion(m_mochaContext, JSVERSION_1_2); + + if (!JS_InitStandardClasses(m_mochaContext, + m_GlobalConfigObject)) { + JS_EndRequest(m_mochaContext); return 0; + } JS_SetBranchCallback(m_mochaContext, pref_BranchCallback); JS_SetErrorReporter(m_mochaContext, NULL); - m_mochaPrefObject = JS_DefineObject(m_mochaContext, m_GlobalConfigObject, + m_mochaPrefObject = JS_DefineObject(m_mochaContext, + m_GlobalConfigObject, "PrefConfig", &autoconf_class, NULL, @@ -389,12 +400,14 @@ PREF_Init(char *filename) if (!JS_DefineProperties(m_mochaContext, m_mochaPrefObject, autoconf_props)) { + JS_EndRequest(m_mochaContext); return 0; } if (!JS_DefineFunctions(m_mochaContext, m_mochaPrefObject, autoconf_methods)) { + JS_EndRequest(m_mochaContext); return 0; } @@ -403,6 +416,8 @@ PREF_Init(char *filename) #if !defined(XP_WIN) && !defined(XP_OS2) ok = pref_InitInitialObjects(); #endif + } else { + JS_BeginRequest(m_mochaContext); } if (ok && filename) { @@ -411,6 +426,7 @@ PREF_Init(char *filename) else if (!ok) { m_ErrorOpeningUserPrefs = TRUE; } + JS_EndRequest(m_mochaContext); return ok; } @@ -420,8 +436,10 @@ PREF_GetConfigContext(JSContext **js_context) if (!js_context) return FALSE; *js_context = NULL; - if (m_mochaContext) + if (m_mochaContext) { *js_context = m_mochaContext; + JS_SetContextThread(m_mochaContext); + } return TRUE; } @@ -504,6 +522,7 @@ PREF_EvaluateConfigScript(const char * js_buffer, size_t length, if (!m_mochaContext || !scope) return JS_FALSE; + JS_BeginRequest(m_mochaContext); errReporter = JS_SetErrorReporter(m_mochaContext, pref_ErrorReporter); m_CallbacksEnabled = bCallbacks; @@ -513,6 +532,7 @@ PREF_EvaluateConfigScript(const char * js_buffer, size_t length, m_CallbacksEnabled = TRUE; /* ?? want to enable after reading user/lock file */ JS_SetErrorReporter(m_mochaContext, errReporter); + JS_EndRequest(m_mochaContext); return ok; } @@ -536,9 +556,11 @@ PREF_QuietEvaluateJSBuffer(const char * js_buffer, size_t length) if (!m_mochaContext || !m_mochaPrefObject) return PREF_NOT_INITIALIZED; + JS_BeginRequest(m_mochaContext); ok = JS_EvaluateScript(m_mochaContext, m_mochaPrefObject, js_buffer, length, NULL, 0, &result); + JS_EndRequest(m_mochaContext); /* Hey, this really returns a JSBool */ return ok; } @@ -552,8 +574,10 @@ PREF_QuietEvaluateJSBufferWithGlobalScope(const char * js_buffer, size_t length) if (!m_mochaContext || !m_GlobalConfigObject) return PREF_NOT_INITIALIZED; + JS_BeginRequest(m_mochaContext); ok = JS_EvaluateScript(m_mochaContext, m_GlobalConfigObject, js_buffer, length, NULL, 0, &result); + JS_EndRequest(m_mochaContext); /* Hey, this really returns a JSBool */ return ok;