Web Inspector: ES6: Provide a better view for Classes in the console
[WebKit-https.git] / Source / JavaScriptCore / runtime / Executable.h
1 /*
2  * Copyright (C) 2009, 2010, 2013-2015 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef Executable_h
27 #define Executable_h
28
29 #include "ArityCheckMode.h"
30 #include "CallData.h"
31 #include "CodeBlockHash.h"
32 #include "CodeSpecializationKind.h"
33 #include "CompilationResult.h"
34 #include "DFGPlan.h"
35 #include "HandlerInfo.h"
36 #include "JSFunction.h"
37 #include "Interpreter.h"
38 #include "JITCode.h"
39 #include "JSGlobalObject.h"
40 #include "RegisterPreservationMode.h"
41 #include "SamplingTool.h"
42 #include "SourceCode.h"
43 #include "TypeSet.h"
44 #include "UnlinkedCodeBlock.h"
45
46 namespace JSC {
47
48 class CodeBlock;
49 class Debugger;
50 class EvalCodeBlock;
51 class FunctionCodeBlock;
52 class LLIntOffsetsExtractor;
53 class ProgramCodeBlock;
54 class JSScope;
55     
56 enum CompilationKind { FirstCompilation, OptimizingCompilation };
57
58 inline bool isCall(CodeSpecializationKind kind)
59 {
60     if (kind == CodeForCall)
61         return true;
62     ASSERT(kind == CodeForConstruct);
63     return false;
64 }
65
66 class ExecutableBase : public JSCell {
67     friend class JIT;
68
69 protected:
70     static const int NUM_PARAMETERS_IS_HOST = 0;
71     static const int NUM_PARAMETERS_NOT_COMPILED = -1;
72
73     ExecutableBase(VM& vm, Structure* structure, int numParameters)
74         : JSCell(vm, structure)
75         , m_numParametersForCall(numParameters)
76         , m_numParametersForConstruct(numParameters)
77     {
78     }
79
80     void finishCreation(VM& vm)
81     {
82         Base::finishCreation(vm);
83     }
84
85 public:
86     typedef JSCell Base;
87
88     static const bool needsDestruction = true;
89     static const bool hasImmortalStructure = true;
90     static void destroy(JSCell*);
91         
92     CodeBlockHash hashFor(CodeSpecializationKind) const;
93
94     bool isEvalExecutable()
95     {
96         return type() == EvalExecutableType;
97     }
98     bool isFunctionExecutable()
99     {
100         return type() == FunctionExecutableType;
101     }
102     bool isProgramExecutable()
103     {
104         return type() == ProgramExecutableType;
105     }
106
107     bool isHostFunction() const
108     {
109         ASSERT((m_numParametersForCall == NUM_PARAMETERS_IS_HOST) == (m_numParametersForConstruct == NUM_PARAMETERS_IS_HOST));
110         return m_numParametersForCall == NUM_PARAMETERS_IS_HOST;
111     }
112
113     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto) { return Structure::create(vm, globalObject, proto, TypeInfo(CellType, StructureFlags), info()); }
114         
115     void clearCode();
116
117     DECLARE_EXPORT_INFO;
118
119 protected:
120     static const unsigned StructureFlags = StructureIsImmortal;
121     int m_numParametersForCall;
122     int m_numParametersForConstruct;
123
124 public:
125     static void clearCodeVirtual(ExecutableBase*);
126
127     PassRefPtr<JITCode> generatedJITCodeForCall()
128     {
129         ASSERT(m_jitCodeForCall);
130         return m_jitCodeForCall;
131     }
132
133     PassRefPtr<JITCode> generatedJITCodeForConstruct()
134     {
135         ASSERT(m_jitCodeForConstruct);
136         return m_jitCodeForConstruct;
137     }
138         
139     PassRefPtr<JITCode> generatedJITCodeFor(CodeSpecializationKind kind)
140     {
141         if (kind == CodeForCall)
142             return generatedJITCodeForCall();
143         ASSERT(kind == CodeForConstruct);
144         return generatedJITCodeForConstruct();
145     }
146     
147     MacroAssemblerCodePtr entrypointFor(
148         VM& vm, CodeSpecializationKind kind, ArityCheckMode arity, RegisterPreservationMode registers)
149     {
150         // Check if we have a cached result. We only have it for arity check because we use the
151         // no-arity entrypoint in non-virtual calls, which will "cache" this value directly in
152         // machine code.
153         if (arity == MustCheckArity) {
154             switch (kind) {
155             case CodeForCall:
156                 switch (registers) {
157                 case RegisterPreservationNotRequired:
158                     if (MacroAssemblerCodePtr result = m_jitCodeForCallWithArityCheck)
159                         return result;
160                     break;
161                 case MustPreserveRegisters:
162                     if (MacroAssemblerCodePtr result = m_jitCodeForCallWithArityCheckAndPreserveRegs)
163                         return result;
164                     break;
165                 }
166                 break;
167             case CodeForConstruct:
168                 switch (registers) {
169                 case RegisterPreservationNotRequired:
170                     if (MacroAssemblerCodePtr result = m_jitCodeForConstructWithArityCheck)
171                         return result;
172                     break;
173                 case MustPreserveRegisters:
174                     if (MacroAssemblerCodePtr result = m_jitCodeForConstructWithArityCheckAndPreserveRegs)
175                         return result;
176                     break;
177                 }
178                 break;
179             }
180         }
181         MacroAssemblerCodePtr result =
182             generatedJITCodeFor(kind)->addressForCall(vm, this, arity, registers);
183         if (arity == MustCheckArity) {
184             // Cache the result; this is necessary for the JIT's virtual call optimizations.
185             switch (kind) {
186             case CodeForCall:
187                 switch (registers) {
188                 case RegisterPreservationNotRequired:
189                     m_jitCodeForCallWithArityCheck = result;
190                     break;
191                 case MustPreserveRegisters:
192                     m_jitCodeForCallWithArityCheckAndPreserveRegs = result;
193                     break;
194                 }
195                 break;
196             case CodeForConstruct:
197                 switch (registers) {
198                 case RegisterPreservationNotRequired:
199                     m_jitCodeForConstructWithArityCheck = result;
200                     break;
201                 case MustPreserveRegisters:
202                     m_jitCodeForConstructWithArityCheckAndPreserveRegs = result;
203                     break;
204                 }
205                 break;
206             }
207         }
208         return result;
209     }
210
211     static ptrdiff_t offsetOfJITCodeWithArityCheckFor(
212         CodeSpecializationKind kind, RegisterPreservationMode registers)
213     {
214         switch (kind) {
215         case CodeForCall:
216             switch (registers) {
217             case RegisterPreservationNotRequired:
218                 return OBJECT_OFFSETOF(ExecutableBase, m_jitCodeForCallWithArityCheck);
219             case MustPreserveRegisters:
220                 return OBJECT_OFFSETOF(ExecutableBase, m_jitCodeForCallWithArityCheckAndPreserveRegs);
221             }
222         case CodeForConstruct:
223             switch (registers) {
224             case RegisterPreservationNotRequired:
225                 return OBJECT_OFFSETOF(ExecutableBase, m_jitCodeForConstructWithArityCheck);
226             case MustPreserveRegisters:
227                 return OBJECT_OFFSETOF(ExecutableBase, m_jitCodeForConstructWithArityCheckAndPreserveRegs);
228             }
229         }
230         RELEASE_ASSERT_NOT_REACHED();
231         return 0;
232     }
233     
234     static ptrdiff_t offsetOfNumParametersFor(CodeSpecializationKind kind)
235     {
236         if (kind == CodeForCall)
237             return OBJECT_OFFSETOF(ExecutableBase, m_numParametersForCall);
238         ASSERT(kind == CodeForConstruct);
239         return OBJECT_OFFSETOF(ExecutableBase, m_numParametersForConstruct);
240     }
241
242     bool hasJITCodeForCall() const
243     {
244         return m_numParametersForCall >= 0;
245     }
246         
247     bool hasJITCodeForConstruct() const
248     {
249         return m_numParametersForConstruct >= 0;
250     }
251         
252     bool hasJITCodeFor(CodeSpecializationKind kind) const
253     {
254         if (kind == CodeForCall)
255             return hasJITCodeForCall();
256         ASSERT(kind == CodeForConstruct);
257         return hasJITCodeForConstruct();
258     }
259
260     // Intrinsics are only for calls, currently.
261     Intrinsic intrinsic() const;
262         
263     Intrinsic intrinsicFor(CodeSpecializationKind kind) const
264     {
265         if (isCall(kind))
266             return intrinsic();
267         return NoIntrinsic;
268     }
269     
270     void dump(PrintStream&) const;
271         
272 protected:
273     RefPtr<JITCode> m_jitCodeForCall;
274     RefPtr<JITCode> m_jitCodeForConstruct;
275     MacroAssemblerCodePtr m_jitCodeForCallWithArityCheck;
276     MacroAssemblerCodePtr m_jitCodeForConstructWithArityCheck;
277     MacroAssemblerCodePtr m_jitCodeForCallWithArityCheckAndPreserveRegs;
278     MacroAssemblerCodePtr m_jitCodeForConstructWithArityCheckAndPreserveRegs;
279 };
280
281 class NativeExecutable : public ExecutableBase {
282     friend class JIT;
283     friend class LLIntOffsetsExtractor;
284 public:
285     typedef ExecutableBase Base;
286
287     static NativeExecutable* create(VM& vm, PassRefPtr<JITCode> callThunk, NativeFunction function, PassRefPtr<JITCode> constructThunk, NativeFunction constructor, Intrinsic intrinsic)
288     {
289         NativeExecutable* executable;
290         executable = new (NotNull, allocateCell<NativeExecutable>(vm.heap)) NativeExecutable(vm, function, constructor);
291         executable->finishCreation(vm, callThunk, constructThunk, intrinsic);
292         return executable;
293     }
294
295     static void destroy(JSCell*);
296
297     CodeBlockHash hashFor(CodeSpecializationKind) const;
298
299     NativeFunction function() { return m_function; }
300     NativeFunction constructor() { return m_constructor; }
301         
302     NativeFunction nativeFunctionFor(CodeSpecializationKind kind)
303     {
304         if (kind == CodeForCall)
305             return function();
306         ASSERT(kind == CodeForConstruct);
307         return constructor();
308     }
309         
310     static ptrdiff_t offsetOfNativeFunctionFor(CodeSpecializationKind kind)
311     {
312         if (kind == CodeForCall)
313             return OBJECT_OFFSETOF(NativeExecutable, m_function);
314         ASSERT(kind == CodeForConstruct);
315         return OBJECT_OFFSETOF(NativeExecutable, m_constructor);
316     }
317
318     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto) { return Structure::create(vm, globalObject, proto, TypeInfo(CellType, StructureFlags), info()); }
319         
320     DECLARE_INFO;
321
322     Intrinsic intrinsic() const;
323
324 protected:
325     void finishCreation(VM& vm, PassRefPtr<JITCode> callThunk, PassRefPtr<JITCode> constructThunk, Intrinsic intrinsic)
326     {
327         Base::finishCreation(vm);
328         m_jitCodeForCall = callThunk;
329         m_jitCodeForConstruct = constructThunk;
330         m_intrinsic = intrinsic;
331     }
332
333 private:
334     NativeExecutable(VM& vm, NativeFunction function, NativeFunction constructor)
335         : ExecutableBase(vm, vm.nativeExecutableStructure.get(), NUM_PARAMETERS_IS_HOST)
336         , m_function(function)
337         , m_constructor(constructor)
338     {
339     }
340
341     NativeFunction m_function;
342     NativeFunction m_constructor;
343         
344     Intrinsic m_intrinsic;
345 };
346
347 class ScriptExecutable : public ExecutableBase {
348 public:
349     typedef ExecutableBase Base;
350
351     ScriptExecutable(Structure* structure, VM& vm, const SourceCode& source, bool isInStrictContext);
352
353     static void destroy(JSCell*);
354         
355     CodeBlockHash hashFor(CodeSpecializationKind) const;
356
357     const SourceCode& source() const { return m_source; }
358     intptr_t sourceID() const { return m_source.providerID(); }
359     const String& sourceURL() const { return m_source.provider()->url(); }
360     int firstLine() const { return m_firstLine; }
361     void setOverrideLineNumber(int overrideLineNumber) { m_overrideLineNumber = overrideLineNumber; }
362     bool hasOverrideLineNumber() const { return m_overrideLineNumber != -1; }
363     int overrideLineNumber() const { return m_overrideLineNumber; }
364     int lastLine() const { return m_lastLine; }
365     unsigned startColumn() const { return m_startColumn; }
366     unsigned endColumn() const { return m_endColumn; }
367     unsigned typeProfilingStartOffset() const { return m_typeProfilingStartOffset; }
368     unsigned typeProfilingEndOffset() const { return m_typeProfilingEndOffset; }
369
370     bool usesEval() const { return m_features & EvalFeature; }
371     bool usesArguments() const { return m_features & ArgumentsFeature; }
372     bool needsActivation() const { return m_hasCapturedVariables || m_features & (EvalFeature | WithFeature | CatchFeature); }
373     bool isStrictMode() const { return m_features & StrictModeFeature; }
374     ECMAMode ecmaMode() const { return isStrictMode() ? StrictMode : NotStrictMode; }
375         
376     void setNeverInline(bool value) { m_neverInline = value; }
377     void setDidTryToEnterInLoop(bool value) { m_didTryToEnterInLoop = value; }
378     bool neverInline() const { return m_neverInline; }
379     bool didTryToEnterInLoop() const { return m_didTryToEnterInLoop; }
380     bool isInliningCandidate() const { return !neverInline(); }
381     
382     bool* addressOfDidTryToEnterInLoop() { return &m_didTryToEnterInLoop; }
383
384     void unlinkCalls();
385         
386     CodeFeatures features() const { return m_features; }
387         
388     DECLARE_INFO;
389
390     void recordParse(CodeFeatures features, bool hasCapturedVariables, int firstLine, int lastLine, unsigned startColumn, unsigned endColumn)
391     {
392         m_features = features;
393         m_hasCapturedVariables = hasCapturedVariables;
394         m_firstLine = firstLine;
395         m_lastLine = lastLine;
396         ASSERT(startColumn != UINT_MAX);
397         m_startColumn = startColumn;
398         ASSERT(endColumn != UINT_MAX);
399         m_endColumn = endColumn;
400     }
401
402     void installCode(CodeBlock*);
403     PassRefPtr<CodeBlock> newCodeBlockFor(CodeSpecializationKind, JSFunction*, JSScope*, JSObject*& exception);
404     PassRefPtr<CodeBlock> newReplacementCodeBlockFor(CodeSpecializationKind);
405     
406     JSObject* prepareForExecution(ExecState* exec, JSFunction* function, JSScope* scope, CodeSpecializationKind kind)
407     {
408         if (hasJITCodeFor(kind))
409             return 0;
410         return prepareForExecutionImpl(exec, function, scope, kind);
411     }
412
413     template <typename Functor> void forEachCodeBlock(Functor&&);
414
415 private:
416     JSObject* prepareForExecutionImpl(ExecState*, JSFunction*, JSScope*, CodeSpecializationKind);
417
418 protected:
419     void finishCreation(VM& vm)
420     {
421         Base::finishCreation(vm);
422         vm.heap.addCompiledCode(this); // Balanced by Heap::deleteUnmarkedCompiledCode().
423
424 #if ENABLE(CODEBLOCK_SAMPLING)
425         if (SamplingTool* sampler = vm.interpreter->sampler())
426             sampler->notifyOfScope(vm, this);
427 #endif
428     }
429
430     SourceCode m_source;
431     CodeFeatures m_features;
432     bool m_hasCapturedVariables;
433     bool m_neverInline;
434     bool m_didTryToEnterInLoop;
435     int m_overrideLineNumber;
436     int m_firstLine;
437     int m_lastLine;
438     unsigned m_startColumn;
439     unsigned m_endColumn;
440     unsigned m_typeProfilingStartOffset;
441     unsigned m_typeProfilingEndOffset;
442 };
443
444 class EvalExecutable : public ScriptExecutable {
445     friend class LLIntOffsetsExtractor;
446 public:
447     typedef ScriptExecutable Base;
448
449     static void destroy(JSCell*);
450
451     EvalCodeBlock* codeBlock()
452     {
453         return m_evalCodeBlock.get();
454     }
455
456     static EvalExecutable* create(ExecState*, const SourceCode&, bool isInStrictContext);
457
458     PassRefPtr<JITCode> generatedJITCode()
459     {
460         return generatedJITCodeForCall();
461     }
462
463     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
464     {
465         return Structure::create(vm, globalObject, proto, TypeInfo(EvalExecutableType, StructureFlags), info());
466     }
467         
468     DECLARE_INFO;
469
470     void unlinkCalls();
471
472     void clearCode();
473
474     ExecutableInfo executableInfo() const { return ExecutableInfo(needsActivation(), usesEval(), isStrictMode(), false, false, ConstructorKind::None); }
475
476     unsigned numVariables() { return m_unlinkedEvalCodeBlock->numVariables(); }
477     unsigned numberOfFunctionDecls() { return m_unlinkedEvalCodeBlock->numberOfFunctionDecls(); }
478
479 private:
480     friend class ScriptExecutable;
481     EvalExecutable(ExecState*, const SourceCode&, bool);
482
483     static void visitChildren(JSCell*, SlotVisitor&);
484
485     RefPtr<EvalCodeBlock> m_evalCodeBlock;
486     WriteBarrier<UnlinkedEvalCodeBlock> m_unlinkedEvalCodeBlock;
487 };
488
489 class ProgramExecutable : public ScriptExecutable {
490     friend class LLIntOffsetsExtractor;
491 public:
492     typedef ScriptExecutable Base;
493
494     static ProgramExecutable* create(ExecState* exec, const SourceCode& source)
495     {
496         ProgramExecutable* executable = new (NotNull, allocateCell<ProgramExecutable>(*exec->heap())) ProgramExecutable(exec, source);
497         executable->finishCreation(exec->vm());
498         return executable;
499     }
500
501
502     JSObject* initializeGlobalProperties(VM&, CallFrame*, JSScope*);
503
504     static void destroy(JSCell*);
505
506     ProgramCodeBlock* codeBlock()
507     {
508         return m_programCodeBlock.get();
509     }
510
511     JSObject* checkSyntax(ExecState*);
512
513     PassRefPtr<JITCode> generatedJITCode()
514     {
515         return generatedJITCodeForCall();
516     }
517         
518     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
519     {
520         return Structure::create(vm, globalObject, proto, TypeInfo(ProgramExecutableType, StructureFlags), info());
521     }
522         
523     DECLARE_INFO;
524         
525     void unlinkCalls();
526
527     void clearCode();
528
529     ExecutableInfo executableInfo() const { return ExecutableInfo(needsActivation(), usesEval(), isStrictMode(), false, false, ConstructorKind::None); }
530
531 private:
532     friend class ScriptExecutable;
533
534     ProgramExecutable(ExecState*, const SourceCode&);
535
536     static void visitChildren(JSCell*, SlotVisitor&);
537
538     WriteBarrier<UnlinkedProgramCodeBlock> m_unlinkedProgramCodeBlock;
539     RefPtr<ProgramCodeBlock> m_programCodeBlock;
540 };
541
542 class FunctionExecutable : public ScriptExecutable {
543     friend class JIT;
544     friend class LLIntOffsetsExtractor;
545 public:
546     typedef ScriptExecutable Base;
547
548     static FunctionExecutable* create(
549         VM& vm, const SourceCode& source, UnlinkedFunctionExecutable* unlinkedExecutable, 
550         unsigned firstLine, unsigned lastLine, unsigned startColumn, unsigned endColumn)
551     {
552         FunctionExecutable* executable = new (NotNull, allocateCell<FunctionExecutable>(vm.heap)) FunctionExecutable(vm, source, unlinkedExecutable, firstLine, lastLine, startColumn, endColumn);
553         executable->finishCreation(vm);
554         return executable;
555     }
556     static FunctionExecutable* fromGlobalCode(
557         const Identifier& name, ExecState&, const SourceCode&, 
558         JSObject*& exception, int overrideLineNumber);
559
560     static void destroy(JSCell*);
561         
562     UnlinkedFunctionExecutable* unlinkedExecutable()
563     {
564         return m_unlinkedExecutable.get();
565     }
566
567     // Returns either call or construct bytecode. This can be appropriate
568     // for answering questions that that don't vary between call and construct --
569     // for example, argumentsRegister().
570     FunctionCodeBlock* eitherCodeBlock()
571     {
572         if (m_codeBlockForCall)
573             return m_codeBlockForCall.get();
574         return m_codeBlockForConstruct.get();
575     }
576         
577     bool isGeneratedForCall() const
578     {
579         return m_codeBlockForCall;
580     }
581
582     FunctionCodeBlock* codeBlockForCall()
583     {
584         return m_codeBlockForCall.get();
585     }
586
587     bool isGeneratedForConstruct() const
588     {
589         return m_codeBlockForConstruct;
590     }
591
592     FunctionCodeBlock* codeBlockForConstruct()
593     {
594         return m_codeBlockForConstruct.get();
595     }
596         
597     bool isGeneratedFor(CodeSpecializationKind kind)
598     {
599         if (kind == CodeForCall)
600             return isGeneratedForCall();
601         ASSERT(kind == CodeForConstruct);
602         return isGeneratedForConstruct();
603     }
604         
605     FunctionCodeBlock* codeBlockFor(CodeSpecializationKind kind)
606     {
607         if (kind == CodeForCall)
608             return codeBlockForCall();
609         ASSERT(kind == CodeForConstruct);
610         return codeBlockForConstruct();
611     }
612
613     FunctionCodeBlock* baselineCodeBlockFor(CodeSpecializationKind);
614         
615     FunctionCodeBlock* profiledCodeBlockFor(CodeSpecializationKind kind)
616     {
617         return baselineCodeBlockFor(kind);
618     }
619
620     RefPtr<TypeSet> returnStatementTypeSet() 
621     {
622         if (!m_returnStatementTypeSet)
623             m_returnStatementTypeSet = TypeSet::create();
624
625         return m_returnStatementTypeSet;
626     }
627         
628     FunctionMode functionMode() { return m_unlinkedExecutable->functionMode(); }
629     bool isBuiltinFunction() const { return m_unlinkedExecutable->isBuiltinFunction(); }
630     bool isClassConstructorFunction() const { return m_unlinkedExecutable->isClassConstructorFunction(); }
631     const Identifier& name() { return m_unlinkedExecutable->name(); }
632     const Identifier& inferredName() { return m_unlinkedExecutable->inferredName(); }
633     JSString* nameValue() const { return m_unlinkedExecutable->nameValue(); }
634     size_t parameterCount() const { return m_unlinkedExecutable->parameterCount(); } // Excluding 'this'!
635     SymbolTable* symbolTable(CodeSpecializationKind);
636
637     void clearCodeIfNotCompiling();
638     void clearUnlinkedCodeForRecompilationIfNotCompiling();
639     static void visitChildren(JSCell*, SlotVisitor&);
640     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
641     {
642         return Structure::create(vm, globalObject, proto, TypeInfo(FunctionExecutableType, StructureFlags), info());
643     }
644
645     unsigned parametersStartOffset() const { return m_parametersStartOffset; }
646
647     DECLARE_INFO;
648         
649     void unlinkCalls();
650
651     void clearCode();
652
653 private:
654     FunctionExecutable(
655         VM&, const SourceCode&, UnlinkedFunctionExecutable*, unsigned firstLine, 
656         unsigned lastLine, unsigned startColumn, unsigned endColumn);
657
658     bool isCompiling()
659     {
660 #if ENABLE(JIT)
661         if (!m_jitCodeForCall && m_codeBlockForCall)
662             return true;
663         if (!m_jitCodeForConstruct && m_codeBlockForConstruct)
664             return true;
665 #endif
666         return false;
667     }
668
669     friend class ScriptExecutable;
670
671     WriteBarrier<UnlinkedFunctionExecutable> m_unlinkedExecutable;
672     RefPtr<FunctionCodeBlock> m_codeBlockForCall;
673     RefPtr<FunctionCodeBlock> m_codeBlockForConstruct;
674     RefPtr<TypeSet> m_returnStatementTypeSet;
675     unsigned m_parametersStartOffset;
676 };
677
678 inline void ExecutableBase::clearCodeVirtual(ExecutableBase* executable)
679 {
680     switch (executable->type()) {
681     case EvalExecutableType:
682         return jsCast<EvalExecutable*>(executable)->clearCode();
683     case ProgramExecutableType:
684         return jsCast<ProgramExecutable*>(executable)->clearCode();
685     case FunctionExecutableType:
686         return jsCast<FunctionExecutable*>(executable)->clearCode();
687     default:
688         return jsCast<NativeExecutable*>(executable)->clearCode();
689     }
690 }
691
692 inline void ScriptExecutable::unlinkCalls()
693 {
694     switch (type()) {
695     case EvalExecutableType:
696         return jsCast<EvalExecutable*>(this)->unlinkCalls();
697     case ProgramExecutableType:
698         return jsCast<ProgramExecutable*>(this)->unlinkCalls();
699     case FunctionExecutableType:
700         return jsCast<FunctionExecutable*>(this)->unlinkCalls();
701     default:
702         RELEASE_ASSERT_NOT_REACHED();
703     }
704 }
705
706 }
707
708 #endif