1 | // -*- mode: c++; c-basic-offset: 4 -*-
|
---|
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, 2007 Apple Inc. All rights reserved.
|
---|
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 "config.h"
|
---|
26 | #include "ExecState.h"
|
---|
27 |
|
---|
28 | #include "JSGlobalObject.h"
|
---|
29 | #include "function.h"
|
---|
30 | #include "internal.h"
|
---|
31 |
|
---|
32 | namespace KJS {
|
---|
33 |
|
---|
34 | // ECMA 10.2
|
---|
35 | ExecState::ExecState(JSGlobalObject* globalObject, JSObject* thisV,
|
---|
36 | ScopeNode* scopeNode, CodeType type, ExecState* callingExec, ExecState* currentExec,
|
---|
37 | FunctionImp* func, const List* args)
|
---|
38 | : m_globalObject(globalObject)
|
---|
39 | , m_exception(0)
|
---|
40 | , m_propertyNames(CommonIdentifiers::shared())
|
---|
41 | , m_callingExec(callingExec)
|
---|
42 | , m_savedExec(currentExec)
|
---|
43 | , m_scopeNode(scopeNode)
|
---|
44 | , m_function(func)
|
---|
45 | , m_arguments(args)
|
---|
46 | , m_iterationDepth(0)
|
---|
47 | , m_switchDepth(0)
|
---|
48 | , m_codeType(type)
|
---|
49 | {
|
---|
50 | // create and initialize activation object (ECMA 10.1.6)
|
---|
51 | if (type == FunctionCode) {
|
---|
52 | m_activation = new ActivationImp(this);
|
---|
53 | m_variableObject = m_activation;
|
---|
54 | } else {
|
---|
55 | m_activation = 0;
|
---|
56 | m_variableObject = globalObject;
|
---|
57 | }
|
---|
58 |
|
---|
59 | // ECMA 10.2
|
---|
60 | switch(type) {
|
---|
61 | case EvalCode:
|
---|
62 | if (m_callingExec) {
|
---|
63 | m_scopeChain = m_callingExec->scopeChain();
|
---|
64 | m_variableObject = m_callingExec->variableObject();
|
---|
65 | m_thisVal = m_callingExec->thisValue();
|
---|
66 | break;
|
---|
67 | } // else same as GlobalCode
|
---|
68 | case GlobalCode:
|
---|
69 | m_scopeChain.push(globalObject);
|
---|
70 | m_thisVal = globalObject;
|
---|
71 | break;
|
---|
72 | case FunctionCode:
|
---|
73 | m_scopeChain = func->scope();
|
---|
74 | m_scopeChain.push(m_activation);
|
---|
75 | m_variableObject = m_activation;
|
---|
76 | m_thisVal = thisV;
|
---|
77 | break;
|
---|
78 | }
|
---|
79 |
|
---|
80 | m_localStorage = &m_variableObject->localStorage();
|
---|
81 |
|
---|
82 | if (scopeNode)
|
---|
83 | m_globalObject->setCurrentExec(this);
|
---|
84 | }
|
---|
85 |
|
---|
86 | ExecState::~ExecState()
|
---|
87 | {
|
---|
88 | m_globalObject->setCurrentExec(m_savedExec);
|
---|
89 | }
|
---|
90 |
|
---|
91 | void ExecState::mark()
|
---|
92 | {
|
---|
93 | for (ExecState* exec = this; exec; exec = exec->m_callingExec)
|
---|
94 | exec->m_scopeChain.mark();
|
---|
95 | }
|
---|
96 |
|
---|
97 | JSGlobalObject* ExecState::lexicalGlobalObject() const
|
---|
98 | {
|
---|
99 | if (scopeChain().isEmpty())
|
---|
100 | return dynamicGlobalObject();
|
---|
101 |
|
---|
102 | JSObject* object = scopeChain().bottom();
|
---|
103 | if (object && object->isGlobalObject())
|
---|
104 | return static_cast<JSGlobalObject*>(object);
|
---|
105 |
|
---|
106 | return dynamicGlobalObject();
|
---|
107 | }
|
---|
108 |
|
---|
109 | } // namespace KJS
|
---|