Exemple #1
0
bool
XDRState<mode>::codeScript(MutableHandleScript scriptp)
{
    RootedScript script(cx());
    if (mode == XDR_DECODE) {
        script = NULL;
        scriptp.set(NULL);
    } else {
        script = scriptp.get();
    }

    if (!VersionCheck(this))
        return false;

    if (!XDRScript(this, NullPtr(), NullPtr(), NullPtr(), &script))
        return false;

    if (mode == XDR_DECODE) {
        JS_ASSERT(!script->compileAndGo);
        CallNewScriptHook(cx(), script, NullPtr());
        Debugger::onNewScript(cx(), script, NULL);
        scriptp.set(script);
    }

    return true;
}
Exemple #2
0
bool
XDRState<mode>::codeScript(MutableHandleScript scriptp)
{
    if (mode == XDR_DECODE)
        scriptp.set(nullptr);
    else
        MOZ_ASSERT(!scriptp->enclosingScope());

    if (!VersionCheck(this))
        return false;

    return XDRScript(this, nullptr, nullptr, nullptr, scriptp);
}
Exemple #3
0
bool
XDRState<mode>::codeScript(MutableHandleScript scriptp)
{
    if (mode == XDR_DECODE)
        scriptp.set(nullptr);
    else
        MOZ_ASSERT(!scriptp->enclosingScope());

    if (!VersionCheck(this)) {
        postProcessContextErrors(cx());
        return false;
    }

    if (!XDRScript(this, nullptr, nullptr, nullptr, scriptp)) {
        postProcessContextErrors(cx());
        scriptp.set(nullptr);
        return false;
    }

    return true;
}
Exemple #4
0
bool
XDRState<mode>::codeScript(MutableHandleScript scriptp)
{
    if (mode == XDR_DECODE)
        scriptp.set(nullptr);

    if (!VersionCheck(this))
        return false;

    if (!XDRScript(this, NullPtr(), NullPtr(), NullPtr(), scriptp))
        return false;

    return true;
}
Exemple #5
0
bool
XDRState<mode>::codeScript(MutableHandleScript scriptp)
{
    if (mode == XDR_DECODE)
        scriptp.set(nullptr);

    if (!VersionCheck(this))
        return false;

    RootedObject staticLexical(cx(), &cx()->global()->lexicalScope().staticBlock());
    if (!XDRScript(this, staticLexical, nullptr, nullptr, scriptp))
        return false;

    return true;
}
// We only serialize scripts with system principals. So we don't serialize the
// principals when writing a script. Instead, when reading it back, we set the
// principals to the system principals.
nsresult
ReadCachedScript(StartupCache* cache, nsACString& uri, JSContext* cx,
                 nsIPrincipal* systemPrincipal, MutableHandleScript scriptp)
{
    UniquePtr<char[]> buf;
    uint32_t len;
    nsresult rv = cache->GetBuffer(PromiseFlatCString(uri).get(), &buf, &len);
    if (NS_FAILED(rv))
        return rv; // don't warn since NOT_AVAILABLE is an ok error

    scriptp.set(JS_DecodeScript(cx, buf.get(), len));
    if (!scriptp)
        return NS_ERROR_OUT_OF_MEMORY;
    return NS_OK;
}
Exemple #7
0
void
ion::GetPcScript(JSContext *cx, MutableHandleScript scriptRes, jsbytecode **pcRes)
{
    JS_ASSERT(cx->fp()->beginsIonActivation());
    IonSpew(IonSpew_Snapshots, "Recover PC & Script from the last frame.");

    JSRuntime *rt = cx->runtime;

    // Recover the return address.
    IonFrameIterator it(rt->ionTop);
    uint8_t *retAddr = it.returnAddress();
    uint32_t hash = PcScriptCache::Hash(retAddr);
    JS_ASSERT(retAddr != NULL);

    // Lazily initialize the cache. The allocation may safely fail and will not GC.
    if (JS_UNLIKELY(rt->ionPcScriptCache == NULL)) {
        rt->ionPcScriptCache = (PcScriptCache *)js_malloc(sizeof(struct PcScriptCache));
        if (rt->ionPcScriptCache)
            rt->ionPcScriptCache->clear(rt->gcNumber);
    }

    // Attempt to lookup address in cache.
    if (rt->ionPcScriptCache && rt->ionPcScriptCache->get(rt, hash, retAddr, scriptRes, pcRes))
        return;

    // Lookup failed: undertake expensive process to recover the innermost inlined frame.
    ++it; // Skip exit frame.
    InlineFrameIterator ifi(&it);

    // Set the result.
    scriptRes.set(ifi.script());
    if (pcRes)
        *pcRes = ifi.pc();

    // Add entry to cache.
    if (rt->ionPcScriptCache)
        rt->ionPcScriptCache->add(hash, retAddr, ifi.pc(), ifi.script());
}