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

Last change on this file since 47236 was 47236, checked in by Darin Adler, 16 years ago

JavaScriptCore: JavaScriptCore tweaks to get ready for the parser arena
https://bugs.webkit.org/show_bug.cgi?id=28243

Patch by Darin Adler <Darin Adler> on 2009-08-13
Reviewed by David Levin.

Eliminate dependencies on Nodes.h outside JavaScriptCore,
and cut down on them inside JavaScriptCore.

Change regular expression parsing to use identifiers as
with other strings we parse.

Fix a couple things that are needed to use const Identifier
more, which will be part of the parser arena work.

CollectorHeapIterator.h to be project-internal.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::emitPushNewScope): Added const.

  • bytecompiler/BytecodeGenerator.h: Ditto.
  • debugger/Debugger.cpp:

(JSC::Debugger::recompileAllJSFunctions): Moved this function
here from WebCore. Here is better since it uses so many internals.
Removed unimportant optimization for the no listener case.

  • debugger/Debugger.h: Ditto. Also removed unneeded include

and tweaked formatting and comments.

  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::functionName): Call asFunction instead
of doing the unchecked static_cast.
(JSC::DebuggerCallFrame::calculatedFunctionName): Ditto.

  • jit/JITStubs.cpp:

(JSC::op_call_JSFunction): Call isHostFunction on the body rather
than on the JSFunction.
(JSC::vm_lazyLinkCall): Ditto.
(JSC::op_construct_JSConstruct): Ditto.

  • parser/Grammar.y: Changed callers to use new scanRegExp with

out arguments instead of relying on state in the Lexer. And
callers that just want to skip a regular expression to use
skipRegExp.

  • parser/Lexer.cpp:

(JSC::Lexer::scanRegExp): Changed to use out arguments, and to
add a prefix argument so we can add in the "=" character as needed.
Also rewrote to streamline the logic a bit inspired by suggestions
by David Levin.
(JSC::Lexer::skipRegExp): Added. Version of the function above that
does not actually put the regular expression into a string.
(JSC::Lexer::clear): Removed code to clear m_pattern and m_flags.

  • parser/Lexer.h: Changed scanRegExp to have out arguments. Added

skipRegExp. Eliminated pattern, flags, m_pattern, and m_flags.

  • parser/NodeConstructors.h:

(JSC::RegExpNode::RegExpNode): Changed to take const Identifier&.

  • parser/Nodes.cpp:

(JSC::RegExpNode::emitBytecode): Changed since m_pattern and
m_flags are now Identifier instead of UString.
(JSC::FunctionBodyNode::make): Moved this function here instead
of putting it in the JSFunction.h header.

  • parser/Nodes.h: Changed RegExpNode to use Identifier.
  • profiler/Profiler.cpp:

(JSC::Profiler::createCallIdentifier): Changed to use isHostFunction
on the body instead of on the JSFunction object.

  • runtime/FunctionPrototype.cpp:

(JSC::functionProtoFuncToString): Ditto.

  • runtime/JSFunction.cpp:

(JSC::JSFunction::isHostFunction): Moved here from header.
(JSC::JSFunction::isHostFunctionNonInline): Added.
(JSC::JSFunction::JSFunction): Removed unneeded initialization of
m_body to 0.
(JSC::JSFunction::setBody): Moved here from header.

  • runtime/JSFunction.h: Removed unneeded includes. Moved private

constructor down to the private section. Made virtual functions
private. Removed unneeded overload of setBody and moved the body
of the function into the .cpp file. Changed assertions to use
the non-inline version of isHostFunction.

  • runtime/PropertySlot.cpp:

(JSC::PropertySlot::functionGetter): Use asFunction instead
of doing the unchecked static_cast.

  • wtf/SegmentedVector.h:

(WTF::SegmentedVector::isEmpty): Added.

WebCore: JavaScriptCore tweaks to get ready for the parser arena
https://bugs.webkit.org/show_bug.cgi?id=28243

Patch by Darin Adler <Darin Adler> on 2009-08-13
Reviewed by David Levin.

  • ForwardingHeaders/runtime/CollectorHeapIterator.h: Removed.
  • WebCore.xcodeproj/project.pbxproj: Exposed a couple header

files as Private that are now needed to compile Mac WebKit.

  • bindings/js/JSAudioConstructor.cpp:
  • bindings/js/JSDOMBinding.cpp:
  • bindings/js/JSDOMBinding.h:
  • bindings/js/JSDOMWindowCustom.cpp:
  • bindings/js/JSHTMLInputElementCustom.cpp:
  • bindings/js/JSHistoryCustom.cpp:
  • bindings/js/JSImageConstructor.cpp:
  • bindings/js/JSLazyEventListener.cpp:
  • bindings/js/JSLocationCustom.cpp:
  • bindings/js/JSMessageChannelConstructor.cpp:
  • bindings/js/JSOptionConstructor.cpp:
  • bindings/js/JSWebSocketConstructor.cpp:
  • bindings/js/JSWebSocketCustom.cpp:
  • bindings/js/JSWorkerConstructor.cpp:
  • bindings/js/JSXMLHttpRequestConstructor.cpp:
  • bridge/jni/jni_jsobject.mm:

Updated includes.

  • inspector/JavaScriptDebugServer.cpp:

(WebCore::JavaScriptDebugServer::sourceParsed):
Change to not assert if this is called with no listeners.
I don't think this was guaranteed before, and we now use
this code path when recompiling. Slightly less efficient,
but this is a one-time cost when turning on the debugger.
(WebCore::JavaScriptDebugServer::recompileAllJSFunctions):
Change to call Debugger::recompileAllJSFunctions.

WebKit/mac: * Plugins/Hosted/NetscapePluginInstanceProxy.mm: Updated includes.

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