2 * Copyright (C) 2009, 2010 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.
27 #include "Executable.h"
29 #include "BytecodeGenerator.h"
30 #include "CodeBlock.h"
31 #include "DFGDriver.h"
34 #include "UStringBuilder.h"
39 const ClassInfo ExecutableBase::s_info = { "Executable", 0, 0, 0 };
41 void ExecutableBase::clearCode()
44 m_jitCodeForCall.clear();
45 m_jitCodeForConstruct.clear();
46 m_jitCodeForCallWithArityCheck = MacroAssemblerCodePtr();
47 m_jitCodeForConstructWithArityCheck = MacroAssemblerCodePtr();
49 m_numParametersForCall = NUM_PARAMETERS_NOT_COMPILED;
50 m_numParametersForConstruct = NUM_PARAMETERS_NOT_COMPILED;
53 class ExecutableFinalizer : public WeakHandleOwner {
54 virtual void finalize(Handle<Unknown> handle, void*)
56 Weak<ExecutableBase> executable(Weak<ExecutableBase>::Adopt, handle);
57 executable->clearCode();
61 WeakHandleOwner* ExecutableBase::executableFinalizer()
63 DEFINE_STATIC_LOCAL(ExecutableFinalizer, finalizer, ());
67 const ClassInfo NativeExecutable::s_info = { "NativeExecutable", &ExecutableBase::s_info, 0, 0 };
69 NativeExecutable::~NativeExecutable()
73 const ClassInfo ScriptExecutable::s_info = { "ScriptExecutable", &ExecutableBase::s_info, 0, 0 };
75 const ClassInfo EvalExecutable::s_info = { "EvalExecutable", &ScriptExecutable::s_info, 0, 0 };
77 EvalExecutable::EvalExecutable(ExecState* exec, const SourceCode& source, bool inStrictContext)
78 : ScriptExecutable(exec->globalData().evalExecutableStructure.get(), exec, source, inStrictContext)
82 EvalExecutable::~EvalExecutable()
86 const ClassInfo ProgramExecutable::s_info = { "ProgramExecutable", &ScriptExecutable::s_info, 0, 0 };
88 ProgramExecutable::ProgramExecutable(ExecState* exec, const SourceCode& source)
89 : ScriptExecutable(exec->globalData().programExecutableStructure.get(), exec, source, false)
93 ProgramExecutable::~ProgramExecutable()
97 const ClassInfo FunctionExecutable::s_info = { "FunctionExecutable", &ScriptExecutable::s_info, 0, 0 };
99 FunctionExecutable::FunctionExecutable(JSGlobalData& globalData, const Identifier& name, const SourceCode& source, bool forceUsesArguments, FunctionParameters* parameters, bool inStrictContext)
100 : ScriptExecutable(globalData.functionExecutableStructure.get(), globalData, source, inStrictContext)
101 , m_numCapturedVariables(0)
102 , m_forceUsesArguments(forceUsesArguments)
103 , m_parameters(parameters)
109 FunctionExecutable::FunctionExecutable(ExecState* exec, const Identifier& name, const SourceCode& source, bool forceUsesArguments, FunctionParameters* parameters, bool inStrictContext)
110 : ScriptExecutable(exec->globalData().functionExecutableStructure.get(), exec, source, inStrictContext)
111 , m_numCapturedVariables(0)
112 , m_forceUsesArguments(forceUsesArguments)
113 , m_parameters(parameters)
119 JSObject* EvalExecutable::compileOptimized(ExecState* exec, ScopeChainNode* scopeChainNode)
121 ASSERT(exec->globalData().dynamicGlobalObject);
122 ASSERT(!!m_evalCodeBlock);
124 if (m_evalCodeBlock->getJITType() != JITCode::topTierJIT())
125 error = compileInternal(exec, scopeChainNode, JITCode::nextTierJIT(m_evalCodeBlock->getJITType()));
126 ASSERT(!!m_evalCodeBlock);
130 JSObject* EvalExecutable::compileInternal(ExecState* exec, ScopeChainNode* scopeChainNode, JITCode::JITType jitType)
133 UNUSED_PARAM(jitType);
135 JSObject* exception = 0;
136 JSGlobalData* globalData = &exec->globalData();
137 JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject();
138 if (!lexicalGlobalObject->evalEnabled())
139 return throwError(exec, createEvalError(exec, "Eval is disabled"));
140 RefPtr<EvalNode> evalNode = globalData->parser->parse<EvalNode>(lexicalGlobalObject, lexicalGlobalObject->debugger(), exec, m_source, 0, isStrictMode() ? JSParseStrict : JSParseNormal, &exception);
145 recordParse(evalNode->features(), evalNode->hasCapturedVariables(), evalNode->lineNo(), evalNode->lastLine());
147 JSGlobalObject* globalObject = scopeChainNode->globalObject.get();
149 OwnPtr<CodeBlock> previousCodeBlock = m_evalCodeBlock.release();
150 ASSERT((jitType == JITCode::bottomTierJIT()) == !previousCodeBlock);
151 m_evalCodeBlock = adoptPtr(new EvalCodeBlock(this, globalObject, source().provider(), scopeChainNode->localDepth(), previousCodeBlock.release()));
152 OwnPtr<BytecodeGenerator> generator(adoptPtr(new BytecodeGenerator(evalNode.get(), scopeChainNode, m_evalCodeBlock->symbolTable(), m_evalCodeBlock.get(), !!m_evalCodeBlock->alternative() ? BytecodeGenerator::OptimizingCompilation : BytecodeGenerator::FirstCompilation)));
153 if ((exception = generator->generate())) {
154 m_evalCodeBlock = static_pointer_cast<EvalCodeBlock>(m_evalCodeBlock->releaseAlternative());
155 evalNode->destroyData();
159 evalNode->destroyData();
160 m_evalCodeBlock->copyDataFromAlternative();
163 if (exec->globalData().canUseJIT()) {
164 bool dfgCompiled = false;
165 if (jitType == JITCode::DFGJIT)
166 dfgCompiled = DFG::tryCompile(exec, m_evalCodeBlock.get(), m_jitCodeForCall);
168 ASSERT(!m_evalCodeBlock->alternative() || !m_evalCodeBlock->alternative()->hasIncomingCalls());
170 if (m_evalCodeBlock->alternative()) {
171 // There is already an alternative piece of code compiled with a different
172 // JIT, so we can silently fail.
173 m_evalCodeBlock = static_pointer_cast<EvalCodeBlock>(m_evalCodeBlock->releaseAlternative());
176 m_jitCodeForCall = JIT::compile(scopeChainNode->globalData, m_evalCodeBlock.get());
178 #if !ENABLE(OPCODE_SAMPLING)
179 if (!BytecodeGenerator::dumpsGeneratedCode())
180 m_evalCodeBlock->discardBytecode();
182 m_evalCodeBlock->setJITCode(m_jitCodeForCall, MacroAssemblerCodePtr());
187 #if ENABLE(INTERPRETER)
188 if (!m_jitCodeForCall)
189 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_evalCodeBlock));
192 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_evalCodeBlock) + m_jitCodeForCall.size());
194 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_evalCodeBlock));
200 void EvalExecutable::visitChildren(SlotVisitor& visitor)
202 ASSERT_GC_OBJECT_INHERITS(this, &s_info);
203 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
204 ASSERT(structure()->typeInfo().overridesVisitChildren());
205 ScriptExecutable::visitChildren(visitor);
207 m_evalCodeBlock->visitAggregate(visitor);
210 void EvalExecutable::unlinkCalls()
213 if (!m_jitCodeForCall)
215 ASSERT(m_evalCodeBlock);
216 m_evalCodeBlock->unlinkCalls();
220 void EvalExecutable::clearCode()
222 if (m_evalCodeBlock) {
223 m_evalCodeBlock->clearEvalCache();
224 m_evalCodeBlock.clear();
229 JSObject* ProgramExecutable::checkSyntax(ExecState* exec)
231 JSObject* exception = 0;
232 JSGlobalData* globalData = &exec->globalData();
233 JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject();
234 RefPtr<ProgramNode> programNode = globalData->parser->parse<ProgramNode>(lexicalGlobalObject, lexicalGlobalObject->debugger(), exec, m_source, 0, JSParseNormal, &exception);
241 JSObject* ProgramExecutable::compileOptimized(ExecState* exec, ScopeChainNode* scopeChainNode)
243 ASSERT(exec->globalData().dynamicGlobalObject);
244 ASSERT(!!m_programCodeBlock);
246 if (m_programCodeBlock->getJITType() != JITCode::topTierJIT())
247 error = compileInternal(exec, scopeChainNode, JITCode::nextTierJIT(m_programCodeBlock->getJITType()));
248 ASSERT(!!m_programCodeBlock);
252 JSObject* ProgramExecutable::compileInternal(ExecState* exec, ScopeChainNode* scopeChainNode, JITCode::JITType jitType)
255 UNUSED_PARAM(jitType);
257 JSObject* exception = 0;
258 JSGlobalData* globalData = &exec->globalData();
259 JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject();
260 RefPtr<ProgramNode> programNode = globalData->parser->parse<ProgramNode>(lexicalGlobalObject, lexicalGlobalObject->debugger(), exec, m_source, 0, isStrictMode() ? JSParseStrict : JSParseNormal, &exception);
265 recordParse(programNode->features(), programNode->hasCapturedVariables(), programNode->lineNo(), programNode->lastLine());
267 JSGlobalObject* globalObject = scopeChainNode->globalObject.get();
269 OwnPtr<CodeBlock> previousCodeBlock = m_programCodeBlock.release();
270 ASSERT((jitType == JITCode::bottomTierJIT()) == !previousCodeBlock);
271 m_programCodeBlock = adoptPtr(new ProgramCodeBlock(this, GlobalCode, globalObject, source().provider(), previousCodeBlock.release()));
272 OwnPtr<BytecodeGenerator> generator(adoptPtr(new BytecodeGenerator(programNode.get(), scopeChainNode, &globalObject->symbolTable(), m_programCodeBlock.get(), !!m_programCodeBlock->alternative() ? BytecodeGenerator::OptimizingCompilation : BytecodeGenerator::FirstCompilation)));
273 if ((exception = generator->generate())) {
274 m_programCodeBlock = static_pointer_cast<ProgramCodeBlock>(m_programCodeBlock->releaseAlternative());
275 programNode->destroyData();
279 programNode->destroyData();
280 m_programCodeBlock->copyDataFromAlternative();
283 if (exec->globalData().canUseJIT()) {
284 bool dfgCompiled = false;
285 if (jitType == JITCode::DFGJIT)
286 dfgCompiled = DFG::tryCompile(exec, m_programCodeBlock.get(), m_jitCodeForCall);
288 if (m_programCodeBlock->alternative())
289 m_programCodeBlock->alternative()->unlinkIncomingCalls();
291 if (m_programCodeBlock->alternative()) {
292 m_programCodeBlock = static_pointer_cast<ProgramCodeBlock>(m_programCodeBlock->releaseAlternative());
295 m_jitCodeForCall = JIT::compile(scopeChainNode->globalData, m_programCodeBlock.get());
297 #if !ENABLE(OPCODE_SAMPLING)
298 if (!BytecodeGenerator::dumpsGeneratedCode())
299 m_programCodeBlock->discardBytecode();
301 m_programCodeBlock->setJITCode(m_jitCodeForCall, MacroAssemblerCodePtr());
306 #if ENABLE(INTERPRETER)
307 if (!m_jitCodeForCall)
308 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_programCodeBlock));
311 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_programCodeBlock) + m_jitCodeForCall.size());
313 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_programCodeBlock));
319 void ProgramExecutable::unlinkCalls()
322 if (!m_jitCodeForCall)
324 ASSERT(m_programCodeBlock);
325 m_programCodeBlock->unlinkCalls();
329 void ProgramExecutable::visitChildren(SlotVisitor& visitor)
331 ASSERT_GC_OBJECT_INHERITS(this, &s_info);
332 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
333 ASSERT(structure()->typeInfo().overridesVisitChildren());
334 ScriptExecutable::visitChildren(visitor);
335 if (m_programCodeBlock)
336 m_programCodeBlock->visitAggregate(visitor);
339 void ProgramExecutable::clearCode()
341 if (m_programCodeBlock) {
342 m_programCodeBlock->clearEvalCache();
343 m_programCodeBlock.clear();
348 JSObject* FunctionExecutable::compileOptimizedForCall(ExecState* exec, ScopeChainNode* scopeChainNode, ExecState* calleeArgsExec)
350 ASSERT(exec->globalData().dynamicGlobalObject);
351 ASSERT(!!m_codeBlockForCall);
353 if (m_codeBlockForCall->getJITType() != JITCode::topTierJIT())
354 error = compileForCallInternal(exec, scopeChainNode, calleeArgsExec, JITCode::nextTierJIT(m_codeBlockForCall->getJITType()));
355 ASSERT(!!m_codeBlockForCall);
359 JSObject* FunctionExecutable::compileOptimizedForConstruct(ExecState* exec, ScopeChainNode* scopeChainNode)
361 ASSERT(exec->globalData().dynamicGlobalObject);
362 ASSERT(!!m_codeBlockForConstruct);
364 if (m_codeBlockForConstruct->getJITType() != JITCode::topTierJIT())
365 error = compileForConstructInternal(exec, scopeChainNode, JITCode::nextTierJIT(m_codeBlockForConstruct->getJITType()));
366 ASSERT(!!m_codeBlockForConstruct);
370 JSObject* FunctionExecutable::compileForCallInternal(ExecState* exec, ScopeChainNode* scopeChainNode, ExecState* calleeArgsExec, JITCode::JITType jitType)
373 UNUSED_PARAM(jitType);
375 JSObject* exception = 0;
376 JSGlobalData* globalData = scopeChainNode->globalData;
377 RefPtr<FunctionBodyNode> body = globalData->parser->parse<FunctionBodyNode>(exec->lexicalGlobalObject(), 0, 0, m_source, m_parameters.get(), isStrictMode() ? JSParseStrict : JSParseNormal, &exception);
382 if (m_forceUsesArguments)
383 body->setUsesArguments();
384 body->finishParsing(m_parameters, m_name);
385 recordParse(body->features(), body->hasCapturedVariables(), body->lineNo(), body->lastLine());
387 JSGlobalObject* globalObject = scopeChainNode->globalObject.get();
389 OwnPtr<CodeBlock> previousCodeBlock = m_codeBlockForCall.release();
390 ASSERT((jitType == JITCode::bottomTierJIT()) == !previousCodeBlock);
391 m_codeBlockForCall = adoptPtr(new FunctionCodeBlock(this, FunctionCode, globalObject, source().provider(), source().startOffset(), false, previousCodeBlock.release()));
392 OwnPtr<BytecodeGenerator> generator(adoptPtr(new BytecodeGenerator(body.get(), scopeChainNode, m_codeBlockForCall->symbolTable(), m_codeBlockForCall.get(), !!m_codeBlockForCall->alternative() ? BytecodeGenerator::OptimizingCompilation : BytecodeGenerator::FirstCompilation)));
393 if ((exception = generator->generate())) {
394 m_codeBlockForCall = static_pointer_cast<FunctionCodeBlock>(m_codeBlockForCall->releaseAlternative());
399 m_numParametersForCall = m_codeBlockForCall->m_numParameters;
400 ASSERT(m_numParametersForCall);
401 m_numCapturedVariables = m_codeBlockForCall->m_numCapturedVars;
402 m_symbolTable = m_codeBlockForCall->sharedSymbolTable();
405 m_codeBlockForCall->copyDataFromAlternative();
408 if (exec->globalData().canUseJIT()) {
409 bool dfgCompiled = false;
410 if (jitType == JITCode::DFGJIT)
411 dfgCompiled = DFG::tryCompileFunction(exec, calleeArgsExec, m_codeBlockForCall.get(), m_jitCodeForCall, m_jitCodeForCallWithArityCheck);
413 if (m_codeBlockForCall->alternative())
414 m_codeBlockForCall->alternative()->unlinkIncomingCalls();
416 if (m_codeBlockForCall->alternative()) {
417 m_codeBlockForCall = static_pointer_cast<FunctionCodeBlock>(m_codeBlockForCall->releaseAlternative());
418 m_symbolTable = m_codeBlockForCall->sharedSymbolTable();
421 m_jitCodeForCall = JIT::compile(scopeChainNode->globalData, m_codeBlockForCall.get(), &m_jitCodeForCallWithArityCheck);
423 #if !ENABLE(OPCODE_SAMPLING)
424 if (!BytecodeGenerator::dumpsGeneratedCode())
425 m_codeBlockForCall->discardBytecode();
428 m_codeBlockForCall->setJITCode(m_jitCodeForCall, m_jitCodeForCallWithArityCheck);
431 UNUSED_PARAM(calleeArgsExec);
435 #if ENABLE(INTERPRETER)
436 if (!m_jitCodeForCall)
437 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForCall));
440 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForCall) + m_jitCodeForCall.size());
442 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForCall));
448 JSObject* FunctionExecutable::compileForConstructInternal(ExecState* exec, ScopeChainNode* scopeChainNode, JITCode::JITType jitType)
450 UNUSED_PARAM(jitType);
452 JSObject* exception = 0;
453 JSGlobalData* globalData = scopeChainNode->globalData;
454 RefPtr<FunctionBodyNode> body = globalData->parser->parse<FunctionBodyNode>(exec->lexicalGlobalObject(), 0, 0, m_source, m_parameters.get(), isStrictMode() ? JSParseStrict : JSParseNormal, &exception);
459 if (m_forceUsesArguments)
460 body->setUsesArguments();
461 body->finishParsing(m_parameters, m_name);
462 recordParse(body->features(), body->hasCapturedVariables(), body->lineNo(), body->lastLine());
464 JSGlobalObject* globalObject = scopeChainNode->globalObject.get();
466 OwnPtr<CodeBlock> previousCodeBlock = m_codeBlockForConstruct.release();
467 ASSERT((jitType == JITCode::bottomTierJIT()) == !previousCodeBlock);
468 m_codeBlockForConstruct = adoptPtr(new FunctionCodeBlock(this, FunctionCode, globalObject, source().provider(), source().startOffset(), true, previousCodeBlock.release()));
469 OwnPtr<BytecodeGenerator> generator(adoptPtr(new BytecodeGenerator(body.get(), scopeChainNode, m_codeBlockForConstruct->symbolTable(), m_codeBlockForConstruct.get(), !!m_codeBlockForConstruct->alternative() ? BytecodeGenerator::OptimizingCompilation : BytecodeGenerator::FirstCompilation)));
470 if ((exception = generator->generate())) {
471 m_codeBlockForConstruct = static_pointer_cast<FunctionCodeBlock>(m_codeBlockForConstruct->releaseAlternative());
476 m_numParametersForConstruct = m_codeBlockForConstruct->m_numParameters;
477 ASSERT(m_numParametersForConstruct);
478 m_numCapturedVariables = m_codeBlockForConstruct->m_numCapturedVars;
479 m_symbolTable = m_codeBlockForConstruct->sharedSymbolTable();
482 m_codeBlockForConstruct->copyDataFromAlternative();
485 if (exec->globalData().canUseJIT()) {
486 bool dfgCompiled = false;
487 // FIXME: Make it possible to compile constructors with DFG.
489 if (m_codeBlockForConstruct->alternative())
490 m_codeBlockForConstruct->alternative()->unlinkIncomingCalls();
492 if (m_codeBlockForConstruct->alternative()) {
493 m_codeBlockForConstruct = static_pointer_cast<FunctionCodeBlock>(m_codeBlockForConstruct->releaseAlternative());
494 m_symbolTable = m_codeBlockForConstruct->sharedSymbolTable();
497 m_jitCodeForConstruct = JIT::compile(scopeChainNode->globalData, m_codeBlockForConstruct.get(), &m_jitCodeForConstructWithArityCheck);
499 #if !ENABLE(OPCODE_SAMPLING)
500 if (!BytecodeGenerator::dumpsGeneratedCode())
501 m_codeBlockForConstruct->discardBytecode();
504 m_codeBlockForConstruct->setJITCode(m_jitCodeForConstruct, m_jitCodeForConstructWithArityCheck);
509 #if ENABLE(INTERPRETER)
510 if (!m_jitCodeForConstruct)
511 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForConstruct));
514 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForConstruct) + m_jitCodeForConstruct.size());
516 Heap::heap(this)->reportExtraMemoryCost(sizeof(*m_codeBlockForConstruct));
522 void FunctionExecutable::visitChildren(SlotVisitor& visitor)
524 ASSERT_GC_OBJECT_INHERITS(this, &s_info);
525 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
526 ASSERT(structure()->typeInfo().overridesVisitChildren());
527 ScriptExecutable::visitChildren(visitor);
529 visitor.append(&m_nameValue);
530 if (m_codeBlockForCall)
531 m_codeBlockForCall->visitAggregate(visitor);
532 if (m_codeBlockForConstruct)
533 m_codeBlockForConstruct->visitAggregate(visitor);
536 void FunctionExecutable::discardCode()
539 // These first two checks are to handle the rare case where
540 // we are trying to evict code for a function during its
542 if (!m_jitCodeForCall && m_codeBlockForCall)
544 if (!m_jitCodeForConstruct && m_codeBlockForConstruct)
550 void FunctionExecutable::clearCode()
552 if (m_codeBlockForCall) {
553 m_codeBlockForCall->clearEvalCache();
554 m_codeBlockForCall.clear();
556 if (m_codeBlockForConstruct) {
557 m_codeBlockForConstruct->clearEvalCache();
558 m_codeBlockForConstruct.clear();
563 void FunctionExecutable::unlinkCalls()
566 if (!!m_jitCodeForCall) {
567 ASSERT(m_codeBlockForCall);
568 m_codeBlockForCall->unlinkCalls();
570 if (!!m_jitCodeForConstruct) {
571 ASSERT(m_codeBlockForConstruct);
572 m_codeBlockForConstruct->unlinkCalls();
577 FunctionExecutable* FunctionExecutable::fromGlobalCode(const Identifier& functionName, ExecState* exec, Debugger* debugger, const SourceCode& source, JSObject** exception)
579 JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject();
580 RefPtr<ProgramNode> program = exec->globalData().parser->parse<ProgramNode>(lexicalGlobalObject, debugger, exec, source, 0, JSParseNormal, exception);
586 // Uses of this function that would not result in a single function expression are invalid.
587 StatementNode* exprStatement = program->singleStatement();
588 ASSERT(exprStatement);
589 ASSERT(exprStatement->isExprStatement());
590 ExpressionNode* funcExpr = static_cast<ExprStatementNode*>(exprStatement)->expr();
592 ASSERT(funcExpr->isFuncExprNode());
593 FunctionBodyNode* body = static_cast<FuncExprNode*>(funcExpr)->body();
596 return FunctionExecutable::create(exec->globalData(), functionName, body->source(), body->usesArguments(), body->parameters(), body->isStrictMode(), body->lineNo(), body->lastLine());
599 UString FunctionExecutable::paramString() const
601 FunctionParameters& parameters = *m_parameters;
602 UStringBuilder builder;
603 for (size_t pos = 0; pos < parameters.size(); ++pos) {
604 if (!builder.isEmpty())
605 builder.append(", ");
606 builder.append(parameters[pos].ustring());
608 return builder.toUString();