source: webkit/trunk/JavaScriptCore/kjs/Arguments.cpp@ 35906

Last change on this file since 35906 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.)

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1/*
2 * Copyright (C) 1999-2002 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 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#include "config.h"
26#include "Arguments.h"
27
28#include "JSActivation.h"
29#include "JSFunction.h"
30#include "JSGlobalObject.h"
31#include "ObjectPrototype.h"
32
33namespace KJS {
34
35ASSERT_CLASS_FITS_IN_CELL(Arguments);
36
37const ClassInfo Arguments::info = { "Arguments", 0, 0, 0 };
38
39// ECMA 10.1.8
40Arguments::Arguments(ExecState* exec, JSFunction* function, const ArgList& args, JSActivation* activation)
41 : JSObject(exec->lexicalGlobalObject()->objectPrototype())
42 , d(new ArgumentsData(activation, function, args))
43{
44 ASSERT(activation);
45
46 putDirect(exec->propertyNames().callee, function, DontEnum);
47 putDirect(exec, exec->propertyNames().length, args.size(), DontEnum);
48
49 int i = 0;
50 ArgList::const_iterator end = args.end();
51 for (ArgList::const_iterator it = args.begin(); it != end; ++it, ++i) {
52 Identifier name = Identifier::from(exec, i);
53 if (!d->indexToNameMap.isMapped(name))
54 putDirect(name, (*it).jsValue(exec), DontEnum);
55 }
56}
57
58void Arguments::mark()
59{
60 JSObject::mark();
61 if (!d->activation->marked())
62 d->activation->mark();
63}
64
65JSValue* Arguments::mappedIndexGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
66{
67 Arguments* thisObj = static_cast<Arguments*>(slot.slotBase());
68 return thisObj->d->activation->get(exec, thisObj->d->indexToNameMap[propertyName]);
69}
70
71bool Arguments::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
72{
73 if (d->indexToNameMap.isMapped(propertyName)) {
74 slot.setCustom(this, mappedIndexGetter);
75 return true;
76 }
77
78 return JSObject::getOwnPropertySlot(exec, propertyName, slot);
79}
80
81void Arguments::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
82{
83 if (d->indexToNameMap.isMapped(propertyName))
84 d->activation->put(exec, d->indexToNameMap[propertyName], value);
85 else
86 JSObject::put(exec, propertyName, value);
87}
88
89bool Arguments::deleteProperty(ExecState* exec, const Identifier& propertyName)
90{
91 if (d->indexToNameMap.isMapped(propertyName)) {
92 d->indexToNameMap.unMap(exec, propertyName);
93 return true;
94 }
95
96 return JSObject::deleteProperty(exec, propertyName);
97}
98
99} // namespace KJS
Note: See TracBrowser for help on using the repository browser.