mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 678830 - Use JSScript, not script objects, in compile/evaluate API. r=jorendorff
This commit is contained in:
parent
cd298c2787
commit
9dc4e22f8a
@ -650,7 +650,7 @@ ContentScriptErrorReporter(JSContext* aCx,
|
||||
#endif
|
||||
}
|
||||
|
||||
nsDataHashtable<nsStringHashKey, nsFrameScriptExecutorJSObjectHolder*>*
|
||||
nsDataHashtable<nsStringHashKey, nsFrameJSScriptExecutorHolder*>*
|
||||
nsFrameScriptExecutor::sCachedScripts = nsnull;
|
||||
nsRefPtr<nsScriptCacheCleaner> nsFrameScriptExecutor::sScriptCacheCleaner;
|
||||
|
||||
@ -660,7 +660,7 @@ nsFrameScriptExecutor::DidCreateCx()
|
||||
NS_ASSERTION(mCx, "Should have mCx!");
|
||||
if (!sCachedScripts) {
|
||||
sCachedScripts =
|
||||
new nsDataHashtable<nsStringHashKey, nsFrameScriptExecutorJSObjectHolder*>;
|
||||
new nsDataHashtable<nsStringHashKey, nsFrameJSScriptExecutorHolder*>;
|
||||
sCachedScripts->Init();
|
||||
|
||||
sScriptCacheCleaner = new nsScriptCacheCleaner();
|
||||
@ -689,11 +689,11 @@ nsFrameScriptExecutor::DestroyCx()
|
||||
|
||||
static PLDHashOperator
|
||||
CachedScriptUnrooter(const nsAString& aKey,
|
||||
nsFrameScriptExecutorJSObjectHolder*& aData,
|
||||
nsFrameJSScriptExecutorHolder*& aData,
|
||||
void* aUserArg)
|
||||
{
|
||||
JSContext* cx = static_cast<JSContext*>(aUserArg);
|
||||
JS_RemoveObjectRoot(cx, &(aData->mObject));
|
||||
JS_RemoveScriptRoot(cx, &(aData->mScript));
|
||||
delete aData;
|
||||
return PL_DHASH_REMOVE;
|
||||
}
|
||||
@ -730,7 +730,7 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
|
||||
return;
|
||||
}
|
||||
|
||||
nsFrameScriptExecutorJSObjectHolder* holder = sCachedScripts->Get(aURL);
|
||||
nsFrameJSScriptExecutorHolder* holder = sCachedScripts->Get(aURL);
|
||||
if (holder) {
|
||||
nsContentUtils::ThreadJSContextStack()->Push(mCx);
|
||||
{
|
||||
@ -740,7 +740,7 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
|
||||
JSObject* global = nsnull;
|
||||
mGlobal->GetJSObject(&global);
|
||||
if (global) {
|
||||
(void) JS_ExecuteScript(mCx, global, holder->mObject, nsnull);
|
||||
(void) JS_ExecuteScript(mCx, global, holder->mScript, nsnull);
|
||||
}
|
||||
}
|
||||
JSContext* unused;
|
||||
@ -798,7 +798,7 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
|
||||
uint32 oldopts = JS_GetOptions(mCx);
|
||||
JS_SetOptions(mCx, oldopts | JSOPTION_NO_SCRIPT_RVAL);
|
||||
|
||||
JSObject* scriptObj =
|
||||
JSScript* script =
|
||||
JS_CompileUCScriptForPrincipals(mCx, nsnull, jsprin,
|
||||
(jschar*)dataString.get(),
|
||||
dataString.Length(),
|
||||
@ -806,19 +806,19 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
|
||||
|
||||
JS_SetOptions(mCx, oldopts);
|
||||
|
||||
if (scriptObj) {
|
||||
if (script) {
|
||||
nsCAutoString scheme;
|
||||
uri->GetScheme(scheme);
|
||||
// We don't cache data: scripts!
|
||||
if (!scheme.EqualsLiteral("data")) {
|
||||
nsFrameScriptExecutorJSObjectHolder* holder =
|
||||
new nsFrameScriptExecutorJSObjectHolder(scriptObj);
|
||||
nsFrameJSScriptExecutorHolder* holder =
|
||||
new nsFrameJSScriptExecutorHolder(script);
|
||||
// Root the object also for caching.
|
||||
JS_AddNamedObjectRoot(mCx, &(holder->mObject),
|
||||
JS_AddNamedScriptRoot(mCx, &(holder->mScript),
|
||||
"Cached message manager script");
|
||||
sCachedScripts->Put(aURL, holder);
|
||||
}
|
||||
(void) JS_ExecuteScript(mCx, global, scriptObj, nsnull);
|
||||
(void) JS_ExecuteScript(mCx, global, script, nsnull);
|
||||
}
|
||||
//XXX Argh, JSPrincipals are manually refcounted!
|
||||
JSPRINCIPALS_DROP(mCx, jsprin);
|
||||
|
@ -197,13 +197,13 @@ ContentScriptErrorReporter(JSContext* aCx,
|
||||
|
||||
class nsScriptCacheCleaner;
|
||||
|
||||
struct nsFrameScriptExecutorJSObjectHolder
|
||||
struct nsFrameJSScriptExecutorHolder
|
||||
{
|
||||
nsFrameScriptExecutorJSObjectHolder(JSObject* aObject) : mObject(aObject)
|
||||
{ MOZ_COUNT_CTOR(nsFrameScriptExecutorJSObjectHolder); }
|
||||
~nsFrameScriptExecutorJSObjectHolder()
|
||||
{ MOZ_COUNT_DTOR(nsFrameScriptExecutorJSObjectHolder); }
|
||||
JSObject* mObject;
|
||||
nsFrameJSScriptExecutorHolder(JSScript* aScript) : mScript(aScript)
|
||||
{ MOZ_COUNT_CTOR(nsFrameJSScriptExecutorHolder); }
|
||||
~nsFrameJSScriptExecutorHolder()
|
||||
{ MOZ_COUNT_DTOR(nsFrameJSScriptExecutorHolder); }
|
||||
JSScript* mScript;
|
||||
};
|
||||
|
||||
class nsFrameScriptExecutor
|
||||
@ -228,7 +228,7 @@ protected:
|
||||
PRUint32 mCxStackRefCnt;
|
||||
PRPackedBool mDelayedCxDestroy;
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
static nsDataHashtable<nsStringHashKey, nsFrameScriptExecutorJSObjectHolder*>* sCachedScripts;
|
||||
static nsDataHashtable<nsStringHashKey, nsFrameJSScriptExecutorHolder*>* sCachedScripts;
|
||||
static nsRefPtr<nsScriptCacheCleaner> sScriptCacheCleaner;
|
||||
};
|
||||
|
||||
|
@ -1558,7 +1558,7 @@ nsJSContext::CompileScript(const PRUnichar* aText,
|
||||
if (ok && ((JSVersion)aVersion) != JSVERSION_UNKNOWN) {
|
||||
JSAutoRequest ar(mContext);
|
||||
|
||||
JSObject* scriptObj =
|
||||
JSScript* script =
|
||||
::JS_CompileUCScriptForPrincipalsVersion(mContext,
|
||||
(JSObject *)aScopeObject,
|
||||
jsprin,
|
||||
@ -1567,10 +1567,10 @@ nsJSContext::CompileScript(const PRUnichar* aText,
|
||||
aURL,
|
||||
aLineNo,
|
||||
JSVersion(aVersion));
|
||||
if (scriptObj) {
|
||||
if (script) {
|
||||
NS_ASSERTION(aScriptObject.getScriptTypeID()==JAVASCRIPT,
|
||||
"Expecting JS script object holder");
|
||||
rv = aScriptObject.set(scriptObj);
|
||||
rv = aScriptObject.set(script);
|
||||
} else {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
@ -1620,10 +1620,12 @@ nsJSContext::ExecuteScript(void *aScriptObject,
|
||||
jsval val;
|
||||
JSBool ok;
|
||||
|
||||
JSObject *scriptObj = (JSObject*)aScriptObject;
|
||||
JSScript *script = static_cast<JSScript *>(aScriptObject);
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
|
||||
rv = sSecurityManager->GetObjectPrincipal(mContext, scriptObj, getter_AddRefs(principal));
|
||||
rv = sSecurityManager->GetObjectPrincipal(mContext,
|
||||
JS_GetObjectFromScript(script),
|
||||
getter_AddRefs(principal));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = sSecurityManager->PushContextPrincipal(mContext, nsnull, principal);
|
||||
@ -1632,7 +1634,7 @@ nsJSContext::ExecuteScript(void *aScriptObject,
|
||||
nsJSContext::TerminationFuncHolder holder(this);
|
||||
JSAutoRequest ar(mContext);
|
||||
++mExecuteDepth;
|
||||
ok = ::JS_ExecuteScript(mContext, (JSObject *)aScopeObject, scriptObj, &val);
|
||||
ok = ::JS_ExecuteScript(mContext, (JSObject *)aScopeObject, script, &val);
|
||||
|
||||
if (ok) {
|
||||
// If all went well, convert val to a string (XXXbe unless undefined?).
|
||||
@ -2010,8 +2012,8 @@ nsJSContext::BindCompiledEventHandler(nsISupports* aTarget, void *aScope,
|
||||
nsresult
|
||||
nsJSContext::Serialize(nsIObjectOutputStream* aStream, void *aScriptObject)
|
||||
{
|
||||
JSObject *mJSObject = (JSObject *)aScriptObject;
|
||||
if (!mJSObject)
|
||||
JSScript *script = static_cast<JSScript *>(aScriptObject);
|
||||
if (!script)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsresult rv;
|
||||
@ -2023,7 +2025,7 @@ nsJSContext::Serialize(nsIObjectOutputStream* aStream, void *aScriptObject)
|
||||
xdr->userdata = (void*) aStream;
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
if (! ::JS_XDRScriptObject(xdr, &mJSObject)) {
|
||||
if (! ::JS_XDRScript(xdr, &script)) {
|
||||
rv = NS_ERROR_FAILURE; // likely to be a principals serialization error
|
||||
} else {
|
||||
// Get the encoded JSXDRState data and write it. The JSXDRState owns
|
||||
@ -2060,7 +2062,7 @@ nsresult
|
||||
nsJSContext::Deserialize(nsIObjectInputStream* aStream,
|
||||
nsScriptObjectHolder &aResult)
|
||||
{
|
||||
JSObject *result = nsnull;
|
||||
JSScript *result = nsnull;
|
||||
nsresult rv;
|
||||
|
||||
NS_TIME_FUNCTION_MIN(1.0);
|
||||
@ -2083,7 +2085,7 @@ nsJSContext::Deserialize(nsIObjectInputStream* aStream,
|
||||
JSAutoRequest ar(cx);
|
||||
::JS_XDRMemSetData(xdr, data, size);
|
||||
|
||||
if (! ::JS_XDRScriptObject(xdr, &result)) {
|
||||
if (! ::JS_XDRScript(xdr, &result)) {
|
||||
rv = NS_ERROR_FAILURE; // principals deserialization error?
|
||||
}
|
||||
|
||||
|
@ -311,7 +311,7 @@ Load(JSContext *cx,
|
||||
{
|
||||
uintN i;
|
||||
JSString *str;
|
||||
JSObject *scriptObj;
|
||||
JSScript *script;
|
||||
jsval result;
|
||||
FILE *file;
|
||||
|
||||
@ -333,14 +333,14 @@ Load(JSContext *cx,
|
||||
JS_ReportError(cx, "cannot open file '%s' for reading", filename.ptr());
|
||||
return JS_FALSE;
|
||||
}
|
||||
scriptObj = JS_CompileFileHandleForPrincipals(cx, obj, filename.ptr(), file,
|
||||
Environment(cx)->GetPrincipal());
|
||||
script = JS_CompileFileHandleForPrincipals(cx, obj, filename.ptr(), file,
|
||||
Environment(cx)->GetPrincipal());
|
||||
fclose(file);
|
||||
if (!scriptObj)
|
||||
if (!script)
|
||||
return JS_FALSE;
|
||||
|
||||
if (!Environment(cx)->ShouldCompileOnly() &&
|
||||
!JS_ExecuteScript(cx, obj, scriptObj, &result)) {
|
||||
!JS_ExecuteScript(cx, obj, script, &result)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
@ -582,7 +582,7 @@ ProcessFile(JSContext *cx,
|
||||
XPCShellEnvironment* env = Environment(cx);
|
||||
XPCShellEnvironment::AutoContextPusher pusher(env);
|
||||
|
||||
JSObject *scriptObj;
|
||||
JSScript *script;
|
||||
jsval result;
|
||||
int lineno, startline;
|
||||
JSBool ok, hitEOF;
|
||||
@ -622,11 +622,11 @@ ProcessFile(JSContext *cx,
|
||||
return;
|
||||
}
|
||||
|
||||
JSObject* scriptObj =
|
||||
JSScript* script =
|
||||
JS_CompileFileHandleForPrincipals(cx, obj, filename, file,
|
||||
env->GetPrincipal());
|
||||
if (scriptObj && !env->ShouldCompileOnly())
|
||||
(void)JS_ExecuteScript(cx, obj, scriptObj, &result);
|
||||
if (script && !env->ShouldCompileOnly())
|
||||
(void)JS_ExecuteScript(cx, obj, script, &result);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -664,14 +664,14 @@ ProcessFile(JSContext *cx,
|
||||
|
||||
/* Clear any pending exception from previous failed compiles. */
|
||||
JS_ClearPendingException(cx);
|
||||
scriptObj =
|
||||
script =
|
||||
JS_CompileScriptForPrincipals(cx, obj, env->GetPrincipal(), buffer,
|
||||
strlen(buffer), "typein", startline);
|
||||
if (scriptObj) {
|
||||
if (script) {
|
||||
JSErrorReporter older;
|
||||
|
||||
if (!env->ShouldCompileOnly()) {
|
||||
ok = JS_ExecuteScript(cx, obj, scriptObj, &result);
|
||||
ok = JS_ExecuteScript(cx, obj, script, &result);
|
||||
if (ok && result != JSVAL_VOID) {
|
||||
/* Suppress error reports from JS_ValueToString(). */
|
||||
older = JS_SetErrorReporter(cx, NULL);
|
||||
@ -1237,11 +1237,11 @@ XPCShellEnvironment::EvaluateString(const nsString& aString,
|
||||
return false;
|
||||
}
|
||||
|
||||
JSObject* scriptObj =
|
||||
JSScript* script =
|
||||
JS_CompileUCScriptForPrincipals(mCx, global, GetPrincipal(),
|
||||
aString.get(), aString.Length(),
|
||||
"typein", 0);
|
||||
if (!scriptObj) {
|
||||
if (!script) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1251,7 +1251,7 @@ XPCShellEnvironment::EvaluateString(const nsString& aString,
|
||||
}
|
||||
|
||||
jsval result;
|
||||
JSBool ok = JS_ExecuteScript(mCx, global, scriptObj, &result);
|
||||
JSBool ok = JS_ExecuteScript(mCx, global, script, &result);
|
||||
if (ok && result != JSVAL_VOID) {
|
||||
JSErrorReporter old = JS_SetErrorReporter(mCx, NULL);
|
||||
JSString* str = JS_ValueToString(mCx, result);
|
||||
|
@ -1042,7 +1042,6 @@ jsdScript::CreatePPLineMap()
|
||||
JSFunction *fun = JSD_GetJSFunction (mCx, mScript);
|
||||
JSScript *script; /* In JSD compartment */
|
||||
PRUint32 baseLine;
|
||||
JSObject *scriptObj = NULL;
|
||||
JSString *jsstr;
|
||||
size_t length;
|
||||
const jschar *chars;
|
||||
@ -1093,17 +1092,12 @@ jsdScript::CreatePPLineMap()
|
||||
}
|
||||
|
||||
JS::Anchor<JSString *> kungFuDeathGrip(jsstr);
|
||||
scriptObj = JS_CompileUCScript (cx, obj, chars, length, "x-jsd:ppbuffer?type=script", 1);
|
||||
if (!scriptObj)
|
||||
script = JS_CompileUCScript (cx, obj, chars, length, "x-jsd:ppbuffer?type=script", 1);
|
||||
if (!script)
|
||||
return nsnull;
|
||||
script = JS_GetScriptFromObject(scriptObj);
|
||||
baseLine = 1;
|
||||
}
|
||||
|
||||
/* Make sure that a non-function script is rooted via scriptObj until the
|
||||
* end of script usage. */
|
||||
JS::Anchor<JSObject *> scriptAnchor(scriptObj);
|
||||
|
||||
PRUint32 scriptExtent = JS_GetScriptLineExtent (cx, script);
|
||||
jsbytecode* firstPC = JS_LineNumberToPC (cx, script, 0);
|
||||
/* allocate worst case size of map (number of lines in script + 1
|
||||
|
@ -34,12 +34,10 @@ BEGIN_TEST(testScriptInfo)
|
||||
{
|
||||
uintN startLine = 1000;
|
||||
|
||||
JSObject *scriptObj = JS_CompileScript(cx, global, code, strlen(code),
|
||||
__FILE__, startLine);
|
||||
JSScript *script = JS_CompileScript(cx, global, code, strlen(code), __FILE__, startLine);
|
||||
|
||||
CHECK(scriptObj);
|
||||
CHECK(script);
|
||||
|
||||
JSScript *script = JS_GetScriptFromObject(scriptObj);
|
||||
jsbytecode *start = JS_LineNumberToPC(cx, script, startLine);
|
||||
CHECK_EQUAL(JS_GetScriptBaseLineNumber(cx, script), startLine);
|
||||
CHECK_EQUAL(JS_PCToLineNumber(cx, script, start), startLine);
|
||||
|
@ -15,15 +15,15 @@ struct ScriptObjectFixture : public JSAPITest {
|
||||
uc_code[i] = code[i];
|
||||
}
|
||||
|
||||
bool tryScript(JSObject *scriptObj)
|
||||
bool tryScript(JSScript *script)
|
||||
{
|
||||
CHECK(scriptObj);
|
||||
CHECK(script);
|
||||
|
||||
JS_GC(cx);
|
||||
|
||||
/* After a garbage collection, the script should still work. */
|
||||
jsval result;
|
||||
CHECK(JS_ExecuteScript(cx, global, scriptObj, &result));
|
||||
CHECK(JS_ExecuteScript(cx, global, script, &result));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -87,9 +87,9 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile)
|
||||
FILE *script_stream = tempScript.open(script_filename);
|
||||
CHECK(fputs(code, script_stream) != EOF);
|
||||
tempScript.close();
|
||||
JSObject *scriptObj = JS_CompileFile(cx, global, script_filename);
|
||||
JSScript *script = JS_CompileFile(cx, global, script_filename);
|
||||
tempScript.remove();
|
||||
return tryScript(scriptObj);
|
||||
return tryScript(script);
|
||||
}
|
||||
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile)
|
||||
|
||||
@ -99,9 +99,9 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile_empty)
|
||||
static const char script_filename[] = "temp-bug438633_JS_CompileFile_empty";
|
||||
tempScript.open(script_filename);
|
||||
tempScript.close();
|
||||
JSObject *scriptObj = JS_CompileFile(cx, global, script_filename);
|
||||
JSScript *script = JS_CompileFile(cx, global, script_filename);
|
||||
tempScript.remove();
|
||||
return tryScript(scriptObj);
|
||||
return tryScript(script);
|
||||
}
|
||||
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile_empty)
|
||||
|
||||
|
@ -30,12 +30,12 @@ BEGIN_TEST(testTrap_gc)
|
||||
;
|
||||
|
||||
// compile
|
||||
JSObject *scriptObj = JS_CompileScript(cx, global, source, strlen(source), __FILE__, 1);
|
||||
CHECK(scriptObj);
|
||||
JSScript *script = JS_CompileScript(cx, global, source, strlen(source), __FILE__, 1);
|
||||
CHECK(script);
|
||||
|
||||
// execute
|
||||
jsvalRoot v2(cx);
|
||||
CHECK(JS_ExecuteScript(cx, global, scriptObj, v2.addr()));
|
||||
CHECK(JS_ExecuteScript(cx, global, script, v2.addr()));
|
||||
CHECK(JSVAL_IS_OBJECT(v2));
|
||||
CHECK_EQUAL(emptyTrapCallCount, 0);
|
||||
|
||||
@ -51,7 +51,6 @@ BEGIN_TEST(testTrap_gc)
|
||||
// JS_ExecuteScript. This way we avoid using Anchor.
|
||||
JSString *trapClosure;
|
||||
{
|
||||
JSScript *script = JS_GetScriptFromObject(scriptObj);
|
||||
jsbytecode *line2 = JS_LineNumberToPC(cx, script, 1);
|
||||
CHECK(line2);
|
||||
|
||||
@ -69,7 +68,7 @@ BEGIN_TEST(testTrap_gc)
|
||||
}
|
||||
|
||||
// execute
|
||||
CHECK(JS_ExecuteScript(cx, global, scriptObj, v2.addr()));
|
||||
CHECK(JS_ExecuteScript(cx, global, script, v2.addr()));
|
||||
CHECK_EQUAL(emptyTrapCallCount, 11);
|
||||
|
||||
JS_GC(cx);
|
||||
|
@ -42,7 +42,7 @@ struct VersionFixture : public JSAPITest
|
||||
EvalScriptVersion16, 0, 0);
|
||||
}
|
||||
|
||||
JSObject *fakeScript(const char *contents, size_t length) {
|
||||
JSScript *fakeScript(const char *contents, size_t length) {
|
||||
return JS_CompileScript(cx, global, contents, length, "<test>", 1);
|
||||
}
|
||||
|
||||
@ -75,9 +75,9 @@ struct VersionFixture : public JSAPITest
|
||||
|
||||
/* Check that script compilation results in a version without XML. */
|
||||
bool checkNewScriptNoXML() {
|
||||
JSObject *scriptObj = fakeScript("", 0);
|
||||
CHECK(scriptObj);
|
||||
CHECK(!hasXML(JS_GetScriptFromObject(scriptObj)->getVersion()));
|
||||
JSScript *script = fakeScript("", 0);
|
||||
CHECK(script);
|
||||
CHECK(!hasXML(script->getVersion()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -196,9 +196,9 @@ BEGIN_FIXTURE_TEST(VersionFixture, testOptionsAreUsedForVersionFlags)
|
||||
"disableXMLOption();"
|
||||
"callSetVersion17();"
|
||||
"checkNewScriptNoXML();";
|
||||
JSObject *toActivate = fakeScript(toActivateChars, sizeof(toActivateChars) - 1);
|
||||
JSScript *toActivate = fakeScript(toActivateChars, sizeof(toActivateChars) - 1);
|
||||
CHECK(toActivate);
|
||||
CHECK(hasXML(JS_GetScriptFromObject(toActivate)));
|
||||
CHECK(hasXML(toActivate));
|
||||
|
||||
disableXML();
|
||||
|
||||
|
@ -16,13 +16,13 @@ BEGIN_TEST(testXDR_bug506491)
|
||||
"var f = makeClosure('0;', 'status', 'ok');\n";
|
||||
|
||||
// compile
|
||||
JSObject *scriptObj = JS_CompileScript(cx, global, s, strlen(s), __FILE__, __LINE__);
|
||||
CHECK(scriptObj);
|
||||
JSScript *script = JS_CompileScript(cx, global, s, strlen(s), __FILE__, __LINE__);
|
||||
CHECK(script);
|
||||
|
||||
// freeze
|
||||
JSXDRState *w = JS_XDRNewMem(cx, JSXDR_ENCODE);
|
||||
CHECK(w);
|
||||
CHECK(JS_XDRScriptObject(w, &scriptObj));
|
||||
CHECK(JS_XDRScript(w, &script));
|
||||
uint32 nbytes;
|
||||
void *p = JS_XDRMemGetData(w, &nbytes);
|
||||
CHECK(p);
|
||||
@ -32,15 +32,15 @@ BEGIN_TEST(testXDR_bug506491)
|
||||
JS_XDRDestroy(w);
|
||||
|
||||
// thaw
|
||||
scriptObj = NULL;
|
||||
script = NULL;
|
||||
JSXDRState *r = JS_XDRNewMem(cx, JSXDR_DECODE);
|
||||
JS_XDRMemSetData(r, frozen, nbytes);
|
||||
CHECK(JS_XDRScriptObject(r, &scriptObj));
|
||||
CHECK(JS_XDRScript(r, &script));
|
||||
JS_XDRDestroy(r); // this frees `frozen`
|
||||
|
||||
// execute
|
||||
jsvalRoot v2(cx);
|
||||
CHECK(JS_ExecuteScript(cx, global, scriptObj, v2.addr()));
|
||||
CHECK(JS_ExecuteScript(cx, global, script, v2.addr()));
|
||||
|
||||
// try to break the Block object that is the parent of f
|
||||
JS_GC(cx);
|
||||
@ -56,13 +56,13 @@ END_TEST(testXDR_bug506491)
|
||||
BEGIN_TEST(testXDR_bug516827)
|
||||
{
|
||||
// compile an empty script
|
||||
JSObject *scriptObj = JS_CompileScript(cx, global, "", 0, __FILE__, __LINE__);
|
||||
CHECK(scriptObj);
|
||||
JSScript *script = JS_CompileScript(cx, global, "", 0, __FILE__, __LINE__);
|
||||
CHECK(script);
|
||||
|
||||
// freeze
|
||||
JSXDRState *w = JS_XDRNewMem(cx, JSXDR_ENCODE);
|
||||
CHECK(w);
|
||||
CHECK(JS_XDRScriptObject(w, &scriptObj));
|
||||
CHECK(JS_XDRScript(w, &script));
|
||||
uint32 nbytes;
|
||||
void *p = JS_XDRMemGetData(w, &nbytes);
|
||||
CHECK(p);
|
||||
@ -72,14 +72,14 @@ BEGIN_TEST(testXDR_bug516827)
|
||||
JS_XDRDestroy(w);
|
||||
|
||||
// thaw
|
||||
scriptObj = NULL;
|
||||
script = NULL;
|
||||
JSXDRState *r = JS_XDRNewMem(cx, JSXDR_DECODE);
|
||||
JS_XDRMemSetData(r, frozen, nbytes);
|
||||
CHECK(JS_XDRScriptObject(r, &scriptObj));
|
||||
CHECK(JS_XDRScript(r, &script));
|
||||
JS_XDRDestroy(r); // this frees `frozen`
|
||||
|
||||
// execute with null result meaning no result wanted
|
||||
CHECK(JS_ExecuteScript(cx, global, scriptObj, NULL));
|
||||
CHECK(JS_ExecuteScript(cx, global, script, NULL));
|
||||
return true;
|
||||
}
|
||||
END_TEST(testXDR_bug516827)
|
||||
|
@ -2085,6 +2085,13 @@ JS_AddNamedObjectRoot(JSContext *cx, JSObject **rp, const char *name)
|
||||
return js_AddGCThingRoot(cx, (void **)rp, name);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_AddNamedScriptRoot(JSContext *cx, JSScript **rp, const char *name)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
return js_AddGCThingRoot(cx, (void **)rp, name);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_AddNamedGCThingRoot(JSContext *cx, void **rp, const char *name)
|
||||
{
|
||||
@ -2113,6 +2120,13 @@ JS_RemoveObjectRoot(JSContext *cx, JSObject **rp)
|
||||
return js_RemoveRoot(cx->runtime, (void *)rp);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_RemoveScriptRoot(JSContext *cx, JSScript **rp)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
return js_RemoveRoot(cx->runtime, (void *)rp);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_RemoveGCThingRoot(JSContext *cx, void **rp)
|
||||
{
|
||||
@ -4462,7 +4476,7 @@ JS_OPTIONS_TO_TCFLAGS(JSContext *cx)
|
||||
(cx->hasRunOption(JSOPTION_NO_SCRIPT_RVAL) ? TCF_NO_SCRIPT_RVAL : 0);
|
||||
}
|
||||
|
||||
static JSObject *
|
||||
static JSScript *
|
||||
CompileUCScriptForPrincipalsCommon(JSContext *cx, JSObject *obj, JSPrincipals *principals,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno, JSVersion version)
|
||||
@ -4473,15 +4487,11 @@ CompileUCScriptForPrincipalsCommon(JSContext *cx, JSObject *obj, JSPrincipals *p
|
||||
AutoLastFrameCheck lfc(cx);
|
||||
|
||||
uint32 tcflags = JS_OPTIONS_TO_TCFLAGS(cx) | TCF_NEED_MUTABLE_SCRIPT | TCF_NEED_SCRIPT_OBJECT;
|
||||
JSScript *script = Compiler::compileScript(cx, obj, NULL, principals, tcflags,
|
||||
chars, length, filename, lineno, version);
|
||||
if (!script)
|
||||
return NULL;
|
||||
JS_ASSERT(script->u.object);
|
||||
return script->u.object;
|
||||
return Compiler::compileScript(cx, obj, NULL, principals, tcflags,
|
||||
chars, length, filename, lineno, version);
|
||||
}
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals,
|
||||
const jschar *chars, size_t length,
|
||||
@ -4493,7 +4503,7 @@ JS_CompileUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
||||
avi.version());
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj, JSPrincipals *principals,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno)
|
||||
@ -4502,7 +4512,7 @@ JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj, JSPrincipals *prin
|
||||
cx->findVersion());
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileUCScript(JSContext *cx, JSObject *obj, const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno)
|
||||
{
|
||||
@ -4510,7 +4520,7 @@ JS_CompileUCScript(JSContext *cx, JSObject *obj, const jschar *chars, size_t len
|
||||
return JS_CompileUCScriptForPrincipals(cx, obj, NULL, chars, length, filename, lineno);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals,
|
||||
const char *bytes, size_t length,
|
||||
@ -4521,7 +4531,7 @@ JS_CompileScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
||||
return JS_CompileScriptForPrincipals(cx, obj, principals, bytes, length, filename, lineno);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals,
|
||||
const char *bytes, size_t length,
|
||||
@ -4533,13 +4543,13 @@ JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
jschar *chars = InflateString(cx, bytes, &length);
|
||||
if (!chars)
|
||||
return NULL;
|
||||
JSObject *scriptObj =
|
||||
JSScript *script =
|
||||
JS_CompileUCScriptForPrincipals(cx, obj, principals, chars, length, filename, lineno);
|
||||
cx->free_(chars);
|
||||
return scriptObj;
|
||||
return script;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileScript(JSContext *cx, JSObject *obj, const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno)
|
||||
{
|
||||
@ -4600,7 +4610,7 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSBool bytes_are_utf8, JSObject *obj, c
|
||||
# define fast_getc getc
|
||||
#endif
|
||||
|
||||
static JSObject *
|
||||
static JSScript *
|
||||
CompileFileHelper(JSContext *cx, JSObject *obj, JSPrincipals *principals,
|
||||
const char* filename, FILE *fp)
|
||||
{
|
||||
@ -4657,13 +4667,10 @@ CompileFileHelper(JSContext *cx, JSObject *obj, JSPrincipals *principals,
|
||||
script = Compiler::compileScript(cx, obj, NULL, principals, tcflags, buf, len, filename, 1,
|
||||
cx->findVersion());
|
||||
cx->free_(buf);
|
||||
if (!script)
|
||||
return NULL;
|
||||
JS_ASSERT(script->u.object);
|
||||
return script->u.object;
|
||||
return script;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename)
|
||||
{
|
||||
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
|
||||
@ -4683,13 +4690,13 @@ JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
JSObject *scriptObj = CompileFileHelper(cx, obj, NULL, filename, fp);
|
||||
JSScript *script = CompileFileHelper(cx, obj, NULL, filename, fp);
|
||||
if (fp != stdin)
|
||||
fclose(fp);
|
||||
return scriptObj;
|
||||
return script;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj, const char *filename,
|
||||
FILE *file, JSPrincipals *principals)
|
||||
{
|
||||
@ -4701,7 +4708,7 @@ JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj, const char *file
|
||||
return CompileFileHelper(cx, obj, principals, filename, file);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileFileHandleForPrincipalsVersion(JSContext *cx, JSObject *obj, const char *filename,
|
||||
FILE *file, JSPrincipals *principals, JSVersion version)
|
||||
{
|
||||
@ -4709,19 +4716,19 @@ JS_CompileFileHandleForPrincipalsVersion(JSContext *cx, JSObject *obj, const cha
|
||||
return JS_CompileFileHandleForPrincipals(cx, obj, filename, file, principals);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileFileHandle(JSContext *cx, JSObject *obj, const char *filename, FILE *file)
|
||||
{
|
||||
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
|
||||
return JS_CompileFileHandleForPrincipals(cx, obj, filename, file, NULL);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_GetScriptFromObject(JSObject *scriptObj)
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_GetObjectFromScript(JSScript *script)
|
||||
{
|
||||
JS_ASSERT(scriptObj->isScript());
|
||||
JS_ASSERT(script->u.object);
|
||||
|
||||
return (JSScript *) scriptObj->getPrivate();
|
||||
return script->u.object;
|
||||
}
|
||||
|
||||
static JSFunction *
|
||||
@ -4861,12 +4868,6 @@ JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, uintN inde
|
||||
return str;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSString *)
|
||||
JS_DecompileScriptObject(JSContext *cx, JSObject *scriptObj, const char *name, uintN indent)
|
||||
{
|
||||
return JS_DecompileScript(cx, scriptObj->getScript(), name, indent);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSString *)
|
||||
JS_DecompileFunction(JSContext *cx, JSFunction *fun, uintN indent)
|
||||
{
|
||||
@ -4892,22 +4893,22 @@ JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, uintN indent)
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_ExecuteScript(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval)
|
||||
JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval)
|
||||
{
|
||||
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, obj, scriptObj);
|
||||
assertSameCompartment(cx, obj, script);
|
||||
AutoLastFrameCheck lfc(cx);
|
||||
|
||||
return Execute(cx, scriptObj->getScript(), *obj, Valueify(rval));
|
||||
return Execute(cx, script, *obj, Valueify(rval));
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval,
|
||||
JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval,
|
||||
JSVersion version)
|
||||
{
|
||||
AutoVersionAPI ava(cx, version);
|
||||
return JS_ExecuteScript(cx, obj, scriptObj, rval);
|
||||
return JS_ExecuteScript(cx, obj, script, rval);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -1322,6 +1322,9 @@ JS_AddNamedStringRoot(JSContext *cx, JSString **rp, const char *name);
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_AddNamedObjectRoot(JSContext *cx, JSObject **rp, const char *name);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_AddNamedScriptRoot(JSContext *cx, JSScript **rp, const char *name);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_AddNamedGCThingRoot(JSContext *cx, void **rp, const char *name);
|
||||
|
||||
@ -1334,6 +1337,9 @@ JS_RemoveStringRoot(JSContext *cx, JSString **rp);
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_RemoveObjectRoot(JSContext *cx, JSObject **rp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_RemoveScriptRoot(JSContext *cx, JSScript **rp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_RemoveGCThingRoot(JSContext *cx, void **rp);
|
||||
|
||||
@ -2722,60 +2728,63 @@ extern JS_PUBLIC_API(JSBool)
|
||||
JS_BufferIsCompilableUnit(JSContext *cx, JSBool bytes_are_utf8,
|
||||
JSObject *obj, const char *bytes, size_t length);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileScript(JSContext *cx, JSObject *obj,
|
||||
const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals,
|
||||
const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals,
|
||||
const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno,
|
||||
JSVersion version);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileUCScript(JSContext *cx, JSObject *obj,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno,
|
||||
JSVersion version);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileFileHandle(JSContext *cx, JSObject *obj, const char *filename,
|
||||
FILE *fh);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj,
|
||||
const char *filename, FILE *fh,
|
||||
JSPrincipals *principals);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileFileHandleForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
||||
const char *filename, FILE *fh,
|
||||
JSPrincipals *principals,
|
||||
JSVersion version);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_GetObjectFromScript(JSScript *script);
|
||||
|
||||
extern JS_PUBLIC_API(JSFunction *)
|
||||
JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
|
||||
uintN nargs, const char **argnames,
|
||||
@ -2811,7 +2820,7 @@ JS_CompileUCFunctionForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
||||
JSVersion version);
|
||||
|
||||
extern JS_PUBLIC_API(JSString *)
|
||||
JS_DecompileScriptObject(JSContext *cx, JSObject *scriptObj, const char *name, uintN indent);
|
||||
JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, uintN indent);
|
||||
|
||||
/*
|
||||
* API extension: OR this into indent to avoid pretty-printing the decompiled
|
||||
@ -2861,10 +2870,10 @@ JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, uintN indent);
|
||||
* etc., entry points.
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_ExecuteScript(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval);
|
||||
JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval,
|
||||
JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval,
|
||||
JSVersion version);
|
||||
|
||||
/*
|
||||
|
@ -90,9 +90,6 @@ class JS_PUBLIC_API(AutoEnterFrameCompartment) : public AutoEnterScriptCompartme
|
||||
JS_BEGIN_EXTERN_C
|
||||
#endif
|
||||
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_GetScriptFromObject(JSObject *scriptObject);
|
||||
|
||||
extern JS_PUBLIC_API(JSString *)
|
||||
JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, uintN indent);
|
||||
|
||||
|
@ -85,7 +85,6 @@ typedef struct JSFunctionBox JSFunctionBox;
|
||||
typedef struct JSObjectBox JSObjectBox;
|
||||
typedef struct JSParseNode JSParseNode;
|
||||
typedef struct JSProperty JSProperty;
|
||||
typedef struct JSScript JSScript;
|
||||
typedef struct JSSharpObjectMap JSSharpObjectMap;
|
||||
typedef struct JSThread JSThread;
|
||||
typedef struct JSTreeContext JSTreeContext;
|
||||
|
@ -163,6 +163,7 @@ typedef struct JSLocaleCallbacks JSLocaleCallbacks;
|
||||
typedef struct JSSecurityCallbacks JSSecurityCallbacks;
|
||||
typedef struct JSCompartment JSCompartment;
|
||||
typedef struct JSCrossCompartmentCall JSCrossCompartmentCall;
|
||||
typedef struct JSScript JSScript;
|
||||
typedef struct JSStructuredCloneWriter JSStructuredCloneWriter;
|
||||
typedef struct JSStructuredCloneReader JSStructuredCloneReader;
|
||||
typedef struct JSStructuredCloneCallbacks JSStructuredCloneCallbacks;
|
||||
|
@ -682,7 +682,7 @@ XDRScriptState::~XDRScriptState()
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_XDRScriptObject(JSXDRState *xdr, JSObject **scriptObjp)
|
||||
JS_XDRScript(JSXDRState *xdr, JSScript **scriptp)
|
||||
{
|
||||
JS_ASSERT(!xdr->state);
|
||||
|
||||
@ -690,9 +690,9 @@ JS_XDRScriptObject(JSXDRState *xdr, JSObject **scriptObjp)
|
||||
uint32 magic;
|
||||
if (xdr->mode == JSXDR_DECODE) {
|
||||
script = NULL;
|
||||
*scriptObjp = NULL;
|
||||
*scriptp = NULL;
|
||||
} else {
|
||||
script = (*scriptObjp)->getScript();
|
||||
script = *scriptp;
|
||||
magic = JSXDR_MAGIC_SCRIPT_CURRENT;
|
||||
}
|
||||
|
||||
@ -718,11 +718,11 @@ JS_XDRScriptObject(JSXDRState *xdr, JSObject **scriptObjp)
|
||||
return false;
|
||||
|
||||
if (xdr->mode == JSXDR_DECODE) {
|
||||
*scriptObjp = js_NewScriptObject(xdr->cx, script);
|
||||
if (!*scriptObjp)
|
||||
if (!js_NewScriptObject(xdr->cx, script))
|
||||
return false;
|
||||
js_CallNewScriptHook(xdr->cx, script, NULL);
|
||||
Debugger::onNewScript(xdr->cx, script, *scriptObjp, Debugger::NewHeldScript);
|
||||
Debugger::onNewScript(xdr->cx, script, script->u.object, Debugger::NewHeldScript);
|
||||
*scriptp = script;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -186,7 +186,7 @@ extern JS_PUBLIC_API(JSBool)
|
||||
JS_XDRValue(JSXDRState *xdr, jsval *vp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_XDRScriptObject(JSXDRState *xdr, JSObject **scriptObjp);
|
||||
JS_XDRScript(JSXDRState *xdr, JSScript **scriptp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_XDRRegisterClass(JSXDRState *xdr, JSClass *clasp, uint32 *lp);
|
||||
|
@ -427,7 +427,7 @@ static void
|
||||
Process(JSContext *cx, JSObject *obj, const char *filename, bool forceTTY)
|
||||
{
|
||||
JSBool ok, hitEOF;
|
||||
JSObject *scriptObj;
|
||||
JSScript *script;
|
||||
jsval result;
|
||||
JSString *str;
|
||||
char *buffer;
|
||||
@ -477,10 +477,10 @@ Process(JSContext *cx, JSObject *obj, const char *filename, bool forceTTY)
|
||||
int64 t1 = PRMJ_Now();
|
||||
oldopts = JS_GetOptions(cx);
|
||||
JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
|
||||
scriptObj = JS_CompileFileHandle(cx, obj, filename, file);
|
||||
script = JS_CompileFileHandle(cx, obj, filename, file);
|
||||
JS_SetOptions(cx, oldopts);
|
||||
if (scriptObj && !compileOnly) {
|
||||
(void) JS_ExecuteScript(cx, obj, scriptObj, NULL);
|
||||
if (script && !compileOnly) {
|
||||
(void) JS_ExecuteScript(cx, obj, script, NULL);
|
||||
int64 t2 = PRMJ_Now() - t1;
|
||||
if (printTiming)
|
||||
printf("runtime = %.3f ms\n", double(t2) / PRMJ_USEC_PER_MSEC);
|
||||
@ -575,13 +575,12 @@ Process(JSContext *cx, JSObject *obj, const char *filename, bool forceTTY)
|
||||
oldopts = JS_GetOptions(cx);
|
||||
if (!compileOnly)
|
||||
JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO);
|
||||
scriptObj = JS_CompileUCScript(cx, obj, uc_buffer, uc_len, "typein",
|
||||
startline);
|
||||
script = JS_CompileUCScript(cx, obj, uc_buffer, uc_len, "typein", startline);
|
||||
if (!compileOnly)
|
||||
JS_SetOptions(cx, oldopts);
|
||||
|
||||
if (scriptObj && !compileOnly) {
|
||||
ok = JS_ExecuteScript(cx, obj, scriptObj, &result);
|
||||
if (script && !compileOnly) {
|
||||
ok = JS_ExecuteScript(cx, obj, script, &result);
|
||||
if (ok && !JSVAL_IS_VOID(result)) {
|
||||
str = JS_ValueToSource(cx, result);
|
||||
ok = !!str;
|
||||
@ -786,12 +785,12 @@ Load(JSContext *cx, uintN argc, jsval *vp)
|
||||
errno = 0;
|
||||
uint32 oldopts = JS_GetOptions(cx);
|
||||
JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
|
||||
JSObject *scriptObj = JS_CompileFile(cx, thisobj, filename.ptr());
|
||||
JSScript *script = JS_CompileFile(cx, thisobj, filename.ptr());
|
||||
JS_SetOptions(cx, oldopts);
|
||||
if (!scriptObj)
|
||||
if (!script)
|
||||
return false;
|
||||
|
||||
if (!compileOnly && !JS_ExecuteScript(cx, thisobj, scriptObj, NULL))
|
||||
if (!compileOnly && !JS_ExecuteScript(cx, thisobj, script, NULL))
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -955,9 +954,9 @@ Run(JSContext *cx, uintN argc, jsval *vp)
|
||||
JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
|
||||
|
||||
int64 startClock = PRMJ_Now();
|
||||
JSObject *scriptObj = JS_CompileUCScript(cx, thisobj, ucbuf, buflen, filename.ptr(), 1);
|
||||
JSScript *script = JS_CompileUCScript(cx, thisobj, ucbuf, buflen, filename.ptr(), 1);
|
||||
JS_SetOptions(cx, oldopts);
|
||||
if (!scriptObj || !JS_ExecuteScript(cx, thisobj, scriptObj, NULL))
|
||||
if (!script || !JS_ExecuteScript(cx, thisobj, script, NULL))
|
||||
return false;
|
||||
|
||||
int64 endClock = PRMJ_Now();
|
||||
@ -1551,10 +1550,10 @@ FinalizeCount(JSContext *cx, uintN argc, jsval *vp)
|
||||
}
|
||||
|
||||
static JSScript *
|
||||
ValueToScript(JSContext *cx, jsval v)
|
||||
ValueToScript(JSContext *cx, jsval v, JSFunction **funp = NULL)
|
||||
{
|
||||
JSScript *script = NULL;
|
||||
JSFunction *fun;
|
||||
JSFunction *fun = NULL;
|
||||
|
||||
if (!JSVAL_IS_PRIMITIVE(v)) {
|
||||
JSObject *obj = JSVAL_TO_OBJECT(v);
|
||||
@ -1579,6 +1578,8 @@ ValueToScript(JSContext *cx, jsval v)
|
||||
JSSMSG_SCRIPTS_ONLY);
|
||||
}
|
||||
}
|
||||
if (fun && funp)
|
||||
*funp = fun;
|
||||
|
||||
return script;
|
||||
}
|
||||
@ -2002,58 +2003,51 @@ TryNotes(JSContext *cx, JSScript *script, Sprinter *sp)
|
||||
}
|
||||
|
||||
static bool
|
||||
DisassembleValue(JSContext *cx, jsval v, bool lines, bool recursive, Sprinter *sp)
|
||||
DisassembleScript(JSContext *cx, JSScript *script, JSFunction *fun, bool lines, bool recursive,
|
||||
Sprinter *sp)
|
||||
{
|
||||
JSScript *script = ValueToScript(cx, v);
|
||||
if (!script)
|
||||
return false;
|
||||
if (!JSVAL_IS_PRIMITIVE(v) && JSVAL_TO_OBJECT(v)->isFunction()) {
|
||||
JSFunction *fun = JS_ValueToFunction(cx, v);
|
||||
if (fun && (fun->flags & ~7U)) {
|
||||
uint16 flags = fun->flags;
|
||||
Sprint(sp, "flags:");
|
||||
|
||||
if (fun && (fun->flags & ~7U)) {
|
||||
uint16 flags = fun->flags;
|
||||
Sprint(sp, "flags:");
|
||||
|
||||
#define SHOW_FLAG(flag) if (flags & JSFUN_##flag) Sprint(sp, " " #flag);
|
||||
|
||||
SHOW_FLAG(LAMBDA);
|
||||
SHOW_FLAG(HEAVYWEIGHT);
|
||||
SHOW_FLAG(EXPR_CLOSURE);
|
||||
SHOW_FLAG(TRCINFO);
|
||||
|
||||
|
||||
SHOW_FLAG(LAMBDA);
|
||||
SHOW_FLAG(HEAVYWEIGHT);
|
||||
SHOW_FLAG(EXPR_CLOSURE);
|
||||
SHOW_FLAG(TRCINFO);
|
||||
|
||||
#undef SHOW_FLAG
|
||||
|
||||
if (fun->isInterpreted()) {
|
||||
if (fun->isNullClosure())
|
||||
Sprint(sp, " NULL_CLOSURE");
|
||||
else if (fun->isFlatClosure())
|
||||
Sprint(sp, " FLAT_CLOSURE");
|
||||
|
||||
JSScript *script = fun->script();
|
||||
if (script->bindings.hasUpvars()) {
|
||||
Sprint(sp, "\nupvars: {\n");
|
||||
|
||||
Vector<JSAtom *> localNames(cx);
|
||||
if (!script->bindings.getLocalNameArray(cx, &localNames))
|
||||
return false;
|
||||
|
||||
JSUpvarArray *uva = script->upvars();
|
||||
uintN upvar_base = script->bindings.countArgsAndVars();
|
||||
|
||||
for (uint32 i = 0, n = uva->length; i < n; i++) {
|
||||
JSAtom *atom = localNames[upvar_base + i];
|
||||
UpvarCookie cookie = uva->vector[i];
|
||||
JSAutoByteString printable;
|
||||
if (js_AtomToPrintableString(cx, atom, &printable)) {
|
||||
Sprint(sp, " %s: {skip:%u, slot:%u},\n",
|
||||
printable.ptr(), cookie.level(), cookie.slot());
|
||||
}
|
||||
}
|
||||
|
||||
Sprint(sp, "}");
|
||||
|
||||
if (fun->isNullClosure())
|
||||
Sprint(sp, " NULL_CLOSURE");
|
||||
else if (fun->isFlatClosure())
|
||||
Sprint(sp, " FLAT_CLOSURE");
|
||||
|
||||
JSScript *script = fun->script();
|
||||
if (script->bindings.hasUpvars()) {
|
||||
Sprint(sp, "\nupvars: {\n");
|
||||
|
||||
Vector<JSAtom *> localNames(cx);
|
||||
if (!script->bindings.getLocalNameArray(cx, &localNames))
|
||||
return false;
|
||||
|
||||
JSUpvarArray *uva = script->upvars();
|
||||
uintN upvar_base = script->bindings.countArgsAndVars();
|
||||
|
||||
for (uint32 i = 0, n = uva->length; i < n; i++) {
|
||||
JSAtom *atom = localNames[upvar_base + i];
|
||||
UpvarCookie cookie = uva->vector[i];
|
||||
JSAutoByteString printable;
|
||||
if (js_AtomToPrintableString(cx, atom, &printable)) {
|
||||
Sprint(sp, " %s: {skip:%u, slot:%u},\n",
|
||||
printable.ptr(), cookie.level(), cookie.slot());
|
||||
}
|
||||
}
|
||||
Sprint(sp, "\n");
|
||||
|
||||
Sprint(sp, "}");
|
||||
}
|
||||
Sprint(sp, "\n");
|
||||
}
|
||||
|
||||
if (!js_Disassemble(cx, script, lines, sp))
|
||||
@ -2067,7 +2061,9 @@ DisassembleValue(JSContext *cx, jsval v, bool lines, bool recursive, Sprinter *s
|
||||
JSObject *obj = objects->vector[i];
|
||||
if (obj->isFunction()) {
|
||||
Sprint(sp, "\n");
|
||||
if (!DisassembleValue(cx, OBJECT_TO_JSVAL(obj), lines, recursive, sp))
|
||||
JSFunction *fun = obj->getFunctionPrivate();
|
||||
JSScript *nested = fun->maybeScript();
|
||||
if (!DisassembleScript(cx, nested, fun, lines, recursive, sp))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -2075,24 +2071,44 @@ DisassembleValue(JSContext *cx, jsval v, bool lines, bool recursive, Sprinter *s
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct DisassembleOptionParser {
|
||||
uintN argc;
|
||||
jsval *argv;
|
||||
bool lines;
|
||||
bool recursive;
|
||||
|
||||
DisassembleOptionParser(uintN argc, jsval *argv)
|
||||
: argc(argc), argv(argv), lines(false), recursive(false) {}
|
||||
|
||||
bool parse(JSContext *cx) {
|
||||
/* Read options off early arguments */
|
||||
while (argc > 0 && JSVAL_IS_STRING(argv[0])) {
|
||||
JSString *str = JSVAL_TO_STRING(argv[0]);
|
||||
JSFlatString *flatStr = JS_FlattenString(cx, str);
|
||||
if (!flatStr)
|
||||
return false;
|
||||
if (JS_FlatStringEqualsAscii(flatStr, "-l"))
|
||||
lines = true;
|
||||
else if (JS_FlatStringEqualsAscii(flatStr, "-r"))
|
||||
recursive = true;
|
||||
else
|
||||
break;
|
||||
argv++, argc--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} /* anonymous namespace */
|
||||
|
||||
static JSBool
|
||||
DisassembleToString(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
|
||||
/* Read options off early arguments */
|
||||
bool lines = false, recursive = false;
|
||||
while (argc > 0 && JSVAL_IS_STRING(argv[0])) {
|
||||
JSString *str = JSVAL_TO_STRING(argv[0]);
|
||||
JSFlatString *flatStr = JS_FlattenString(cx, str);
|
||||
if (!flatStr)
|
||||
return JS_FALSE;
|
||||
lines |= !!JS_FlatStringEqualsAscii(flatStr, "-l");
|
||||
recursive |= !!JS_FlatStringEqualsAscii(flatStr, "-r");
|
||||
if (!lines && !recursive)
|
||||
break;
|
||||
argv++, argc--;
|
||||
}
|
||||
DisassembleOptionParser p(argc, JS_ARGV(cx, vp));
|
||||
if (!p.parse(cx))
|
||||
return false;
|
||||
|
||||
void *mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
Sprinter sprinter;
|
||||
@ -2100,11 +2116,11 @@ DisassembleToString(JSContext *cx, uintN argc, jsval *vp)
|
||||
Sprinter *sp = &sprinter;
|
||||
|
||||
bool ok = true;
|
||||
if (argc == 0) {
|
||||
if (p.argc == 0) {
|
||||
/* Without arguments, disassemble the current script. */
|
||||
if (JSStackFrame *frame = JS_GetScriptedCaller(cx, NULL)) {
|
||||
JSScript *script = JS_GetFrameScript(cx, frame);
|
||||
if (js_Disassemble(cx, script, lines, sp)) {
|
||||
if (js_Disassemble(cx, script, p.lines, sp)) {
|
||||
SrcNotes(cx, script, sp);
|
||||
TryNotes(cx, script, sp);
|
||||
} else {
|
||||
@ -2112,8 +2128,11 @@ DisassembleToString(JSContext *cx, uintN argc, jsval *vp)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (uintN i = 0; i < argc; i++)
|
||||
ok = ok && DisassembleValue(cx, argv[i], lines, recursive, sp);
|
||||
for (uintN i = 0; i < p.argc; i++) {
|
||||
JSFunction *fun;
|
||||
JSScript *script = ValueToScript(cx, p.argv[i], &fun);
|
||||
ok = ok && script && DisassembleScript(cx, script, fun, p.lines, p.recursive, sp);
|
||||
}
|
||||
}
|
||||
|
||||
JSString *str = ok ? JS_NewStringCopyZ(cx, sprinter.base) : NULL;
|
||||
@ -2127,21 +2146,9 @@ DisassembleToString(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool
|
||||
Disassemble(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
|
||||
/* Read options off early arguments */
|
||||
bool lines = false, recursive = false;
|
||||
while (argc > 0 && JSVAL_IS_STRING(argv[0])) {
|
||||
JSString *str = JSVAL_TO_STRING(argv[0]);
|
||||
JSFlatString *flatStr = JS_FlattenString(cx, str);
|
||||
if (!flatStr)
|
||||
return JS_FALSE;
|
||||
lines |= !!JS_FlatStringEqualsAscii(flatStr, "-l");
|
||||
recursive |= !!JS_FlatStringEqualsAscii(flatStr, "-r");
|
||||
if (!lines && !recursive)
|
||||
break;
|
||||
argv++, argc--;
|
||||
}
|
||||
DisassembleOptionParser p(argc, JS_ARGV(cx, vp));
|
||||
if (!p.parse(cx))
|
||||
return false;
|
||||
|
||||
void *mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
Sprinter sprinter;
|
||||
@ -2149,11 +2156,11 @@ Disassemble(JSContext *cx, uintN argc, jsval *vp)
|
||||
Sprinter *sp = &sprinter;
|
||||
|
||||
bool ok = true;
|
||||
if (argc == 0) {
|
||||
if (p.argc == 0) {
|
||||
/* Without arguments, disassemble the current script. */
|
||||
if (JSStackFrame *frame = JS_GetScriptedCaller(cx, NULL)) {
|
||||
JSScript *script = JS_GetFrameScript(cx, frame);
|
||||
if (js_Disassemble(cx, script, lines, sp)) {
|
||||
if (js_Disassemble(cx, script, p.lines, sp)) {
|
||||
SrcNotes(cx, script, sp);
|
||||
TryNotes(cx, script, sp);
|
||||
} else {
|
||||
@ -2161,8 +2168,11 @@ Disassemble(JSContext *cx, uintN argc, jsval *vp)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (uintN i = 0; i < argc; i++)
|
||||
ok = ok && DisassembleValue(cx, argv[i], lines, recursive, sp);
|
||||
for (uintN i = 0; i < p.argc; i++) {
|
||||
JSFunction *fun;
|
||||
JSScript *script = ValueToScript(cx, p.argv[i], &fun);
|
||||
ok = ok && script && DisassembleScript(cx, script, fun, p.lines, p.recursive, sp);
|
||||
}
|
||||
}
|
||||
|
||||
if (ok)
|
||||
@ -2175,23 +2185,21 @@ Disassemble(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool
|
||||
DisassFile(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
|
||||
if (!argc) {
|
||||
/* Support extra options at the start, just like Dissassemble. */
|
||||
DisassembleOptionParser p(argc, JS_ARGV(cx, vp));
|
||||
if (!p.parse(cx))
|
||||
return false;
|
||||
|
||||
if (!p.argc) {
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* Support extra options at the start, just like Dissassemble. */
|
||||
uintN _argc = argc;
|
||||
argv += argc-1;
|
||||
argc = 1;
|
||||
|
||||
JSObject *thisobj = JS_THIS_OBJECT(cx, vp);
|
||||
if (!thisobj)
|
||||
return JS_FALSE;
|
||||
|
||||
JSString *str = JS_ValueToString(cx, argv[0]);
|
||||
JSString *str = JS_ValueToString(cx, p.argv[0]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
JSAutoByteString filename(cx, str);
|
||||
@ -2200,15 +2208,23 @@ DisassFile(JSContext *cx, uintN argc, jsval *vp)
|
||||
|
||||
uint32 oldopts = JS_GetOptions(cx);
|
||||
JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
|
||||
JSObject *scriptObj = JS_CompileFile(cx, thisobj, filename.ptr());
|
||||
JSScript *script = JS_CompileFile(cx, thisobj, filename.ptr());
|
||||
JS_SetOptions(cx, oldopts);
|
||||
if (!scriptObj)
|
||||
if (!script)
|
||||
return false;
|
||||
|
||||
argv[0] = OBJECT_TO_JSVAL(scriptObj);
|
||||
JSBool ok = Disassemble(cx, _argc, vp); /* gross, but works! */
|
||||
void *mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
Sprinter sprinter;
|
||||
INIT_SPRINTER(cx, &sprinter, &cx->tempPool, 0);
|
||||
bool ok = DisassembleScript(cx, script, NULL, p.lines, p.recursive, &sprinter);
|
||||
if (ok)
|
||||
fprintf(stdout, "%s\n", sprinter.base);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return ok;
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
|
@ -894,12 +894,12 @@ class InitEvent : public Event
|
||||
if (!filename)
|
||||
return fail;
|
||||
|
||||
JSObject *scriptObj = JS_CompileFile(cx, child->getGlobal(), filename.ptr());
|
||||
if (!scriptObj)
|
||||
JSScript *script = JS_CompileFile(cx, child->getGlobal(), filename.ptr());
|
||||
if (!script)
|
||||
return fail;
|
||||
|
||||
AutoValueRooter rval(cx);
|
||||
JSBool ok = JS_ExecuteScript(cx, child->getGlobal(), scriptObj, Jsvalify(rval.addr()));
|
||||
JSBool ok = JS_ExecuteScript(cx, child->getGlobal(), script, Jsvalify(rval.addr()));
|
||||
return Result(ok);
|
||||
}
|
||||
};
|
||||
|
@ -835,7 +835,7 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
||||
JSObject *scriptObj = nsnull;
|
||||
JSScript *script = nsnull;
|
||||
|
||||
// Before compiling the script, first check to see if we have it in
|
||||
// the startupcache. Note: as a rule, startupcache errors are not fatal
|
||||
@ -849,7 +849,7 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (cache) {
|
||||
rv = ReadCachedScript(cache, cachePath, cx, &scriptObj);
|
||||
rv = ReadCachedScript(cache, cachePath, cx, &script);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
LOG(("Successfully loaded %s from startupcache\n", nativePath.get()));
|
||||
} else {
|
||||
@ -860,7 +860,7 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
|
||||
}
|
||||
}
|
||||
|
||||
if (!scriptObj) {
|
||||
if (!script) {
|
||||
// The script wasn't in the cache , so compile it now.
|
||||
LOG(("Slow loading %s\n", nativePath.get()));
|
||||
|
||||
@ -919,7 +919,7 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
scriptObj = JS_CompileScriptForPrincipalsVersion(
|
||||
script = JS_CompileScriptForPrincipalsVersion(
|
||||
cx, global, jsPrincipals, buf, fileSize32, nativePath.get(), 1,
|
||||
JSVERSION_LATEST);
|
||||
|
||||
@ -939,7 +939,7 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
scriptObj = JS_CompileFileHandleForPrincipalsVersion(
|
||||
script = JS_CompileFileHandleForPrincipalsVersion(
|
||||
cx, global, nativePath.get(), fileHandle, jsPrincipals, JSVERSION_LATEST);
|
||||
|
||||
/* JS will close the filehandle after compilation is complete. */
|
||||
@ -975,20 +975,20 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
|
||||
|
||||
buf[len] = '\0';
|
||||
|
||||
scriptObj = JS_CompileScriptForPrincipalsVersion(
|
||||
script = JS_CompileScriptForPrincipalsVersion(
|
||||
cx, global, jsPrincipals, buf, bytesRead, nativePath.get(), 1,
|
||||
JSVERSION_LATEST);
|
||||
}
|
||||
// Propagate the exception, if one exists. Also, don't leave the stale
|
||||
// exception on this context.
|
||||
JS_SetOptions(cx, oldopts);
|
||||
if (!scriptObj && exception) {
|
||||
if (!script && exception) {
|
||||
JS_GetPendingException(cx, exception);
|
||||
JS_ClearPendingException(cx);
|
||||
}
|
||||
}
|
||||
|
||||
if (!scriptObj) {
|
||||
if (!script) {
|
||||
#ifdef DEBUG_shaver_off
|
||||
fprintf(stderr, "mJCL: script compilation of %s FAILED\n",
|
||||
nativePath.get());
|
||||
@ -1003,7 +1003,7 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
|
||||
|
||||
if (writeToCache) {
|
||||
// We successfully compiled the script, so cache it.
|
||||
rv = WriteCachedScript(cache, cachePath, cx, scriptObj);
|
||||
rv = WriteCachedScript(cache, cachePath, cx, script);
|
||||
|
||||
// Don't treat failure to write as fatal, since we might be working
|
||||
// with a read-only cache.
|
||||
@ -1018,7 +1018,7 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
|
||||
// See bug 384168.
|
||||
*aGlobal = global;
|
||||
|
||||
if (!JS_ExecuteScriptVersion(cx, global, scriptObj, NULL, JSVERSION_LATEST)) {
|
||||
if (!JS_ExecuteScriptVersion(cx, global, script, NULL, JSVERSION_LATEST)) {
|
||||
#ifdef DEBUG_shaver_off
|
||||
fprintf(stderr, "mJCL: failed to execute %s\n", nativePath.get());
|
||||
#endif
|
||||
|
@ -48,9 +48,9 @@ using namespace mozilla::scache;
|
||||
|
||||
static nsresult
|
||||
ReadScriptFromStream(JSContext *cx, nsIObjectInputStream *stream,
|
||||
JSObject **scriptObj)
|
||||
JSScript **script)
|
||||
{
|
||||
*scriptObj = nsnull;
|
||||
*script = nsnull;
|
||||
|
||||
PRUint32 size;
|
||||
nsresult rv = stream->Read32(&size);
|
||||
@ -66,7 +66,7 @@ ReadScriptFromStream(JSContext *cx, nsIObjectInputStream *stream,
|
||||
xdr->userdata = stream;
|
||||
JS_XDRMemSetData(xdr, data, size);
|
||||
|
||||
if (!JS_XDRScriptObject(xdr, scriptObj)) {
|
||||
if (!JS_XDRScript(xdr, script)) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ ReadScriptFromStream(JSContext *cx, nsIObjectInputStream *stream,
|
||||
}
|
||||
|
||||
static nsresult
|
||||
WriteScriptToStream(JSContext *cx, JSObject *scriptObj,
|
||||
WriteScriptToStream(JSContext *cx, JSScript *script,
|
||||
nsIObjectOutputStream *stream)
|
||||
{
|
||||
JSXDRState *xdr = JS_XDRNewMem(cx, JSXDR_ENCODE);
|
||||
@ -112,7 +112,7 @@ WriteScriptToStream(JSContext *cx, JSObject *scriptObj,
|
||||
xdr->userdata = stream;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (JS_XDRScriptObject(xdr, &scriptObj)) {
|
||||
if (JS_XDRScript(xdr, &script)) {
|
||||
// Get the encoded JSXDRState data and write it. The JSXDRState owns
|
||||
// this buffer memory and will free it beneath ::JS_XDRDestroy.
|
||||
//
|
||||
@ -145,7 +145,7 @@ WriteScriptToStream(JSContext *cx, JSObject *scriptObj,
|
||||
}
|
||||
|
||||
nsresult
|
||||
ReadCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, JSObject **scriptObj)
|
||||
ReadCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, JSScript **script)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@ -162,11 +162,11 @@ ReadCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, JSObject *
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
buf.forget();
|
||||
|
||||
return ReadScriptFromStream(cx, ois, scriptObj);
|
||||
return ReadScriptFromStream(cx, ois, script);
|
||||
}
|
||||
|
||||
nsresult
|
||||
WriteCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, JSObject *scriptObj)
|
||||
WriteCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, JSScript *script)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@ -177,7 +177,7 @@ WriteCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, JSObject
|
||||
true);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = WriteScriptToStream(cx, scriptObj, oos);
|
||||
rv = WriteScriptToStream(cx, script, oos);
|
||||
oos->Close();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -52,9 +52,9 @@ class StartupCache;
|
||||
|
||||
nsresult
|
||||
ReadCachedScript(mozilla::scache::StartupCache* cache, nsACString &uri,
|
||||
JSContext *cx, JSObject **scriptObj);
|
||||
JSContext *cx, JSScript **script);
|
||||
|
||||
nsresult
|
||||
WriteCachedScript(mozilla::scache::StartupCache* cache, nsACString &uri,
|
||||
JSContext *cx, JSObject *scriptObj);
|
||||
JSContext *cx, JSScript *script);
|
||||
#endif /* mozJSLoaderUtils_h */
|
||||
|
@ -108,7 +108,7 @@ nsresult
|
||||
mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *target_obj,
|
||||
jschar *charset, const char *uriStr,
|
||||
nsIIOService *serv, nsIPrincipal *principal,
|
||||
JSObject **scriptObjp)
|
||||
JSScript **scriptp)
|
||||
{
|
||||
nsCOMPtr<nsIChannel> chan;
|
||||
nsCOMPtr<nsIInputStream> instream;
|
||||
@ -164,13 +164,13 @@ mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *target_ob
|
||||
return ReportError(cx, LOAD_ERROR_BADCHARSET);
|
||||
}
|
||||
|
||||
*scriptObjp =
|
||||
*scriptp =
|
||||
JS_CompileUCScriptForPrincipals(cx, target_obj, jsPrincipals,
|
||||
reinterpret_cast<const jschar*>(script.get()),
|
||||
script.Length(), uriStr, 1);
|
||||
} else {
|
||||
*scriptObjp = JS_CompileScriptForPrincipals(cx, target_obj, jsPrincipals, buf.get(),
|
||||
len, uriStr, 1);
|
||||
*scriptp = JS_CompileScriptForPrincipals(cx, target_obj, jsPrincipals, buf.get(),
|
||||
len, uriStr, 1);
|
||||
}
|
||||
|
||||
JSPRINCIPALS_DROP(cx, jsPrincipals);
|
||||
@ -398,26 +398,24 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * aURL
|
||||
}
|
||||
|
||||
bool writeScript = false;
|
||||
JSObject *scriptObj = nsnull;
|
||||
JSVersion version = cx->findVersion();
|
||||
nsCAutoString cachePath;
|
||||
cachePath.AppendPrintf("jssubloader/%d", version);
|
||||
PathifyURI(uri, cachePath);
|
||||
|
||||
script = nsnull;
|
||||
if (cache)
|
||||
rv = ReadCachedScript(cache, cachePath, cx, &scriptObj);
|
||||
if (!scriptObj) {
|
||||
rv = ReadCachedScript(cache, cachePath, cx, &script);
|
||||
if (!script) {
|
||||
rv = ReadScript(uri, cx, target_obj, charset, (char *)uriStr.get(), serv,
|
||||
principal, &scriptObj);
|
||||
principal, &script);
|
||||
writeScript = true;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv) || !scriptObj)
|
||||
if (NS_FAILED(rv) || !script)
|
||||
return rv;
|
||||
|
||||
ok = false;
|
||||
if (scriptObj)
|
||||
ok = JS_ExecuteScriptVersion(cx, target_obj, scriptObj, rval, version);
|
||||
ok = JS_ExecuteScriptVersion(cx, target_obj, script, rval, version);
|
||||
|
||||
if (ok) {
|
||||
JSAutoEnterCompartment rac;
|
||||
@ -426,7 +424,7 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * aURL
|
||||
}
|
||||
|
||||
if (cache && ok && writeScript) {
|
||||
WriteCachedScript(cache, cachePath, cx, scriptObj);
|
||||
WriteCachedScript(cache, cachePath, cx, script);
|
||||
}
|
||||
|
||||
cc->SetReturnValueWasSet (ok);
|
||||
|
@ -67,7 +67,7 @@ private:
|
||||
nsresult ReadScript(nsIURI *uri, JSContext *cx, JSObject *target_obj,
|
||||
jschar *charset, const char *uriStr,
|
||||
nsIIOService *serv, nsIPrincipal *principal,
|
||||
JSObject **scriptObjp);
|
||||
JSScript **scriptp);
|
||||
|
||||
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
|
||||
};
|
||||
|
@ -477,14 +477,14 @@ Load(JSContext *cx, uintN argc, jsval *vp)
|
||||
filename.ptr());
|
||||
return false;
|
||||
}
|
||||
JSObject *scriptObj = JS_CompileFileHandleForPrincipals(cx, obj, filename.ptr(),
|
||||
file, gJSPrincipals);
|
||||
JSScript *script = JS_CompileFileHandleForPrincipals(cx, obj, filename.ptr(),
|
||||
file, gJSPrincipals);
|
||||
fclose(file);
|
||||
if (!scriptObj)
|
||||
if (!script)
|
||||
return false;
|
||||
|
||||
jsval result;
|
||||
if (!compileOnly && !JS_ExecuteScript(cx, obj, scriptObj, &result))
|
||||
if (!compileOnly && !JS_ExecuteScript(cx, obj, script, &result))
|
||||
return false;
|
||||
}
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
@ -1011,7 +1011,7 @@ static void
|
||||
ProcessFile(JSContext *cx, JSObject *obj, const char *filename, FILE *file,
|
||||
JSBool forceTTY)
|
||||
{
|
||||
JSObject *scriptObj;
|
||||
JSScript *script;
|
||||
jsval result;
|
||||
int lineno, startline;
|
||||
JSBool ok, hitEOF;
|
||||
@ -1044,11 +1044,11 @@ ProcessFile(JSContext *cx, JSObject *obj, const char *filename, FILE *file,
|
||||
ungetc(ch, file);
|
||||
DoBeginRequest(cx);
|
||||
|
||||
scriptObj = JS_CompileFileHandleForPrincipals(cx, obj, filename, file,
|
||||
gJSPrincipals);
|
||||
script = JS_CompileFileHandleForPrincipals(cx, obj, filename, file,
|
||||
gJSPrincipals);
|
||||
|
||||
if (scriptObj && !compileOnly)
|
||||
(void)JS_ExecuteScript(cx, obj, scriptObj, &result);
|
||||
if (script && !compileOnly)
|
||||
(void)JS_ExecuteScript(cx, obj, script, &result);
|
||||
DoEndRequest(cx);
|
||||
|
||||
return;
|
||||
@ -1080,13 +1080,13 @@ ProcessFile(JSContext *cx, JSObject *obj, const char *filename, FILE *file,
|
||||
DoBeginRequest(cx);
|
||||
/* Clear any pending exception from previous failed compiles. */
|
||||
JS_ClearPendingException(cx);
|
||||
scriptObj = JS_CompileScriptForPrincipals(cx, obj, gJSPrincipals, buffer,
|
||||
strlen(buffer), "typein", startline);
|
||||
if (scriptObj) {
|
||||
script = JS_CompileScriptForPrincipals(cx, obj, gJSPrincipals, buffer,
|
||||
strlen(buffer), "typein", startline);
|
||||
if (script) {
|
||||
JSErrorReporter older;
|
||||
|
||||
if (!compileOnly) {
|
||||
ok = JS_ExecuteScript(cx, obj, scriptObj, &result);
|
||||
ok = JS_ExecuteScript(cx, obj, script, &result);
|
||||
if (ok && result != JSVAL_VOID) {
|
||||
/* Suppress error reports from JS_ValueToString(). */
|
||||
older = JS_SetErrorReporter(cx, NULL);
|
||||
|
@ -426,9 +426,9 @@ nsXPConnect::GarbageCollect()
|
||||
// JSTRACE_XML can recursively hold on to more JSTRACE_XML objects, adding it to
|
||||
// the cycle collector avoids stack overflow.
|
||||
inline bool
|
||||
AddToCCKind(uint32 kind)
|
||||
AddToCCKind(JSGCTraceKind kind)
|
||||
{
|
||||
return kind == JSTRACE_OBJECT || kind == JSTRACE_XML;
|
||||
return kind == JSTRACE_OBJECT || kind == JSTRACE_XML || kind == JSTRACE_SCRIPT;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CC
|
||||
@ -445,7 +445,7 @@ struct NoteJSRootTracer : public JSTracer
|
||||
};
|
||||
|
||||
static void
|
||||
NoteJSRoot(JSTracer *trc, void *thing, uint32 kind)
|
||||
NoteJSRoot(JSTracer *trc, void *thing, JSGCTraceKind kind)
|
||||
{
|
||||
if(AddToCCKind(kind))
|
||||
{
|
||||
|
@ -114,8 +114,8 @@ Load(JSContext *cx, uintN argc, jsval *vp)
|
||||
JSAutoByteString filename(cx, str);
|
||||
if (!filename)
|
||||
return false;
|
||||
JSObject *scriptObj = JS_CompileFile(cx, obj, filename.ptr());
|
||||
if (!scriptObj || !JS_ExecuteScript(cx, obj, scriptObj, &result))
|
||||
JSScript *script = JS_CompileFile(cx, obj, filename.ptr());
|
||||
if (!script || !JS_ExecuteScript(cx, obj, script, &result))
|
||||
return false;
|
||||
}
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
|
Loading…
Reference in New Issue
Block a user