1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
|
/*
* Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef Executable_h
#define Executable_h
#include "CallData.h"
#include "CodeSpecializationKind.h"
#include "JSFunction.h"
#include "Interpreter.h"
#include "Nodes.h"
#include "SamplingTool.h"
#include <wtf/PassOwnPtr.h>
namespace JSC {
class CodeBlock;
class Debugger;
class EvalCodeBlock;
class FunctionCodeBlock;
class LLIntOffsetsExtractor;
class ProgramCodeBlock;
class ScopeChainNode;
struct ExceptionInfo;
enum CompilationKind { FirstCompilation, OptimizingCompilation };
inline bool isCall(CodeSpecializationKind kind)
{
if (kind == CodeForCall)
return true;
ASSERT(kind == CodeForConstruct);
return false;
}
class ExecutableBase : public JSCell {
friend class JIT;
protected:
static const int NUM_PARAMETERS_IS_HOST = 0;
static const int NUM_PARAMETERS_NOT_COMPILED = -1;
ExecutableBase(JSGlobalData& globalData, Structure* structure, int numParameters)
: JSCell(globalData, structure)
, m_numParametersForCall(numParameters)
, m_numParametersForConstruct(numParameters)
{
}
void finishCreation(JSGlobalData& globalData)
{
Base::finishCreation(globalData);
}
public:
typedef JSCell Base;
#if ENABLE(JIT)
static void destroy(JSCell*);
#endif
bool isHostFunction() const
{
ASSERT((m_numParametersForCall == NUM_PARAMETERS_IS_HOST) == (m_numParametersForConstruct == NUM_PARAMETERS_IS_HOST));
return m_numParametersForCall == NUM_PARAMETERS_IS_HOST;
}
static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue proto) { return Structure::create(globalData, globalObject, proto, TypeInfo(CompoundType, StructureFlags), &s_info); }
static JS_EXPORTDATA const ClassInfo s_info;
protected:
static const unsigned StructureFlags = 0;
int m_numParametersForCall;
int m_numParametersForConstruct;
#if ENABLE(JIT)
public:
JITCode& generatedJITCodeForCall()
{
ASSERT(m_jitCodeForCall);
return m_jitCodeForCall;
}
JITCode& generatedJITCodeForConstruct()
{
ASSERT(m_jitCodeForConstruct);
return m_jitCodeForConstruct;
}
JITCode& generatedJITCodeFor(CodeSpecializationKind kind)
{
if (kind == CodeForCall)
return generatedJITCodeForCall();
ASSERT(kind == CodeForConstruct);
return generatedJITCodeForConstruct();
}
MacroAssemblerCodePtr generatedJITCodeForCallWithArityCheck()
{
ASSERT(m_jitCodeForCall);
ASSERT(m_jitCodeForCallWithArityCheck);
return m_jitCodeForCallWithArityCheck;
}
MacroAssemblerCodePtr generatedJITCodeForConstructWithArityCheck()
{
ASSERT(m_jitCodeForConstruct);
ASSERT(m_jitCodeForConstructWithArityCheck);
return m_jitCodeForConstructWithArityCheck;
}
MacroAssemblerCodePtr generatedJITCodeWithArityCheckFor(CodeSpecializationKind kind)
{
if (kind == CodeForCall)
return generatedJITCodeForCallWithArityCheck();
ASSERT(kind == CodeForConstruct);
return generatedJITCodeForConstructWithArityCheck();
}
bool hasJITCodeForCall() const
{
return m_numParametersForCall >= 0;
}
bool hasJITCodeForConstruct() const
{
return m_numParametersForConstruct >= 0;
}
bool hasJITCodeFor(CodeSpecializationKind kind) const
{
if (kind == CodeForCall)
return hasJITCodeForCall();
ASSERT(kind == CodeForConstruct);
return hasJITCodeForConstruct();
}
// Intrinsics are only for calls, currently.
Intrinsic intrinsic() const;
Intrinsic intrinsicFor(CodeSpecializationKind kind) const
{
if (isCall(kind))
return intrinsic();
return NoIntrinsic;
}
protected:
JITCode m_jitCodeForCall;
JITCode m_jitCodeForConstruct;
MacroAssemblerCodePtr m_jitCodeForCallWithArityCheck;
MacroAssemblerCodePtr m_jitCodeForConstructWithArityCheck;
#endif
void clearCode();
};
class NativeExecutable : public ExecutableBase {
friend class JIT;
friend class LLIntOffsetsExtractor;
public:
typedef ExecutableBase Base;
#if ENABLE(JIT)
static NativeExecutable* create(JSGlobalData& globalData, MacroAssemblerCodeRef callThunk, NativeFunction function, MacroAssemblerCodeRef constructThunk, NativeFunction constructor, Intrinsic intrinsic)
{
ASSERT(!globalData.interpreter->classicEnabled());
NativeExecutable* executable;
if (!callThunk) {
executable = new (NotNull, allocateCell<NativeExecutable>(globalData.heap)) NativeExecutable(globalData, function, constructor);
executable->finishCreation(globalData, JITCode(), JITCode(), intrinsic);
} else {
executable = new (NotNull, allocateCell<NativeExecutable>(globalData.heap)) NativeExecutable(globalData, function, constructor);
executable->finishCreation(globalData, JITCode::HostFunction(callThunk), JITCode::HostFunction(constructThunk), intrinsic);
}
globalData.heap.addFinalizer(executable, &finalize);
return executable;
}
#endif
#if ENABLE(CLASSIC_INTERPRETER)
static NativeExecutable* create(JSGlobalData& globalData, NativeFunction function, NativeFunction constructor)
{
ASSERT(!globalData.canUseJIT());
NativeExecutable* executable = new (NotNull, allocateCell<NativeExecutable>(globalData.heap)) NativeExecutable(globalData, function, constructor);
executable->finishCreation(globalData);
globalData.heap.addFinalizer(executable, &finalize);
return executable;
}
#endif
#if ENABLE(JIT)
static void destroy(JSCell*);
#endif
NativeFunction function() { return m_function; }
NativeFunction constructor() { return m_constructor; }
static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue proto) { return Structure::create(globalData, globalObject, proto, TypeInfo(LeafType, StructureFlags), &s_info); }
static const ClassInfo s_info;
Intrinsic intrinsic() const;
protected:
#if ENABLE(JIT)
void finishCreation(JSGlobalData& globalData, JITCode callThunk, JITCode constructThunk, Intrinsic intrinsic)
{
ASSERT(!globalData.interpreter->classicEnabled());
Base::finishCreation(globalData);
m_jitCodeForCall = callThunk;
m_jitCodeForConstruct = constructThunk;
m_jitCodeForCallWithArityCheck = callThunk.addressForCall();
m_jitCodeForConstructWithArityCheck = constructThunk.addressForCall();
m_intrinsic = intrinsic;
}
#endif
#if ENABLE(CLASSIC_INTERPRETER)
void finishCreation(JSGlobalData& globalData)
{
ASSERT(!globalData.canUseJIT());
Base::finishCreation(globalData);
m_intrinsic = NoIntrinsic;
}
#endif
static void finalize(JSCell*);
private:
NativeExecutable(JSGlobalData& globalData, NativeFunction function, NativeFunction constructor)
: ExecutableBase(globalData, globalData.nativeExecutableStructure.get(), NUM_PARAMETERS_IS_HOST)
, m_function(function)
, m_constructor(constructor)
{
}
NativeFunction m_function;
NativeFunction m_constructor;
Intrinsic m_intrinsic;
};
class ScriptExecutable : public ExecutableBase {
public:
typedef ExecutableBase Base;
ScriptExecutable(Structure* structure, JSGlobalData& globalData, const SourceCode& source, bool isInStrictContext)
: ExecutableBase(globalData, structure, NUM_PARAMETERS_NOT_COMPILED)
, m_source(source)
, m_scopeFlags(isInStrictContext ? StrictModeFlag : NoScopeFlags)
{
}
ScriptExecutable(Structure* structure, ExecState* exec, const SourceCode& source, bool isInStrictContext)
: ExecutableBase(exec->globalData(), structure, NUM_PARAMETERS_NOT_COMPILED)
, m_source(source)
, m_scopeFlags(isInStrictContext ? StrictModeFlag : NoScopeFlags)
{
}
#if ENABLE(JIT)
static void destroy(JSCell*);
#endif
const SourceCode& source() { return m_source; }
intptr_t sourceID() const { return m_source.provider()->asID(); }
const UString& sourceURL() const { return m_source.provider()->url(); }
int lineNo() const { return m_firstLine; }
int lastLine() const { return m_lastLine; }
bool usesEval() const { return m_scopeFlags & UsesEvalFlag; }
bool usesArguments() const { return m_scopeFlags & UsesArgumentsFlag; }
bool needsActivation() const { return m_hasCapturedVariables || m_scopeFlags & (UsesEvalFlag | UsesWithFlag | UsesCatchFlag); }
bool isStrictMode() const { return m_scopeFlags & StrictModeFlag; }
void unlinkCalls();
static const ClassInfo s_info;
protected:
void finishCreation(JSGlobalData& globalData)
{
Base::finishCreation(globalData);
#if ENABLE(CODEBLOCK_SAMPLING)
if (SamplingTool* sampler = globalData.interpreter->sampler())
sampler->notifyOfScope(globalData, this);
#endif
}
void recordParse(ScopeFlags scopeFlags, bool hasCapturedVariables, int firstLine, int lastLine)
{
m_scopeFlags = scopeFlags;
m_hasCapturedVariables = hasCapturedVariables;
m_firstLine = firstLine;
m_lastLine = lastLine;
}
SourceCode m_source;
ScopeFlags m_scopeFlags;
bool m_hasCapturedVariables;
int m_firstLine;
int m_lastLine;
};
class EvalExecutable : public ScriptExecutable {
friend class LLIntOffsetsExtractor;
public:
typedef ScriptExecutable Base;
static void destroy(JSCell*);
JSObject* compile(ExecState* exec, ScopeChainNode* scopeChainNode)
{
ASSERT(exec->globalData().dynamicGlobalObject);
JSObject* error = 0;
if (!m_evalCodeBlock)
error = compileInternal(exec, scopeChainNode, JITCode::bottomTierJIT());
ASSERT(!error == !!m_evalCodeBlock);
return error;
}
JSObject* compileOptimized(ExecState*, ScopeChainNode*);
#if ENABLE(JIT)
void jettisonOptimizedCode(JSGlobalData&);
bool jitCompile(JSGlobalData&);
#endif
EvalCodeBlock& generatedBytecode()
{
ASSERT(m_evalCodeBlock);
return *m_evalCodeBlock;
}
static EvalExecutable* create(ExecState* exec, const SourceCode& source, bool isInStrictContext)
{
EvalExecutable* executable = new (NotNull, allocateCell<EvalExecutable>(*exec->heap())) EvalExecutable(exec, source, isInStrictContext);
executable->finishCreation(exec->globalData());
exec->globalData().heap.addFinalizer(executable, &finalize);
return executable;
}
#if ENABLE(JIT)
JITCode& generatedJITCode()
{
return generatedJITCodeForCall();
}
#endif
static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue proto)
{
return Structure::create(globalData, globalObject, proto, TypeInfo(EvalExecutableType, StructureFlags), &s_info);
}
static const ClassInfo s_info;
void unlinkCalls();
protected:
void clearCode();
static void finalize(JSCell*);
private:
static const unsigned StructureFlags = OverridesVisitChildren | ScriptExecutable::StructureFlags;
EvalExecutable(ExecState*, const SourceCode&, bool);
JSObject* compileInternal(ExecState*, ScopeChainNode*, JITCode::JITType);
static void visitChildren(JSCell*, SlotVisitor&);
OwnPtr<EvalCodeBlock> m_evalCodeBlock;
};
class ProgramExecutable : public ScriptExecutable {
friend class LLIntOffsetsExtractor;
public:
typedef ScriptExecutable Base;
static ProgramExecutable* create(ExecState* exec, const SourceCode& source)
{
ProgramExecutable* executable = new (NotNull, allocateCell<ProgramExecutable>(*exec->heap())) ProgramExecutable(exec, source);
executable->finishCreation(exec->globalData());
exec->globalData().heap.addFinalizer(executable, &finalize);
return executable;
}
static void destroy(JSCell*);
JSObject* compile(ExecState* exec, ScopeChainNode* scopeChainNode)
{
ASSERT(exec->globalData().dynamicGlobalObject);
JSObject* error = 0;
if (!m_programCodeBlock)
error = compileInternal(exec, scopeChainNode, JITCode::bottomTierJIT());
ASSERT(!error == !!m_programCodeBlock);
return error;
}
JSObject* compileOptimized(ExecState*, ScopeChainNode*);
#if ENABLE(JIT)
void jettisonOptimizedCode(JSGlobalData&);
bool jitCompile(JSGlobalData&);
#endif
ProgramCodeBlock& generatedBytecode()
{
ASSERT(m_programCodeBlock);
return *m_programCodeBlock;
}
JSObject* checkSyntax(ExecState*);
#if ENABLE(JIT)
JITCode& generatedJITCode()
{
return generatedJITCodeForCall();
}
#endif
static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue proto)
{
return Structure::create(globalData, globalObject, proto, TypeInfo(ProgramExecutableType, StructureFlags), &s_info);
}
static const ClassInfo s_info;
void unlinkCalls();
protected:
void clearCode();
static void finalize(JSCell*);
private:
static const unsigned StructureFlags = OverridesVisitChildren | ScriptExecutable::StructureFlags;
ProgramExecutable(ExecState*, const SourceCode&);
JSObject* compileInternal(ExecState*, ScopeChainNode*, JITCode::JITType);
static void visitChildren(JSCell*, SlotVisitor&);
OwnPtr<ProgramCodeBlock> m_programCodeBlock;
};
class FunctionExecutable : public ScriptExecutable, public DoublyLinkedListNode<FunctionExecutable> {
friend class JIT;
friend class LLIntOffsetsExtractor;
friend class WTF::DoublyLinkedListNode<FunctionExecutable>;
public:
typedef ScriptExecutable Base;
static FunctionExecutable* create(ExecState* exec, const Identifier& name, const Identifier& inferredName, const SourceCode& source, bool forceUsesArguments, FunctionParameters* parameters, bool isInStrictContext, int firstLine, int lastLine)
{
FunctionExecutable* executable = new (NotNull, allocateCell<FunctionExecutable>(*exec->heap())) FunctionExecutable(exec, name, inferredName, source, forceUsesArguments, parameters, isInStrictContext);
executable->finishCreation(exec->globalData(), name, firstLine, lastLine);
exec->globalData().heap.addFunctionExecutable(executable);
exec->globalData().heap.addFinalizer(executable, &finalize);
return executable;
}
static FunctionExecutable* create(JSGlobalData& globalData, const Identifier& name, const Identifier& inferredName, const SourceCode& source, bool forceUsesArguments, FunctionParameters* parameters, bool isInStrictContext, int firstLine, int lastLine)
{
FunctionExecutable* executable = new (NotNull, allocateCell<FunctionExecutable>(globalData.heap)) FunctionExecutable(globalData, name, inferredName, source, forceUsesArguments, parameters, isInStrictContext);
executable->finishCreation(globalData, name, firstLine, lastLine);
globalData.heap.addFunctionExecutable(executable);
globalData.heap.addFinalizer(executable, &finalize);
return executable;
}
static void destroy(JSCell*);
JSFunction* make(ExecState* exec, ScopeChainNode* scopeChain)
{
return JSFunction::create(exec, this, scopeChain);
}
// Returns either call or construct bytecode. This can be appropriate
// for answering questions that that don't vary between call and construct --
// for example, argumentsRegister().
FunctionCodeBlock& generatedBytecode()
{
if (m_codeBlockForCall)
return *m_codeBlockForCall;
ASSERT(m_codeBlockForConstruct);
return *m_codeBlockForConstruct;
}
FunctionCodeBlock* codeBlockWithBytecodeFor(CodeSpecializationKind);
PassOwnPtr<FunctionCodeBlock> produceCodeBlockFor(ScopeChainNode*, CompilationKind, CodeSpecializationKind, JSObject*& exception);
JSObject* compileForCall(ExecState* exec, ScopeChainNode* scopeChainNode)
{
ASSERT(exec->globalData().dynamicGlobalObject);
JSObject* error = 0;
if (!m_codeBlockForCall)
error = compileForCallInternal(exec, scopeChainNode, JITCode::bottomTierJIT());
ASSERT(!error == !!m_codeBlockForCall);
return error;
}
JSObject* compileOptimizedForCall(ExecState*, ScopeChainNode*);
#if ENABLE(JIT)
void jettisonOptimizedCodeForCall(JSGlobalData&);
bool jitCompileForCall(JSGlobalData&);
#endif
bool isGeneratedForCall() const
{
return m_codeBlockForCall;
}
FunctionCodeBlock& generatedBytecodeForCall()
{
ASSERT(m_codeBlockForCall);
return *m_codeBlockForCall;
}
JSObject* compileForConstruct(ExecState* exec, ScopeChainNode* scopeChainNode)
{
ASSERT(exec->globalData().dynamicGlobalObject);
JSObject* error = 0;
if (!m_codeBlockForConstruct)
error = compileForConstructInternal(exec, scopeChainNode, JITCode::bottomTierJIT());
ASSERT(!error == !!m_codeBlockForConstruct);
return error;
}
JSObject* compileOptimizedForConstruct(ExecState*, ScopeChainNode*);
#if ENABLE(JIT)
void jettisonOptimizedCodeForConstruct(JSGlobalData&);
bool jitCompileForConstruct(JSGlobalData&);
#endif
bool isGeneratedForConstruct() const
{
return m_codeBlockForConstruct;
}
FunctionCodeBlock& generatedBytecodeForConstruct()
{
ASSERT(m_codeBlockForConstruct);
return *m_codeBlockForConstruct;
}
JSObject* compileFor(ExecState* exec, ScopeChainNode* scopeChainNode, CodeSpecializationKind kind)
{
ASSERT(exec->callee());
ASSERT(exec->callee()->inherits(&JSFunction::s_info));
ASSERT(jsCast<JSFunction*>(exec->callee())->jsExecutable() == this);
if (kind == CodeForCall)
return compileForCall(exec, scopeChainNode);
ASSERT(kind == CodeForConstruct);
return compileForConstruct(exec, scopeChainNode);
}
JSObject* compileOptimizedFor(ExecState* exec, ScopeChainNode* scopeChainNode, CodeSpecializationKind kind)
{
ASSERT(exec->callee());
ASSERT(exec->callee()->inherits(&JSFunction::s_info));
ASSERT(jsCast<JSFunction*>(exec->callee())->jsExecutable() == this);
if (kind == CodeForCall)
return compileOptimizedForCall(exec, scopeChainNode);
ASSERT(kind == CodeForConstruct);
return compileOptimizedForConstruct(exec, scopeChainNode);
}
#if ENABLE(JIT)
void jettisonOptimizedCodeFor(JSGlobalData& globalData, CodeSpecializationKind kind)
{
if (kind == CodeForCall)
jettisonOptimizedCodeForCall(globalData);
else {
ASSERT(kind == CodeForConstruct);
jettisonOptimizedCodeForConstruct(globalData);
}
}
bool jitCompileFor(JSGlobalData& globalData, CodeSpecializationKind kind)
{
if (kind == CodeForCall)
return jitCompileForCall(globalData);
ASSERT(kind == CodeForConstruct);
return jitCompileForConstruct(globalData);
}
#endif
bool isGeneratedFor(CodeSpecializationKind kind)
{
if (kind == CodeForCall)
return isGeneratedForCall();
ASSERT(kind == CodeForConstruct);
return isGeneratedForConstruct();
}
FunctionCodeBlock& generatedBytecodeFor(CodeSpecializationKind kind)
{
if (kind == CodeForCall)
return generatedBytecodeForCall();
ASSERT(kind == CodeForConstruct);
return generatedBytecodeForConstruct();
}
FunctionCodeBlock* baselineCodeBlockFor(CodeSpecializationKind);
FunctionCodeBlock* profiledCodeBlockFor(CodeSpecializationKind kind)
{
return baselineCodeBlockFor(kind);
}
const Identifier& name() { return m_name; }
const Identifier& inferredName() { return m_inferredName; }
JSString* nameValue() const { return m_nameValue.get(); }
size_t parameterCount() const { return m_parameters->size(); } // Excluding 'this'!
unsigned capturedVariableCount() const { return m_numCapturedVariables; }
UString paramString() const;
SharedSymbolTable* symbolTable() const { return m_symbolTable; }
void discardCode();
static void visitChildren(JSCell*, SlotVisitor&);
static FunctionExecutable* fromGlobalCode(const Identifier&, ExecState*, Debugger*, const SourceCode&, JSObject** exception);
static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue proto)
{
return Structure::create(globalData, globalObject, proto, TypeInfo(FunctionExecutableType, StructureFlags), &s_info);
}
static const ClassInfo s_info;
void unlinkCalls();
protected:
void clearCode();
static void finalize(JSCell*);
void finishCreation(JSGlobalData& globalData, const Identifier& name, int firstLine, int lastLine)
{
Base::finishCreation(globalData);
m_firstLine = firstLine;
m_lastLine = lastLine;
m_nameValue.set(globalData, this, jsString(&globalData, name.ustring()));
}
private:
FunctionExecutable(JSGlobalData&, const Identifier& name, const Identifier& inferredName, const SourceCode&, bool forceUsesArguments, FunctionParameters*, bool);
FunctionExecutable(ExecState*, const Identifier& name, const Identifier& inferredName, const SourceCode&, bool forceUsesArguments, FunctionParameters*, bool);
JSObject* compileForCallInternal(ExecState*, ScopeChainNode*, JITCode::JITType);
JSObject* compileForConstructInternal(ExecState*, ScopeChainNode*, JITCode::JITType);
OwnPtr<FunctionCodeBlock>& codeBlockFor(CodeSpecializationKind kind)
{
if (kind == CodeForCall)
return m_codeBlockForCall;
ASSERT(kind == CodeForConstruct);
return m_codeBlockForConstruct;
}
static const unsigned StructureFlags = OverridesVisitChildren | ScriptExecutable::StructureFlags;
unsigned m_numCapturedVariables : 31;
bool m_forceUsesArguments : 1;
RefPtr<FunctionParameters> m_parameters;
OwnPtr<FunctionCodeBlock> m_codeBlockForCall;
OwnPtr<FunctionCodeBlock> m_codeBlockForConstruct;
Identifier m_name;
Identifier m_inferredName;
WriteBarrier<JSString> m_nameValue;
SharedSymbolTable* m_symbolTable;
FunctionExecutable* m_next;
FunctionExecutable* m_prev;
};
inline FunctionExecutable* JSFunction::jsExecutable() const
{
ASSERT(!isHostFunctionNonInline());
return static_cast<FunctionExecutable*>(m_executable.get());
}
inline bool JSFunction::isHostFunction() const
{
ASSERT(m_executable);
return m_executable->isHostFunction();
}
inline NativeFunction JSFunction::nativeFunction()
{
ASSERT(isHostFunction());
return static_cast<NativeExecutable*>(m_executable.get())->function();
}
inline NativeFunction JSFunction::nativeConstructor()
{
ASSERT(isHostFunction());
return static_cast<NativeExecutable*>(m_executable.get())->constructor();
}
inline bool isHostFunction(JSValue value, NativeFunction nativeFunction)
{
JSFunction* function = jsCast<JSFunction*>(getJSFunction(value));
if (!function || !function->isHostFunction())
return false;
return function->nativeFunction() == nativeFunction;
}
inline void ScriptExecutable::unlinkCalls()
{
switch (structure()->typeInfo().type()) {
case EvalExecutableType:
return jsCast<EvalExecutable*>(this)->unlinkCalls();
case ProgramExecutableType:
return jsCast<ProgramExecutable*>(this)->unlinkCalls();
case FunctionExecutableType:
return jsCast<FunctionExecutable*>(this)->unlinkCalls();
default:
ASSERT_NOT_REACHED();
}
}
}
#endif
|