source: webkit/trunk/JavaScriptCore/runtime/JSFunction.h@ 47089

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

JavaScriptCore: Restrict use of FuncDeclNode & FuncExprNode to the parser.
https://bugs.webkit.org/show_bug.cgi?id=28209

Reviewed by Oliver Hunt.

These objects were also being referenced from the CodeBlock. By changing this
to just retain pointers to FunctionBodyNodes these classes can be restricted to
use during parsing.

No performance impact (or sub-percent progression).

Update symbols.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::mark):
(JSC::CodeBlock::reparseForExceptionInfoIfNecessary):
(JSC::CodeBlock::shrinkToFit):

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::addFunction):
(JSC::CodeBlock::function):

Unify m_functions & m_functionExpressions into a single Vector<RefPtr<FuncExprNode> >.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::addConstant):
(JSC::BytecodeGenerator::emitNewFunction):
(JSC::BytecodeGenerator::emitNewFunctionExpression):

  • bytecompiler/BytecodeGenerator.h:

FunctionStacks now contain FunctionBodyNodes not FuncDeclNodes.

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::execute):
(JSC::Interpreter::privateExecute):

Update to reflect chnages in CodeBlock.

  • jit/JITOpcodes.cpp:

(JSC::JIT::emit_op_new_func_exp):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • jit/JITStubs.h:

(JSC::):

Update to reflect chnages in CodeBlock.

  • parser/Grammar.y:

FunctionStacks now contain FunctionBodyNodes not FuncDeclNodes.

  • parser/NodeConstructors.h:

(JSC::FuncExprNode::FuncExprNode):
(JSC::FuncDeclNode::FuncDeclNode):

  • parser/Nodes.cpp:

(JSC::ScopeNodeData::mark):
(JSC::FunctionBodyNode::finishParsing):

  • parser/Nodes.h:

(JSC::FunctionBodyNode::ident):

Move m_ident & make methods from FuncDeclNode & FuncExprNode to FunctionBodyNode.

  • runtime/JSFunction.h:

(JSC::FunctionBodyNode::make):

Make this method inline (was FuncDeclNode::makeFunction).

WebCore: Restrict use of FuncDeclNode & FuncExprNode to the parser.
https://bugs.webkit.org/show_bug.cgi?id=28209

Reviewed by Oliver Hunt.

  • inspector/JavaScriptDebugServer.cpp:

(WebCore::JavaScriptDebugServer::recompileAllJSFunctions):

Function signature change.

  • Property svn:eol-style set to native
File size: 4.8 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 JSFunction_h
25#define JSFunction_h
26
27#include "InternalFunction.h"
28#include "JSVariableObject.h"
29#include "SymbolTable.h"
30#include "Nodes.h"
31#include "JSObject.h"
32
33namespace JSC {
34
35 class FunctionBodyNode;
36 class FunctionPrototype;
37 class JSActivation;
38 class JSGlobalObject;
39
40 class JSFunction : public InternalFunction {
41 friend class JIT;
42 friend struct VPtrSet;
43
44 typedef InternalFunction Base;
45
46 JSFunction(PassRefPtr<Structure> structure)
47 : InternalFunction(structure)
48 {
49 clearScopeChain();
50 }
51
52 public:
53 JSFunction(ExecState*, PassRefPtr<Structure>, int length, const Identifier&, NativeFunction);
54 JSFunction(ExecState*, const Identifier&, FunctionBodyNode*, ScopeChainNode*);
55 ~JSFunction();
56
57 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
58 virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
59 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
60
61 JSObject* construct(ExecState*, const ArgList&);
62 JSValue call(ExecState*, JSValue thisValue, const ArgList&);
63
64 void setScope(const ScopeChain& scopeChain) { setScopeChain(scopeChain); }
65 ScopeChain& scope() { return scopeChain(); }
66
67 void setBody(FunctionBodyNode* body) { m_body = body; }
68 void setBody(PassRefPtr<FunctionBodyNode> body) { m_body = body; }
69 FunctionBodyNode* body() const { return m_body.get(); }
70
71 virtual void markChildren(MarkStack&);
72
73 static JS_EXPORTDATA const ClassInfo info;
74
75 static PassRefPtr<Structure> createStructure(JSValue prototype)
76 {
77 return Structure::create(prototype, TypeInfo(ObjectType, ImplementsHasInstance));
78 }
79
80#if ENABLE(JIT)
81 bool isHostFunction() const { return m_body && m_body->isHostFunction(); }
82#else
83 bool isHostFunction() const { return false; }
84#endif
85 NativeFunction nativeFunction()
86 {
87 return *reinterpret_cast<NativeFunction*>(m_data);
88 }
89
90 virtual ConstructType getConstructData(ConstructData&);
91 virtual CallType getCallData(CallData&);
92
93 private:
94 virtual const ClassInfo* classInfo() const { return &info; }
95
96 static JSValue argumentsGetter(ExecState*, const Identifier&, const PropertySlot&);
97 static JSValue callerGetter(ExecState*, const Identifier&, const PropertySlot&);
98 static JSValue lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
99
100 RefPtr<FunctionBodyNode> m_body;
101 ScopeChain& scopeChain()
102 {
103 ASSERT(!isHostFunction());
104 return *reinterpret_cast<ScopeChain*>(m_data);
105 }
106 void clearScopeChain()
107 {
108 ASSERT(!isHostFunction());
109 new (m_data) ScopeChain(NoScopeChain());
110 }
111 void setScopeChain(ScopeChainNode* sc)
112 {
113 ASSERT(!isHostFunction());
114 new (m_data) ScopeChain(sc);
115 }
116 void setScopeChain(const ScopeChain& sc)
117 {
118 ASSERT(!isHostFunction());
119 *reinterpret_cast<ScopeChain*>(m_data) = sc;
120 }
121 void setNativeFunction(NativeFunction func)
122 {
123 *reinterpret_cast<NativeFunction*>(m_data) = func;
124 }
125 unsigned char m_data[sizeof(void*)];
126 };
127
128 JSFunction* asFunction(JSValue);
129
130 inline JSFunction* asFunction(JSValue value)
131 {
132 ASSERT(asObject(value)->inherits(&JSFunction::info));
133 return static_cast<JSFunction*>(asObject(value));
134 }
135
136 inline JSFunction* FunctionBodyNode::make(ExecState* exec, ScopeChainNode* scopeChain)
137 {
138 return new (exec) JSFunction(exec, m_ident, this, scopeChain);
139 }
140
141} // namespace JSC
142
143#endif // JSFunction_h
Note: See TracBrowser for help on using the repository browser.