CallIdentifier Profiler::createCallIdentifier(TiExcState* exec, TiValue functionValue, const UString& defaultSourceURL, int defaultLineNumber) { if (!functionValue) return CallIdentifier(GlobalCodeExecution, defaultSourceURL, defaultLineNumber); if (!functionValue.isObject()) return CallIdentifier("(unknown)", defaultSourceURL, defaultLineNumber); if (asObject(functionValue)->inherits(&TiFunction::info)) { TiFunction* function = asFunction(functionValue); if (!function->executable()->isHostFunction()) return createCallIdentifierFromFunctionImp(exec, function); } if (asObject(functionValue)->inherits(&InternalFunction::info)) return CallIdentifier(static_cast<InternalFunction*>(asObject(functionValue))->name(exec), defaultSourceURL, defaultLineNumber); return CallIdentifier(makeString("(", asObject(functionValue)->className(), " object)"), defaultSourceURL, defaultLineNumber); }
void Debugger::recompileAllTiFunctions(TiGlobalData* globalData) { // If Ti is running, it's not safe to recompile, since we'll end // up throwing away code that is live on the stack. ASSERT(!globalData->dynamicGlobalObject); if (globalData->dynamicGlobalObject) return; typedef HashSet<FunctionExecutable*> FunctionExecutableSet; typedef HashMap<SourceProvider*, TiExcState*> SourceProviderMap; FunctionExecutableSet functionExecutables; SourceProviderMap sourceProviders; Heap::iterator heapEnd = globalData->heap.primaryHeapEnd(); for (Heap::iterator it = globalData->heap.primaryHeapBegin(); it != heapEnd; ++it) { if (!(*it)->inherits(&TiFunction::info)) continue; TiFunction* function = asFunction(*it); if (function->executable()->isHostFunction()) continue; FunctionExecutable* executable = function->jsExecutable(); // Check if the function is already in the set - if so, // we've already retranslated it, nothing to do here. if (!functionExecutables.add(executable).second) continue; TiExcState* exec = function->scope().globalObject()->TiGlobalObject::globalExec(); executable->recompile(exec); if (function->scope().globalObject()->debugger() == this) sourceProviders.add(executable->source().provider(), exec); } // Call sourceParsed() after reparsing all functions because it will execute // Ti in the inspector. SourceProviderMap::const_iterator end = sourceProviders.end(); for (SourceProviderMap::const_iterator iter = sourceProviders.begin(); iter != end; ++iter) sourceParsed(iter->second, SourceCode(iter->first), -1, 0); }
EncodedTiValue JSC_HOST_CALL functionProtoFuncToString(TiExcState* exec) { TiValue thisValue = exec->hostThisValue(); if (thisValue.inherits(&TiFunction::s_info)) { TiFunction* function = asFunction(thisValue); if (function->isHostFunction()) return TiValue::encode(jsMakeNontrivialString(exec, "function ", function->name(exec), "() {\n [native code]\n}")); FunctionExecutable* executable = function->jsExecutable(); UString sourceString = executable->source().toString(); insertSemicolonIfNeeded(sourceString); return TiValue::encode(jsMakeNontrivialString(exec, "function ", function->name(exec), "(", executable->paramString(), ") ", sourceString)); } if (thisValue.inherits(&InternalFunction::s_info)) { InternalFunction* function = asInternalFunction(thisValue); return TiValue::encode(jsMakeNontrivialString(exec, "function ", function->name(exec), "() {\n [native code]\n}")); } return throwVMTypeError(exec); }
TiValue TiFunction::lengthGetter(TiExcState* exec, TiValue slotBase, const Identifier&) { TiFunction* thisObj = asFunction(slotBase); ASSERT(!thisObj->isHostFunction()); return jsNumber(exec, thisObj->jsExecutable()->parameterCount()); }
TiValue TiFunction::callerGetter(TiExcState* exec, TiValue slotBase, const Identifier&) { TiFunction* thisObj = asFunction(slotBase); ASSERT(!thisObj->isHostFunction()); return exec->interpreter()->retrieveCaller(exec, thisObj); }