source: webkit/trunk/JavaScriptCore/runtime/Arguments.h@ 57055

Last change on this file since 57055 was 54022, checked in by [email protected], 15 years ago

2010-01-28 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

Simplify anonymous slot implementation
https://bugs.webkit.org/show_bug.cgi?id=34282

A class must now specify the number of slots it needs at construction time
rather than later on with a transition. This makes many things simpler,
we no longer need to need an additional transition on object creation to
add the anonymous slots, and we remove the need for a number of transition
type checks.

  • API/JSCallbackConstructor.h: (JSC::JSCallbackConstructor::createStructure):
  • API/JSCallbackFunction.h: (JSC::JSCallbackFunction::createStructure):
  • API/JSCallbackObject.h: (JSC::JSCallbackObject::createStructure):
  • JavaScriptCore.exp:
  • debugger/DebuggerActivation.h: (JSC::DebuggerActivation::createStructure):
  • runtime/Arguments.h: (JSC::Arguments::createStructure):
  • runtime/BooleanObject.h: (JSC::BooleanObject::createStructure):
  • runtime/DateInstance.h: (JSC::DateInstance::createStructure):
  • runtime/DatePrototype.h: (JSC::DatePrototype::createStructure):
  • runtime/FunctionPrototype.h: (JSC::FunctionPrototype::createStructure):
  • runtime/GetterSetter.h: (JSC::GetterSetter::createStructure):
  • runtime/GlobalEvalFunction.h: (JSC::GlobalEvalFunction::createStructure):
  • runtime/InternalFunction.h: (JSC::InternalFunction::createStructure):
  • runtime/JSAPIValueWrapper.h: (JSC::JSAPIValueWrapper::createStructure):
  • runtime/JSActivation.h: (JSC::JSActivation::createStructure):
  • runtime/JSArray.h: (JSC::JSArray::createStructure):
  • runtime/JSByteArray.cpp: (JSC::JSByteArray::createStructure):
  • runtime/JSCell.h: (JSC::JSCell::createDummyStructure):
  • runtime/JSFunction.h: (JSC::JSFunction::createStructure):
  • runtime/JSGlobalObject.h: (JSC::JSGlobalObject::createStructure):
  • runtime/JSNotAnObject.h: (JSC::JSNotAnObject::createStructure):
  • runtime/JSONObject.h: (JSC::JSONObject::createStructure):
  • runtime/JSObject.h: (JSC::JSObject::createStructure): (JSC::JSObject::putAnonymousValue): (JSC::JSObject::getAnonymousValue):
  • runtime/JSPropertyNameIterator.h: (JSC::JSPropertyNameIterator::createStructure):
  • runtime/JSStaticScopeObject.h: (JSC::JSStaticScopeObject::createStructure):
  • runtime/JSString.h: (JSC::Fiber::createStructure):
  • runtime/JSVariableObject.h: (JSC::JSVariableObject::createStructure):
  • runtime/JSWrapperObject.h: (JSC::JSWrapperObject::createStructure): (JSC::JSWrapperObject::JSWrapperObject):
  • runtime/MathObject.h: (JSC::MathObject::createStructure):
  • runtime/NumberConstructor.h: (JSC::NumberConstructor::createStructure):
  • runtime/NumberObject.h: (JSC::NumberObject::createStructure):
  • runtime/RegExpConstructor.h: (JSC::RegExpConstructor::createStructure):
  • runtime/RegExpObject.h: (JSC::RegExpObject::createStructure):
  • runtime/StringObject.h: (JSC::StringObject::createStructure):
  • runtime/StringObjectThatMasqueradesAsUndefined.h: (JSC::StringObjectThatMasqueradesAsUndefined::createStructure):
  • runtime/Structure.cpp: (JSC::Structure::~Structure): (JSC::Structure::materializePropertyMap):
  • runtime/Structure.h: (JSC::Structure::create): (JSC::Structure::anonymousSlotCount):
  • runtime/StructureTransitionTable.h:

2010-01-28 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

Simplify anonymous slot implementation
https://bugs.webkit.org/show_bug.cgi?id=34282

Update JSGlue Structure usage to pass the anonymous slot count.

  • UserObjectImp.h: (UserObjectImp::createStructure):

2010-01-28 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

Simplify anonymous slot implementation
https://bugs.webkit.org/show_bug.cgi?id=34282

