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

Last change on this file since 27339 was 27339, checked in by mjs, 18 years ago

Reviewed by Oliver.


  • shave some cycles off of local storage access for a 1% SunSpider speedup


Keep the LocalStorage pointer in the ExecState, not

  • kjs/ExecState.cpp: (KJS::ExecState::updateLocalStorage):
  • kjs/ExecState.h: (KJS::ExecState::localStorage):
  • kjs/nodes.cpp: (KJS::LocalVarAccessNode::evaluate): (KJS::LocalVarFunctionCallNode::evaluate): (KJS::PostIncLocalVarNode::evaluate): (KJS::PostDecLocalVarNode::evaluate): (KJS::LocalVarTypeOfNode::evaluate): (KJS::PreIncLocalVarNode::evaluate): (KJS::PreDecLocalVarNode::evaluate): (KJS::ReadModifyLocalVarNode::evaluate): (KJS::AssignLocalVarNode::evaluate): (KJS::FunctionBodyNode::processDeclarationsForFunctionCode):
  • Property svn:eol-style set to native
File size: 3.8 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(func, *args);
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 // The arguments list is only needed to potentially create the arguments object,
92 // which isn't accessible from nested scopes so we can discard the list as soon
93 // as the function is done running.
94 // This prevents lists of Lists from building up, waiting to be garbage collected
95 ActivationImp* activation = static_cast<ActivationImp*>(m_activation);
96 if (activation)
97 activation->releaseArguments();
98}
99
100void ExecState::mark()
101{
102 for (ExecState* exec = this; exec; exec = exec->m_callingExecState)
103 exec->scope.mark();
104}
105
106Interpreter* ExecState::lexicalInterpreter() const
107{
108 if (scopeChain().isEmpty())
109 return dynamicInterpreter();
110
111 JSObject* object = scopeChain().bottom();
112 if (object && object->isGlobalObject())
113 return static_cast<JSGlobalObject*>(object)->interpreter();
114
115 return dynamicInterpreter();
116}
117
118void ExecState::updateLocalStorage()
119{
120 m_localStorageBuffer = static_cast<ActivationImp*>(m_activation)->localStorage().data();
121}
122
123} // namespace KJS
Note: See TracBrowser for help on using the repository browser.