source: webkit/trunk/JavaScriptCore/kjs/function.h@ 28887

Last change on this file since 28887 was 28887, checked in by Darin Adler, 17 years ago

Reviewed by Eric.

SuSpider shows 2.4% speedup.

Stop using completions in the execution engine.
Instead, the completion type and label target are both
stored in the ExecState.

  • API/JSContextRef.cpp: Removed unneeded include of "completion.h".
  • bindings/runtime_method.cpp: Removed unused execute function.
  • bindings/runtime_method.h: Ditto.
  • kjs/ExecState.h: Added completionType, breakOrContinueTarget, setCompletionType, setNormalCompletion, setBreakCompletion, setContinueCompletion, setReturnValueCompletion, setThrowCompletion, setInterruptedCompletion, m_completionType, and m_breakOrContinueTarget.
  • kjs/completion.h: Removed constructor and getter for target for break and continue from Completion. This class is now only used for the public API to Interpreter and such.
  • kjs/date_object.h: Removed unused execute function.
  • kjs/function.cpp: (KJS::FunctionImp::callAsFunction): Removed some unneeded exception processing. Updated to call the new execute function and to get the completion type from the ExecState. Merged in the execute function, which repeated some of the same logic and was called only from here. (KJS::GlobalFuncImp::callAsFunction): More of the same for eval.
  • kjs/function.h: Removed execute.
  • kjs/interpreter.cpp: (KJS::Interpreter::evaluate): Added code to convert the result of execut into a Completion.
  • kjs/nodes.cpp: (KJS::Node::setErrorCompletion): Renamed from createErrorCompletion. Now sets the completion type in the ExecState. (KJS::Node::rethrowException): Now sets the completion type in the ExecState. (KJS::StatementNode::hitStatement): Now sets the completion type in the ExecState. (KJS::VarStatementNode::execute): Updated to put completion type in the ExecState instead of a Completion object. (KJS::statementListExecute): Ditto. Also changed the for loop to use indices instead of iterators. (KJS::BlockNode::execute): Updated return type. (KJS::EmptyStatementNode::execute): Updated to put completion type in the ExecState instead of a Completion object. (KJS::ExprStatementNode::execute): Ditto. (KJS::IfNode::execute): Ditto. (KJS::DoWhileNode::execute): Ditto. Also streamlined the logic a little to make the normal case a little faster and moved the end outside the loop so that "break" can do a break. (KJS::WhileNode::execute): Ditto. (KJS::ForNode::execute): Ditto. (KJS::ForInNode::execute): Ditto. (KJS::ContinueNode::execute): Updated to put completion type in the ExecState instead of a Completion object. (KJS::BreakNode::execute): Ditto. (KJS::ReturnNode::execute): Ditto. (KJS::WithNode::execute): Ditto. (KJS::CaseClauseNode::executeStatements): Ditto. Also renamed to have execute in its name to reflect the fact that it's a member of the same family of functions. (KJS::CaseBlockNode::executeBlock): Ditto. (KJS::SwitchNode::execute): Ditto. (KJS::LabelNode::execute): Ditto. (KJS::ThrowNode::execute): Ditto. (KJS::TryNode::execute): Ditto. (KJS::ProgramNode::execute): Ditto. (KJS::EvalNode::execute): Ditto. (KJS::FunctionBodyNode::execute): Ditto. (KJS::FuncDeclNode::execute): Ditto.
  • kjs/nodes.h: Renamed setErrorCompletion to createErrorCompletion, made hitStatement protected, changed return value of execute to a JSValue, renamed evalStatements to executeStatements, and evalBlock to executeBlock.
  • kjs/number_object.h: Removed unused execute function.
  • Property svn:eol-style set to native
