delete [] runtimeLookups;
delete [] runtimeRegularExpressions;
free(runtimeClasses);
+ qDeleteAll(runtimeFunctions);
}
QV4::Function *CompilationUnit::linkToEngine(ExecutionEngine *engine)
QV4::Function *vmFunction = _engine->newFunction(irFunction->name ? *irFunction->name : QString());
_irToVM.insert(irFunction, vmFunction);
- if (outer)
- outer->addNestedFunction(vmFunction);
-
foreach (V4IR::Function *function, irFunction->nestedFunctions)
createFunctionMapping(vmFunction, function);
{
engine->functions.remove(engine->functions.indexOf(this));
UnwindHelper::deregisterFunction(this); // ### move to masm compilation unit
-
- Q_ASSERT(!refCount);
- foreach (Function *f, nestedFunctions)
- f->deref();
- if (compilationUnit)
- compilationUnit->deref();
}
void Function::init(CompiledData::CompilationUnit *unit, const CompiledData::Function *function, Value (*codePtr)(ExecutionContext *, const uchar *),
{
Q_ASSERT(!compilationUnit);
compilationUnit = unit;
- compilationUnit->ref();
compiledFunction = function;
code = codePtr;
};
struct Function {
- int refCount;
String *name;
const CompiledData::Function *compiledFunction;
QVector<String *> formals;
QVector<String *> locals;
- QVector<Function *> nestedFunctions;
ExecutionEngine *engine;
Function(ExecutionEngine *engine, String *name)
- : refCount(0)
- , name(name)
+ : name(name)
, compiledFunction(0)
, compilationUnit(0)
, code(0)
void init(CompiledData::CompilationUnit *unit, const CompiledData::Function *function,
Value (*codePtr)(ExecutionContext *, const uchar *), quint32 _codeSize);
- void ref() { ++refCount; }
- void deref() { if (!--refCount) delete this; }
-
- void addNestedFunction(Function *f)
- {
- f->ref();
- nestedFunctions.append(f);
- }
-
inline QString sourceFile() const { return compilationUnit->fileName(); }
inline bool usesArgumentsObject() const { return compiledFunction->flags & CompiledData::Function::UsesArgumentsObject; }
FunctionObject::~FunctionObject()
{
if (function)
- function->deref();
+ function->compilationUnit->deref();
}
Value FunctionObject::newInstance()
{
vtbl = &static_vtbl;
this->function = function;
- this->function->ref();
+ this->function->compilationUnit->ref();
assert(function);
assert(function->code);
{
vtbl = &static_vtbl;
function = f;
- function->ref();
+ function->compilationUnit->ref();
usesArgumentsObject = function->usesArgumentsObject();
needsActivation = function->needsActivation();
defineReadonlyProperty(scope->engine->id_length, Value::fromInt32(1));
QV4::Script script(ctx, code, fn);
script.parseAsBinding = runAsQml;
script.parse();
+ script.function()->compilationUnit->ref();
QV4::Value result = script.run();
if (!result.isUndefined()) {
if (! qgetenv("SHOW_EXIT_VALUE").isEmpty())
std::cout << "exit value: " << qPrintable(result.toString(ctx)->toQString()) << std::endl;
}
+ script.function()->compilationUnit->deref();
} catch (QV4::Exception& ex) {
ex.accept(ctx);
showException(ctx, ex);