source: webkit/trunk/JavaScriptCore/kjs/JSActivation.cpp@ 35900

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

JavaScriptCore:

2008-08-17 Geoffrey Garen <[email protected]>

Reviewed by Cameron Zwarich.

Made room for a free word in JSCell.


SunSpider says no change.


I changed JSCallbackObjectData, Arguments, JSArray, and RegExpObject to
store auxiliary data in a secondary structure.

I changed InternalFunction to store the function's name in the property
map.


I changed JSGlobalObjectData to use a virtual destructor, so WebCore's
JSDOMWindowBaseData could inherit from it safely. (It's a strange design
for JSDOMWindowBase to allocate an object that JSGlobalObject deletes,
but that's really our only option, given the size constraint.)


I also added a bunch of compile-time ASSERTs, and removed lots of comments
in JSObject.h because they were often out of date, and they got in the
way of reading what was actually going on.


Also renamed JSArray::getLength to JSArray::length, to match our style
guidelines.

WebCore:

2008-08-17 Geoffrey Garen <[email protected]>

Reviewed by Cameron Zwarich.

Made room for a free word in JSCell.


Changed JSDOMWindowBase to store its auxiliary data in a subclass of
JSGlobalData, so the two could share a pointer.


Added a bunch of ASSERTs, to help catch over-sized objects.

WebKit/mac:

2008-08-17 Geoffrey Garen <[email protected]>

Reviewed by Cameron Zwarich.

Made room for a free word in JSCell.


(Updated for JavaScriptCore changes.)

File size: 5.7 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "config.h"
30#include "JSActivation.h"
31
32#include "Arguments.h"
33#include "CodeBlock.h"
34#include "Machine.h"
35#include "Register.h"
36#include "JSFunction.h"
37
38namespace KJS {
39
40ASSERT_CLASS_FITS_IN_CELL(JSActivation);
41
42const ClassInfo JSActivation::info = { "JSActivation", 0, 0, 0 };
43
44JSActivation::JSActivation(PassRefPtr<FunctionBodyNode> functionBody, Register* registers)
45 : Base(new JSActivationData(functionBody, registers))
46{
47}
48
49JSActivation::~JSActivation()
50{
51 delete d();
52}
53
54void JSActivation::copyRegisters()
55{
56 int numLocals = d()->functionBody->generatedByteCode().numLocals;
57 if (!numLocals)
58 return;
59
60 copyRegisterArray(d()->registers - numLocals, numLocals);
61}
62
63bool JSActivation::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
64{
65 if (symbolTableGet(propertyName, slot))
66 return true;
67
68 if (JSValue** location = getDirectLocation(propertyName)) {
69 slot.setValueSlot(location);
70 return true;
71 }
72
73 // Only return the built-in arguments object if it wasn't overridden above.
74 if (propertyName == exec->propertyNames().arguments) {
75 slot.setCustom(this, getArgumentsGetter());
76 return true;
77 }
78
79 // We don't call through to JSObject because there's no way to give an
80 // activation object getter properties or a prototype.
81 ASSERT(!m_propertyMap.hasGetterSetterProperties());
82 ASSERT(prototype() == jsNull());
83 return false;
84}
85
86void JSActivation::put(ExecState*, const Identifier& propertyName, JSValue* value)
87{
88 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
89
90 if (symbolTablePut(propertyName, value))
91 return;
92
93 // We don't call through to JSObject because __proto__ and getter/setter
94 // properties are non-standard extensions that other implementations do not
95 // expose in the activation object.
96 ASSERT(!m_propertyMap.hasGetterSetterProperties());
97 m_propertyMap.put(propertyName, value, 0, true);
98}
99
100// FIXME: Make this function honor ReadOnly (const) and DontEnum
101void JSActivation::putWithAttributes(ExecState*, const Identifier& propertyName, JSValue* value, unsigned attributes)
102{
103 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
104
105 if (symbolTablePutWithAttributes(propertyName, value, attributes))
106 return;
107
108 // We don't call through to JSObject because __proto__ and getter/setter
109 // properties are non-standard extensions that other implementations do not
110 // expose in the activation object.
111 ASSERT(!m_propertyMap.hasGetterSetterProperties());
112 m_propertyMap.put(propertyName, value, attributes, true);
113}
114
115bool JSActivation::deleteProperty(ExecState* exec, const Identifier& propertyName)
116{
117 if (propertyName == exec->propertyNames().arguments)
118 return false;
119
120 return Base::deleteProperty(exec, propertyName);
121}
122
123JSObject* JSActivation::toThisObject(ExecState* exec) const
124{
125 return exec->globalThisValue();
126}
127
128void JSActivation::mark()
129{
130 Base::mark();
131
132 if (d()->argumentsObject)
133 d()->argumentsObject->mark();
134}
135
136bool JSActivation::isActivationObject() const
137{
138 return true;
139}
140
141bool JSActivation::isDynamicScope() const
142{
143 return d()->functionBody->usesEval();
144}
145
146JSValue* JSActivation::argumentsGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
147{
148 JSActivation* thisObj = static_cast<JSActivation*>(slot.slotBase());
149 if (!thisObj->d()->argumentsObject)
150 thisObj->d()->argumentsObject = thisObj->createArgumentsObject(exec);
151
152 return thisObj->d()->argumentsObject;
153}
154
155// These two functions serve the purpose of isolating the common case from a
156// PIC branch.
157
158PropertySlot::GetValueFunc JSActivation::getArgumentsGetter()
159{
160 return argumentsGetter;
161}
162
163JSObject* JSActivation::createArgumentsObject(ExecState* exec)
164{
165 Register* callFrame = d()->registers - d()->functionBody->generatedByteCode().numLocals - RegisterFile::CallFrameHeaderSize;
166
167 JSFunction* function;
168 Register* argv;
169 int argc;
170 exec->machine()->getArgumentsData(callFrame, function, argv, argc);
171
172 ArgList args(argv, argc);
173 return new (exec) Arguments(exec, function, args, this);
174}
175
176} // namespace KJS
Note: See TracBrowser for help on using the repository browser.