File size: 6.9 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * Copyright (C) 1999-2000 Harri Porten ([email protected])
4 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Cameron Zwarich ([email protected])
6 * Copyright (C) 2007 Maks Orlovich
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#ifndef KJS_FUNCTION_H
26#define KJS_FUNCTION_H
27
28#include "JSVariableObject.h"
29#include "LocalStorage.h"
30#include "SymbolTable.h"
31#include "nodes.h"
32#include "object.h"
33
34namespace KJS {
35
36 class ActivationImp;
37 class FunctionBodyNode;
38 class FunctionPrototype;
39
40 class InternalFunctionImp : public JSObject {
41 public:
42 InternalFunctionImp();
43 InternalFunctionImp(FunctionPrototype*);
44 InternalFunctionImp(FunctionPrototype*, const Identifier&);
45
46 virtual bool implementsCall() const;
47 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObjec, const List& args) = 0;
48 virtual bool implementsHasInstance() const;
49
50 virtual const ClassInfo* classInfo() const { return &info; }
51 static const ClassInfo info;
52 const Identifier& functionName() const { return m_name; }
53
54 private:
55 Identifier m_name;
56 };
57
58 /**
59 * @internal
60 *
61 * The initial value of Function.prototype (and thus all objects created
62 * with the Function constructor)
63 */
64 class FunctionPrototype : public InternalFunctionImp {
65 public:
66 FunctionPrototype(ExecState *exec);
67 virtual ~FunctionPrototype();
68
69 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
70 };
71
72 class FunctionImp : public InternalFunctionImp {
73 friend class ActivationImp;
74 public:
75 FunctionImp(ExecState*, const Identifier& name, FunctionBodyNode*, const ScopeChain&);
76
77 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
78 virtual void put(ExecState*, const Identifier& propertyName, JSValue* value, int attr = None);
79 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
80
81 virtual bool implementsConstruct() const { return true; }
82 virtual JSObject* construct(ExecState*, const List& args);
83
84 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args);
85
86 // Note: unlike body->paramName, this returns Identifier::null for parameters
87 // that will never get set, due to later param having the same name
88 Identifier getParameterName(int index);
89
90 virtual const ClassInfo* classInfo() const { return &info; }
91 static const ClassInfo info;
92
93 RefPtr<FunctionBodyNode> body;
94
95 void setScope(const ScopeChain& s) { _scope = s; }
96 const ScopeChain& scope() const { return _scope; }
97
98 virtual void mark();
99
100 private:
101 ScopeChain _scope;
102
103 static JSValue* argumentsGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
104 static JSValue* callerGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
105 static JSValue* lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
106 };
107
108 class IndexToNameMap {
109 public:
110 IndexToNameMap(FunctionImp* func, const List& args);
111 ~IndexToNameMap();
112
113 Identifier& operator[](int index);
114 Identifier& operator[](const Identifier &indexIdentifier);
115 bool isMapped(const Identifier& index) const;
116 void unMap(const Identifier& index);
117
118 private:
119 IndexToNameMap(); // prevent construction w/o parameters
120 int size;
121 Identifier* _map;
122 };
123
124 class Arguments : public JSObject {
125 public:
126 Arguments(ExecState*, FunctionImp* func, const List& args, ActivationImp* act);
127 virtual void mark();
128 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
129 virtual void put(ExecState*, const Identifier& propertyName, JSValue* value, int attr = None);
130 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
131 virtual const ClassInfo* classInfo() const { return &info; }
132 static const ClassInfo info;
133 private:
134 static JSValue* mappedIndexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot);
135
136 ActivationImp* _activationObject;
137 mutable IndexToNameMap indexToNameMap;
138 };
139
140 class ActivationImp : public JSVariableObject {
141 private:
142 using JSVariableObject::JSVariableObjectData;
143
144 struct ActivationImpData : public JSVariableObjectData {
145 ActivationImpData(ExecState* e)
146 : JSVariableObjectData(&e->function()->body->symbolTable())
147 , exec(e)
148 , function(e->function()) // Store this pointer for marking, to keep our symbol table / scope alive after exec has gone out of scope.
149 , argumentsObject(0)
150 {
151 }
152
153 ExecState* exec;
154 FunctionImp* function;
155 Arguments* argumentsObject;
156 };
157
158 public:
159 ActivationImp(ExecState* exec)
160 : JSVariableObject(new ActivationImpData(exec))
161 {
162 }
163
164 virtual ~ActivationImp()
165 {
166 delete d();
167 }
168
169 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
170 virtual void put(ExecState*, const Identifier& propertyName, JSValue* value, int attr = None);
171 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
172
173 virtual const ClassInfo* classInfo() const { return &info; }
174 static const ClassInfo info;
175
176 virtual void mark();
177
178 virtual bool isActivationObject() { return true; }
179
180 private:
181 static PropertySlot::GetValueFunc getArgumentsGetter();
182 static JSValue* argumentsGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot);
183 void createArgumentsObject(ExecState*);
184 ActivationImpData* d() { return static_cast<ActivationImpData*>(JSVariableObject::d); }
185 };
186
187 class GlobalFuncImp : public InternalFunctionImp {
188 public:
189 GlobalFuncImp(ExecState*, FunctionPrototype*, int i, int len, const Identifier&);
190 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args);
191 enum { Eval, ParseInt, ParseFloat, IsNaN, IsFinite, Escape, UnEscape,
192 DecodeURI, DecodeURIComponent, EncodeURI, EncodeURIComponent
193#ifndef NDEBUG
194 , KJSPrint
195#endif
196};
197 private:
198 int id;
199 };
200
201 static const double mantissaOverflowLowerBound = 9007199254740992.0;
202 double parseIntOverflow(const char* s, int length, int radix);
203
204} // namespace
205
206#endif
Note: See TracBrowser for help on using the repository browser.