Update the WebCore JS DOM bindings to correctly pass and
propagate the anonymous slot count information.

  • bindings/js/JSDOMBinding.h: (WebCore::DOMObjectWithGlobalPointer::createStructure): (WebCore::DOMConstructorObject::createStructure):
  • bindings/js/JSDOMWindowShell.h: (WebCore::JSDOMWindowShell::createStructure):
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/objc/objc_runtime.h: (JSC::Bindings::ObjcFallbackObjectImp::createStructure):
  • bridge/runtime_array.h: (JSC::RuntimeArray::createStructure):
  • bridge/runtime_method.h: (JSC::RuntimeMethod::createStructure):
  • bridge/runtime_object.h: (JSC::RuntimeObjectImp::createStructure):
  • Property svn:eol-style set to native
File size: 8.9 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2003, 2006, 2007, 2008, 2009 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 Arguments_h
25#define Arguments_h
26
27#include "JSActivation.h"
28#include "JSFunction.h"
29#include "JSGlobalObject.h"
30#include "Interpreter.h"
31#include "ObjectConstructor.h"
32#include "PrototypeFunction.h"
33
34namespace JSC {
35
36 struct ArgumentsData : Noncopyable {
37 JSActivation* activation;
38
39 unsigned numParameters;
40 ptrdiff_t firstParameterIndex;
41 unsigned numArguments;
42
43 Register* registers;
44 OwnArrayPtr<Register> registerArray;
45
46 Register* extraArguments;
47 OwnArrayPtr<bool> deletedArguments;
48 Register extraArgumentsFixedBuffer[4];
49
50 JSFunction* callee;
51 bool overrodeLength : 1;
52 bool overrodeCallee : 1;
53 };
54
55
56 class Arguments : public JSObject {
57 public:
58 enum NoParametersType { NoParameters };
59
60 Arguments(CallFrame*);
61 Arguments(CallFrame*, NoParametersType);
62 virtual ~Arguments();
63
64 static const ClassInfo info;
65
66 virtual void markChildren(MarkStack&);
67
68 void fillArgList(ExecState*, MarkedArgumentBuffer&);
69
70 uint32_t numProvidedArguments(ExecState* exec) const
71 {
72 if (UNLIKELY(d->overrodeLength))
73 return get(exec, exec->propertyNames().length).toUInt32(exec);
74 return d->numArguments;
75 }
76
77 void copyToRegisters(ExecState* exec, Register* buffer, uint32_t maxSize);
78 void copyRegisters();
79 bool isTornOff() const { return d->registerArray; }
80 void setActivation(JSActivation* activation)
81 {
82 d->activation = activation;
83 d->registers = &activation->registerAt(0);
84 }
85
86 static PassRefPtr<Structure> createStructure(JSValue prototype)
87 {
88 return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount);
89 }
90
91 protected:
92 static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesMarkChildren | OverridesGetPropertyNames | JSObject::StructureFlags;
93
94 private:
95 void getArgumentsData(CallFrame*, JSFunction*&, ptrdiff_t& firstParameterIndex, Register*& argv, int& argc);
96 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
97 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
98 virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
99 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
100 virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
101 virtual void put(ExecState*, unsigned propertyName, JSValue, PutPropertySlot&);
102 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
103 virtual bool deleteProperty(ExecState*, unsigned propertyName);
104
105 virtual const ClassInfo* classInfo() const { return &info; }
106
107 void init(CallFrame*);
108
109 OwnPtr<ArgumentsData> d;
110 };
111
112 Arguments* asArguments(JSValue);
113
114 inline Arguments* asArguments(JSValue value)
115 {
116 ASSERT(asObject(value)->inherits(&Arguments::info));
117 return static_cast<Arguments*>(asObject(value));
118 }
119
120 ALWAYS_INLINE void Arguments::getArgumentsData(CallFrame* callFrame, JSFunction*& function, ptrdiff_t& firstParameterIndex, Register*& argv, int& argc)
121 {
122 function = callFrame->callee();
123
124 int numParameters = function->jsExecutable()->parameterCount();
125 argc = callFrame->argumentCount();
126
127 if (argc <= numParameters)
128 argv = callFrame->registers() - RegisterFile::CallFrameHeaderSize - numParameters;
129 else
130 argv = callFrame->registers() - RegisterFile::CallFrameHeaderSize - numParameters - argc;
131
132 argc -= 1; // - 1 to skip "this"
133 firstParameterIndex = -RegisterFile::CallFrameHeaderSize - numParameters;
134 }
135
136 inline Arguments::Arguments(CallFrame* callFrame)
137 : JSObject(callFrame->lexicalGlobalObject()->argumentsStructure())
138 , d(new ArgumentsData)
139 {
140 JSFunction* callee;
141 ptrdiff_t firstParameterIndex;
142 Register* argv;
143 int numArguments;
144 getArgumentsData(callFrame, callee, firstParameterIndex, argv, numArguments);
145
146 d->numParameters = callee->jsExecutable()->parameterCount();
147 d->firstParameterIndex = firstParameterIndex;
148 d->numArguments = numArguments;
149
150 d->activation = 0;
151 d->registers = callFrame->registers();
152
153 Register* extraArguments;
154 if (d->numArguments <= d->numParameters)
155 extraArguments = 0;
156 else {
157 unsigned numExtraArguments = d->numArguments - d->numParameters;
158 if (numExtraArguments > sizeof(d->extraArgumentsFixedBuffer) / sizeof(Register))
159 extraArguments = new Register[numExtraArguments];
160 else
161 extraArguments = d->extraArgumentsFixedBuffer;
162 for (unsigned i = 0; i < numExtraArguments; ++i)
163 extraArguments[i] = argv[d->numParameters + i];
164 }
165
166 d->extraArguments = extraArguments;
167
168 d->callee = callee;
169 d->overrodeLength = false;
170 d->overrodeCallee = false;
171 }
172
173 inline Arguments::Arguments(CallFrame* callFrame, NoParametersType)
174 : JSObject(callFrame->lexicalGlobalObject()->argumentsStructure())
175 , d(new ArgumentsData)
176 {
177 ASSERT(!callFrame->callee()->jsExecutable()->parameterCount());
178
179 unsigned numArguments = callFrame->argumentCount() - 1;
180
181 d->numParameters = 0;
182 d->numArguments = numArguments;
183 d->activation = 0;
184
185 Register* extraArguments;
186 if (numArguments > sizeof(d->extraArgumentsFixedBuffer) / sizeof(Register))
187 extraArguments = new Register[numArguments];
188 else
189 extraArguments = d->extraArgumentsFixedBuffer;
190
191 Register* argv = callFrame->registers() - RegisterFile::CallFrameHeaderSize - numArguments - 1;
192 for (unsigned i = 0; i < numArguments; ++i)
193 extraArguments[i] = argv[i];
194
195 d->extraArguments = extraArguments;
196
197 d->callee = callFrame->callee();
198 d->overrodeLength = false;
199 d->overrodeCallee = false;
200 }
201
202 inline void Arguments::copyRegisters()
203 {
204 ASSERT(!isTornOff());
205
206 if (!d->numParameters)
207 return;
208
209 int registerOffset = d->numParameters + RegisterFile::CallFrameHeaderSize;
210 size_t registerArraySize = d->numParameters;
211
212 Register* registerArray = new Register[registerArraySize];
213 memcpy(registerArray, d->registers - registerOffset, registerArraySize * sizeof(Register));
214 d->registerArray.set(registerArray);
215 d->registers = registerArray + registerOffset;
216 }
217
218 // This JSActivation function is defined here so it can get at Arguments::setRegisters.
219 inline void JSActivation::copyRegisters(Arguments* arguments)
220 {
221 ASSERT(!d()->registerArray);
222
223 size_t numParametersMinusThis = d()->functionExecutable->generatedBytecode().m_numParameters - 1;
224 size_t numVars = d()->functionExecutable->generatedBytecode().m_numVars;
225 size_t numLocals = numVars + numParametersMinusThis;
226
227 if (!numLocals)
228 return;
229
230 int registerOffset = numParametersMinusThis + RegisterFile::CallFrameHeaderSize;
231 size_t registerArraySize = numLocals + RegisterFile::CallFrameHeaderSize;
232
233 Register* registerArray = copyRegisterArray(d()->registers - registerOffset, registerArraySize);
234 setRegisters(registerArray + registerOffset, registerArray);
235 if (arguments && !arguments->isTornOff())
236 static_cast<Arguments*>(arguments)->setActivation(this);
237 }
238
239 ALWAYS_INLINE Arguments* Register::arguments() const
240 {
241 if (jsValue() == JSValue())
242 return 0;
243 return asArguments(jsValue());
244 }
245
246
247} // namespace JSC
248
249#endif // Arguments_h
Note: See TracBrowser for help on using the repository browser.