~ubuntu-branches/debian/jessie/qtdeclarative-opensource-src/jessie

« back to all changes in this revision

Viewing changes to src/qml/jsruntime/qv4context.cpp

  • Committer: Package Import Robot
  • Author(s): Lisandro Damián Nicanor Pérez Meyer
  • Date: 2014-03-24 21:45:21 UTC
  • mfrom: (8.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20140324214521-ckebji2azn0geinj
Tags: 5.2.1-4
* Upload to unstable.
* Add license to mark_private_symbols.sh and corresponding entry in
  debian/copyright.
* Update symbols files with buildd's logs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
using namespace QV4;
53
53
 
 
54
const ManagedVTable ExecutionContext::static_vtbl =
 
55
{
 
56
    call,
 
57
    construct,
 
58
    markObjects,
 
59
    destroy,
 
60
    0 /*collectDeletables*/,
 
61
    0,
 
62
    0,
 
63
    0,
 
64
    0,
 
65
    0,
 
66
    0,
 
67
    0,
 
68
    0,
 
69
    0,
 
70
    0,
 
71
    isEqualTo,
 
72
    0,
 
73
    "ExecutionContext",
 
74
};
 
75
 
54
76
CallContext *ExecutionContext::newCallContext(FunctionObject *function, CallData *callData)
55
77
{
56
 
    CallContext *c = static_cast<CallContext *>(engine->memoryManager->allocContext(requiredMemoryForExecutionContect(function, callData->argc)));
57
 
 
58
 
    engine->current = c;
59
 
 
60
 
    c->initBaseContext(Type_CallContext, engine, this);
 
78
    CallContext *c = static_cast<CallContext *>(engine->memoryManager->allocManaged(requiredMemoryForExecutionContect(function, callData->argc)));
 
79
    new (c) CallContext(engine, Type_CallContext);
61
80
 
62
81
    c->function = function;
63
82
    c->realArgumentCount = callData->argc;
64
83
 
65
84
    c->strictMode = function->strictMode;
66
 
    c->marked = false;
67
85
    c->outer = function->scope;
68
 
#ifndef QT_NO_DEBUG
69
 
    assert(c->outer->next != (ExecutionContext *)0x1);
70
 
#endif
71
86
 
72
87
    c->activation = 0;
73
88
 
92
107
 
93
108
WithContext *ExecutionContext::newWithContext(ObjectRef with)
94
109
{
95
 
    WithContext *w = static_cast<WithContext *>(engine->memoryManager->allocContext(sizeof(WithContext)));
96
 
    engine->current = w;
97
 
    w->initWithContext(this, with);
 
110
    WithContext *w = new (engine->memoryManager) WithContext(engine, with);
98
111
    return w;
99
112
}
100
113
 
101
114
CatchContext *ExecutionContext::newCatchContext(const StringRef exceptionVarName, const ValueRef exceptionValue)
102
115
{
103
 
    CatchContext *c = static_cast<CatchContext *>(engine->memoryManager->allocContext(sizeof(CatchContext)));
104
 
    engine->current = c;
105
 
    c->initCatchContext(this, exceptionVarName, exceptionValue);
 
116
    CatchContext *c = new (engine->memoryManager) CatchContext(engine, exceptionVarName, exceptionValue);
106
117
    return c;
107
118
}
108
119
 
109
120
CallContext *ExecutionContext::newQmlContext(FunctionObject *f, ObjectRef qml)
110
121
{
111
 
    CallContext *c = static_cast<CallContext *>(engine->memoryManager->allocContext(requiredMemoryForExecutionContect(f, 0)));
112
 
 
113
 
    engine->current = c;
114
 
    c->initQmlContext(this, qml, f);
115
 
 
 
122
    CallContext *c = static_cast<CallContext *>(engine->memoryManager->allocManaged(requiredMemoryForExecutionContect(f, 0)));
 
123
    new (c) CallContext(engine, qml, f);
116
124
    return c;
117
125
}
118
126
 
149
157
    if (type < Type_SimpleCallContext)
150
158
        return 0;
151
159
    QV4::FunctionObject *f = static_cast<const CallContext *>(this)->function;
152
 
    return f ? f->formalParameterList : 0;
 
160
    return (f && f->function) ? f->function->internalClass->nameMap.constData() : 0;
153
161
}
154
162
 
155
163
unsigned int ExecutionContext::formalCount() const
165
173
    if (type < Type_SimpleCallContext)
166
174
        return 0;
167
175
    QV4::FunctionObject *f = static_cast<const CallContext *>(this)->function;
168
 
    return f ? f->varList : 0;
 
176
    return (f && f->function) ? f->function->internalClass->nameMap.constData() + f->function->nArguments : 0;
169
177
}
170
178
 
