Re: Show stopper issue for our GECKO 1.9.2 embedding project and we have expensive business impact
Benjamin Smedberg <[email protected]> Thu, 22 Dec 2011 11:39:16 -0500
| Newsgroups | gmane.comp.mozilla.devel.embedding |
|---|---|
| Message-ID | <[email protected]> |
On 12/22/2011 10:45 AM, lord_nemesis wrote:
> Hello Benjamin (I am putting the name directly as I got help through
> him and now having issue in that area),
> This issue is putting us in most discomfort situation in business
> line... Please take time and help us out from here....
>
> Problem:
> We have a page that that is throwing a JS exception when running in
> our embedded gecko browser, but working fine in firefox. The page a
> javascript function which checks the value of a global though an if
> condition. the same is set an initial value in the<head> section of
> the page. some thing like this
I really have no clue about the correct way to do what you're doing.
Perhaps bholley.
--BDS
>
> test = "";
>
> myfunc()
> {
> if (test&& ...) {
> }
> }
>
> as you can see, test is not a var type. Its a global property. In our
> embedded gecko application, we are getting a "ReferenceError: test is
> undefined" exception when trying to check the value of test. This is
> however not happening in Firefox browser built from the same
> codebase.
>
> After some debugging, we arrived at the conclusion that our own code
> to call javascript functions on the page is causing some issue.
>
> our code for the same looks some thing like this. This is used to
> invoke custom js functions in some pages, but not on on the particular
> one that we are having problem with. can you please see if there is
> anything wrong with this code and also help us with solving the
> problem.
>
>
>
> CallJavaScript(const CString& strJSFnName, const CStringArray&
> paramArray, CString& strRetVal)
> {
> try {
> nsresult resultVal = NS_OK;
> nsCOMPtr<nsIDOMDocument> domDoc;
>
> if(nsnull == m_webNavigation ) //null check to avoid crash
> & show blank page incase of Webnavigation handle null
> {
> return false;
> }
>
> // Get the Document DOM
> resultVal = m_webNavigation-
>> GetDocument(getter_AddRefs(domDoc));
> if (NS_FAILED(resultVal))
> {
> return false;
> }
>
> // Get Document from DOM.
> nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc,
> &resultVal);
> if (NS_FAILED(resultVal))
> {
> return false;
> }
>
> // Get the Script Global Object from Document
>
> nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObj(doc-
>> GetScriptGlobalObject());
> if (scriptGlobalObj == nsnull) {
> return false;
> }
>
> // Get the Script Context
> nsCOMPtr<nsIScriptContext> scriptContext(scriptGlobalObj-
>> GetContext());
> if (scriptContext == nsnull) {
> return false;
> }
>
> // Get the JSContext.
> JSContext *pJSContext =
> reinterpret_cast<JSContext*>(scriptContext->GetNativeContext());
> JSObject *pJSObject = scriptGlobalObj->GetGlobalJSObject();
>
> {
> AutoSetupJSContext setupJSContext(pJSContext);
>
> jsval jsReturnVal = 0;
>
> // Build the Input argument list
> int argCount =paramArray.GetSize();
> jsval *pJSInputArgs = new jsval[argCount];
>
> for (int argIndex = 0; argIndex< argCount; +
> +argIndex) {
> CString argStr = paramArray.GetAt(argIndex);
> jschar *pJSArgChars = (jschar *)
> (argStr.GetBuffer(argStr.GetLength()));
> JSString *jsArgStr =
> JS_NewUCStringCopyZ(pJSContext, pJSArgChars);
> argStr.ReleaseBuffer();
> pJSInputArgs[argIndex] =
> STRING_TO_JSVAL(jsArgStr);
> }
>
> int jsFuncNameLen = WideCharToMultiByte(CP_ACP, 0,
> (LPCWSTR)(LPCTSTR)strJSFnName, -1, 0, 0, NULL, NULL);
> char* pJSFuncName = new char[jsFuncNameLen + 1];
> WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)
> (LPCTSTR)strJSFnName, -1, pJSFuncName, jsFuncNameLen, NULL, NULL);
>
> JSBool isJSCallSuccess =
> JS_CallFunctionName(pJSContext, pJSObject, pJSFuncName, argCount,
> pJSInputArgs,&jsReturnVal);
>
>
> class AutoSetupJSContext {
> public:
> AutoSetupJSContext(JSContext *pJSContext)
> : m_JSContextStack(), m_pJSContext(pJSContext)
> {
> nsresult resultVal = NS_OK;
>
> // Get the JSContext Stack.
> m_JSContextStack = do_GetService("@mozilla.org/js/xpc/
> ContextStack;1",&resultVal);
> ASSERT(m_JSContextStack != nsnull);
>
> // Push the JSContext to JSContext Stack.
> resultVal = m_JSContextStack->Push(m_pJSContext);
> ASSERT(resultVal == NS_OK);
>
> // Set an Error handler on the JSContext. This handler will
> get control when ever
> // there is an error with executing a JS Function.
> JS_SetErrorReporter(pJSContext, JSErrorHandler);
>
> // Begin JS Request. This will ensure that we wait till any
> current activity on the
> // JSContext is completed before we do our own.
> JS_BeginRequest(pJSContext);
> }
>
> ~AutoSetupJSContext(void)
> {
> nsresult resultVal = NS_OK;
>
> // End the JS Request. We relinquish hold on the JSContext.
> JS_EndRequest(m_pJSContext);
>
> // Pop the JSContext from stack.
> resultVal = m_JSContextStack->Pop(nsnull);
> ASSERT(resultVal == NS_OK);
> }
>
> private:
> nsCOMPtr<nsIJSContextStack> m_JSContextStack;
> JSContext *m_pJSContext;
> };
> _______________________________________________
> dev-embedding mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-embedding