2 * Copyright (C) 2012-2015 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 "ConstructAbility.h"
33 #include "ExpressionRangeInfo.h"
34 #include "HandlerInfo.h"
35 #include "Identifier.h"
38 #include "ParserModes.h"
40 #include "SpecialPointer.h"
41 #include "UnlinkedFunctionExecutable.h"
42 #include "VariableEnvironment.h"
43 #include "VirtualRegister.h"
44 #include <wtf/FastBitVector.h>
45 #include <wtf/RefCountedArray.h>
46 #include <wtf/Vector.h>
51 class FunctionMetadataNode;
52 class FunctionExecutable;
55 class ScriptExecutable;
58 class UnlinkedCodeBlock;
59 class UnlinkedFunctionCodeBlock;
60 class UnlinkedFunctionExecutable;
61 class UnlinkedInstructionStream;
62 struct ExecutableInfo;
64 typedef unsigned UnlinkedValueProfile;
65 typedef unsigned UnlinkedArrayProfile;
66 typedef unsigned UnlinkedArrayAllocationProfile;
67 typedef unsigned UnlinkedObjectAllocationProfile;
68 typedef unsigned UnlinkedLLIntCallLinkInfo;
70 struct UnlinkedStringJumpTable {
71 typedef HashMap<RefPtr<StringImpl>, int32_t> StringOffsetTable;
72 StringOffsetTable offsetTable;
74 inline int32_t offsetForValue(StringImpl* value, int32_t defaultOffset)
76 StringOffsetTable::const_iterator end = offsetTable.end();
77 StringOffsetTable::const_iterator loc = offsetTable.find(value);
85 struct UnlinkedSimpleJumpTable {
86 Vector<int32_t> branchOffsets;
89 int32_t offsetForValue(int32_t value, int32_t defaultOffset);
90 void add(int32_t key, int32_t offset)
92 if (!branchOffsets[key])
93 branchOffsets[key] = offset;
97 struct UnlinkedInstruction {
98 UnlinkedInstruction() { u.operand = 0; }
99 UnlinkedInstruction(OpcodeID opcode) { u.opcode = opcode; }
100 UnlinkedInstruction(int operand) { u.operand = operand; }
108 class UnlinkedCodeBlock : public JSCell {
111 static const unsigned StructureFlags = Base::StructureFlags;
113 static const bool needsDestruction = true;
115 enum { CallFunction, ApplyFunction };
117 bool isConstructor() const { return m_isConstructor; }
118 bool isStrictMode() const { return m_isStrictMode; }
119 bool usesEval() const { return m_usesEval; }
120 SourceParseMode parseMode() const { return m_parseMode; }
121 bool isArrowFunction() const { return m_parseMode == SourceParseMode::ArrowFunctionMode; }
122 bool isDerivedConstructorContext() const { return m_isDerivedConstructorContext; }
123 bool isArrowFunctionContext() const { return m_isArrowFunctionContext; }
125 bool needsFullScopeChain() const { return m_needsFullScopeChain; }
127 void addExpressionInfo(unsigned instructionOffset, int divot,
128 int startOffset, int endOffset, unsigned line, unsigned column);
130 void addTypeProfilerExpressionInfo(unsigned instructionOffset, unsigned startDivot, unsigned endDivot);
132 bool hasExpressionInfo() { return m_expressionInfo.size(); }
135 void setThisRegister(VirtualRegister thisRegister) { m_thisRegister = thisRegister; }
136 void setScopeRegister(VirtualRegister scopeRegister) { m_scopeRegister = scopeRegister; }
137 void setActivationRegister(VirtualRegister activationRegister) { m_lexicalEnvironmentRegister = activationRegister; }
139 bool usesGlobalObject() const { return m_globalObjectRegister.isValid(); }
140 void setGlobalObjectRegister(VirtualRegister globalObjectRegister) { m_globalObjectRegister = globalObjectRegister; }
141 VirtualRegister globalObjectRegister() const { return m_globalObjectRegister; }
143 // Parameter information
144 void setNumParameters(int newValue) { m_numParameters = newValue; }
145 void addParameter() { m_numParameters++; }
146 unsigned numParameters() const { return m_numParameters; }
148 unsigned addRegExp(RegExp* r)
150 createRareDataIfNecessary();
151 unsigned size = m_rareData->m_regexps.size();
152 m_rareData->m_regexps.append(WriteBarrier<RegExp>(*m_vm, this, r));
155 unsigned numberOfRegExps() const
159 return m_rareData->m_regexps.size();
161 RegExp* regexp(int index) const { ASSERT(m_rareData); return m_rareData->m_regexps[index].get(); }
165 size_t numberOfIdentifiers() const { return m_identifiers.size(); }
166 void addIdentifier(const Identifier& i) { return m_identifiers.append(i); }
167 const Identifier& identifier(int index) const { return m_identifiers[index]; }
168 const Vector<Identifier>& identifiers() const { return m_identifiers; }
170 unsigned addConstant(JSValue v, SourceCodeRepresentation sourceCodeRepresentation = SourceCodeRepresentation::Other)
172 unsigned result = m_constantRegisters.size();
173 m_constantRegisters.append(WriteBarrier<Unknown>());
174 m_constantRegisters.last().set(*m_vm, this, v);
175 m_constantsSourceCodeRepresentation.append(sourceCodeRepresentation);
178 unsigned addConstant(LinkTimeConstant type)
180 unsigned result = m_constantRegisters.size();
182 unsigned index = static_cast<unsigned>(type);
183 ASSERT(index < LinkTimeConstantCount);
184 m_linkTimeConstants[index] = result;
185 m_constantRegisters.append(WriteBarrier<Unknown>());
186 m_constantsSourceCodeRepresentation.append(SourceCodeRepresentation::Other);
189 unsigned registerIndexForLinkTimeConstant(LinkTimeConstant type)
191 unsigned index = static_cast<unsigned>(type);
192 ASSERT(index < LinkTimeConstantCount);
193 return m_linkTimeConstants[index];
195 const Vector<WriteBarrier<Unknown>>& constantRegisters() { return m_constantRegisters; }
196 const WriteBarrier<Unknown>& constantRegister(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex]; }
197 ALWAYS_INLINE bool isConstantRegisterIndex(int index) const { return index >= FirstConstantRegisterIndex; }
198 const Vector<SourceCodeRepresentation>& constantsSourceCodeRepresentation() { return m_constantsSourceCodeRepresentation; }
201 size_t numberOfJumpTargets() const { return m_jumpTargets.size(); }
202 void addJumpTarget(unsigned jumpTarget) { m_jumpTargets.append(jumpTarget); }
203 unsigned jumpTarget(int index) const { return m_jumpTargets[index]; }
204 unsigned lastJumpTarget() const { return m_jumpTargets.last(); }
206 bool isBuiltinFunction() const { return m_isBuiltinFunction; }
208 ConstructorKind constructorKind() const { return static_cast<ConstructorKind>(m_constructorKind); }
209 SuperBinding superBinding() const { return static_cast<SuperBinding>(m_superBinding); }
213 m_jumpTargets.shrinkToFit();
214 m_identifiers.shrinkToFit();
215 m_constantRegisters.shrinkToFit();
216 m_constantsSourceCodeRepresentation.shrinkToFit();
217 m_functionDecls.shrinkToFit();
218 m_functionExprs.shrinkToFit();
219 m_propertyAccessInstructions.shrinkToFit();
220 m_expressionInfo.shrinkToFit();
222 #if ENABLE(BYTECODE_COMMENTS)
223 m_bytecodeComments.shrinkToFit();
226 m_rareData->m_exceptionHandlers.shrinkToFit();
227 m_rareData->m_regexps.shrinkToFit();
228 m_rareData->m_constantBuffers.shrinkToFit();
229 m_rareData->m_switchJumpTables.shrinkToFit();
230 m_rareData->m_stringSwitchJumpTables.shrinkToFit();
231 m_rareData->m_expressionInfoFatPositions.shrinkToFit();
235 void setInstructions(std::unique_ptr<UnlinkedInstructionStream>);
236 const UnlinkedInstructionStream& instructions() const;
239 int m_numCapturedVars;
240 int m_numCalleeLocals;
244 size_t numberOfSwitchJumpTables() const { return m_rareData ? m_rareData->m_switchJumpTables.size() : 0; }
245 UnlinkedSimpleJumpTable& addSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_switchJumpTables.append(UnlinkedSimpleJumpTable()); return m_rareData->m_switchJumpTables.last(); }
246 UnlinkedSimpleJumpTable& switchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_switchJumpTables[tableIndex]; }
248 size_t numberOfStringSwitchJumpTables() const { return m_rareData ? m_rareData->m_stringSwitchJumpTables.size() : 0; }
249 UnlinkedStringJumpTable& addStringSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_stringSwitchJumpTables.append(UnlinkedStringJumpTable()); return m_rareData->m_stringSwitchJumpTables.last(); }
250 UnlinkedStringJumpTable& stringSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_stringSwitchJumpTables[tableIndex]; }
252 unsigned addFunctionDecl(UnlinkedFunctionExecutable* n)
254 unsigned size = m_functionDecls.size();
255 m_functionDecls.append(WriteBarrier<UnlinkedFunctionExecutable>());
256 m_functionDecls.last().set(*m_vm, this, n);
259 UnlinkedFunctionExecutable* functionDecl(int index) { return m_functionDecls[index].get(); }
260 size_t numberOfFunctionDecls() { return m_functionDecls.size(); }
261 unsigned addFunctionExpr(UnlinkedFunctionExecutable* n)
263 unsigned size = m_functionExprs.size();
264 m_functionExprs.append(WriteBarrier<UnlinkedFunctionExecutable>());
265 m_functionExprs.last().set(*m_vm, this, n);
268 UnlinkedFunctionExecutable* functionExpr(int index) { return m_functionExprs[index].get(); }
269 size_t numberOfFunctionExprs() { return m_functionExprs.size(); }
271 // Exception handling support
272 size_t numberOfExceptionHandlers() const { return m_rareData ? m_rareData->m_exceptionHandlers.size() : 0; }
273 void addExceptionHandler(const UnlinkedHandlerInfo& handler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(handler); }
274 UnlinkedHandlerInfo& exceptionHandler(int index) { ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; }
276 VM* vm() const { return m_vm; }
278 UnlinkedArrayProfile addArrayProfile() { return m_arrayProfileCount++; }
279 unsigned numberOfArrayProfiles() { return m_arrayProfileCount; }
280 UnlinkedArrayAllocationProfile addArrayAllocationProfile() { return m_arrayAllocationProfileCount++; }
281 unsigned numberOfArrayAllocationProfiles() { return m_arrayAllocationProfileCount; }
282 UnlinkedObjectAllocationProfile addObjectAllocationProfile() { return m_objectAllocationProfileCount++; }
283 unsigned numberOfObjectAllocationProfiles() { return m_objectAllocationProfileCount; }
284 UnlinkedValueProfile addValueProfile() { return m_valueProfileCount++; }
285 unsigned numberOfValueProfiles() { return m_valueProfileCount; }
287 UnlinkedLLIntCallLinkInfo addLLIntCallLinkInfo() { return m_llintCallLinkInfoCount++; }
288 unsigned numberOfLLintCallLinkInfos() { return m_llintCallLinkInfoCount; }
290 CodeType codeType() const { return m_codeType; }
292 VirtualRegister thisRegister() const { return m_thisRegister; }
293 VirtualRegister scopeRegister() const { return m_scopeRegister; }
294 VirtualRegister activationRegister() const { return m_lexicalEnvironmentRegister; }
295 bool hasActivationRegister() const { return m_lexicalEnvironmentRegister.isValid(); }
297 void addPropertyAccessInstruction(unsigned propertyAccessInstruction)
299 m_propertyAccessInstructions.append(propertyAccessInstruction);
302 size_t numberOfPropertyAccessInstructions() const { return m_propertyAccessInstructions.size(); }
303 const Vector<unsigned>& propertyAccessInstructions() const { return m_propertyAccessInstructions; }
305 typedef Vector<JSValue> ConstantBuffer;
307 size_t constantBufferCount() { ASSERT(m_rareData); return m_rareData->m_constantBuffers.size(); }
308 unsigned addConstantBuffer(unsigned length)
310 createRareDataIfNecessary();
311 unsigned size = m_rareData->m_constantBuffers.size();
312 m_rareData->m_constantBuffers.append(Vector<JSValue>(length));
316 const ConstantBuffer& constantBuffer(unsigned index) const
319 return m_rareData->m_constantBuffers[index];
322 ConstantBuffer& constantBuffer(unsigned index)
325 return m_rareData->m_constantBuffers[index];
328 bool hasRareData() const { return m_rareData.get(); }
330 int lineNumberForBytecodeOffset(unsigned bytecodeOffset);
332 void expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot,
333 int& startOffset, int& endOffset, unsigned& line, unsigned& column);
335 bool typeProfilerExpressionInfoForBytecodeOffset(unsigned bytecodeOffset, unsigned& startDivot, unsigned& endDivot);
337 void recordParse(CodeFeatures features, bool hasCapturedVariables, unsigned firstLine, unsigned lineCount, unsigned endColumn)
339 m_features = features;
340 m_hasCapturedVariables = hasCapturedVariables;
341 m_firstLine = firstLine;
342 m_lineCount = lineCount;
343 // For the UnlinkedCodeBlock, startColumn is always 0.
344 m_endColumn = endColumn;
347 CodeFeatures codeFeatures() const { return m_features; }
348 bool hasCapturedVariables() const { return m_hasCapturedVariables; }
349 unsigned firstLine() const { return m_firstLine; }
350 unsigned lineCount() const { return m_lineCount; }
351 ALWAYS_INLINE unsigned startColumn() const { return 0; }
352 unsigned endColumn() const { return m_endColumn; }
354 void addOpProfileControlFlowBytecodeOffset(size_t offset) { m_opProfileControlFlowBytecodeOffsets.append(offset); }
355 const Vector<size_t>& opProfileControlFlowBytecodeOffsets() const { return m_opProfileControlFlowBytecodeOffsets; }
357 void dumpExpressionRangeInfo(); // For debugging purpose only.
360 UnlinkedCodeBlock(VM*, Structure*, CodeType, const ExecutableInfo&);
361 ~UnlinkedCodeBlock();
363 void finishCreation(VM& vm)
365 Base::finishCreation(vm);
370 void createRareDataIfNecessary()
373 m_rareData = std::make_unique<RareData>();
376 void getLineAndColumn(ExpressionRangeInfo&, unsigned& line, unsigned& column);
378 std::unique_ptr<UnlinkedInstructionStream> m_unlinkedInstructions;
383 VirtualRegister m_thisRegister;
384 VirtualRegister m_scopeRegister;
385 VirtualRegister m_lexicalEnvironmentRegister;
386 VirtualRegister m_globalObjectRegister;
388 unsigned m_needsFullScopeChain : 1;
389 unsigned m_usesEval : 1;
390 unsigned m_isStrictMode : 1;
391 unsigned m_isConstructor : 1;
392 unsigned m_hasCapturedVariables : 1;
393 unsigned m_isBuiltinFunction : 1;
394 unsigned m_constructorKind : 2;
395 unsigned m_superBinding : 1;
396 unsigned m_isDerivedConstructorContext : 1;
397 unsigned m_isArrowFunctionContext : 1;
399 unsigned m_firstLine;
400 unsigned m_lineCount;
401 unsigned m_endColumn;
403 SourceParseMode m_parseMode;
404 CodeFeatures m_features;
407 Vector<unsigned> m_jumpTargets;
410 Vector<Identifier> m_identifiers;
411 Vector<WriteBarrier<Unknown>> m_constantRegisters;
412 Vector<SourceCodeRepresentation> m_constantsSourceCodeRepresentation;
413 std::array<unsigned, LinkTimeConstantCount> m_linkTimeConstants;
414 typedef Vector<WriteBarrier<UnlinkedFunctionExecutable>> FunctionExpressionVector;
415 FunctionExpressionVector m_functionDecls;
416 FunctionExpressionVector m_functionExprs;
418 Vector<unsigned> m_propertyAccessInstructions;
420 #if ENABLE(BYTECODE_COMMENTS)
421 Vector<Comment> m_bytecodeComments;
422 size_t m_bytecodeCommentIterator;
425 unsigned m_arrayProfileCount;
426 unsigned m_arrayAllocationProfileCount;
427 unsigned m_objectAllocationProfileCount;
428 unsigned m_valueProfileCount;
429 unsigned m_llintCallLinkInfoCount;
433 WTF_MAKE_FAST_ALLOCATED;
435 Vector<UnlinkedHandlerInfo> m_exceptionHandlers;
438 Vector<WriteBarrier<RegExp>> m_regexps;
440 // Buffers used for large array literals
441 Vector<ConstantBuffer> m_constantBuffers;
444 Vector<UnlinkedSimpleJumpTable> m_switchJumpTables;
445 Vector<UnlinkedStringJumpTable> m_stringSwitchJumpTables;
447 Vector<ExpressionRangeInfo::FatPosition> m_expressionInfoFatPositions;
451 std::unique_ptr<RareData> m_rareData;
452 Vector<ExpressionRangeInfo> m_expressionInfo;
453 struct TypeProfilerExpressionRange {
454 unsigned m_startDivot;
457 HashMap<unsigned, TypeProfilerExpressionRange> m_typeProfilerInfoMap;
458 Vector<size_t> m_opProfileControlFlowBytecodeOffsets;
461 static void visitChildren(JSCell*, SlotVisitor&);
467 class UnlinkedGlobalCodeBlock : public UnlinkedCodeBlock {
469 typedef UnlinkedCodeBlock Base;
472 UnlinkedGlobalCodeBlock(VM* vm, Structure* structure, CodeType codeType, const ExecutableInfo& info)
473 : Base(vm, structure, codeType, info)
480 class UnlinkedProgramCodeBlock final : public UnlinkedGlobalCodeBlock {
482 friend class CodeCache;
483 static UnlinkedProgramCodeBlock* create(VM* vm, const ExecutableInfo& info)
485 UnlinkedProgramCodeBlock* instance = new (NotNull, allocateCell<UnlinkedProgramCodeBlock>(vm->heap)) UnlinkedProgramCodeBlock(vm, vm->unlinkedProgramCodeBlockStructure.get(), info);
486 instance->finishCreation(*vm);
491 typedef UnlinkedGlobalCodeBlock Base;
492 static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
494 static void destroy(JSCell*);
496 void setVariableDeclarations(const VariableEnvironment& environment) { m_varDeclarations = environment; }
497 const VariableEnvironment& variableDeclarations() const { return m_varDeclarations; }
499 void setLexicalDeclarations(const VariableEnvironment& environment) { m_lexicalDeclarations = environment; }
500 const VariableEnvironment& lexicalDeclarations() const { return m_lexicalDeclarations; }
502 static void visitChildren(JSCell*, SlotVisitor&);
505 UnlinkedProgramCodeBlock(VM* vm, Structure* structure, const ExecutableInfo& info)
506 : Base(vm, structure, GlobalCode, info)
510 VariableEnvironment m_varDeclarations;
511 VariableEnvironment m_lexicalDeclarations;
514 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
516 return Structure::create(vm, globalObject, proto, TypeInfo(UnlinkedProgramCodeBlockType, StructureFlags), info());
522 class UnlinkedModuleProgramCodeBlock final : public UnlinkedGlobalCodeBlock {
524 friend class CodeCache;
525 static UnlinkedModuleProgramCodeBlock* create(VM* vm, const ExecutableInfo& info)
527 UnlinkedModuleProgramCodeBlock* instance = new (NotNull, allocateCell<UnlinkedModuleProgramCodeBlock>(vm->heap)) UnlinkedModuleProgramCodeBlock(vm, vm->unlinkedModuleProgramCodeBlockStructure.get(), info);
528 instance->finishCreation(*vm);
533 typedef UnlinkedGlobalCodeBlock Base;
534 static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
536 static void destroy(JSCell*);
538 static void visitChildren(JSCell*, SlotVisitor&);
540 // This offset represents the constant register offset to the stored symbol table that represents the layout of the
541 // module environment. This symbol table is created by the byte code generator since the module environment includes
542 // the top-most lexical captured variables inside the module code. This means that, once the module environment is
543 // allocated and instantiated from this symbol table, it is titely coupled with the specific unlinked module program
544 // code block and the stored symbol table. So before executing the module code, we should not clear the unlinked module
545 // program code block in the module executable. This requirement is met because the garbage collector only clears
546 // unlinked code in (1) unmarked executables and (2) function executables.
548 // Since the function code may be executed repeatedly and the environment of each function execution is different,
549 // the function code need to allocate and instantiate the environment in the prologue of the function code. On the
550 // other hand, the module code is executed only once. So we can instantiate the module environment outside the module
551 // code. At that time, we construct the module environment by using the symbol table that is held by the module executable.
552 // The symbol table held by the executable is the cloned one from one in the unlinked code block. Instantiating the module
553 // environment before executing and linking the module code is required to link the imported bindings between the modules.
555 // The unlinked module program code block only holds the pre-cloned symbol table in its constant register pool. It does
556 // not hold the instantiated module environment. So while the module environment requires the specific unlinked module
557 // program code block, the unlinked module code block can be used for the module environment instantiated from this
558 // unlinked code block. There is 1:N relation between the unlinked module code block and the module environments. So the
559 // unlinked module program code block can be cached.
561 // On the other hand, the linked code block for the module environment includes the resolved references to the imported
562 // bindings. The imported binding references the other module environment, so the linked code block is titly coupled
563 // with the specific set of the module environments. Thus, the linked code block should not be cached.
564 int moduleEnvironmentSymbolTableConstantRegisterOffset() { return m_moduleEnvironmentSymbolTableConstantRegisterOffset; }
565 void setModuleEnvironmentSymbolTableConstantRegisterOffset(int offset)
567 m_moduleEnvironmentSymbolTableConstantRegisterOffset = offset;
571 UnlinkedModuleProgramCodeBlock(VM* vm, Structure* structure, const ExecutableInfo& info)
572 : Base(vm, structure, ModuleCode, info)
576 int m_moduleEnvironmentSymbolTableConstantRegisterOffset { 0 };
579 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
581 return Structure::create(vm, globalObject, proto, TypeInfo(UnlinkedModuleProgramCodeBlockType, StructureFlags), info());
587 class UnlinkedEvalCodeBlock final : public UnlinkedGlobalCodeBlock {
589 friend class CodeCache;
591 static UnlinkedEvalCodeBlock* create(VM* vm, const ExecutableInfo& info)
593 UnlinkedEvalCodeBlock* instance = new (NotNull, allocateCell<UnlinkedEvalCodeBlock>(vm->heap)) UnlinkedEvalCodeBlock(vm, vm->unlinkedEvalCodeBlockStructure.get(), info);
594 instance->finishCreation(*vm);
599 typedef UnlinkedGlobalCodeBlock Base;
600 static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
602 static void destroy(JSCell*);
604 const Identifier& variable(unsigned index) { return m_variables[index]; }
605 unsigned numVariables() { return m_variables.size(); }
606 void adoptVariables(Vector<Identifier, 0, UnsafeVectorOverflow>& variables)
608 ASSERT(m_variables.isEmpty());
609 m_variables.swap(variables);
613 UnlinkedEvalCodeBlock(VM* vm, Structure* structure, const ExecutableInfo& info)
614 : Base(vm, structure, EvalCode, info)
618 Vector<Identifier, 0, UnsafeVectorOverflow> m_variables;
621 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
623 return Structure::create(vm, globalObject, proto, TypeInfo(UnlinkedEvalCodeBlockType, StructureFlags), info());
629 class UnlinkedFunctionCodeBlock final : public UnlinkedCodeBlock {
631 typedef UnlinkedCodeBlock Base;
632 static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
634 static UnlinkedFunctionCodeBlock* create(VM* vm, CodeType codeType, const ExecutableInfo& info)
636 UnlinkedFunctionCodeBlock* instance = new (NotNull, allocateCell<UnlinkedFunctionCodeBlock>(vm->heap)) UnlinkedFunctionCodeBlock(vm, vm->unlinkedFunctionCodeBlockStructure.get(), codeType, info);
637 instance->finishCreation(*vm);
641 static void destroy(JSCell*);
644 UnlinkedFunctionCodeBlock(VM* vm, Structure* structure, CodeType codeType, const ExecutableInfo& info)
645 : Base(vm, structure, codeType, info)
650 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
652 return Structure::create(vm, globalObject, proto, TypeInfo(UnlinkedFunctionCodeBlockType, StructureFlags), info());
660 #endif // UnlinkedCodeBlock_h