Bug 839376 (part 3) - Some low-hanging exact rooting fruit. sfink.

--HG--
extra : rebase_source : 1d236895915f9474fd8e50c399bf2cd8139a6b5f
This commit is contained in:
Nicholas Nethercote 2013-02-11 14:04:25 -08:00
parent bf0a2be76d
commit 4ede79f464
9 changed files with 17 additions and 19 deletions

View File

@ -163,7 +163,8 @@ EvalKernel(JSContext *cx, const CallArgs &args, EvalType evalType, AbstractFrame
JS_ASSERT_IF(evalType == INDIRECT_EVAL, scopeobj->isGlobal());
AssertInnerizedScopeChain(cx, *scopeobj);
if (!scopeobj->global().isRuntimeCodeGenEnabled(cx)) {
Rooted<GlobalObject*> scopeObjGlobal(cx, &scopeobj->global());
if (!GlobalObject::isRuntimeCodeGenEnabled(cx, scopeObjGlobal)) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CSP_BLOCKED_EVAL);
return false;
}

View File

@ -1418,7 +1418,7 @@ ParallelArrayObject::scatter(JSContext *cx, CallArgs args)
return false;
// The default value is optional and defaults to undefined.
Value defaultValue;
RootedValue defaultValue(cx);
if (args.length() >= 2)
defaultValue = args[1];
else

View File

@ -377,7 +377,6 @@ js::Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib)
if (!JSString::validateLength(cx, length))
return NULL;
UnrootedAtom atom;
static const unsigned ATOMIZE_BUF_MAX = 32;
if (length < ATOMIZE_BUF_MAX) {
/*
@ -390,15 +389,13 @@ js::Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib)
jschar inflated[ATOMIZE_BUF_MAX];
size_t inflatedLength = ATOMIZE_BUF_MAX - 1;
InflateStringToBuffer(cx, bytes, length, inflated, &inflatedLength);
atom = AtomizeAndCopyStableChars<CanGC>(cx, inflated, inflatedLength, ib);
} else {
jschar *tbcharsZ = InflateString(cx, bytes, &length);
if (!tbcharsZ)
return UnrootedAtom();
atom = AtomizeAndTakeOwnership(cx, StableCharPtr(tbcharsZ, length), length, ib);
return AtomizeAndCopyStableChars<CanGC>(cx, inflated, inflatedLength, ib);
}
return atom;
jschar *tbcharsZ = InflateString(cx, bytes, &length);
if (!tbcharsZ)
return UnrootedAtom();
return AtomizeAndTakeOwnership(cx, StableCharPtr(tbcharsZ, length), length, ib);
}
template <AllowGC allowGC>

View File

@ -1230,7 +1230,7 @@ js::Function(JSContext *cx, unsigned argc, Value *vp)
/* Block this call if security callbacks forbid it. */
Rooted<GlobalObject*> global(cx, &args.callee().global());
if (!global->isRuntimeCodeGenEnabled(cx)) {
if (!GlobalObject::isRuntimeCodeGenEnabled(cx, global)) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CSP_BLOCKED_FUNCTION);
return false;
}

View File

@ -1534,7 +1534,7 @@ FindStartPC(JSContext *cx, ScriptFrameIter &iter, int spindex, int skipStackHits
}
static bool
DecompileExpressionFromStack(JSContext *cx, int spindex, int skipStackHits, Value v, char **res)
DecompileExpressionFromStack(JSContext *cx, int spindex, int skipStackHits, HandleValue v, char **res)
{
AssertCanGC();
JS_ASSERT(spindex < 0 ||

View File

@ -481,17 +481,17 @@ GlobalObject::initStandardClasses(JSContext *cx, Handle<GlobalObject*> global)
true;
}
bool
GlobalObject::isRuntimeCodeGenEnabled(JSContext *cx)
/* static */ bool
GlobalObject::isRuntimeCodeGenEnabled(JSContext *cx, Handle<GlobalObject*> global)
{
HeapSlot &v = getSlotRef(RUNTIME_CODEGEN_ENABLED);
HeapSlot &v = global->getSlotRef(RUNTIME_CODEGEN_ENABLED);
if (v.isUndefined()) {
/*
* If there are callbacks, make sure that the CSP callback is installed
* and that it permits runtime code generation, then cache the result.
*/
JSCSPEvalChecker allows = cx->runtime->securityCallbacks->contentSecurityPolicyAllows;
v.set(this, HeapSlot::Slot, RUNTIME_CODEGEN_ENABLED, BooleanValue(!allows || allows(cx)));
v.set(global, HeapSlot::Slot, RUNTIME_CODEGEN_ENABLED, BooleanValue(!allows || allows(cx)));
}
return !v.isFalse();
}

View File

@ -420,7 +420,7 @@ class GlobalObject : public JSObject
return getSlot(PROTO_GETTER);
}
bool isRuntimeCodeGenEnabled(JSContext *cx);
static bool isRuntimeCodeGenEnabled(JSContext *cx, Handle<GlobalObject*> global);
const Value &getOriginalEval() const {
JS_ASSERT(getSlot(EVAL).isObject());

View File

@ -699,7 +699,7 @@ RegExpCompartment::get(JSContext *cx, JSAtom *source, RegExpFlag flags, RegExpGu
}
bool
RegExpCompartment::get(JSContext *cx, JSAtom *atom, JSString *opt, RegExpGuard *g)
RegExpCompartment::get(JSContext *cx, HandleAtom atom, JSString *opt, RegExpGuard *g)
{
RegExpFlag flags = RegExpFlag(0);
if (opt && !ParseRegExpFlags(cx, opt, &flags))

View File

@ -278,7 +278,7 @@ class RegExpCompartment
bool get(JSContext *cx, JSAtom *source, RegExpFlag flags, RegExpGuard *g);
/* Like 'get', but compile 'maybeOpt' (if non-null). */
bool get(JSContext *cx, JSAtom *source, JSString *maybeOpt, RegExpGuard *g);
bool get(JSContext *cx, HandleAtom source, JSString *maybeOpt, RegExpGuard *g);
size_t sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf);
};