171
179
unsigned int ExecutionContext::variableCount() const
177
185
}
178
186
 
179
187
 
180
 
void GlobalContext::initGlobalContext(ExecutionEngine *eng)
 
188
GlobalContext::GlobalContext(ExecutionEngine *eng)
 
189
    : ExecutionContext(eng, Type_GlobalContext)
181
190
{
182
 
    initBaseContext(Type_GlobalContext, eng, /*parentContext*/0);
183
 
    callData = reinterpret_cast<CallData *>(this + 1);
184
 
    callData->tag = QV4::Value::_Integer_Type;
185
 
    callData->argc = 0;
186
 
    callData->thisObject = eng->globalObject;
187
 
    global = 0;
 
191
    global = eng->globalObject;
188
192
}
189
193
 
190
 
void WithContext::initWithContext(ExecutionContext *p, ObjectRef with)
 
194
WithContext::WithContext(ExecutionEngine *engine, ObjectRef with)
 
195
    : ExecutionContext(engine, Type_WithContext)
191
196
{
192
 
    initBaseContext(Type_WithContext, p->engine, p);
193
 
    callData = p->callData;
194
 
    outer = p;
195
 
    lookups = p->lookups;
196
 
    compilationUnit = p->compilationUnit;
 
197
    callData = parent->callData;
 
198
    outer = parent;
 
199
    lookups = parent->lookups;
 
200
    compilationUnit = parent->compilationUnit;
197
201
 
198
202
    withObject = with.getPointer();
199
203
}
200
204
 
201
 
void CatchContext::initCatchContext(ExecutionContext *p, const StringRef exceptionVarName, const ValueRef exceptionValue)
 
205
CatchContext::CatchContext(ExecutionEngine *engine, const StringRef exceptionVarName, const ValueRef exceptionValue)
 
206
    : ExecutionContext(engine, Type_CatchContext)
202
207
{
203
 
    initBaseContext(Type_CatchContext, p->engine, p);
204
 
    strictMode = p->strictMode;
205
 
    callData = p->callData;
206
 
    outer = p;
207
 
    lookups = p->lookups;
208
 
    compilationUnit = p->compilationUnit;
 
208
    strictMode = parent->strictMode;
 
209
    callData = parent->callData;
 
210
    outer = parent;
 
211
    lookups = parent->lookups;
 
212
    compilationUnit = parent->compilationUnit;
209
213
 
210
214
    this->exceptionVarName = exceptionVarName;
211
215
    this->exceptionValue = exceptionValue;
212
216
}
213
217
 
214
 
void CallContext::initQmlContext(ExecutionContext *parentContext, ObjectRef qml, FunctionObject *function)
 
218
CallContext::CallContext(ExecutionEngine *engine, ObjectRef qml, FunctionObject *function)
 
219
    : ExecutionContext(engine, Type_QmlContext)
