js/src/jsscriptinlines.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set ts=8 sts=4 et sw=4 tw=99:
     3  * This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef jsscriptinlines_h
     8 #define jsscriptinlines_h
    10 #include "jsscript.h"
    12 #include "jit/AsmJSLink.h"
    13 #include "jit/BaselineJIT.h"
    14 #include "jit/IonAnalysis.h"
    15 #include "vm/ScopeObject.h"
    17 #include "jscompartmentinlines.h"
    19 #include "vm/Shape-inl.h"
    21 namespace js {
    23 inline
    24 Bindings::Bindings()
    25     : callObjShape_(nullptr), bindingArrayAndFlag_(TEMPORARY_STORAGE_BIT),
    26       numArgs_(0), numBlockScoped_(0), numVars_(0)
    27 {}
    29 inline
    30 AliasedFormalIter::AliasedFormalIter(JSScript *script)
    31   : begin_(script->bindingArray()),
    32     p_(begin_),
    33     end_(begin_ + (script->funHasAnyAliasedFormal() ? script->numArgs() : 0)),
    34     slot_(CallObject::RESERVED_SLOTS)
    35 {
    36     settle();
    37 }
    39 inline void
    40 ScriptCounts::destroy(FreeOp *fop)
    41 {
    42     fop->free_(pcCountsVector);
    43     fop->delete_(ionCounts);
    44 }
    46 void
    47 SetFrameArgumentsObject(JSContext *cx, AbstractFramePtr frame,
    48                         HandleScript script, JSObject *argsobj);
    50 inline JSFunction *
    51 LazyScript::functionDelazifying(JSContext *cx) const
    52 {
    53     if (function_ && !function_->getOrCreateScript(cx))
    54         return nullptr;
    55     return function_;
    56 }
    58 } // namespace js
    60 inline JSFunction *
    61 JSScript::functionDelazifying() const
    62 {
    63     if (function_ && function_->isInterpretedLazy()) {
    64         function_->setUnlazifiedScript(const_cast<JSScript *>(this));
    65         // If this script has a LazyScript, make sure the LazyScript has a
    66         // reference to the script when delazifying its canonical function.
    67         if (lazyScript && !lazyScript->maybeScript())
    68             lazyScript->initScript(const_cast<JSScript *>(this));
    69     }
    70     return function_;
    71 }
    73 inline void
    74 JSScript::setFunction(JSFunction *fun)
    75 {
    76     JS_ASSERT(fun->isTenured());
    77     function_ = fun;
    78 }
    80 inline void
    81 JSScript::ensureNonLazyCanonicalFunction(JSContext *cx)
    82 {
    83     // Infallibly delazify the canonical script.
    84     if (function_ && function_->isInterpretedLazy())
    85         functionDelazifying();
    86 }
    88 inline JSFunction *
    89 JSScript::getFunction(size_t index)
    90 {
    91     JSFunction *fun = &getObject(index)->as<JSFunction>();
    92     JS_ASSERT_IF(fun->isNative(), IsAsmJSModuleNative(fun->native()));
    93     return fun;
    94 }
    96 inline JSFunction *
    97 JSScript::getCallerFunction()
    98 {
    99     JS_ASSERT(savedCallerFun());
   100     return getFunction(0);
   101 }
   103 inline JSFunction *
   104 JSScript::functionOrCallerFunction()
   105 {
   106     if (functionNonDelazifying())
   107         return functionNonDelazifying();
   108     if (savedCallerFun())
   109         return getCallerFunction();
   110     return nullptr;
   111 }
   113 inline js::RegExpObject *
   114 JSScript::getRegExp(size_t index)
   115 {
   116     js::ObjectArray *arr = regexps();
   117     JS_ASSERT(uint32_t(index) < arr->length);
   118     JSObject *obj = arr->vector[index];
   119     JS_ASSERT(obj->is<js::RegExpObject>());
   120     return (js::RegExpObject *) obj;
   121 }
   123 inline js::RegExpObject *
   124 JSScript::getRegExp(jsbytecode *pc)
   125 {
   126     JS_ASSERT(containsPC(pc) && containsPC(pc + sizeof(uint32_t)));
   127     return getRegExp(GET_UINT32_INDEX(pc));
   128 }
   130 inline js::GlobalObject &
   131 JSScript::global() const
   132 {
   133     /*
   134      * A JSScript always marks its compartment's global (via bindings) so we
   135      * can assert that maybeGlobal is non-null here.
   136      */
   137     return *compartment()->maybeGlobal();
   138 }
   140 inline JSPrincipals *
   141 JSScript::principals()
   142 {
   143     return compartment()->principals;
   144 }
   146 inline JSFunction *
   147 JSScript::donorFunction() const
   148 {
   149     if (!isCallsiteClone())
   150         return nullptr;
   151     return &enclosingScopeOrOriginalFunction_->as<JSFunction>();
   152 }
   154 inline void
   155 JSScript::setIsCallsiteClone(JSObject *fun)
   156 {
   157     JS_ASSERT(shouldCloneAtCallsite());
   158     shouldCloneAtCallsite_ = false;
   159     isCallsiteClone_ = true;
   160     JS_ASSERT(isCallsiteClone());
   161     JS_ASSERT(fun->is<JSFunction>());
   162     enclosingScopeOrOriginalFunction_ = fun;
   163 }
   165 inline void
   166 JSScript::setBaselineScript(JSContext *maybecx, js::jit::BaselineScript *baselineScript)
   167 {
   168 #ifdef JS_ION
   169     if (hasBaselineScript())
   170         js::jit::BaselineScript::writeBarrierPre(tenuredZone(), baseline);
   171 #endif
   172     MOZ_ASSERT(!hasIonScript());
   173     baseline = baselineScript;
   174     updateBaselineOrIonRaw();
   175 }
   177 inline bool
   178 JSScript::ensureHasAnalyzedArgsUsage(JSContext *cx)
   179 {
   180     if (analyzedArgsUsage())
   181         return true;
   182 #ifdef JS_ION
   183     return js::jit::AnalyzeArgumentsUsage(cx, this);
   184 #else
   185     MOZ_CRASH();
   186 #endif
   187 }
   189 #endif /* jsscriptinlines_h */

mercurial