FunctionExecutable* FunctionExecutable::fromGlobalCode(const Identifier& name, ExecState* exec, Debugger* debugger, const SourceCode& source, JSObject** exception) { UnlinkedFunctionExecutable* unlinkedFunction = UnlinkedFunctionExecutable::fromGlobalCode(name, exec, debugger, source, exception); if (!unlinkedFunction) return 0; unsigned firstLine = source.firstLine() + unlinkedFunction->firstLineOffset(); unsigned startOffset = source.startOffset() + unlinkedFunction->startOffset(); unsigned sourceLength = unlinkedFunction->sourceLength(); SourceCode functionSource(source.provider(), startOffset, startOffset + sourceLength, firstLine); return FunctionExecutable::create(exec->globalData(), functionSource, unlinkedFunction, firstLine, unlinkedFunction->lineCount()); }
UnlinkedFunctionCodeBlock* CodeCache::getFunctionCodeBlock(JSGlobalData& globalData, UnlinkedFunctionExecutable* executable, const SourceCode& source, CodeSpecializationKind kind, DebuggerMode debuggerMode, ProfilerMode profilerMode, ParserError& error) { if (debuggerMode == DebuggerOn || profilerMode == ProfilerOn) return generateFunctionCodeBlock(globalData, executable, source, kind, debuggerMode, profilerMode, error); SourceCode functionSource(source.provider(), executable->functionStartOffset(), source.endOffset(), source.firstLine()); CodeBlockKey key = makeCodeBlockKey(functionSource, kind == CodeForCall ? FunctionCallType : FunctionConstructType, executable->isInStrictContext() ? JSParseStrict : JSParseNormal); if (const Strong<UnlinkedFunctionCodeBlock>* cacheEntry = m_cachedFunctionExecutables.find(key)) { if (cacheEntry) { UnlinkedFunctionCodeBlock* unlinkedCode = cacheEntry->get(); unsigned firstLine = source.firstLine() + unlinkedCode->firstLine(); executable->recordParse(unlinkedCode->codeFeatures(), unlinkedCode->hasCapturedVariables(), firstLine, firstLine + unlinkedCode->lineCount()); m_recentlyUsedFunctionCode.add(unlinkedCode, *cacheEntry); return unlinkedCode; } } UnlinkedFunctionCodeBlock* result = generateFunctionCodeBlock(globalData, executable, source, kind, debuggerMode, profilerMode, error); m_cachedFunctionExecutables.add(key, Strong<UnlinkedFunctionCodeBlock>(globalData, result)); return result; }