From c03e13b22a31aa624f0f6bdaeccd16af2fe54a54 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 23 May 2010 17:14:59 -0700 Subject: [PATCH] Avoid resolving while looking up constants during parsing (bug 561923 part 2, r=brendan). --- js/src/jsemit.cpp | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/js/src/jsemit.cpp b/js/src/jsemit.cpp index 5e836edfdd..ca057927e9 100644 --- a/js/src/jsemit.cpp +++ b/js/src/jsemit.cpp @@ -65,8 +65,9 @@ #include "jsregexp.h" #include "jsscan.h" #include "jsscope.h" +#include "jsscopeinlines.h" #include "jsscript.h" -#include "jsautooplen.h" +#include "jsautooplen.h" // generated headers last #include "jsstaticcheck.h" /* Allocation chunk counts, must be powers of two in general. */ @@ -1612,14 +1613,6 @@ js_LexicalLookup(JSTreeContext *tc, JSAtom *atom, jsint *slotp, JSStmtInfo *stmt } /* - * Check if the attributes describe a property holding a compile-time constant - * or a permanent, read-only property without a getter. - */ -#define IS_CONSTANT_PROPERTY(attrs) \ - (((attrs) & (JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_GETTER)) == \ - (JSPROP_READONLY | JSPROP_PERMANENT)) - -/* * The function sets vp to JSVAL_HOLE when the atom does not corresponds to a * name defining a constant. */ @@ -1627,11 +1620,8 @@ static JSBool LookupCompileTimeConstant(JSContext *cx, JSCodeGenerator *cg, JSAtom *atom, jsval *vp) { - JSBool ok; JSStmtInfo *stmt; - JSObject *obj, *objbox; - JSProperty *prop; - uintN attrs; + JSObject *obj; /* * Chase down the cg stack, but only until we reach the outermost cg. @@ -1640,7 +1630,7 @@ LookupCompileTimeConstant(JSContext *cx, JSCodeGenerator *cg, JSAtom *atom, */ *vp = JSVAL_HOLE; do { - if (cg->inFunction() && cg->compileAndGo()) { + if (cg->inFunction() || cg->compileAndGo()) { /* XXX this will need revising if 'const' becomes block-scoped. */ stmt = js_LexicalLookup(cg, atom, NULL); if (stmt) @@ -1665,27 +1655,25 @@ LookupCompileTimeConstant(JSContext *cx, JSCodeGenerator *cg, JSAtom *atom, } else { JS_ASSERT(cg->compileAndGo()); obj = cg->scopeChain; - ok = obj->lookupProperty(cx, ATOM_TO_JSID(atom), &objbox, &prop); - if (!ok) - return JS_FALSE; - if (objbox == obj) { + + JS_LOCK_OBJ(cx, obj); + JSScope *scope = obj->scope(); + JSScopeProperty *sprop = scope->lookup(ATOM_TO_JSID(atom)); + if (sprop) { /* * We're compiling code that will be executed immediately, * not re-executed against a different scope chain and/or * variable object. Therefore we can get constant values * from our variable object here. */ - ok = obj->getAttributes(cx, ATOM_TO_JSID(atom), prop, &attrs); - if (ok && IS_CONSTANT_PROPERTY(attrs)) { - ok = obj->getProperty(cx, ATOM_TO_JSID(atom), vp); - JS_ASSERT_IF(ok, *vp != JSVAL_HOLE); + if (!sprop->writable() && !sprop->configurable() && + sprop->hasDefaultGetter() && SPROP_HAS_VALID_SLOT(sprop, scope)) { + *vp = obj->lockedGetSlot(sprop->slot); } } - if (prop) - objbox->dropProperty(cx, prop); - if (!ok) - return JS_FALSE; - if (prop) + JS_UNLOCK_SCOPE(cx, scope); + + if (sprop) break; } } -- 2.11.4.GIT