215
220
{
216
 
    initBaseContext(Type_QmlContext, parentContext->engine, parentContext);
217
 
 
218
221
    this->function = function;
219
 
    this->callData = reinterpret_cast<CallData *>(this + 1);
220
 
    this->callData->tag = QV4::Value::_Integer_Type;
221
 
    this->callData->argc = 0;
222
 
    this->callData->thisObject = Primitive::undefinedValue();
 
222
    callData = reinterpret_cast<CallData *>(this + 1);
 
223
    callData->tag = QV4::Value::_Integer_Type;
 
224
    callData->argc = 0;
 
225
    callData->thisObject = Primitive::undefinedValue();
223
226
 
224
227
    strictMode = true;
225
 
    marked = false;
226
 
    this->outer = function->scope;
227
 
#ifndef QT_NO_DEBUG
228
 
    assert(outer->next != (ExecutionContext *)0x1);
229
 
#endif
 
228
    outer = function->scope;
230
229
 
231
230
    activation = qml.getPointer();
232
231
 
259
258
            CallContext *c = static_cast<CallContext *>(ctx);
260
259
            FunctionObject *f = c->function;
261
260
            if (f->needsActivation || hasWith) {
262
 
                for (unsigned int i = 0; i < f->varCount; ++i)
263
 
                    if (f->varList[i]->isEqualTo(name))
264
 
                        return false;
265
 
                for (int i = (int)f->formalParameterCount - 1; i >= 0; --i)
266
 
                    if (f->formalParameterList[i]->isEqualTo(name))
267
 
                        return false;
 
261
                uint index = f->function->internalClass->find(name);
 
262
                if (index < UINT_MAX)
 
263
                    // ### throw in strict mode?
 
264
                    return false;
268
265
            }
269
266
            if (c->activation && c->activation->__hasProperty__(name))
270
267
                return c->activation->deleteProperty(name);
285
282
    return function->needsActivation || callData->argc < static_cast<int>(function->formalParameterCount);
286
283
}
287
284
 
288
 
void ExecutionContext::mark()
 
285
void ExecutionContext::markObjects(Managed *m, ExecutionEngine *engine)
289
286
{
290
 
    if (marked)
291
 
        return;
292
 
    marked = true;
 
287
    ExecutionContext *ctx = static_cast<ExecutionContext *>(m);
293
288
 
294
 
    if (outer)
295
 
        outer->mark();
 
289
    if (ctx->outer)
 
290
        ctx->outer->mark(engine);
296
291
 
297
292
    // ### shouldn't need these 3 lines
298
 
    callData->thisObject.mark(engine);
299
 
    for (int arg = 0; arg < callData->argc; ++arg)
300
 
        callData->args[arg].mark(engine);
 
293
    ctx->callData->thisObject.mark(engine);
 
294
    for (int arg = 0; arg < ctx->callData->argc; ++arg)
 
295
        ctx->callData->args[arg].mark(engine);
301
296
 
302
 
    if (type >= Type_CallContext) {
303
 
        QV4::CallContext *c = static_cast<CallContext *>(this);
 
297
    if (ctx->type >= Type_CallContext) {
 
298
        QV4::CallContext *c = static_cast<CallContext *>(ctx);
304
299
        for (unsigned local = 0, lastLocal = c->variableCount(); local < lastLocal; ++local)
305
300
            c->locals[local].mark(engine);
306
301
        if (c->activation)
307
302
            c->activation->mark(engine);
308
303
        c->function->mark(engine);
309
 
    } else if (type == Type_WithContext) {
310
 
        WithContext *w = static_cast<WithContext *>(this);
 
304
    } else if (ctx->type == Type_WithContext) {
 
305
        WithContext *w = static_cast<WithContext *>(ctx);
311
306
        w->withObject->mark(engine);
312
 
    } else if (type == Type_CatchContext) {
313
 
        CatchContext *c = static_cast<CatchContext *>(this);
 
307
    } else if (ctx->type == Type_CatchContext) {
 
308
        CatchContext *c = static_cast<CatchContext *>(ctx);
314
309
        c->exceptionVarName->mark(engine);
315
310
        c->exceptionValue.mark(engine);
316
 
    } else if (type == Type_GlobalContext) {
317
 
        GlobalContext *g = static_cast<GlobalContext *>(this);
 
311
    } else if (ctx->type == Type_GlobalContext) {
 
312
        GlobalContext *g = static_cast<GlobalContext *>(ctx);
318
313
        g->global->mark(engine);
319
314
    }
320
315
}
336
331
            ScopedObject activation(scope, (Object *)0);
337
332
            if (ctx->type >= Type_CallContext) {
338
333
                CallContext *c = static_cast<CallContext *>(ctx);
339
 
                for (unsigned int i = 0; i < c->function->varCount; ++i)
340
 
                    if (c->function->varList[i]->isEqualTo(name)) {
341
 
                        c->locals[i] = *value;
342
 
                        return;
343
 
                    }
344
 
                for (int i = (int)c->function->formalParameterCount - 1; i >= 0; --i)
345
 
                    if (c->function->formalParameterList[i]->isEqualTo(name)) {
346
 
                        c->callData->args[i] = *value;
347
 
                        return;
348
 
                    }
 
334
                if (c->function->function) {
 
335
                    uint index = c->function->function->internalClass->find(name);
 
336
                    if (index < UINT_MAX) {
 
337
                        if (index < c->function->formalParameterCount) {
 
338
                            c->callData->args[c->function->formalParameterCount - index - 1] = *value;
 
339
                        } else {
 
340
                            index -= c->function->formalParameterCount;
 
341
                            c->locals[index] = *value;
 
342
                        }
 
343
                        return;
 
344
                    }
 
345
                }
349
346
                activation = c->activation;
350
347
            } else if (ctx->type == Type_GlobalContext) {
351
348
                activation = static_cast<GlobalContext *>(ctx)->global;
352
349
            }
353
350
 
354
 
            if (activation && (ctx->type == Type_QmlContext || activation->__hasProperty__(name))) {
355
 
                activation->put(name, value);
356
 
                return;
 
351
            if (activation) {
 
352
                if (ctx->type == Type_QmlContext) {
 
353
                    activation->put(name, value);
 
354
                    return;
 
355
                } else {
 
356
                    PropertyAttributes attrs;
 
357
                    Property *p = activation->__getOwnProperty__(name, &attrs);
 
358
                    if (p) {
 
359
                        activation->putValue(p, attrs, value);
 
360
                        return;
 
361
                    }
 
362
                }
357
363
            }
358
364
        }
359
365
    }
