本文整理汇总了C++中StatementNode::isBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ StatementNode::isBlock方法的具体用法?C++ StatementNode::isBlock怎么用?C++ StatementNode::isBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StatementNode
的用法示例。
在下文中一共展示了StatementNode::isBlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFunctionExecutableFromGlobalCode
// FIXME: There's no need to add the function's name to the key here. It's already in the source code.
UnlinkedFunctionExecutable* CodeCache::getFunctionExecutableFromGlobalCode(VM& vm, const Identifier& name, const SourceCode& source, ParserError& error)
{
bool isArrowFunctionContext = false;
SourceCodeKey key(
source, name.string(), SourceCodeType::FunctionType,
JSParserBuiltinMode::NotBuiltin,
JSParserStrictMode::NotStrict,
JSParserCommentMode::Classic,
DerivedContextType::None,
EvalContextType::None,
isArrowFunctionContext);
SourceCodeValue* cache = m_sourceCode.findCacheAndUpdateAge(key);
if (cache) {
UnlinkedFunctionExecutable* executable = jsCast<UnlinkedFunctionExecutable*>(cache->cell.get());
source.provider()->setSourceURLDirective(executable->sourceURLDirective());
source.provider()->setSourceMappingURLDirective(executable->sourceMappingURLDirective());
return executable;
}
JSTextPosition positionBeforeLastNewline;
std::unique_ptr<ProgramNode> program = parse<ProgramNode>(
&vm, source, Identifier(), JSParserBuiltinMode::NotBuiltin,
JSParserStrictMode::NotStrict, JSParserCommentMode::Classic, SourceParseMode::ProgramMode, SuperBinding::NotNeeded,
error, &positionBeforeLastNewline);
if (!program) {
RELEASE_ASSERT(error.isValid());
return nullptr;
}
// This function assumes an input string that would result in a single function declaration.
StatementNode* statement = program->singleStatement();
ASSERT(statement);
ASSERT(statement->isBlock());
if (!statement || !statement->isBlock())
return nullptr;
StatementNode* funcDecl = static_cast<BlockNode*>(statement)->singleStatement();
ASSERT(funcDecl);
ASSERT(funcDecl->isFuncDeclNode());
if (!funcDecl || !funcDecl->isFuncDeclNode())
return nullptr;
FunctionMetadataNode* metadata = static_cast<FuncDeclNode*>(funcDecl)->metadata();
ASSERT(metadata);
if (!metadata)
return nullptr;
metadata->overrideName(name);
metadata->setEndPosition(positionBeforeLastNewline);
// The Function constructor only has access to global variables, so no variables will be under TDZ.
VariableEnvironment emptyTDZVariables;
UnlinkedFunctionExecutable* functionExecutable = UnlinkedFunctionExecutable::create(&vm, source, metadata, UnlinkedNormalFunction, ConstructAbility::CanConstruct, JSParserCommentMode::Classic, emptyTDZVariables, DerivedContextType::None);
functionExecutable->setSourceURLDirective(source.provider()->sourceURL());
functionExecutable->setSourceMappingURLDirective(source.provider()->sourceMappingURL());
m_sourceCode.addCache(key, SourceCodeValue(vm, functionExecutable, m_sourceCode.age()));
return functionExecutable;
}
示例2: getFunctionExecutableFromGlobalCode
// FIXME: There's no need to add the function's name to the key here. It's already in the source code.
UnlinkedFunctionExecutable* CodeCache::getFunctionExecutableFromGlobalCode(VM& vm, const Identifier& name, const SourceCode& source, ParserError& error)
{
SourceCodeKey key = SourceCodeKey(
source, name.string(), SourceCodeKey::FunctionType,
JSParserBuiltinMode::NotBuiltin,
JSParserStrictMode::NotStrict);
SourceCodeValue* cache = m_sourceCode.findCacheAndUpdateAge(key);
if (cache)
return jsCast<UnlinkedFunctionExecutable*>(cache->cell.get());
JSTextPosition positionBeforeLastNewline;
std::unique_ptr<ProgramNode> program = parse<ProgramNode>(
&vm, source, Identifier(), JSParserBuiltinMode::NotBuiltin,
JSParserStrictMode::NotStrict, JSParserCodeType::Program,
error, &positionBeforeLastNewline);
if (!program) {
RELEASE_ASSERT(error.isValid());
return nullptr;
}
// This function assumes an input string that would result in a single function declaration.
StatementNode* statement = program->singleStatement();
ASSERT(statement);
ASSERT(statement->isBlock());
if (!statement || !statement->isBlock())
return nullptr;
StatementNode* funcDecl = static_cast<BlockNode*>(statement)->singleStatement();
ASSERT(funcDecl);
ASSERT(funcDecl->isFuncDeclNode());
if (!funcDecl || !funcDecl->isFuncDeclNode())
return nullptr;
FunctionBodyNode* body = static_cast<FuncDeclNode*>(funcDecl)->body();
ASSERT(body);
if (!body)
return nullptr;
body->setEndPosition(positionBeforeLastNewline);
// The Function constructor only has access to global variables, so no variables will be under TDZ.
VariableEnvironment emptyTDZVariables;
UnlinkedFunctionExecutable* functionExecutable = UnlinkedFunctionExecutable::create(&vm, source, body, UnlinkedNormalFunction, ConstructAbility::CanConstruct, emptyTDZVariables);
functionExecutable->m_nameValue.set(vm, functionExecutable, jsString(&vm, name.string()));
m_sourceCode.addCache(key, SourceCodeValue(vm, functionExecutable, m_sourceCode.age()));
return functionExecutable;
}