1 | // -*- c-basic-offset: 2 -*-
|
---|
2 | /*
|
---|
3 | * This file is part of the KDE libraries
|
---|
4 | * Copyright (C) 1999-2001 Harri Porten ([email protected])
|
---|
5 | * Copyright (C) 2001 Peter Kelly ([email protected])
|
---|
6 | * Copyright (C) 2003, 2006 Apple Computer, Inc.
|
---|
7 | *
|
---|
8 | * This library is free software; you can redistribute it and/or
|
---|
9 | * modify it under the terms of the GNU Library General Public
|
---|
10 | * License as published by the Free Software Foundation; either
|
---|
11 | * version 2 of the License, or (at your option) any later version.
|
---|
12 | *
|
---|
13 | * This library is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
16 | * Library General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU Library General Public License
|
---|
19 | * along with this library; see the file COPYING.LIB. If not, write to
|
---|
20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
---|
21 | * Boston, MA 02110-1301, USA.
|
---|
22 | *
|
---|
23 | */
|
---|
24 |
|
---|
25 | #include "context.h"
|
---|
26 |
|
---|
27 | namespace KJS {
|
---|
28 |
|
---|
29 | // ECMA 10.2
|
---|
30 | Context::Context(JSObject* glob, Interpreter* interpreter, JSObject* thisV,
|
---|
31 | FunctionBodyNode* currentBody, CodeType type, Context* callingCon,
|
---|
32 | FunctionImp* func, const List* args)
|
---|
33 | : m_interpreter(interpreter)
|
---|
34 | , m_currentBody(currentBody)
|
---|
35 | , m_function(func)
|
---|
36 | , m_arguments(args)
|
---|
37 | , m_iterationDepth(0)
|
---|
38 | , m_switchDepth(0)
|
---|
39 | {
|
---|
40 | m_codeType = type;
|
---|
41 | m_callingContext = callingCon;
|
---|
42 |
|
---|
43 | // create and initialize activation object (ECMA 10.1.6)
|
---|
44 | if (type == FunctionCode || type == AnonymousCode ) {
|
---|
45 | m_activation = new ActivationImp(func, *args);
|
---|
46 | m_variable = m_activation;
|
---|
47 | } else {
|
---|
48 | m_activation = 0;
|
---|
49 | m_variable = glob;
|
---|
50 | }
|
---|
51 |
|
---|
52 | // ECMA 10.2
|
---|
53 | switch(type) {
|
---|
54 | case EvalCode:
|
---|
55 | if (m_callingContext) {
|
---|
56 | scope = m_callingContext->scopeChain();
|
---|
57 | m_variable = m_callingContext->variableObject();
|
---|
58 | m_thisVal = m_callingContext->thisValue();
|
---|
59 | break;
|
---|
60 | } // else same as GlobalCode
|
---|
61 | case GlobalCode:
|
---|
62 | scope.clear();
|
---|
63 | scope.push(glob);
|
---|
64 | m_thisVal = static_cast<JSObject*>(glob);
|
---|
65 | break;
|
---|
66 | case FunctionCode:
|
---|
67 | case AnonymousCode:
|
---|
68 | if (type == FunctionCode) {
|
---|
69 | scope = func->scope();
|
---|
70 | scope.push(m_activation);
|
---|
71 | } else {
|
---|
72 | scope.clear();
|
---|
73 | scope.push(glob);
|
---|
74 | scope.push(m_activation);
|
---|
75 | }
|
---|
76 | m_variable = m_activation; // TODO: DontDelete ? (ECMA 10.2.3)
|
---|
77 | m_thisVal = thisV;
|
---|
78 | break;
|
---|
79 | }
|
---|
80 |
|
---|
81 | m_interpreter->setContext(this);
|
---|
82 | }
|
---|
83 |
|
---|
84 | Context::~Context()
|
---|
85 | {
|
---|
86 | m_interpreter->setContext(m_callingContext);
|
---|
87 | }
|
---|
88 |
|
---|
89 | void Context::mark()
|
---|
90 | {
|
---|
91 | for (Context* context = this; context; context = context->m_callingContext)
|
---|
92 | context->scope.mark();
|
---|
93 | }
|
---|
94 |
|
---|
95 | } // namespace KJS
|
---|