source: webkit/trunk/JavaScriptCore/kjs/JSFunction.h@ 37048

Last change on this file since 37048 was 36735, checked in by [email protected], 17 years ago

2008-09-21 Cameron Zwarich <[email protected]>

Reviewed by Maciej Stachowiak.

Bug 20815: 'arguments' object creation is non-optimal
<https://bugs.webkit.org/show_bug.cgi?id=20815>

Fix our inefficient way of creating the arguments object by only
creating named properties for each of the arguments after a use of the
'delete' statement. This patch also speeds up access to the 'arguments'
object slightly, but it still does not use the array fast path for
indexed access that exists for many opcodes.

This is about a 20% improvement on the V8 Raytrace benchmark, and a 1.5%
improvement on the Earley-Boyer benchmark, which gives a 4% improvement
overall.

JavaScriptCore:

  • kjs/Arguments.cpp: (JSC::Arguments::Arguments): (JSC::Arguments::mark): (JSC::Arguments::getOwnPropertySlot): (JSC::Arguments::put): (JSC::Arguments::deleteProperty):
  • kjs/Arguments.h: (JSC::Arguments::ArgumentsData::ArgumentsData):
  • kjs/IndexToNameMap.h: (JSC::IndexToNameMap::size):
  • kjs/JSActivation.cpp: (JSC::JSActivation::createArgumentsObject):
  • kjs/JSActivation.h: (JSC::JSActivation::uncheckedSymbolTableGet): (JSC::JSActivation::uncheckedSymbolTableGetValue): (JSC::JSActivation::uncheckedSymbolTablePut):
  • kjs/JSFunction.h: (JSC::JSFunction::numParameters):

LayoutTests:

  • fast/js/arguments-expected.txt: Added.
  • fast/js/arguments.html: Added.
  • fast/js/resources/arguments.js: Added.
  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Cameron Zwarich ([email protected])
5 * Copyright (C) 2007 Maks Orlovich
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef JSFunction_h
25#define JSFunction_h
26
27#include "InternalFunction.h"
28#include "JSVariableObject.h"
29#include "SymbolTable.h"
30#include "nodes.h"
31#include "JSObject.h"
32
33namespace JSC {
34
35 class FunctionBodyNode;
36 class FunctionPrototype;
37 class JSActivation;
38 class JSGlobalObject;
39
40 class JSFunction : public InternalFunction {
41 friend class Machine;
42
43 typedef InternalFunction Base;
44 JSFunction(PassRefPtr<JSC::StructureID> st) : InternalFunction(st), m_scopeChain(NoScopeChain()) {}
45 public:
46 JSFunction(ExecState*, const Identifier&, FunctionBodyNode*, ScopeChainNode*);
47
48 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
49 virtual void put(ExecState*, const Identifier& propertyName, JSValue*, PutPropertySlot&);
50 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
51
52 JSObject* construct(ExecState*, const ArgList&);
53 JSValue* call(ExecState*, JSValue* thisValue, const ArgList&);
54
55 // Note: Returns a null identifier for any parameters that will never get set
56 // due to a later parameter with the same name.
57 const Identifier& getParameterName(int index);
58
59 unsigned numParameters() const
60 {
61 return m_body->parameters().size();
62 }
63
64 void setScope(const ScopeChain& scopeChain) { m_scopeChain = scopeChain; }
65 ScopeChain& scope() { return m_scopeChain; }
66
67 virtual void mark();
68
69 static const ClassInfo info;
70
71 // FIXME: This should be private
72 RefPtr<FunctionBodyNode> m_body;
73
74 private:
75 virtual const ClassInfo* classInfo() const { return &info; }
76
77 virtual ConstructType getConstructData(ConstructData&);
78 virtual CallType getCallData(CallData&);
79
80 static JSValue* argumentsGetter(ExecState*, const Identifier&, const PropertySlot&);
81 static JSValue* callerGetter(ExecState*, const Identifier&, const PropertySlot&);
82 static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
83
84 ScopeChain m_scopeChain;
85 };
86
87} // namespace kJS
88
89#endif // JSFunction_h
Note: See TracBrowser for help on using the repository browser.