From e2834ef56da871d5be83eb9f072cf06f4525b15c Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Wed, 22 Dec 2010 21:06:08 -0500 Subject: [PATCH] Require JSFunction::inStrictMode() callers to check for isInterpreted() first, since most already know that the function in question is interpreted. r=dmandelin --- js/src/jsfun.cpp | 13 ++++++++----- js/src/jsfun.h | 1 + js/src/jsfuninlines.h | 2 +- js/src/jstracer.cpp | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index cda2986953d..92bd7bb433e 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -1580,10 +1580,13 @@ fun_getProperty(JSContext *cx, JSObject *obj, jsid id, Value *vp) /* Censor the caller if it is from another compartment. */ if (caller.getCompartment() != cx->compartment) { vp->setNull(); - } else if (caller.isFunction() && caller.getFunctionPrivate()->inStrictMode()) { - JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL, - JSMSG_CALLER_IS_STRICT); - return false; + } else if (caller.isFunction()) { + JSFunction *callerFun = caller.getFunctionPrivate(); + if (callerFun->isInterpreted() && callerFun->inStrictMode()) { + JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL, + JSMSG_CALLER_IS_STRICT); + return false; + } } } break; @@ -1753,7 +1756,7 @@ fun_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags, PropertyOp getter, setter; uintN attrs = JSPROP_PERMANENT; - if (fun->inStrictMode() || obj->isBoundFunction()) { + if (fun->isInterpreted() ? fun->inStrictMode() : obj->isBoundFunction()) { JSObject *throwTypeError = obj->getThrowTypeError(); getter = CastAsPropertyOp(throwTypeError); diff --git a/js/src/jsfun.h b/js/src/jsfun.h index 3ed967398d4..6209adf2b6f 100644 --- a/js/src/jsfun.h +++ b/js/src/jsfun.h @@ -180,6 +180,7 @@ struct JSFunction : public JSObject_Slots2 bool isFunctionPrototype() const { return flags & JSFUN_PROTOTYPE; } + /* Returns the strictness of this function, which must be interpreted. */ inline bool inStrictMode() const; uintN countVars() const { diff --git a/js/src/jsfuninlines.h b/js/src/jsfuninlines.h index 9526ea7b880..4cbb744b236 100644 --- a/js/src/jsfuninlines.h +++ b/js/src/jsfuninlines.h @@ -46,7 +46,7 @@ inline bool JSFunction::inStrictMode() const { - return isInterpreted() && u.i.script->strictModeCode; + return script()->strictModeCode; } #endif /* jsfuninlines_h___ */ diff --git a/js/src/jstracer.cpp b/js/src/jstracer.cpp index fb3d1bc6632..c5d30f2f9be 100644 --- a/js/src/jstracer.cpp +++ b/js/src/jstracer.cpp @@ -9970,7 +9970,7 @@ TraceRecorder::getThis(LIns*& this_ins) JS_ASSERT(fp->callee().getGlobal() == globalObj); Value& thisv = fp->thisValue(); - if (fp->fun()->inStrictMode() || thisv.isObject()) { + if (thisv.isObject() || fp->fun()->inStrictMode()) { /* * fp->thisValue() has already been computed. Since the * type-specialization of traces distinguishes between computed and