Bug 751818 - Remove DefineGlobal and lots of related stuff. r=jorendorff.

This commit is contained in:
Nicholas Nethercote
2012-05-09 16:20:11 -07:00
parent e2ca30cccc
commit 1cb595bf7b
8 changed files with 35 additions and 487 deletions

View File

@@ -53,61 +53,14 @@ using namespace js;
using namespace js::frontend;
bool
DefineGlobals(JSContext *cx, GlobalScope &globalScope, JSScript* script)
MarkInnerAndOuterFunctions(JSContext *cx, JSScript* script)
{
Root<JSScript*> root(cx, &script);
HandleObject globalObj = globalScope.globalObj;
/* Define and update global properties. */
for (size_t i = 0; i < globalScope.defs.length(); i++) {
GlobalScope::GlobalDef &def = globalScope.defs[i];
/* Names that could be resolved ahead of time can be skipped. */
if (!def.atom)
continue;
jsid id = AtomToId(def.atom);
Value rval;
if (def.funbox) {
JSFunction *fun = def.funbox->function();
/*
* No need to check for redeclarations or anything, global
* optimizations only take place if the property is not defined.
*/
rval.setObject(*fun);
types::AddTypePropertyId(cx, globalObj, id, rval);
} else {
rval.setUndefined();
}
/*
* Don't update the type information when defining the property for the
* global object, per the consistency rules for type properties. If the
* property is only undefined before it is ever written, we can check
* the global directly during compilation and avoid having to emit type
* checks every time it is accessed in the script.
*/
const Shape *shape =
DefineNativeProperty(cx, globalObj, id, rval, JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_PERMANENT, 0, 0, DNP_SKIP_TYPE);
if (!shape)
return false;
def.knownSlot = shape->slot();
}
Vector<JSScript *, 16> worklist(cx);
if (!worklist.append(script))
return false;
/*
* Recursively walk through all scripts we just compiled. For each script,
* go through all global uses. Each global use indexes into globalScope->defs.
* Use this information to repoint each use to the correct slot in the global
* object.
*/
while (worklist.length()) {
JSScript *outer = worklist.back();
worklist.popBack();
@@ -132,23 +85,12 @@ DefineGlobals(JSContext *cx, GlobalScope &globalScope, JSScript* script)
outer->isOuterFunction = true;
inner->isInnerFunction = true;
}
if (!inner->hasGlobals() && !inner->hasObjects())
if (!inner->hasObjects())
continue;
if (!worklist.append(inner))
return false;
}
}
if (!outer->hasGlobals())
continue;
GlobalSlotArray *globalUses = outer->globals();
uint32_t nGlobalUses = globalUses->length;
for (uint32_t i = 0; i < nGlobalUses; i++) {
uint32_t index = globalUses->vector[i].slot;
JS_ASSERT(index < globalScope.defs.length());
globalUses->vector[i].slot = globalScope.defs[index].knownSlot;
}
}
return true;
@@ -200,7 +142,7 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
RootedVar<JSScript*> script(cx);
GlobalScope globalScope(cx, globalObj, &bce);
GlobalScope globalScope(cx, globalObj);
bce.flags |= tcflags;
bce.setScopeChain(scopeChain);
bce.globalScope = &globalScope;
@@ -328,7 +270,7 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
JS_ASSERT(script->savedCallerFun == savedCallerFun);
if (!DefineGlobals(cx, globalScope, script))
if (!MarkInnerAndOuterFunctions(cx, script))
script = NULL;
out: