source: webkit/trunk/JavaScriptCore/runtime/JSFunction.cpp@ 38528

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

JavaScriptCore:

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

Reviewed by Sam Weinig.


Moved runtime/ExecState.* => interpreter/CallFrame.*.

  • API/JSBase.cpp:
  • API/OpaqueJSString.cpp:
  • GNUmakefile.am:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • debugger/DebuggerCallFrame.h:
  • interpreter/CallFrame.cpp: Copied from runtime/ExecState.cpp.
  • interpreter/CallFrame.h: Copied from runtime/ExecState.h.
  • interpreter/Interpreter.cpp:
  • parser/Nodes.cpp:
  • profiler/ProfileGenerator.cpp:
  • profiler/Profiler.cpp:
  • runtime/ClassInfo.h:
  • runtime/Collector.cpp:
  • runtime/Completion.cpp:
  • runtime/ExceptionHelpers.cpp:
  • runtime/ExecState.cpp: Removed.
  • runtime/ExecState.h: Removed.
  • runtime/Identifier.cpp:
  • runtime/JSFunction.cpp:
  • runtime/JSGlobalObjectFunctions.cpp:
  • runtime/JSLock.cpp:
  • runtime/JSNumberCell.h:
  • runtime/JSObject.h:
  • runtime/JSString.h:
  • runtime/Lookup.h:
  • runtime/PropertyNameArray.h:

JavaScriptGlue:

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

Reviewed by Sam Weinig.


Updated for JavaScriptCore rename.

  • ForwardingHeaders/runtime/CallFrame.h: Copied from JavaScriptGlue/ForwardingHeaders/runtime/ExecState.h.
  • ForwardingHeaders/runtime/ExecState.h: Removed.
  • config.h:

WebCore:

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

Reviewed by Sam Weinig.


Updated for JavaScriptCore rename.

  • ForwardingHeaders/interpreter/CallFrame.h: Copied from WebCore/ForwardingHeaders/runtime/ExecState.h.
  • ForwardingHeaders/runtime/ExecState.h: Removed.
  • bindings/objc/WebScriptObject.mm:
  • bridge/c/c_instance.cpp:
  • bridge/jni/jni_jsobject.mm:
  • dom/Node.cpp:
  • dom/NodeFilter.cpp:
  • dom/NodeIterator.cpp:
  • dom/TreeWalker.cpp:
  • inspector/JavaScriptCallFrame.h:
  • Property svn:eol-style set to native
