mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 899832 - hoist JSScript::originPrincipals and LazyScript::originPrincipals into ScriptSource (r=bhackett)
--HG-- extra : rebase_source : a71608e039c67c7ee9c8b41eb5946ae993d5a697
This commit is contained in:
parent
bef18d48cb
commit
c2378966fa
@ -174,7 +174,7 @@ frontend::CompileScript(ExclusiveContext *cx, LifoAlloc *alloc, HandleObject sco
|
||||
if (!CheckLength(cx, length))
|
||||
return NULL;
|
||||
JS_ASSERT_IF(staticLevel != 0, options.sourcePolicy != CompileOptions::LAZY_SOURCE);
|
||||
ScriptSource *ss = cx->new_<ScriptSource>();
|
||||
ScriptSource *ss = cx->new_<ScriptSource>(options.originPrincipals());
|
||||
if (!ss)
|
||||
return NULL;
|
||||
if (options.filename && !ss->setFilename(cx, options.filename))
|
||||
@ -444,7 +444,7 @@ frontend::CompileFunctionBody(JSContext *cx, MutableHandleFunction fun, CompileO
|
||||
|
||||
if (!CheckLength(cx, length))
|
||||
return false;
|
||||
ScriptSource *ss = cx->new_<ScriptSource>();
|
||||
ScriptSource *ss = cx->new_<ScriptSource>(options.originPrincipals());
|
||||
if (!ss)
|
||||
return false;
|
||||
if (options.filename && !ss->setFilename(cx, options.filename))
|
||||
|
@ -4510,7 +4510,7 @@ EmitFunc(ExclusiveContext *cx, BytecodeEmitter *bce, ParseNode *pn)
|
||||
JSObject *scope = bce->blockChain;
|
||||
if (!scope && bce->sc->isFunctionBox())
|
||||
scope = bce->sc->asFunctionBox()->function();
|
||||
fun->lazyScript()->setParent(scope, bce->script->sourceObject(), bce->script->originPrincipals);
|
||||
fun->lazyScript()->setParent(scope, bce->script->sourceObject());
|
||||
}
|
||||
} else {
|
||||
SharedContext *outersc = bce->sc;
|
||||
@ -4523,7 +4523,7 @@ EmitFunc(ExclusiveContext *cx, BytecodeEmitter *bce, ParseNode *pn)
|
||||
Rooted<JSScript*> parent(cx, bce->script);
|
||||
CompileOptions options(bce->parser->options());
|
||||
options.setPrincipals(parent->principals())
|
||||
.setOriginPrincipals(parent->originPrincipals)
|
||||
.setOriginPrincipals(parent->originPrincipals())
|
||||
.setCompileAndGo(parent->compileAndGo)
|
||||
.setSelfHostingMode(parent->selfHosted)
|
||||
.setNoScriptRval(false)
|
||||
|
@ -280,13 +280,14 @@ TokenStream::TokenStream(ExclusiveContext *cx, const CompileOptions &options,
|
||||
sourceMap(NULL),
|
||||
tokenbuf(cx),
|
||||
cx(cx),
|
||||
originPrincipals(JSScript::normalizeOriginPrincipals(options.principals,
|
||||
options.originPrincipals)),
|
||||
originPrincipals(options.originPrincipals()),
|
||||
strictModeGetter(smg),
|
||||
tokenSkip(cx, &tokens),
|
||||
linebaseSkip(cx, &linebase),
|
||||
prevLinebaseSkip(cx, &prevLinebase)
|
||||
{
|
||||
JS_ASSERT_IF(options.principals(), options.originPrincipals());
|
||||
|
||||
// The caller must ensure that a reference is held on the supplied principals
|
||||
// throughout compilation.
|
||||
JS_ASSERT_IF(originPrincipals, originPrincipals->refcount);
|
||||
|
@ -1539,11 +1539,11 @@ class MOZ_STACK_CLASS ModuleCompiler
|
||||
}
|
||||
|
||||
bool staticallyLink(ScopedJSDeletePtr<AsmJSModule> *module, ScopedJSFreePtr<char> *report) {
|
||||
module_->initPostLinkFailureInfo(cx_->runtime(),
|
||||
parser_.tokenStream.getOriginPrincipals(),
|
||||
parser_.ss,
|
||||
bodyStart_,
|
||||
parser_.tokenStream.currentToken().pos.end);
|
||||
// Record the ScriptSource and [begin, end) range of the module in case
|
||||
// the link-time validation fails in LinkAsmJS and we need to re-parse
|
||||
// the entire module from scratch.
|
||||
uint32_t bodyEnd = parser_.tokenStream.currentToken().pos.end;
|
||||
module_->initPostLinkFailureInfo(parser_.ss, bodyStart_, bodyEnd);
|
||||
|
||||
// Finish the code section.
|
||||
masm_.finish();
|
||||
|
@ -421,7 +421,7 @@ HandleDynamicLinkFailure(JSContext *cx, CallArgs args, AsmJSModule &module, Hand
|
||||
|
||||
CompileOptions options(cx);
|
||||
options.setPrincipals(cx->compartment()->principals)
|
||||
.setOriginPrincipals(info.originPrincipals)
|
||||
.setOriginPrincipals(info.scriptSource->originPrincipals())
|
||||
.setCompileAndGo(false)
|
||||
.setNoScriptRval(false);
|
||||
|
||||
|
@ -321,35 +321,23 @@ class AsmJSModule
|
||||
// This struct holds the data required to do this.
|
||||
struct PostLinkFailureInfo
|
||||
{
|
||||
JSRuntime * rt;
|
||||
JSPrincipals * originPrincipals;
|
||||
ScriptSource * scriptSource;
|
||||
uint32_t bufStart; // offset of the function body's start
|
||||
uint32_t bufEnd; // offset of the function body's end
|
||||
|
||||
PostLinkFailureInfo()
|
||||
: rt(), originPrincipals(), scriptSource(), bufStart(), bufEnd()
|
||||
: scriptSource(), bufStart(), bufEnd()
|
||||
{}
|
||||
|
||||
void init(JSRuntime *rt, JSPrincipals *originPrincipals, ScriptSource *scriptSource,
|
||||
uint32_t bufStart, uint32_t bufEnd)
|
||||
{
|
||||
JS_ASSERT(!this->rt);
|
||||
|
||||
this->rt = rt;
|
||||
this->originPrincipals = originPrincipals;
|
||||
void init(ScriptSource *scriptSource, uint32_t bufStart, uint32_t bufEnd) {
|
||||
JS_ASSERT(!this->scriptSource);
|
||||
this->scriptSource = scriptSource;
|
||||
this->bufStart = bufStart;
|
||||
this->bufEnd = bufEnd;
|
||||
|
||||
if (originPrincipals)
|
||||
JS_HoldPrincipals(originPrincipals);
|
||||
scriptSource->incref();
|
||||
}
|
||||
|
||||
~PostLinkFailureInfo() {
|
||||
if (originPrincipals)
|
||||
JS_DropPrincipals(rt, originPrincipals);
|
||||
if (scriptSource)
|
||||
scriptSource->decref();
|
||||
}
|
||||
@ -718,12 +706,10 @@ class AsmJSModule
|
||||
PropertyName *importArgumentName() const { return importArgumentName_; }
|
||||
PropertyName *bufferArgumentName() const { return bufferArgumentName_; }
|
||||
|
||||
void initPostLinkFailureInfo(JSRuntime *rt,
|
||||
JSPrincipals *originPrincipals,
|
||||
ScriptSource *scriptSource,
|
||||
void initPostLinkFailureInfo(ScriptSource *scriptSource,
|
||||
uint32_t bufStart,
|
||||
uint32_t bufEnd) {
|
||||
postLinkFailureInfo_.init(rt, originPrincipals, scriptSource, bufStart, bufEnd);
|
||||
postLinkFailureInfo_.init(scriptSource, bufStart, bufEnd);
|
||||
}
|
||||
const PostLinkFailureInfo &postLinkFailureInfo() const {
|
||||
return postLinkFailureInfo_;
|
||||
|
@ -47,7 +47,7 @@ FreezeThaw(JSContext *cx, JS::HandleScript script)
|
||||
|
||||
// thaw
|
||||
JSScript *script2 = JS_DecodeScript(cx, memory, nbytes,
|
||||
script->principals(), script->originPrincipals);
|
||||
script->principals(), script->originPrincipals());
|
||||
js_free(memory);
|
||||
return script2;
|
||||
}
|
||||
@ -71,7 +71,7 @@ FreezeThaw(JSContext *cx, JS::HandleObject funobj)
|
||||
JSScript *script = GetScript(cx, funobj);
|
||||
JSObject *funobj2 = JS_DecodeInterpretedFunction(cx, memory, nbytes,
|
||||
script->principals(),
|
||||
script->originPrincipals);
|
||||
script->originPrincipals());
|
||||
js_free(memory);
|
||||
return funobj2;
|
||||
}
|
||||
|
@ -4777,8 +4777,8 @@ AutoFile::open(JSContext *cx, const char *filename)
|
||||
|
||||
|
||||
JS::CompileOptions::CompileOptions(JSContext *cx, JSVersion version)
|
||||
: principals(NULL),
|
||||
originPrincipals(NULL),
|
||||
: principals_(NULL),
|
||||
originPrincipals_(NULL),
|
||||
version(version != JSVERSION_UNKNOWN ? version : cx->findVersion()),
|
||||
versionSet(false),
|
||||
utf8(false),
|
||||
@ -4799,6 +4799,12 @@ JS::CompileOptions::CompileOptions(JSContext *cx, JSVersion version)
|
||||
{
|
||||
}
|
||||
|
||||
JSPrincipals *
|
||||
CompileOptions::originPrincipals() const
|
||||
{
|
||||
return NormalizeOriginPrincipals(principals_, originPrincipals_);
|
||||
}
|
||||
|
||||
JSScript *
|
||||
JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
|
||||
const jschar *chars, size_t length)
|
||||
@ -4807,7 +4813,7 @@ JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, obj);
|
||||
JS_ASSERT_IF(options.principals, cx->compartment()->principals == options.principals);
|
||||
JS_ASSERT_IF(options.principals(), cx->compartment()->principals == options.principals());
|
||||
AutoLastFrameCheck lfc(cx);
|
||||
|
||||
return frontend::CompileScript(cx, &cx->tempLifoAlloc(), obj, NullPtr(), options, chars, length);
|
||||
@ -4960,7 +4966,7 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options,
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, obj);
|
||||
JS_ASSERT_IF(options.principals, cx->compartment()->principals == options.principals);
|
||||
JS_ASSERT_IF(options.principals(), cx->compartment()->principals == options.principals());
|
||||
AutoLastFrameCheck lfc(cx);
|
||||
|
||||
RootedAtom funAtom(cx);
|
||||
@ -5144,7 +5150,7 @@ JS::Evaluate(JSContext *cx, HandleObject obj, CompileOptions options,
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, obj);
|
||||
JS_ASSERT_IF(options.principals, cx->compartment()->principals == options.principals);
|
||||
JS_ASSERT_IF(options.principals(), cx->compartment()->principals == options.principals());
|
||||
|
||||
AutoLastFrameCheck lfc(cx);
|
||||
|
||||
|
@ -3984,9 +3984,15 @@ JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name,
|
||||
namespace JS {
|
||||
|
||||
/* Options for JavaScript compilation. */
|
||||
struct JS_PUBLIC_API(CompileOptions) {
|
||||
JSPrincipals *principals;
|
||||
JSPrincipals *originPrincipals;
|
||||
class JS_PUBLIC_API(CompileOptions)
|
||||
{
|
||||
JSPrincipals *principals_;
|
||||
JSPrincipals *originPrincipals_;
|
||||
|
||||
public:
|
||||
JSPrincipals *principals() const { return principals_; }
|
||||
JSPrincipals *originPrincipals() const;
|
||||
|
||||
JSVersion version;
|
||||
bool versionSet;
|
||||
bool utf8;
|
||||
@ -4010,8 +4016,8 @@ struct JS_PUBLIC_API(CompileOptions) {
|
||||
} sourcePolicy;
|
||||
|
||||
explicit CompileOptions(JSContext *cx, JSVersion version = JSVERSION_UNKNOWN);
|
||||
CompileOptions &setPrincipals(JSPrincipals *p) { principals = p; return *this; }
|
||||
CompileOptions &setOriginPrincipals(JSPrincipals *p) { originPrincipals = p; return *this; }
|
||||
CompileOptions &setPrincipals(JSPrincipals *p) { principals_ = p; return *this; }
|
||||
CompileOptions &setOriginPrincipals(JSPrincipals *p) { originPrincipals_ = p; return *this; }
|
||||
CompileOptions &setVersion(JSVersion v) { version = v; versionSet = true; return *this; }
|
||||
CompileOptions &setUTF8(bool u) { utf8 = u; return *this; }
|
||||
CompileOptions &setFileAndLine(const char *f, unsigned l) {
|
||||
|
@ -360,7 +360,7 @@ PopulateReportBlame(JSContext *cx, JSErrorReport *report)
|
||||
|
||||
report->filename = iter.script()->filename();
|
||||
report->lineno = PCToLineNumber(iter.script(), iter.pc(), &report->column);
|
||||
report->originPrincipals = iter.script()->originPrincipals;
|
||||
report->originPrincipals = iter.script()->originPrincipals();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -289,8 +289,7 @@ class ExclusiveContext : public ThreadSafeContext
|
||||
friend class AutoCompartment;
|
||||
friend class AutoLockForExclusiveAccess;
|
||||
friend struct StackBaseShape;
|
||||
friend void JSScript::initCompartmentAndPrincipals(ExclusiveContext *cx,
|
||||
const JS::CompileOptions &options);
|
||||
friend void JSScript::initCompartment(ExclusiveContext *cx);
|
||||
|
||||
// The worker on which this context is running, if this is not a JSContext.
|
||||
WorkerThread *workerThread;
|
||||
|
@ -539,7 +539,7 @@ JS_GetScriptPrincipals(JSScript *script)
|
||||
JS_PUBLIC_API(JSPrincipals *)
|
||||
JS_GetScriptOriginPrincipals(JSScript *script)
|
||||
{
|
||||
return script->originPrincipals;
|
||||
return script->originPrincipals();
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
@ -1108,9 +1108,6 @@ JSFunction::createScriptForLazilyInterpretedFunction(JSContext *cx, HandleFuncti
|
||||
return false;
|
||||
}
|
||||
|
||||
// The cloned script will have reused the origin principals and
|
||||
// filename from the original script, which may differ.
|
||||
clonedScript->originPrincipals = lazy->originPrincipals();
|
||||
clonedScript->setSourceObject(lazy->sourceObject());
|
||||
|
||||
fun->initAtom(script->function()->displayAtom());
|
||||
|
@ -538,7 +538,6 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
|
||||
JSVersion version_ = JSVersion(version & JS_BITMASK(16));
|
||||
JS_ASSERT((version_ & VersionFlags::MASK) == unsigned(version_));
|
||||
|
||||
// principals and originPrincipals are set with xdr->initScriptPrincipals(script) below.
|
||||
// staticLevel is set below.
|
||||
CompileOptions options(cx);
|
||||
options.setVersion(version_)
|
||||
@ -546,7 +545,7 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
|
||||
.setSelfHostingMode(!!(scriptBits & (1 << SelfHosted)));
|
||||
JS::RootedScriptSource sourceObject(cx);
|
||||
if (scriptBits & (1 << OwnSource)) {
|
||||
ScriptSource *ss = cx->new_<ScriptSource>();
|
||||
ScriptSource *ss = cx->new_<ScriptSource>(xdr->originPrincipals());
|
||||
if (!ss)
|
||||
return false;
|
||||
sourceObject = ScriptSourceObject::create(cx, ss);
|
||||
@ -622,7 +621,6 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
|
||||
script->lineno = lineno;
|
||||
script->nslots = uint16_t(nslots);
|
||||
script->staticLevel = uint16_t(nslots >> 16);
|
||||
xdr->initScriptPrincipals(script);
|
||||
}
|
||||
|
||||
jsbytecode *code = script->code;
|
||||
@ -1358,6 +1356,8 @@ ScriptSource::destroy()
|
||||
adjustDataSize(0);
|
||||
js_free(filename_);
|
||||
js_free(sourceMap_);
|
||||
if (originPrincipals_)
|
||||
JS_DropPrincipals(TlsPerThreadData.get()->runtimeFromMainThread(), originPrincipals_);
|
||||
ready_ = false;
|
||||
js_free(this);
|
||||
}
|
||||
@ -1728,20 +1728,9 @@ ScriptDataSize(uint32_t nbindings, uint32_t nobjects, uint32_t nregexps,
|
||||
}
|
||||
|
||||
void
|
||||
JSScript::initCompartmentAndPrincipals(ExclusiveContext *cx, const CompileOptions &options)
|
||||
JSScript::initCompartment(ExclusiveContext *cx)
|
||||
{
|
||||
compartment_ = cx->compartment_;
|
||||
|
||||
/* Establish invariant: principals implies originPrincipals. */
|
||||
if (options.principals) {
|
||||
JS_ASSERT(options.principals == cx->compartment_->principals);
|
||||
originPrincipals
|
||||
= options.originPrincipals ? options.originPrincipals : options.principals;
|
||||
JS_HoldPrincipals(originPrincipals);
|
||||
} else if (options.originPrincipals) {
|
||||
originPrincipals = options.originPrincipals;
|
||||
JS_HoldPrincipals(originPrincipals);
|
||||
}
|
||||
}
|
||||
|
||||
JSScript *
|
||||
@ -1760,7 +1749,7 @@ JSScript::Create(ExclusiveContext *cx, HandleObject enclosingScope, bool savedCa
|
||||
|
||||
script->enclosingScopeOrOriginalFunction_ = enclosingScope;
|
||||
script->savedCallerFun = savedCallerFun;
|
||||
script->initCompartmentAndPrincipals(cx, options);
|
||||
script->initCompartment(cx);
|
||||
|
||||
script->compileAndGo = options.compileAndGo;
|
||||
script->selfHosted = options.selfHostingMode;
|
||||
@ -2081,9 +2070,6 @@ JSScript::finalize(FreeOp *fop)
|
||||
CallDestroyScriptHook(fop, this);
|
||||
fop->runtime()->spsProfiler.onScriptFinalized(this);
|
||||
|
||||
if (originPrincipals)
|
||||
JS_DropPrincipals(fop->runtime(), originPrincipals);
|
||||
|
||||
if (types)
|
||||
types->destroy();
|
||||
|
||||
@ -2305,7 +2291,7 @@ js::CurrentScriptFileLineOrigin(JSContext *cx, const char **file, unsigned *line
|
||||
JS_ASSERT(*(pc + JSOP_EVAL_LENGTH) == JSOP_LINENO);
|
||||
*file = script->filename();
|
||||
*linenop = GET_UINT16(pc + JSOP_EVAL_LENGTH);
|
||||
*origin = script->originPrincipals;
|
||||
*origin = script->originPrincipals();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2314,14 +2300,14 @@ js::CurrentScriptFileLineOrigin(JSContext *cx, const char **file, unsigned *line
|
||||
if (iter.done()) {
|
||||
*file = NULL;
|
||||
*linenop = 0;
|
||||
*origin = NULL;
|
||||
*origin = cx->compartment()->principals;
|
||||
return;
|
||||
}
|
||||
|
||||
JSScript *script = iter.script();
|
||||
*file = script->filename();
|
||||
*linenop = PCToLineNumber(iter.script(), iter.pc());
|
||||
*origin = script->originPrincipals;
|
||||
*origin = script->originPrincipals();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@ -2427,7 +2413,7 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
|
||||
|
||||
CompileOptions options(cx);
|
||||
options.setPrincipals(cx->compartment()->principals)
|
||||
.setOriginPrincipals(src->originPrincipals)
|
||||
.setOriginPrincipals(src->originPrincipals())
|
||||
.setCompileAndGo(src->compileAndGo)
|
||||
.setSelfHostingMode(src->selfHosted)
|
||||
.setNoScriptRval(src->noScriptRval)
|
||||
@ -2854,9 +2840,6 @@ LazyScript::finalize(FreeOp *fop)
|
||||
{
|
||||
if (table_)
|
||||
fop->free_(table_);
|
||||
|
||||
if (originPrincipals_)
|
||||
JS_DropPrincipals(fop->runtime(), originPrincipals_);
|
||||
}
|
||||
|
||||
void
|
||||
@ -3012,7 +2995,6 @@ LazyScript::LazyScript(JSFunction *fun, void *table, uint32_t numFreeVariables,
|
||||
enclosingScope_(NULL),
|
||||
sourceObject_(NULL),
|
||||
table_(table),
|
||||
originPrincipals_(NULL),
|
||||
version_(version),
|
||||
numFreeVariables_(numFreeVariables),
|
||||
numInnerFunctions_(numInnerFunctions),
|
||||
@ -3039,15 +3021,11 @@ LazyScript::initScript(JSScript *script)
|
||||
}
|
||||
|
||||
void
|
||||
LazyScript::setParent(JSObject *enclosingScope, ScriptSourceObject *sourceObject,
|
||||
JSPrincipals *originPrincipals)
|
||||
LazyScript::setParent(JSObject *enclosingScope, ScriptSourceObject *sourceObject)
|
||||
{
|
||||
JS_ASSERT(sourceObject && !sourceObject_ && !enclosingScope_ && !originPrincipals_);
|
||||
JS_ASSERT(sourceObject && !sourceObject_ && !enclosingScope_);
|
||||
enclosingScope_ = enclosingScope;
|
||||
sourceObject_ = sourceObject;
|
||||
originPrincipals_ = originPrincipals;
|
||||
if (originPrincipals)
|
||||
JS_HoldPrincipals(originPrincipals);
|
||||
}
|
||||
|
||||
ScriptSourceObject *
|
||||
|
@ -295,6 +295,7 @@ class ScriptSource
|
||||
uint32_t compressedLength_;
|
||||
char *filename_;
|
||||
jschar *sourceMap_;
|
||||
JSPrincipals *originPrincipals_;
|
||||
|
||||
// True if we can call JSRuntime::sourceHook to load the source on
|
||||
// demand. If sourceRetrievable_ and hasSourceData() are false, it is not
|
||||
@ -304,17 +305,20 @@ class ScriptSource
|
||||
bool ready_:1;
|
||||
|
||||
public:
|
||||
ScriptSource()
|
||||
ScriptSource(JSPrincipals *originPrincipals)
|
||||
: refs(0),
|
||||
length_(0),
|
||||
compressedLength_(0),
|
||||
filename_(NULL),
|
||||
sourceMap_(NULL),
|
||||
originPrincipals_(originPrincipals),
|
||||
sourceRetrievable_(false),
|
||||
argumentsNotIncluded_(false),
|
||||
ready_(true)
|
||||
{
|
||||
data.source = NULL;
|
||||
if (originPrincipals_)
|
||||
JS_HoldPrincipals(originPrincipals_);
|
||||
}
|
||||
void incref() { refs++; }
|
||||
void decref() {
|
||||
@ -358,6 +362,8 @@ class ScriptSource
|
||||
const jschar *sourceMap();
|
||||
bool hasSourceMap() const { return sourceMap_ != NULL; }
|
||||
|
||||
JSPrincipals *originPrincipals() const { return originPrincipals_; }
|
||||
|
||||
private:
|
||||
void destroy();
|
||||
bool compressed() const { return compressedLength_ != 0; }
|
||||
@ -429,7 +435,6 @@ class JSScript : public js::gc::Cell
|
||||
js::HeapPtrAtom *atoms; /* maps immediate index to literal struct */
|
||||
|
||||
JSCompartment *compartment_;
|
||||
JSPrincipals *originPrincipals; /* see jsapi.h 'originPrincipals' comment */
|
||||
|
||||
/* Persistent type information retained across GCs. */
|
||||
js::types::TypeScript *types;
|
||||
@ -442,6 +447,20 @@ class JSScript : public js::gc::Cell
|
||||
// function; otherwise the enclosing scope
|
||||
js::HeapPtrObject enclosingScopeOrOriginalFunction_;
|
||||
|
||||
/* Information attached by Baseline/Ion for sequential mode execution. */
|
||||
js::ion::IonScript *ion;
|
||||
js::ion::BaselineScript *baseline;
|
||||
|
||||
/* Information attached by Ion for parallel mode execution */
|
||||
js::ion::IonScript *parallelIon;
|
||||
|
||||
/*
|
||||
* Pointer to either baseline->method()->raw() or ion->method()->raw(), or NULL
|
||||
* if there's no Baseline or Ion script.
|
||||
*/
|
||||
uint8_t *baselineOrIonRaw;
|
||||
uint8_t *baselineOrIonSkipArgCheck;
|
||||
|
||||
// 32-bit fields.
|
||||
|
||||
public:
|
||||
@ -595,8 +614,7 @@ class JSScript : public js::gc::Cell
|
||||
JS::HandleScriptSource sourceObject, uint32_t sourceStart,
|
||||
uint32_t sourceEnd);
|
||||
|
||||
void initCompartmentAndPrincipals(js::ExclusiveContext *cx,
|
||||
const JS::CompileOptions &options);
|
||||
void initCompartment(js::ExclusiveContext *cx);
|
||||
|
||||
// Three ways ways to initialize a JSScript. Callers of partiallyInit()
|
||||
// and fullyInitTrivial() are responsible for notifying the debugger after
|
||||
@ -653,26 +671,6 @@ class JSScript : public js::gc::Cell
|
||||
return hasIonScript() || hasParallelIonScript();
|
||||
}
|
||||
|
||||
private:
|
||||
/* Information attached by Baseline/Ion for sequential mode execution. */
|
||||
js::ion::IonScript *ion;
|
||||
js::ion::BaselineScript *baseline;
|
||||
|
||||
/* Information attached by Ion for parallel mode execution */
|
||||
js::ion::IonScript *parallelIon;
|
||||
|
||||
#if JS_BITS_PER_WORD == 32
|
||||
uint32_t padding0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Pointer to either baseline->method()->raw() or ion->method()->raw(), or NULL
|
||||
* if there's no Baseline or Ion script.
|
||||
*/
|
||||
uint8_t *baselineOrIonRaw;
|
||||
uint8_t *baselineOrIonSkipArgCheck;
|
||||
|
||||
public:
|
||||
bool hasIonScript() const {
|
||||
return ion && ion != ION_DISABLED_SCRIPT && ion != ION_COMPILING_SCRIPT;
|
||||
}
|
||||
@ -772,6 +770,7 @@ class JSScript : public js::gc::Cell
|
||||
void setSourceObject(js::ScriptSourceObject *object);
|
||||
js::ScriptSourceObject *sourceObject() const;
|
||||
js::ScriptSource *scriptSource() const { return sourceObject()->source(); }
|
||||
JSPrincipals *originPrincipals() const { return scriptSource()->originPrincipals(); }
|
||||
const char *filename() const { return scriptSource()->filename(); }
|
||||
|
||||
public:
|
||||
@ -1038,11 +1037,6 @@ class JSScript : public js::gc::Cell
|
||||
|
||||
static inline js::ThingRootKind rootKind() { return js::THING_ROOT_SCRIPT; }
|
||||
|
||||
static JSPrincipals *normalizeOriginPrincipals(JSPrincipals *principals,
|
||||
JSPrincipals *originPrincipals) {
|
||||
return originPrincipals ? originPrincipals : principals;
|
||||
}
|
||||
|
||||
void markChildren(JSTracer *trc);
|
||||
};
|
||||
|
||||
@ -1145,8 +1139,11 @@ class LazyScript : public js::gc::Cell
|
||||
// Heap allocated table with any free variables or inner functions.
|
||||
void *table_;
|
||||
|
||||
#if JS_BITS_PER_WORD == 32
|
||||
uint32_t padding;
|
||||
#endif
|
||||
|
||||
// Assorted bits that should really be in ScriptSourceObject.
|
||||
JSPrincipals *originPrincipals_;
|
||||
uint32_t version_ : 8;
|
||||
|
||||
uint32_t numFreeVariables_ : 24;
|
||||
@ -1189,16 +1186,18 @@ class LazyScript : public js::gc::Cell
|
||||
return enclosingScope_;
|
||||
}
|
||||
ScriptSourceObject *sourceObject() const;
|
||||
ScriptSource *scriptSource() const {
|
||||
return sourceObject()->source();
|
||||
}
|
||||
JSPrincipals *originPrincipals() const {
|
||||
return originPrincipals_;
|
||||
return scriptSource()->originPrincipals();
|
||||
}
|
||||
JSVersion version() const {
|
||||
JS_STATIC_ASSERT(JSVERSION_UNKNOWN == -1);
|
||||
return (version_ == JS_BIT(8) - 1) ? JSVERSION_UNKNOWN : JSVersion(version_);
|
||||
}
|
||||
|
||||
void setParent(JSObject *enclosingScope, ScriptSourceObject *sourceObject,
|
||||
JSPrincipals *originPrincipals);
|
||||
void setParent(JSObject *enclosingScope, ScriptSourceObject *sourceObject);
|
||||
|
||||
uint32_t numFreeVariables() const {
|
||||
return numFreeVariables_;
|
||||
@ -1289,6 +1288,9 @@ class LazyScript : public js::gc::Cell
|
||||
static inline void writeBarrierPre(LazyScript *lazy);
|
||||
};
|
||||
|
||||
/* If this fails, add/remove padding within LazyScript. */
|
||||
JS_STATIC_ASSERT(sizeof(LazyScript) % js::gc::CellSize == 0);
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
/*
|
||||
* Background thread to compress JS source code. This happens only while parsing
|
||||
@ -1492,6 +1494,19 @@ bool
|
||||
CloneFunctionScript(JSContext *cx, HandleFunction original, HandleFunction clone,
|
||||
NewObjectKind newKind = GenericObject);
|
||||
|
||||
/*
|
||||
* JSAPI clients are allowed to leave CompileOptions.originPrincipals NULL in
|
||||
* which case the JS engine sets options.originPrincipals = origin.principals.
|
||||
* This normalization step must occur before the originPrincipals get stored in
|
||||
* the JSScript/ScriptSource.
|
||||
*/
|
||||
|
||||
static inline JSPrincipals *
|
||||
NormalizeOriginPrincipals(JSPrincipals *principals, JSPrincipals *originPrincipals)
|
||||
{
|
||||
return originPrincipals ? originPrincipals : principals;
|
||||
}
|
||||
|
||||
/*
|
||||
* NB: after a successful XDR_DECODE, XDRScript callers must do any required
|
||||
* subsequent set-up of owning function or script object and then call
|
||||
|
@ -174,18 +174,18 @@ ParseTask::ParseTask(JSRuntime *rt, ExclusiveContext *cx, const CompileOptions &
|
||||
: runtime(rt), cx(cx), options(options), chars(chars), length(length),
|
||||
alloc(JSRuntime::TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE), script(NULL)
|
||||
{
|
||||
if (options.principals)
|
||||
JS_HoldPrincipals(options.principals);
|
||||
if (options.originPrincipals)
|
||||
JS_HoldPrincipals(options.originPrincipals);
|
||||
if (options.principals())
|
||||
JS_HoldPrincipals(options.principals());
|
||||
if (options.originPrincipals())
|
||||
JS_HoldPrincipals(options.originPrincipals());
|
||||
}
|
||||
|
||||
ParseTask::~ParseTask()
|
||||
{
|
||||
if (options.principals)
|
||||
JS_DropPrincipals(runtime, options.principals);
|
||||
if (options.originPrincipals)
|
||||
JS_DropPrincipals(runtime, options.originPrincipals);
|
||||
if (options.principals())
|
||||
JS_DropPrincipals(runtime, options.principals());
|
||||
if (options.originPrincipals())
|
||||
JS_DropPrincipals(runtime, options.originPrincipals());
|
||||
|
||||
// ParseTask takes over ownership of its input exclusive context.
|
||||
js_delete(cx);
|
||||
|
@ -226,7 +226,7 @@ GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
|
||||
jschar *source = InflateString(cx, rawSource, &sourceLen);
|
||||
if (!source)
|
||||
return NULL;
|
||||
ScriptSource *ss = cx->new_<ScriptSource>();
|
||||
ScriptSource *ss = cx->new_<ScriptSource>(/* originPrincipals = */ (JSPrincipals*) NULL);
|
||||
if (!ss) {
|
||||
js_free(source);
|
||||
return NULL;
|
||||
@ -239,6 +239,7 @@ GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
|
||||
CompileOptions options(cx);
|
||||
options.setNoScriptRval(true)
|
||||
.setVersion(JSVERSION_DEFAULT);
|
||||
|
||||
RootedScript script(cx, JSScript::Create(cx,
|
||||
/* enclosingScope = */ NullPtr(),
|
||||
/* savedCallerFun = */ false,
|
||||
|
@ -465,7 +465,7 @@ class PerThreadData : public PerThreadDataFriendFields,
|
||||
* thread is associated. This is private because accessing the
|
||||
* fields of this runtime can provoke race conditions, so the
|
||||
* intention is that access will be mediated through safe
|
||||
* functions like |associatedWith()| below.
|
||||
* functions like |runtimeFromMainThread| and |associatedWith()| below.
|
||||
*/
|
||||
JSRuntime *runtime_;
|
||||
|
||||
@ -571,6 +571,7 @@ class PerThreadData : public PerThreadDataFriendFields,
|
||||
void removeFromThreadList();
|
||||
|
||||
bool associatedWith(const JSRuntime *rt) { return runtime_ == rt; }
|
||||
inline JSRuntime *runtimeFromMainThread();
|
||||
};
|
||||
|
||||
template<class Client>
|
||||
@ -1683,6 +1684,13 @@ PerThreadData::setIonStackLimit(uintptr_t limit)
|
||||
ionStackLimit = limit;
|
||||
}
|
||||
|
||||
inline JSRuntime *
|
||||
PerThreadData::runtimeFromMainThread()
|
||||
{
|
||||
runtime_->assertValidThread();
|
||||
return runtime_;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
static JS_ALWAYS_INLINE void
|
||||
|
@ -130,31 +130,13 @@ XDRState<mode>::codeScript(MutableHandleScript scriptp)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<XDRMode mode>
|
||||
void
|
||||
XDRState<mode>::initScriptPrincipals(JSScript *script)
|
||||
{
|
||||
JS_ASSERT(mode == XDR_DECODE);
|
||||
|
||||
/* The origin principals must be normalized at this point. */
|
||||
JS_ASSERT_IF(principals, originPrincipals);
|
||||
JS_ASSERT(!script->originPrincipals);
|
||||
if (principals)
|
||||
JS_ASSERT(script->principals() == principals);
|
||||
|
||||
if (originPrincipals) {
|
||||
script->originPrincipals = originPrincipals;
|
||||
JS_HoldPrincipals(originPrincipals);
|
||||
}
|
||||
}
|
||||
|
||||
XDRDecoder::XDRDecoder(JSContext *cx, const void *data, uint32_t length,
|
||||
JSPrincipals *principals, JSPrincipals *originPrincipals)
|
||||
: XDRState<XDR_DECODE>(cx)
|
||||
{
|
||||
buf.setData(data, length);
|
||||
this->principals = principals;
|
||||
this->originPrincipals = JSScript::normalizeOriginPrincipals(principals, originPrincipals);
|
||||
this->principals_ = principals;
|
||||
this->originPrincipals_ = NormalizeOriginPrincipals(principals, originPrincipals);
|
||||
}
|
||||
|
||||
template class js::XDRState<XDR_ENCODE>;
|
||||
|
@ -98,11 +98,11 @@ class XDRState {
|
||||
XDRBuffer buf;
|
||||
|
||||
protected:
|
||||
JSPrincipals *principals;
|
||||
JSPrincipals *originPrincipals;
|
||||
JSPrincipals *principals_;
|
||||
JSPrincipals *originPrincipals_;
|
||||
|
||||
XDRState(JSContext *cx)
|
||||
: buf(cx), principals(NULL), originPrincipals(NULL) {
|
||||
: buf(cx), principals_(NULL), originPrincipals_(NULL) {
|
||||
}
|
||||
|
||||
public:
|
||||
@ -110,6 +110,10 @@ class XDRState {
|
||||
return buf.cx();
|
||||
}
|
||||
|
||||
JSPrincipals *originPrincipals() const {
|
||||
return originPrincipals_;
|
||||
}
|
||||
|
||||
bool codeUint8(uint8_t *n) {
|
||||
if (mode == XDR_ENCODE) {
|
||||
uint8_t *ptr = buf.write(sizeof *n);
|
||||
@ -210,8 +214,6 @@ class XDRState {
|
||||
|
||||
bool codeFunction(JS::MutableHandleObject objp);
|
||||
bool codeScript(MutableHandleScript scriptp);
|
||||
|
||||
void initScriptPrincipals(JSScript *script);
|
||||
};
|
||||
|
||||
class XDREncoder : public XDRState<XDR_ENCODE> {
|
||||
|
Loading…
Reference in New Issue
Block a user