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 |
|
---|
33 | namespace KJS {
|
---|
34 |
|
---|
35 | ASSERT_CLASS_FITS_IN_CELL(Arguments);
|
---|
36 |
|
---|
37 | const ClassInfo Arguments::info = { "Arguments", 0, 0, 0 };
|
---|
38 |
|
---|
39 | // ECMA 10.1.8
|
---|
40 | Arguments::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 |
|
---|
58 | void Arguments::mark()
|
---|
59 | {
|
---|
60 | JSObject::mark();
|
---|
61 | if (!d->activation->marked())
|
---|
62 | d->activation->mark();
|
---|
63 | }
|
---|
64 |
|
---|
65 | JSValue* 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 |
|
---|
71 | bool 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 |
|
---|
81 | void 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 |
|
---|
89 | bool 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
|
---|