本文整理汇总了C++中JSFunction::sourceCode方法的典型用法代码示例。如果您正苦于以下问题:C++ JSFunction::sourceCode方法的具体用法?C++ JSFunction::sourceCode怎么用?C++ JSFunction::sourceCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSFunction
的用法示例。
在下文中一共展示了JSFunction::sourceCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: functionDetails
JSValue JSInjectedScriptHost::functionDetails(ExecState* exec)
{
if (exec->argumentCount() < 1)
return jsUndefined();
JSValue value = exec->argument(0);
if (!value.asCell()->inherits(&JSFunction::s_info))
return jsUndefined();
JSFunction* function = jsCast<JSFunction*>(value);
const SourceCode* sourceCode = function->sourceCode();
if (!sourceCode)
return jsUndefined();
int lineNumber = sourceCode->firstLine();
if (lineNumber)
lineNumber -= 1; // In the inspector protocol all positions are 0-based while in SourceCode they are 1-based
UString scriptId = UString::number(sourceCode->provider()->asID());
JSObject* location = constructEmptyObject(exec);
location->putDirect(exec->globalData(), Identifier(exec, "lineNumber"), jsNumber(lineNumber));
location->putDirect(exec->globalData(), Identifier(exec, "scriptId"), jsString(exec, scriptId));
JSObject* result = constructEmptyObject(exec);
result->putDirect(exec->globalData(), Identifier(exec, "location"), location);
UString name = function->name(exec);
if (!name.isEmpty())
result->putDirect(exec->globalData(), Identifier(exec, "name"), jsString(exec, name));
UString displayName = function->displayName(exec);
if (!displayName.isEmpty())
result->putDirect(exec->globalData(), Identifier(exec, "displayName"), jsString(exec, displayName));
// FIXME: provide function scope data in "scopesRaw" property when JSC supports it.
// https://bugs.webkit.org/show_bug.cgi?id=87192
return result;
}
示例2: functionDetails
JSValue JSInjectedScriptHost::functionDetails(ExecState* exec)
{
if (exec->argumentCount() < 1)
return jsUndefined();
JSValue value = exec->uncheckedArgument(0);
if (!value.asCell()->inherits(JSFunction::info()))
return jsUndefined();
// FIXME: This should provide better details for JSBoundFunctions.
JSFunction* function = jsCast<JSFunction*>(value);
const SourceCode* sourceCode = function->sourceCode();
if (!sourceCode)
return jsUndefined();
// In the inspector protocol all positions are 0-based while in SourceCode they are 1-based
int lineNumber = sourceCode->firstLine();
if (lineNumber)
lineNumber -= 1;
int columnNumber = sourceCode->startColumn();
if (columnNumber)
columnNumber -= 1;
VM& vm = exec->vm();
String scriptID = String::number(sourceCode->provider()->asID());
JSObject* location = constructEmptyObject(exec);
location->putDirect(vm, Identifier::fromString(exec, "scriptId"), jsString(exec, scriptID));
location->putDirect(vm, Identifier::fromString(exec, "lineNumber"), jsNumber(lineNumber));
location->putDirect(vm, Identifier::fromString(exec, "columnNumber"), jsNumber(columnNumber));
JSObject* result = constructEmptyObject(exec);
result->putDirect(vm, Identifier::fromString(exec, "location"), location);
String name = function->name();
if (!name.isEmpty())
result->putDirect(vm, Identifier::fromString(exec, "name"), jsString(exec, name));
String displayName = function->displayName(vm);
if (!displayName.isEmpty())
result->putDirect(vm, Identifier::fromString(exec, "displayName"), jsString(exec, displayName));
// FIXME: provide function scope data in "scopesRaw" property when JSC supports it.
// <https://webkit.org/b/87192> [JSC] expose function (closure) inner context to debugger
return result;
}