2 * Copyright (C) 2012, 2013, 2014 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef UnlinkedCodeBlock_h
27 #define UnlinkedCodeBlock_h
29 #include "BytecodeConventions.h"
30 #include "CodeSpecializationKind.h"
32 #include "ExpressionRangeInfo.h"
33 #include "Identifier.h"
36 #include "ParserModes.h"
38 #include "SpecialPointer.h"
39 #include "SymbolTable.h"
40 #include "VirtualRegister.h"
42 #include <wtf/Compression.h>
43 #include <wtf/RefCountedArray.h>
44 #include <wtf/Vector.h>
49 class FunctionBodyNode;
50 class FunctionExecutable;
51 class FunctionParameters;
54 class ScriptExecutable;
58 class UnlinkedCodeBlock;
59 class UnlinkedFunctionCodeBlock;
60 class UnlinkedInstructionStream;
62 typedef unsigned UnlinkedValueProfile;
63 typedef unsigned UnlinkedArrayProfile;
64 typedef unsigned UnlinkedArrayAllocationProfile;
65 typedef unsigned UnlinkedObjectAllocationProfile;
66 typedef unsigned UnlinkedLLIntCallLinkInfo;
68 struct ExecutableInfo {
69 ExecutableInfo(bool needsActivation, bool usesEval, bool isStrictMode, bool isConstructor)
70 : m_needsActivation(needsActivation)
71 , m_usesEval(usesEval)
72 , m_isStrictMode(isStrictMode)
73 , m_isConstructor(isConstructor)
76 bool m_needsActivation;
82 class UnlinkedFunctionExecutable : public JSCell {
84 friend class CodeCache;
86 static UnlinkedFunctionExecutable* create(VM* vm, const SourceCode& source, FunctionBodyNode* node, bool isFromGlobalCode = false)
88 UnlinkedFunctionExecutable* instance = new (NotNull, allocateCell<UnlinkedFunctionExecutable>(vm->heap)) UnlinkedFunctionExecutable(vm, vm->unlinkedFunctionExecutableStructure.get(), source, node, isFromGlobalCode);
89 instance->finishCreation(*vm);
93 const Identifier& name() const { return m_name; }
94 const Identifier& inferredName() const { return m_inferredName; }
95 JSString* nameValue() const { return m_nameValue.get(); }
96 SymbolTable* symbolTable(CodeSpecializationKind kind)
98 return (kind == CodeForCall) ? m_symbolTableForCall.get() : m_symbolTableForConstruct.get();
100 size_t parameterCount() const;
101 bool isInStrictContext() const { return m_isInStrictContext; }
102 FunctionMode functionMode() const { return m_functionMode; }
104 unsigned firstLineOffset() const { return m_firstLineOffset; }
105 unsigned lineCount() const { return m_lineCount; }
106 unsigned unlinkedFunctionNameStart() const { return m_unlinkedFunctionNameStart; }
107 unsigned unlinkedBodyStartColumn() const { return m_unlinkedBodyStartColumn; }
108 unsigned unlinkedBodyEndColumn() const { return m_unlinkedBodyEndColumn; }
109 unsigned startOffset() const { return m_startOffset; }
110 unsigned sourceLength() { return m_sourceLength; }
112 String paramString() const;
114 UnlinkedFunctionCodeBlock* codeBlockFor(VM&, const SourceCode&, CodeSpecializationKind, DebuggerMode, ProfilerMode, ParserError&);
116 static UnlinkedFunctionExecutable* fromGlobalCode(const Identifier&, ExecState*, Debugger*, const SourceCode&, JSObject** exception);
118 FunctionExecutable* link(VM&, const SourceCode&, size_t lineOffset, size_t sourceOffset);
120 void clearCodeForRecompilation()
122 m_symbolTableForCall.clear();
123 m_symbolTableForConstruct.clear();
124 m_codeBlockForCall.clear();
125 m_codeBlockForConstruct.clear();
128 FunctionParameters* parameters() { return m_parameters.get(); }
130 void recordParse(CodeFeatures features, bool hasCapturedVariables)
132 m_features = features;
133 m_hasCapturedVariables = hasCapturedVariables;
136 bool forceUsesArguments() const { return m_forceUsesArguments; }
138 CodeFeatures features() const { return m_features; }
139 bool hasCapturedVariables() const { return m_hasCapturedVariables; }
141 static const bool needsDestruction = true;
142 static const bool hasImmortalStructure = true;
143 static void destroy(JSCell*);
146 UnlinkedFunctionExecutable(VM*, Structure*, const SourceCode&, FunctionBodyNode*, bool isFromGlobalCode);
147 WriteBarrier<UnlinkedFunctionCodeBlock> m_codeBlockForCall;
148 WriteBarrier<UnlinkedFunctionCodeBlock> m_codeBlockForConstruct;
150 unsigned m_numCapturedVariables : 29;
151 bool m_forceUsesArguments : 1;
152 bool m_isInStrictContext : 1;
153 bool m_hasCapturedVariables : 1;
154 bool m_isFromGlobalCode : 1;
157 Identifier m_inferredName;
158 WriteBarrier<JSString> m_nameValue;
159 WriteBarrier<SymbolTable> m_symbolTableForCall;
160 WriteBarrier<SymbolTable> m_symbolTableForConstruct;
161 RefPtr<FunctionParameters> m_parameters;
162 unsigned m_firstLineOffset;
163 unsigned m_lineCount;
164 unsigned m_unlinkedFunctionNameStart;
165 unsigned m_unlinkedBodyStartColumn;
166 unsigned m_unlinkedBodyEndColumn;
167 unsigned m_startOffset;
168 unsigned m_sourceLength;
170 CodeFeatures m_features;
172 FunctionMode m_functionMode;
175 void finishCreation(VM& vm)
177 Base::finishCreation(vm);
178 m_nameValue.set(vm, this, jsString(&vm, name().string()));
181 static void visitChildren(JSCell*, SlotVisitor&);
184 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
186 return Structure::create(vm, globalObject, proto, TypeInfo(UnlinkedFunctionExecutableType, StructureFlags), info());
189 static const unsigned StructureFlags = OverridesVisitChildren | JSCell::StructureFlags;
194 struct UnlinkedStringJumpTable {
195 typedef HashMap<RefPtr<StringImpl>, int32_t> StringOffsetTable;
196 StringOffsetTable offsetTable;
198 inline int32_t offsetForValue(StringImpl* value, int32_t defaultOffset)
200 StringOffsetTable::const_iterator end = offsetTable.end();
201 StringOffsetTable::const_iterator loc = offsetTable.find(value);
203 return defaultOffset;
209 struct UnlinkedSimpleJumpTable {
210 Vector<int32_t> branchOffsets;
213 int32_t offsetForValue(int32_t value, int32_t defaultOffset);
214 void add(int32_t key, int32_t offset)
216 if (!branchOffsets[key])
217 branchOffsets[key] = offset;
221 struct UnlinkedHandlerInfo {
228 struct UnlinkedInstruction {
229 UnlinkedInstruction() { u.operand = 0; }
230 UnlinkedInstruction(OpcodeID opcode) { u.opcode = opcode; }
231 UnlinkedInstruction(int operand) { u.operand = operand; }
239 class UnlinkedCodeBlock : public JSCell {
242 static const bool needsDestruction = true;
243 static const bool hasImmortalStructure = true;
245 enum { CallFunction, ApplyFunction };
247 bool isConstructor() const { return m_isConstructor; }
248 bool isStrictMode() const { return m_isStrictMode; }
249 bool usesEval() const { return m_usesEval; }
251 bool needsFullScopeChain() const { return m_needsFullScopeChain; }
253 void addExpressionInfo(unsigned instructionOffset, int divot,
254 int startOffset, int endOffset, unsigned line, unsigned column);
256 bool hasExpressionInfo() { return m_expressionInfo.size(); }
259 void setThisRegister(VirtualRegister thisRegister) { m_thisRegister = thisRegister; }
260 void setActivationRegister(VirtualRegister activationRegister) { m_activationRegister = activationRegister; }
262 void setArgumentsRegister(VirtualRegister argumentsRegister) { m_argumentsRegister = argumentsRegister; }
263 bool usesArguments() const { return m_argumentsRegister.isValid(); }
264 VirtualRegister argumentsRegister() const { return m_argumentsRegister; }
267 bool usesGlobalObject() const { return m_globalObjectRegister.isValid(); }
268 void setGlobalObjectRegister(VirtualRegister globalObjectRegister) { m_globalObjectRegister = globalObjectRegister; }
269 VirtualRegister globalObjectRegister() const { return m_globalObjectRegister; }
271 // Parameter information
272 void setNumParameters(int newValue) { m_numParameters = newValue; }
273 void addParameter() { m_numParameters++; }
274 unsigned numParameters() const { return m_numParameters; }
276 unsigned addRegExp(RegExp* r)
278 createRareDataIfNecessary();
279 unsigned size = m_rareData->m_regexps.size();
280 m_rareData->m_regexps.append(WriteBarrier<RegExp>(*m_vm, this, r));
283 unsigned numberOfRegExps() const
287 return m_rareData->m_regexps.size();
289 RegExp* regexp(int index) const { ASSERT(m_rareData); return m_rareData->m_regexps[index].get(); }
293 size_t numberOfIdentifiers() const { return m_identifiers.size(); }
294 void addIdentifier(const Identifier& i) { return m_identifiers.append(i); }
295 const Identifier& identifier(int index) const { return m_identifiers[index]; }
296 const Vector<Identifier>& identifiers() const { return m_identifiers; }
298 size_t numberOfConstantRegisters() const { return m_constantRegisters.size(); }
299 unsigned addConstant(JSValue v)
301 unsigned result = m_constantRegisters.size();
302 m_constantRegisters.append(WriteBarrier<Unknown>());
303 m_constantRegisters.last().set(*m_vm, this, v);
306 unsigned addOrFindConstant(JSValue);
307 const Vector<WriteBarrier<Unknown>>& constantRegisters() { return m_constantRegisters; }
308 const WriteBarrier<Unknown>& constantRegister(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex]; }
309 ALWAYS_INLINE bool isConstantRegisterIndex(int index) const { return index >= FirstConstantRegisterIndex; }
310 ALWAYS_INLINE JSValue getConstant(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex].get(); }
313 size_t numberOfJumpTargets() const { return m_jumpTargets.size(); }
314 void addJumpTarget(unsigned jumpTarget) { m_jumpTargets.append(jumpTarget); }
315 unsigned jumpTarget(int index) const { return m_jumpTargets[index]; }
316 unsigned lastJumpTarget() const { return m_jumpTargets.last(); }
318 void setIsNumericCompareFunction(bool isNumericCompareFunction) { m_isNumericCompareFunction = isNumericCompareFunction; }
319 bool isNumericCompareFunction() const { return m_isNumericCompareFunction; }
323 m_jumpTargets.shrinkToFit();
324 m_identifiers.shrinkToFit();
325 m_constantRegisters.shrinkToFit();
326 m_functionDecls.shrinkToFit();
327 m_functionExprs.shrinkToFit();
328 m_propertyAccessInstructions.shrinkToFit();
329 m_expressionInfo.shrinkToFit();
331 #if ENABLE(BYTECODE_COMMENTS)
332 m_bytecodeComments.shrinkToFit();
335 m_rareData->m_exceptionHandlers.shrinkToFit();
336 m_rareData->m_regexps.shrinkToFit();
337 m_rareData->m_constantBuffers.shrinkToFit();
338 m_rareData->m_switchJumpTables.shrinkToFit();
339 m_rareData->m_stringSwitchJumpTables.shrinkToFit();
340 m_rareData->m_expressionInfoFatPositions.shrinkToFit();
344 void setInstructions(std::unique_ptr<UnlinkedInstructionStream>);
345 const UnlinkedInstructionStream& instructions() const;
348 int m_numCapturedVars;
349 int m_numCalleeRegisters;
353 size_t numberOfSwitchJumpTables() const { return m_rareData ? m_rareData->m_switchJumpTables.size() : 0; }
354 UnlinkedSimpleJumpTable& addSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_switchJumpTables.append(UnlinkedSimpleJumpTable()); return m_rareData->m_switchJumpTables.last(); }
355 UnlinkedSimpleJumpTable& switchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_switchJumpTables[tableIndex]; }
357 size_t numberOfStringSwitchJumpTables() const { return m_rareData ? m_rareData->m_stringSwitchJumpTables.size() : 0; }
358 UnlinkedStringJumpTable& addStringSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_stringSwitchJumpTables.append(UnlinkedStringJumpTable()); return m_rareData->m_stringSwitchJumpTables.last(); }
359 UnlinkedStringJumpTable& stringSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_stringSwitchJumpTables[tableIndex]; }
361 unsigned addFunctionDecl(UnlinkedFunctionExecutable* n)
363 unsigned size = m_functionDecls.size();
364 m_functionDecls.append(WriteBarrier<UnlinkedFunctionExecutable>());
365 m_functionDecls.last().set(*m_vm, this, n);
368 UnlinkedFunctionExecutable* functionDecl(int index) { return m_functionDecls[index].get(); }
369 size_t numberOfFunctionDecls() { return m_functionDecls.size(); }
370 unsigned addFunctionExpr(UnlinkedFunctionExecutable* n)
372 unsigned size = m_functionExprs.size();
373 m_functionExprs.append(WriteBarrier<UnlinkedFunctionExecutable>());
374 m_functionExprs.last().set(*m_vm, this, n);
377 UnlinkedFunctionExecutable* functionExpr(int index) { return m_functionExprs[index].get(); }
378 size_t numberOfFunctionExprs() { return m_functionExprs.size(); }
380 // Exception handling support
381 size_t numberOfExceptionHandlers() const { return m_rareData ? m_rareData->m_exceptionHandlers.size() : 0; }
382 void addExceptionHandler(const UnlinkedHandlerInfo& hanler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(hanler); }
383 UnlinkedHandlerInfo& exceptionHandler(int index) { ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; }
385 SymbolTable* symbolTable() const { return m_symbolTable.get(); }
386 void setSymbolTable(SymbolTable* table) { m_symbolTable.set(*m_vm, this, table); }
388 VM* vm() const { return m_vm; }
390 UnlinkedArrayProfile addArrayProfile() { return m_arrayProfileCount++; }
391 unsigned numberOfArrayProfiles() { return m_arrayProfileCount; }
392 UnlinkedArrayAllocationProfile addArrayAllocationProfile() { return m_arrayAllocationProfileCount++; }
393 unsigned numberOfArrayAllocationProfiles() { return m_arrayAllocationProfileCount; }
394 UnlinkedObjectAllocationProfile addObjectAllocationProfile() { return m_objectAllocationProfileCount++; }
395 unsigned numberOfObjectAllocationProfiles() { return m_objectAllocationProfileCount; }
396 UnlinkedValueProfile addValueProfile() { return m_valueProfileCount++; }
397 unsigned numberOfValueProfiles() { return m_valueProfileCount; }
399 UnlinkedLLIntCallLinkInfo addLLIntCallLinkInfo() { return m_llintCallLinkInfoCount++; }
400 unsigned numberOfLLintCallLinkInfos() { return m_llintCallLinkInfoCount; }
402 CodeType codeType() const { return m_codeType; }
404 VirtualRegister thisRegister() const { return m_thisRegister; }
405 VirtualRegister activationRegister() const { return m_activationRegister; }
406 bool hasActivationRegister() const { return m_activationRegister.isValid(); }
408 void addPropertyAccessInstruction(unsigned propertyAccessInstruction)
410 m_propertyAccessInstructions.append(propertyAccessInstruction);
413 size_t numberOfPropertyAccessInstructions() const { return m_propertyAccessInstructions.size(); }
414 const Vector<unsigned>& propertyAccessInstructions() const { return m_propertyAccessInstructions; }
416 typedef Vector<JSValue> ConstantBuffer;
418 size_t constantBufferCount() { ASSERT(m_rareData); return m_rareData->m_constantBuffers.size(); }
419 unsigned addConstantBuffer(unsigned length)
421 createRareDataIfNecessary();
422 unsigned size = m_rareData->m_constantBuffers.size();
423 m_rareData->m_constantBuffers.append(Vector<JSValue>(length));
427 const ConstantBuffer& constantBuffer(unsigned index) const
430 return m_rareData->m_constantBuffers[index];
433 ConstantBuffer& constantBuffer(unsigned index)
436 return m_rareData->m_constantBuffers[index];
439 bool hasRareData() const { return m_rareData; }
441 int lineNumberForBytecodeOffset(unsigned bytecodeOffset);
443 void expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot,
444 int& startOffset, int& endOffset, unsigned& line, unsigned& column);
446 void recordParse(CodeFeatures features, bool hasCapturedVariables, unsigned firstLine, unsigned lineCount, unsigned endColumn)
448 m_features = features;
449 m_hasCapturedVariables = hasCapturedVariables;
450 m_firstLine = firstLine;
451 m_lineCount = lineCount;
452 // For the UnlinkedCodeBlock, startColumn is always 0.
453 m_endColumn = endColumn;
456 CodeFeatures codeFeatures() const { return m_features; }
457 bool hasCapturedVariables() const { return m_hasCapturedVariables; }
458 unsigned firstLine() const { return m_firstLine; }
459 unsigned lineCount() const { return m_lineCount; }
460 ALWAYS_INLINE unsigned startColumn() const { return 0; }
461 unsigned endColumn() const { return m_endColumn; }
463 void dumpExpressionRangeInfo(); // For debugging purpose only.
466 UnlinkedCodeBlock(VM*, Structure*, CodeType, const ExecutableInfo&);
467 ~UnlinkedCodeBlock();
469 void finishCreation(VM& vm)
471 Base::finishCreation(vm);
472 if (codeType() == GlobalCode)
474 m_symbolTable.set(vm, this, SymbolTable::create(vm));
479 void createRareDataIfNecessary()
482 m_rareData = adoptPtr(new RareData);
485 void getLineAndColumn(ExpressionRangeInfo&, unsigned& line, unsigned& column);
487 std::unique_ptr<UnlinkedInstructionStream> m_unlinkedInstructions;
492 VirtualRegister m_thisRegister;
493 VirtualRegister m_argumentsRegister;
494 VirtualRegister m_activationRegister;
495 VirtualRegister m_globalObjectRegister;
497 bool m_needsFullScopeChain : 1;
499 bool m_isNumericCompareFunction : 1;
500 bool m_isStrictMode : 1;
501 bool m_isConstructor : 1;
502 bool m_hasCapturedVariables : 1;
503 unsigned m_firstLine;
504 unsigned m_lineCount;
505 unsigned m_endColumn;
507 CodeFeatures m_features;
510 Vector<unsigned> m_jumpTargets;
513 Vector<Identifier> m_identifiers;
514 Vector<WriteBarrier<Unknown>> m_constantRegisters;
515 typedef Vector<WriteBarrier<UnlinkedFunctionExecutable>> FunctionExpressionVector;
516 FunctionExpressionVector m_functionDecls;
517 FunctionExpressionVector m_functionExprs;
519 WriteBarrier<SymbolTable> m_symbolTable;
521 Vector<unsigned> m_propertyAccessInstructions;
523 #if ENABLE(BYTECODE_COMMENTS)
524 Vector<Comment> m_bytecodeComments;
525 size_t m_bytecodeCommentIterator;
528 unsigned m_arrayProfileCount;
529 unsigned m_arrayAllocationProfileCount;
530 unsigned m_objectAllocationProfileCount;
531 unsigned m_valueProfileCount;
532 unsigned m_llintCallLinkInfoCount;
536 WTF_MAKE_FAST_ALLOCATED;
538 Vector<UnlinkedHandlerInfo> m_exceptionHandlers;
541 Vector<WriteBarrier<RegExp>> m_regexps;
543 // Buffers used for large array literals
544 Vector<ConstantBuffer> m_constantBuffers;
547 Vector<UnlinkedSimpleJumpTable> m_switchJumpTables;
548 Vector<UnlinkedStringJumpTable> m_stringSwitchJumpTables;
550 Vector<ExpressionRangeInfo::FatPosition> m_expressionInfoFatPositions;
554 OwnPtr<RareData> m_rareData;
555 Vector<ExpressionRangeInfo> m_expressionInfo;
559 static const unsigned StructureFlags = OverridesVisitChildren | Base::StructureFlags;
560 static void visitChildren(JSCell*, SlotVisitor&);
566 class UnlinkedGlobalCodeBlock : public UnlinkedCodeBlock {
568 typedef UnlinkedCodeBlock Base;
571 UnlinkedGlobalCodeBlock(VM* vm, Structure* structure, CodeType codeType, const ExecutableInfo& info)
572 : Base(vm, structure, codeType, info)
576 static const unsigned StructureFlags = OverridesVisitChildren | Base::StructureFlags;
581 class UnlinkedProgramCodeBlock : public UnlinkedGlobalCodeBlock {
583 friend class CodeCache;
584 static UnlinkedProgramCodeBlock* create(VM* vm, const ExecutableInfo& info)
586 UnlinkedProgramCodeBlock* instance = new (NotNull, allocateCell<UnlinkedProgramCodeBlock>(vm->heap)) UnlinkedProgramCodeBlock(vm, vm->unlinkedProgramCodeBlockStructure.get(), info);
587 instance->finishCreation(*vm);
592 typedef UnlinkedGlobalCodeBlock Base;
593 static void destroy(JSCell*);
595 void addFunctionDeclaration(VM& vm, const Identifier& name, UnlinkedFunctionExecutable* functionExecutable)
597 m_functionDeclarations.append(std::make_pair(name, WriteBarrier<UnlinkedFunctionExecutable>(vm, this, functionExecutable)));
600 void addVariableDeclaration(const Identifier& name, bool isConstant)
602 m_varDeclarations.append(std::make_pair(name, isConstant));
605 typedef Vector<std::pair<Identifier, bool>> VariableDeclations;
606 typedef Vector<std::pair<Identifier, WriteBarrier<UnlinkedFunctionExecutable>> > FunctionDeclations;
608 const VariableDeclations& variableDeclarations() const { return m_varDeclarations; }
609 const FunctionDeclations& functionDeclarations() const { return m_functionDeclarations; }
611 static void visitChildren(JSCell*, SlotVisitor&);
614 UnlinkedProgramCodeBlock(VM* vm, Structure* structure, const ExecutableInfo& info)
615 : Base(vm, structure, GlobalCode, info)
619 VariableDeclations m_varDeclarations;
620 FunctionDeclations m_functionDeclarations;
623 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
625 return Structure::create(vm, globalObject, proto, TypeInfo(UnlinkedProgramCodeBlockType, StructureFlags), info());
628 static const unsigned StructureFlags = OverridesVisitChildren | Base::StructureFlags;
633 class UnlinkedEvalCodeBlock : public UnlinkedGlobalCodeBlock {
635 friend class CodeCache;
637 static UnlinkedEvalCodeBlock* create(VM* vm, const ExecutableInfo& info)
639 UnlinkedEvalCodeBlock* instance = new (NotNull, allocateCell<UnlinkedEvalCodeBlock>(vm->heap)) UnlinkedEvalCodeBlock(vm, vm->unlinkedEvalCodeBlockStructure.get(), info);
640 instance->finishCreation(*vm);
645 typedef UnlinkedGlobalCodeBlock Base;
646 static void destroy(JSCell*);
648 const Identifier& variable(unsigned index) { return m_variables[index]; }
649 unsigned numVariables() { return m_variables.size(); }
650 void adoptVariables(Vector<Identifier, 0, UnsafeVectorOverflow>& variables)
652 ASSERT(m_variables.isEmpty());
653 m_variables.swap(variables);
657 UnlinkedEvalCodeBlock(VM* vm, Structure* structure, const ExecutableInfo& info)
658 : Base(vm, structure, EvalCode, info)
662 Vector<Identifier, 0, UnsafeVectorOverflow> m_variables;
665 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
667 return Structure::create(vm, globalObject, proto, TypeInfo(UnlinkedEvalCodeBlockType, StructureFlags), info());
670 static const unsigned StructureFlags = OverridesVisitChildren | Base::StructureFlags;
675 class UnlinkedFunctionCodeBlock : public UnlinkedCodeBlock {
677 static UnlinkedFunctionCodeBlock* create(VM* vm, CodeType codeType, const ExecutableInfo& info)
679 UnlinkedFunctionCodeBlock* instance = new (NotNull, allocateCell<UnlinkedFunctionCodeBlock>(vm->heap)) UnlinkedFunctionCodeBlock(vm, vm->unlinkedFunctionCodeBlockStructure.get(), codeType, info);
680 instance->finishCreation(*vm);
684 typedef UnlinkedCodeBlock Base;
685 static void destroy(JSCell*);
688 UnlinkedFunctionCodeBlock(VM* vm, Structure* structure, CodeType codeType, const ExecutableInfo& info)
689 : Base(vm, structure, codeType, info)
694 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
696 return Structure::create(vm, globalObject, proto, TypeInfo(UnlinkedFunctionCodeBlockType, StructureFlags), info());
699 static const unsigned StructureFlags = OverridesVisitChildren | Base::StructureFlags;
706 #endif // UnlinkedCodeBlock_h