File size: 6.8 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 "JSFunction.h"
27
28#include "CodeBlock.h"
29#include "CommonIdentifiers.h"
30#include "CallFrame.h"
31#include "FunctionPrototype.h"
32#include "JSGlobalObject.h"
33#include "Interpreter.h"
34#include "ObjectPrototype.h"
35#include "Parser.h"
36#include "PropertyNameArray.h"
37#include "ScopeChainMark.h"
38
39using namespace WTF;
40using namespace Unicode;
41
42namespace JSC {
43
44ASSERT_CLASS_FITS_IN_CELL(JSFunction);
45
46const ClassInfo JSFunction::info = { "Function", 0, 0, 0 };
47
48JSFunction::JSFunction(ExecState* exec, const Identifier& name, FunctionBodyNode* body, ScopeChainNode* scopeChainNode)
49 : Base(&exec->globalData(), exec->lexicalGlobalObject()->functionStructure(), name)
50 , m_body(body)
51 , m_scopeChain(scopeChainNode)
52{
53}
54
55JSFunction::~JSFunction()
56{
57#if ENABLE(JIT)
58 // JIT code for other functions may have had calls linked directly to the code for this function; these links
59 // are based on a check for the this pointer value for this JSFunction - which will no longer be valid once
60 // this memory is freed and may be reused (potentially for another, different JSFunction).
61 if (m_body.get() && m_body->isGenerated())
62 m_body->generatedBytecode().unlinkCallers();
63#endif
64}
65
66void JSFunction::mark()
67{
68 Base::mark();
69 m_body->mark();
70 m_scopeChain.mark();
71}
72
73CallType JSFunction::getCallData(CallData& callData)
74{
75 callData.js.functionBody = m_body.get();
76 callData.js.scopeChain = m_scopeChain.node();
77 return CallTypeJS;
78}
79
80JSValue* JSFunction::call(ExecState* exec, JSValue* thisValue, const ArgList& args)
81{
82 return exec->interpreter()->execute(m_body.get(), exec, this, thisValue->toThisObject(exec), args, m_scopeChain.node(), exec->exceptionSlot());
83}
84
85JSValue* JSFunction::argumentsGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
86{
87 JSFunction* thisObj = asFunction(slot.slotBase());
88 return exec->interpreter()->retrieveArguments(exec, thisObj);
89}
90
91JSValue* JSFunction::callerGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
92{
93 JSFunction* thisObj = asFunction(slot.slotBase());
94 return exec->interpreter()->retrieveCaller(exec, thisObj);
95}
96
97JSValue* JSFunction::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
98{
99 JSFunction* thisObj = asFunction(slot.slotBase());
100 return jsNumber(exec, thisObj->m_body->parameterCount());
101}
102
103bool JSFunction::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
104{
105 if (propertyName == exec->propertyNames().prototype) {
106 JSValue** location = getDirectLocation(propertyName);
107
108 if (!location) {
109 JSObject* prototype = new (exec) JSObject(m_scopeChain.globalObject()->emptyObjectStructure());
110 prototype->putDirect(exec->propertyNames().constructor, this, DontEnum);
111 putDirect(exec->propertyNames().prototype, prototype, DontDelete);
112 location = getDirectLocation(propertyName);
113 }
114
115 slot.setValueSlot(this, location, offsetForLocation(location));
116 }
117
118 if (propertyName == exec->propertyNames().arguments) {
119 slot.setCustom(this, argumentsGetter);
120 return true;
121 }
122
123 if (propertyName == exec->propertyNames().length) {
124 slot.setCustom(this, lengthGetter);
125 return true;
126 }
127
128 if (propertyName == exec->propertyNames().caller) {
129 slot.setCustom(this, callerGetter);
130 return true;
131 }
132
133 return Base::getOwnPropertySlot(exec, propertyName, slot);
134}
135
136void JSFunction::put(ExecState* exec, const Identifier& propertyName, JSValue* value, PutPropertySlot& slot)
137{
138 if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length)
139 return;
140 Base::put(exec, propertyName, value, slot);
141}
142
143bool JSFunction::deleteProperty(ExecState* exec, const Identifier& propertyName)
144{
145 if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length)
146 return false;
147 return Base::deleteProperty(exec, propertyName);
148}
149
150/* Returns the parameter name corresponding to the given index. eg:
151 * function f1(x, y, z): getParameterName(0) --> x
152 *
153 * If a name appears more than once, only the last index at which
154 * it appears associates with it. eg:
155 * function f2(x, x): getParameterName(0) --> null
156 */
157const Identifier& JSFunction::getParameterName(int index)
158{
159 const Identifier* parameters = m_body->parameters();
160
161 if (static_cast<size_t>(index) >= m_body->parameterCount())
162 return m_scopeChain.globalObject()->globalData()->propertyNames->nullIdentifier;
163
164 const Identifier& name = parameters[index];
165
166 // Are there any subsequent parameters with the same name?
167 size_t size = m_body->parameterCount();
168 for (size_t i = index + 1; i < size; ++i) {
169 if (parameters[i] == name)
170 return m_scopeChain.globalObject()->globalData()->propertyNames->nullIdentifier;
171 }
172
173 return name;
174}
175
176// ECMA 13.2.2 [[Construct]]
177ConstructType JSFunction::getConstructData(ConstructData& constructData)
178{
179 constructData.js.functionBody = m_body.get();
180 constructData.js.scopeChain = m_scopeChain.node();
181 return ConstructTypeJS;
182}
183
184JSObject* JSFunction::construct(ExecState* exec, const ArgList& args)
185{
186 Structure* structure;
187 JSValue* prototype = get(exec, exec->propertyNames().prototype);
188 if (prototype->isObject())
189 structure = asObject(prototype)->inheritorID();
190 else
191 structure = exec->lexicalGlobalObject()->emptyObjectStructure();
192 JSObject* thisObj = new (exec) JSObject(structure);
193
194 JSValue* result = exec->interpreter()->execute(m_body.get(), exec, this, thisObj, args, m_scopeChain.node(), exec->exceptionSlot());
195 if (exec->hadException() || !result->isObject())
196 return thisObj;
197 return asObject(result);
198}
199
200} // namespace JSC
Note: See TracBrowser for help on using the repository browser.