Пример #1
0
bool
TypeInferenceOracle::analyzeTypesForInlinableCallees(JSContext *cx, StackTypeSet *calleeTypes,
                                                     Vector<JSScript*> &seen)
{
    if (calleeTypes->unknownObject())
        return true;

    size_t count = calleeTypes->getObjectCount();
    for (size_t i = 0; i < count; i++) {
        JSScript *script;
        if (JSObject *singleton = calleeTypes->getSingleObject(i)) {
            if (!singleton->isFunction() || !singleton->toFunction()->hasScript())
                continue;
            script = singleton->toFunction()->nonLazyScript();
        } else if (TypeObject *type = calleeTypes->getTypeObject(i)) {
            JSFunction *fun = type->interpretedFunction;
            if (!fun || !fun->hasScript())
                continue;
            script = fun->nonLazyScript();
        } else {
            continue;
        }

        if (!analyzeTypesForInlinableCallees(cx, script, seen))
            return false;

        // The contents of type sets can change after analyzing the types in a
        // script. Make a sanity check to ensure the set is ok to keep using.
        if (calleeTypes->unknownObject() || calleeTypes->getObjectCount() != count)
            break;
    }

    return true;
}
Пример #2
0
static bool
IsRelazifiableFunction(JSContext *cx, unsigned argc, Value *vp)
{
    CallArgs args = CallArgsFromVp(argc, vp);
    if (argc != 1) {
        JS_ReportError(cx, "The function takes exactly one argument.");
        return false;
    }
    if (!args[0].isObject() ||
        !args[0].toObject().is<JSFunction>())
    {
        JS_ReportError(cx, "The first argument should be a function.");
        return true;
    }

    JSFunction *fun = &args[0].toObject().as<JSFunction>();
    args.rval().setBoolean(fun->hasScript() && fun->nonLazyScript()->isRelazifiable());
    return true;
}
Пример #3
0
static void
MarkFunctionsWithinEvalScript(JSScript *script)
{
    // Mark top level functions in an eval script as being within an eval and,
    // if applicable, inside a with statement.

    if (!script->hasObjects())
        return;

    ObjectArray *objects = script->objects();
    size_t start = script->innerObjectsStart();

    for (size_t i = start; i < objects->length; i++) {
        JSObject *obj = objects->vector[i];
        if (obj->is<JSFunction>()) {
            JSFunction *fun = &obj->as<JSFunction>();
            if (fun->hasScript())
                fun->nonLazyScript()->setDirectlyInsideEval();
            else if (fun->isInterpretedLazy())
                fun->lazyScript()->setDirectlyInsideEval();
        }
    }
}