Subj : Re: freeze and thaw script files To : netscape.public.mozilla.jseng From : frankin@miramar.com (Forest Rankin) Date : Tue Jun 17 2003 12:49 pm I have freezing and thawing working. It was my error when writting and reading from the file. I needed to use the UNICODE jschar. My .js file has script code in the global scope, but it is not executed with the "exec" function call. Do I need to root the script object after it is thaw'd? I can call all of the functions in the .js file no problem, but they can not reference any globally scoped variables. Thanks for the help. -forest JSScript* pjsScript = JS_CompileScript( m_pContext, m_pGlobal, strScriptCode, strScriptCode.GetLength(), m_strScriptPath, 0); if (pjsScript == NULL) { return false; } JSObject* pScriptObject = JS_NewScriptObject(m_pContext, pjsScript); jsval f, scr = OBJECT_TO_JSVAL(pjsScript); // code copied from jsscript.c script_freeze(m_pContext, pScriptObject, 0, &scr, &f); JSString* s = JSVAL_TO_STRING(f); jschar* b = JS_GetStringChars(s); size_t l = (JS_GetStringLength(s) * sizeof(jschar)); CFile file; if (file.Open(strCompiledPath.data(), CFile::modeReadWrite|CFile::modeCreate|CFile::typeBinary)) { file.Write(b, l); file.Close(); } if (file.Open(strCompiledPath.data(), CFile::modeRead|CFile::typeBinary)) { std::auto_ptr pB(new jschar[file.GetLength()]); jschar* pBuf = pB.get(); size_t lLen = file.Read(pBuf, (UINT)file.GetLength()); file.Close(); // convert deserialized script to a JSString lLen /= sizeof(jschar); JSString* pStr = JS_NewUCStringCopyN(m_pContext, pBuf, lLen); jsval argv[1]; argv[0] = STRING_TO_JSVAL(pStr); JSObject* pScriptObject = JS_NewScriptObject(m_pContext, NULL); jsval ret; // code copied from jsscript.c script_static_thaw(m_pContext, pScriptObject, 1, argv, &ret); jsval result; argv[0] = OBJECT_TO_JSVAL(m_pGlobal); JSBool okay = JS_CallFunctionName(m_pContext, pScriptObject, "exec", 1, argv, &result); return (okay == JS_TRUE); // This code fails??? //JSScript* pScript = (JSScript*)JSVAL_TO_OBJECT(ret); //jsval ex; //JS_ExecuteScript(m_pContext, m_pGlobal, pScript, &ex); } .