}
-void GlobalContext::init(ExecutionEngine *eng)
+void GlobalContext::initGlobalContext(ExecutionEngine *eng)
{
- type = Type_GlobalContext;
- strictMode = false;
- marked = false;
+ initBaseContext(Type_GlobalContext, eng);
thisObject = Value::fromObject(eng->globalObject);
- engine = eng;
- outer = 0;
- lookups = 0;
global = 0;
}
-void WithContext::init(ExecutionContext *p, Object *with)
+void WithContext::initWithContext(ExecutionContext *p, Object *with)
{
- type = Type_WithContext;
- strictMode = false;
- marked = false;
+ initBaseContext(Type_WithContext, p->engine);
thisObject = p->thisObject;
- engine = p->engine;
outer = p;
lookups = p->lookups;
withObject = with;
}
-void CatchContext::init(ExecutionContext *p, String *exceptionVarName, const Value &exceptionValue)
+void CatchContext::initCatchContext(ExecutionContext *p, String *exceptionVarName, const Value &exceptionValue)
{
- type = Type_CatchContext;
+ initBaseContext(Type_CatchContext, p->engine);
strictMode = p->strictMode;
- marked = false;
thisObject = p->thisObject;
- engine = p->engine;
outer = p;
lookups = p->lookups;
this->exceptionValue = exceptionValue;
}
-void CallContext::initCallContext(ExecutionEngine *engine)
+void CallContext::initCallContext(ExecutionEngine *engine, FunctionObject *function, Value *_arguments, int _argumentCount, const Value &_thisObject)
{
- type = Type_CallContext;
+ initBaseContext(Type_CallContext, engine);
+
+ this->function = function;
+ this->arguments = _arguments;
+ this->argumentCount = _argumentCount;
+ this->thisObject = _thisObject;
+
strictMode = function->strictMode;
marked = false;
- this->engine = engine;
outer = function->scope;
#ifndef QT_NO_DEBUG
assert(outer->next != (ExecutionContext *)0x1);
Lookup *lookups;
ExecutionContext *next; // used in the GC
+ void initBaseContext(Type type, ExecutionEngine *engine)
+ {
+ this->type = type;
+ strictMode = false;
+ marked = false;
+ thisObject = Value::undefinedValue();
+ this->engine = engine;
+ parent = 0;
+ outer = 0;
+ lookups = 0;
+ }
+
String * const *formals() const;
unsigned int formalCount() const;
String * const *variables() const;
struct SimpleCallContext : public ExecutionContext
{
+ void initSimpleCallContext(ExecutionEngine *engine)
+ {
+ initBaseContext(Type_SimpleCallContext, engine);
+ function = 0;
+ arguments = 0;
+ argumentCount = 0;
+ }
FunctionObject *function;
Value *arguments;
unsigned int argumentCount;
struct CallContext : public SimpleCallContext
{
- void initCallContext(QV4::ExecutionEngine *engine);
+ void initCallContext(QV4::ExecutionEngine *engine, FunctionObject *function, Value *args, int argc,
+ const Value &thisObject);
bool needsOwnArguments() const;
Value *locals;
struct GlobalContext : public ExecutionContext
{
- void init(ExecutionEngine *e);
+ void initGlobalContext(ExecutionEngine *e);
Object *global;
};
struct CatchContext : public ExecutionContext
{
- void init(ExecutionContext *p, String *exceptionVarName, const QV4::Value &exceptionValue);
+ void initCatchContext(ExecutionContext *p, String *exceptionVarName, const QV4::Value &exceptionValue);
String *exceptionVarName;
Value exceptionValue;
{
Object *withObject;
- void init(ExecutionContext *p, Object *with);
+ void initWithContext(ExecutionContext *p, Object *with);
};
inline Value ExecutionContext::argument(unsigned int index)
rootContext = static_cast<GlobalContext *>(memoryManager->allocContext(sizeof(GlobalContext)));
current = rootContext;
current->parent = 0;
- rootContext->init(this);
+ rootContext->initGlobalContext(this);
}
InternalClass *ExecutionEngine::newClass(const InternalClass &other)
{
ExecutionContext *p = current;
WithContext *w = static_cast<WithContext *>(memoryManager->allocContext(sizeof(WithContext)));
+ w->initWithContext(p, with);
w->parent = current;
current = w;
-
- w->init(p, with);
return w;
}
{
ExecutionContext *p = current;
CatchContext *c = static_cast<CatchContext *>(memoryManager->allocContext(sizeof(CatchContext)));
+ c->initCatchContext(p, exceptionVarName, exceptionValue);
c->parent = current;
current = c;
-
- c->init(p, exceptionVarName, exceptionValue);
return c;
}
CallContext *ExecutionEngine::newCallContext(FunctionObject *f, const Value &thisObject, Value *args, int argc)
{
CallContext *c = static_cast<CallContext *>(memoryManager->allocContext(requiredMemoryForExecutionContect(f, argc)));
+
+ c->initCallContext(this, f, args, argc, thisObject);
c->parent = current;
current = c;
- c->function = f;
- c->thisObject = thisObject;
- c->arguments = args;
- c->argumentCount = argc;
- c->initCallContext(this);
-
return c;
}
c->next = (CallContext *)0x1;
#endif
}
+
+ c->initCallContext(this, f, args, argc, thisObject);
c->parent = current;
current = c;
- c->function = f;
- c->thisObject = thisObject;
- c->arguments = args;
- c->argumentCount = argc;
- c->initCallContext(this);
-
return c;
}
{
BuiltinFunctionOld *f = static_cast<BuiltinFunctionOld *>(that);
SimpleCallContext ctx;
- ctx.type = ExecutionContext::Type_SimpleCallContext;
+ ctx.initSimpleCallContext(f->scope->engine);
ctx.strictMode = f->scope->strictMode; // ### needed? scope or parent context?
- ctx.marked = false;
ctx.thisObject = thisObject;
- ctx.engine = f->scope->engine;
ctx.arguments = args;
ctx.argumentCount = argc;
context->engine->pushContext(&ctx);
T *o = reinterpret_cast<T *>(thisO);
QV4::SimpleCallContext ctx;
- ctx.type = ExecutionContext::Type_SimpleCallContext;
+ ctx.initSimpleCallContext(context->engine);
ctx.strictMode = true;
- ctx.marked = false;
ctx.thisObject = thisObject;
- ctx.engine = context->engine;
ctx.arguments = args;
ctx.argumentCount = argc;
context->engine->pushContext(&ctx);
result = that->m_functionTemplate->m_callback(arguments);
else if (that->m_functionTemplate->m_newCallback) {
QV4::SimpleCallContext ctx;
- ctx.type = ExecutionContext::Type_SimpleCallContext;
+ ctx.initSimpleCallContext(context->engine);
ctx.strictMode = true;
- ctx.marked = false;
ctx.thisObject = thisObject;
- ctx.engine = context->engine;
ctx.arguments = args;
ctx.argumentCount = argc;
context->engine->pushContext(&ctx);
result = that->m_functionTemplate->m_callback(arguments);
else if (that->m_functionTemplate->m_newCallback) {
QV4::SimpleCallContext ctx;
- ctx.type = ExecutionContext::Type_SimpleCallContext;
+ ctx.initSimpleCallContext(context->engine);
ctx.strictMode = true;
- ctx.marked = false;
- ctx.thisObject = QV4::Value::undefinedValue();
- ctx.engine = context->engine;
ctx.arguments = args;
ctx.argumentCount = argc;
context->engine->pushContext(&ctx);
if (!o.asObject())
return QV4::Value::fromObject(m_v4Engine->newArrayObject());
QV4::SimpleCallContext ctx;
- ctx.type = QV4::ExecutionContext::Type_SimpleCallContext;
+ ctx.initSimpleCallContext(m_v4Engine);
QV4::Value args = o;
ctx.arguments = &args;
ctx.argumentCount = 1;
- ctx.engine = m_v4Engine;
m_v4Engine->pushContext(&ctx);
QV4::Value result = QV4::ObjectPrototype::method_getOwnPropertyNames(&ctx);
m_v4Engine->popContext();