本文整理汇总了C++中JSFunction::body方法的典型用法代码示例。如果您正苦于以下问题:C++ JSFunction::body方法的具体用法?C++ JSFunction::body怎么用?C++ JSFunction::body使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSFunction
的用法示例。
在下文中一共展示了JSFunction::body方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recompileAllJSFunctions
void JavaScriptDebugServer::recompileAllJSFunctions(Timer<JavaScriptDebugServer>*)
{
JSLock lock(false);
JSGlobalData* globalData = JSDOMWindow::commonJSGlobalData();
// If JavaScript 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;
Vector<ProtectedPtr<JSFunction> > functions;
Heap::iterator heapEnd = globalData->heap.primaryHeapEnd();
for (Heap::iterator it = globalData->heap.primaryHeapBegin(); it != heapEnd; ++it) {
if ((*it)->isObject(&JSFunction::info))
functions.append(static_cast<JSFunction*>(*it));
}
typedef HashMap<RefPtr<FunctionBodyNode>, RefPtr<FunctionBodyNode> > FunctionBodyMap;
typedef HashMap<SourceProvider*, ExecState*> SourceProviderMap;
FunctionBodyMap functionBodies;
SourceProviderMap sourceProviders;
size_t size = functions.size();
for (size_t i = 0; i < size; ++i) {
JSFunction* function = functions[i];
FunctionBodyNode* oldBody = function->body();
pair<FunctionBodyMap::iterator, bool> result = functionBodies.add(oldBody, 0);
if (!result.second) {
function->setBody(result.first->second.get());
continue;
}
ExecState* exec = function->scope().globalObject()->JSGlobalObject::globalExec();
const SourceCode& sourceCode = oldBody->source();
RefPtr<FunctionBodyNode> newBody = globalData->parser->parse<FunctionBodyNode>(exec, 0, sourceCode);
ASSERT(newBody);
newBody->finishParsing(oldBody->copyParameters(), oldBody->parameterCount());
result.first->second = newBody;
function->setBody(newBody.release());
if (hasListeners())
sourceProviders.add(sourceCode.provider(), exec);
}
// Call sourceParsed() after reparsing all functions because it will execute
// JavaScript 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);
}