398
404
        else if (ctx->type >= Type_CallContext) {
399
405
            QV4::CallContext *c = static_cast<CallContext *>(ctx);
400
406
            ScopedFunctionObject f(scope, c->function);
401
 
            if (f->needsActivation || hasWith || hasCatchScope) {
402
 
                for (unsigned int i = 0; i < f->varCount; ++i)
403
 
                    if (f->varList[i]->isEqualTo(name))
404
 
                        return c->locals[i].asReturnedValue();
405
 
                for (int i = (int)f->formalParameterCount - 1; i >= 0; --i)
406
 
                    if (f->formalParameterList[i]->isEqualTo(name))
407
 
                        return c->callData->args[i].asReturnedValue();
 
407
            if (f->function && (f->needsActivation || hasWith || hasCatchScope)) {
 
408
                uint index = f->function->internalClass->find(name);
 
409
                if (index < UINT_MAX) {
 
410
                    if (index < c->function->formalParameterCount)
 
411
                        return c->callData->args[c->function->formalParameterCount - index - 1].asReturnedValue();
 
412
                    return c->locals[index - c->function->formalParameterCount].asReturnedValue();
 
413
                }
408
414
            }
409
415
            if (c->activation) {
410
416
                bool hasProperty = false;
464
470
        else if (ctx->type >= Type_CallContext) {
465
471
            QV4::CallContext *c = static_cast<CallContext *>(ctx);
466
472
            FunctionObject *f = c->function;
467
 
            if (f->needsActivation || hasWith || hasCatchScope) {
468
 
                for (unsigned int i = 0; i < f->varCount; ++i)
469
 
                    if (f->varList[i]->isEqualTo(name))
470
 
                        return c->locals[i].asReturnedValue();
471
 
                for (int i = (int)f->formalParameterCount - 1; i >= 0; --i)
472
 
                    if (f->formalParameterList[i]->isEqualTo(name))
473
 
                        return c->callData->args[i].asReturnedValue();
 
473
            if (f->function && (f->needsActivation || hasWith || hasCatchScope)) {
 
474
                uint index = f->function->internalClass->find(name);
 
475
                if (index < UINT_MAX) {
 
476
                    if (index < c->function->formalParameterCount)
 
477
                        return c->callData->args[c->function->formalParameterCount - index - 1].asReturnedValue();
 
478
                    return c->locals[index - c->function->formalParameterCount].asReturnedValue();
 
479
                }
474
480
            }
475
481
            if (c->activation) {
476
482
                bool hasProperty = false;