source: webkit/trunk/JavaScriptCore/kjs/ExecState.cpp@ 27344

Last change on this file since 27344 was 27344, checked in by ggaren, 18 years ago

Reviewed by Oliver Hunt.


Removed List from ActivationImp, in preparation for making all lists
stack-allocated.


Tests pass.


1.0% speedup on SunSpider, presumably due to reduced List refcount thrash.

  • kjs/ExecState.cpp: (KJS::ExecState::ExecState): (KJS::ExecState::~ExecState):
  • kjs/function.cpp: (KJS::ActivationImp::ActivationImp): (KJS::ActivationImp::createArgumentsObject):
  • kjs/function.h: (KJS::ActivationImp::ActivationImpPrivate::ActivationImpPrivate):
  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
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
32namespace KJS {
33
34
35// ECMA 10.2
36ExecState::ExecState(Interpreter* interpreter, JSGlobalObject* glob, JSObject* thisV,
37 FunctionBodyNode* currentBody, CodeType type, ExecState* callingExec,
38 FunctionImp* func, const List* args)
39 : m_interpreter(interpreter)
40 , m_exception(0)
41 , m_propertyNames(CommonIdentifiers::shared())
42 , m_savedExecState(interpreter->currentExec())
43 , m_currentBody(currentBody)
44 , m_function(func)
45 , m_arguments(args)
46 , m_iterationDepth(0)
47 , m_switchDepth(0)
48{
49 m_codeType = type;
50 m_callingExecState = callingExec;
51
52 // create and initialize activation object (ECMA 10.1.6)
53 if (type == FunctionCode) {
54 m_activation = new ActivationImp(this);
55 m_variable = m_activation;
56 } else {
57 m_activation = 0;
58 m_variable = glob;
59 }
60
61 // ECMA 10.2
62 switch(type) {
63 case EvalCode:
64 if (m_callingExecState) {
65 scope = m_callingExecState->scopeChain();
66 m_variable = m_callingExecState->variableObject();
67 m_thisVal = m_callingExecState->thisValue();
68 break;
69 } // else same as GlobalCode
70 case GlobalCode:
71 scope.clear();
72 scope.push(glob);
73 m_thisVal = static_cast<JSObject*>(glob);
74 break;
75 case FunctionCode:
76 scope = func->scope();
77 scope.push(m_activation);
78 m_variable = m_activation; // TODO: DontDelete ? (ECMA 10.2.3)
79 m_thisVal = thisV;
80 break;
81 }
82
83 if (currentBody)
84 m_interpreter->setCurrentExec(this);
85}
86
87ExecState::~ExecState()
88{
89 m_interpreter->setCurrentExec(m_savedExecState);
90}
91
92void ExecState::mark()
93{
94 for (ExecState* exec = this; exec; exec = exec->m_callingExecState)
95 exec->scope.mark();
96}
97
98Interpreter* ExecState::lexicalInterpreter() const
99{
100 if (scopeChain().isEmpty())
101 return dynamicInterpreter();
102
103 JSObject* object = scopeChain().bottom();
104 if (object && object->isGlobalObject())
105 return static_cast<JSGlobalObject*>(object)->interpreter();
106
107 return dynamicInterpreter();
108}
109
110void ExecState::updateLocalStorage()
111{
112 m_localStorageBuffer = static_cast<ActivationImp*>(m_activation)->localStorage().data();
113}
114
115} // namespace KJS
Note: See TracBrowser for help on using the repository browser.