mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 969786: Add an 'introduction script' compilation option to ReadOnlyCompileOptions, OwningCompileOptions, and CompileOptions. r=sfink
This commit is contained in:
parent
7dcc0af678
commit
bef90394e6
@ -320,7 +320,7 @@ EvalKernel(JSContext *cx, const CallArgs &args, EvalType evalType, AbstractFrame
|
||||
.setNoScriptRval(false)
|
||||
.setPrincipals(principals)
|
||||
.setOriginPrincipals(originPrincipals)
|
||||
.setIntroductionInfo(introducerFilename, "eval", lineno, pcOffset);
|
||||
.setIntroductionInfo(introducerFilename, "eval", lineno, script, pcOffset);
|
||||
JSScript *compiled = frontend::CompileScript(cx, &cx->tempLifoAlloc(),
|
||||
scopeobj, callerScript, options,
|
||||
chars.get(), length, flatStr, staticLevel);
|
||||
@ -392,7 +392,7 @@ js::DirectEvalStringFromIon(JSContext *cx,
|
||||
.setNoScriptRval(false)
|
||||
.setPrincipals(principals)
|
||||
.setOriginPrincipals(originPrincipals)
|
||||
.setIntroductionInfo(introducerFilename, "eval", lineno, pcOffset);
|
||||
.setIntroductionInfo(introducerFilename, "eval", lineno, script, pcOffset);
|
||||
JSScript *compiled = frontend::CompileScript(cx, &cx->tempLifoAlloc(),
|
||||
scopeobj, callerScript, options,
|
||||
chars.get(), length, flatStr, staticLevel);
|
||||
|
@ -4326,7 +4326,8 @@ JS::OwningCompileOptions::OwningCompileOptions(JSContext *cx)
|
||||
: ReadOnlyCompileOptions(),
|
||||
runtime(GetRuntime(cx)),
|
||||
elementRoot(cx),
|
||||
elementAttributeNameRoot(cx)
|
||||
elementAttributeNameRoot(cx),
|
||||
introductionScriptRoot(cx)
|
||||
{
|
||||
}
|
||||
|
||||
@ -4352,6 +4353,7 @@ JS::OwningCompileOptions::copy(JSContext *cx, const ReadOnlyCompileOptions &rhs)
|
||||
setOriginPrincipals(rhs.originPrincipals());
|
||||
setElement(rhs.element());
|
||||
setElementAttributeName(rhs.elementAttributeName());
|
||||
setIntroductionScript(rhs.introductionScript());
|
||||
|
||||
return (setFileAndLine(cx, rhs.filename(), rhs.lineno) &&
|
||||
setSourceMapURL(cx, rhs.sourceMapURL()) &&
|
||||
@ -4428,11 +4430,23 @@ JS::OwningCompileOptions::wrap(JSContext *cx, JSCompartment *compartment)
|
||||
if (!compartment->wrap(cx, elementAttributeNameRoot.address()))
|
||||
return false;
|
||||
}
|
||||
|
||||
// There is no equivalent of cross-compartment wrappers for scripts. If
|
||||
// the introduction script would be in a different compartment from the
|
||||
// compiled code, we would be creating a cross-compartment script
|
||||
// reference, which would be bogus. In that case, just don't bother to
|
||||
// retain the introduction script.
|
||||
if (introductionScriptRoot) {
|
||||
if (introductionScriptRoot->compartment() != compartment)
|
||||
introductionScriptRoot = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
JS::CompileOptions::CompileOptions(JSContext *cx, JSVersion version)
|
||||
: ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx)
|
||||
: ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx),
|
||||
introductionScriptRoot(cx)
|
||||
{
|
||||
this->version = (version != JSVERSION_UNKNOWN) ? version : cx->findVersion();
|
||||
|
||||
@ -4453,6 +4467,17 @@ JS::CompileOptions::wrap(JSContext *cx, JSCompartment *compartment)
|
||||
if (!compartment->wrap(cx, elementAttributeNameRoot.address()))
|
||||
return false;
|
||||
}
|
||||
|
||||
// There is no equivalent of cross-compartment wrappers for scripts. If
|
||||
// the introduction script would be in a different compartment from the
|
||||
// compiled code, we would be creating a cross-compartment script
|
||||
// reference, which would be bogus. In that case, just don't bother to
|
||||
// retain the introduction script.
|
||||
if (introductionScriptRoot) {
|
||||
if (introductionScriptRoot->compartment() != compartment)
|
||||
introductionScriptRoot = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3511,6 +3511,7 @@ class JS_FRIEND_API(ReadOnlyCompileOptions)
|
||||
const jschar *sourceMapURL() const { return sourceMapURL_; }
|
||||
virtual JSObject *element() const = 0;
|
||||
virtual JSString *elementAttributeName() const = 0;
|
||||
virtual JSScript *introductionScript() const = 0;
|
||||
|
||||
// POD options.
|
||||
JSVersion version;
|
||||
@ -3568,6 +3569,7 @@ class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions
|
||||
JSRuntime *runtime;
|
||||
PersistentRootedObject elementRoot;
|
||||
PersistentRootedString elementAttributeNameRoot;
|
||||
PersistentRootedScript introductionScriptRoot;
|
||||
|
||||
public:
|
||||
// A minimal constructor, for use with OwningCompileOptions::copy. This
|
||||
@ -3579,6 +3581,7 @@ class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions
|
||||
|
||||
JSObject *element() const MOZ_OVERRIDE { return elementRoot; }
|
||||
JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; }
|
||||
JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; }
|
||||
|
||||
// Set this to a copy of |rhs|. Return false on OOM.
|
||||
bool copy(JSContext *cx, const ReadOnlyCompileOptions &rhs);
|
||||
@ -3599,6 +3602,10 @@ class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions
|
||||
elementAttributeNameRoot = p;
|
||||
return *this;
|
||||
}
|
||||
OwningCompileOptions &setIntroductionScript(JSScript *s) {
|
||||
introductionScriptRoot = s;
|
||||
return *this;
|
||||
}
|
||||
OwningCompileOptions &setPrincipals(JSPrincipals *p) {
|
||||
if (p) JS_HoldPrincipals(p);
|
||||
if (principals_) JS_DropPrincipals(runtime, principals_);
|
||||
@ -3626,12 +3633,13 @@ class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions
|
||||
OwningCompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; }
|
||||
OwningCompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; }
|
||||
bool setIntroductionInfo(JSContext *cx, const char *introducerFn, const char *intro,
|
||||
unsigned line, uint32_t offset)
|
||||
unsigned line, JSScript *script, uint32_t offset)
|
||||
{
|
||||
if (!setIntroducerFilename(cx, introducerFn))
|
||||
return false;
|
||||
introductionType = intro;
|
||||
introductionLineno = line;
|
||||
introductionScriptRoot = script;
|
||||
introductionOffset = offset;
|
||||
hasIntroductionInfo = true;
|
||||
return true;
|
||||
@ -3651,11 +3659,13 @@ class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOpti
|
||||
{
|
||||
RootedObject elementRoot;
|
||||
RootedString elementAttributeNameRoot;
|
||||
RootedScript introductionScriptRoot;
|
||||
|
||||
public:
|
||||
explicit CompileOptions(JSContext *cx, JSVersion version = JSVERSION_UNKNOWN);
|
||||
CompileOptions(js::ContextFriendFields *cx, const ReadOnlyCompileOptions &rhs)
|
||||
: ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx)
|
||||
: ReadOnlyCompileOptions(), elementRoot(cx), elementAttributeNameRoot(cx),
|
||||
introductionScriptRoot(cx)
|
||||
{
|
||||
copyPODOptions(rhs);
|
||||
|
||||
@ -3665,10 +3675,12 @@ class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOpti
|
||||
sourceMapURL_ = rhs.sourceMapURL();
|
||||
elementRoot = rhs.element();
|
||||
elementAttributeNameRoot = rhs.elementAttributeName();
|
||||
introductionScriptRoot = rhs.introductionScript();
|
||||
}
|
||||
|
||||
JSObject *element() const MOZ_OVERRIDE { return elementRoot; }
|
||||
JSString *elementAttributeName() const MOZ_OVERRIDE { return elementAttributeNameRoot; }
|
||||
JSScript *introductionScript() const MOZ_OVERRIDE { return introductionScriptRoot; }
|
||||
|
||||
CompileOptions &setFile(const char *f) { filename_ = f; return *this; }
|
||||
CompileOptions &setLine(unsigned l) { lineno = l; return *this; }
|
||||
@ -3681,6 +3693,10 @@ class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOpti
|
||||
elementAttributeNameRoot = p;
|
||||
return *this;
|
||||
}
|
||||
CompileOptions &setIntroductionScript(JSScript *s) {
|
||||
introductionScriptRoot = s;
|
||||
return *this;
|
||||
}
|
||||
CompileOptions &setPrincipals(JSPrincipals *p) {
|
||||
principals_ = p;
|
||||
return *this;
|
||||
@ -3704,11 +3720,12 @@ class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOpti
|
||||
CompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; }
|
||||
CompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; }
|
||||
CompileOptions &setIntroductionInfo(const char *introducerFn, const char *intro,
|
||||
unsigned line, uint32_t offset)
|
||||
unsigned line, JSScript *script, uint32_t offset)
|
||||
{
|
||||
introducerFilename_ = introducerFn;
|
||||
introductionType = intro;
|
||||
introductionLineno = line;
|
||||
introductionScriptRoot = script;
|
||||
introductionOffset = offset;
|
||||
hasIntroductionInfo = true;
|
||||
return *this;
|
||||
|
@ -1532,7 +1532,7 @@ FunctionConstructor(JSContext *cx, unsigned argc, Value *vp, GeneratorKind gener
|
||||
.setFileAndLine(filename, 1)
|
||||
.setNoScriptRval(false)
|
||||
.setCompileAndGo(true)
|
||||
.setIntroductionInfo(introducerFilename, introductionType, lineno, pcOffset);
|
||||
.setIntroductionInfo(introducerFilename, introductionType, lineno, script, pcOffset);
|
||||
|
||||
unsigned n = args.length() ? args.length() - 1 : 0;
|
||||
if (n > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user