Skip to content

Commit c4e25ac

Browse files
committed
Drop unnecessary usage of ternary operator in JavaScriptCore
https://bugs.webkit.org/show_bug.cgi?id=306221 rdar://168876630 Reviewed by Darin Adler. This improves readability and enforces more idiomatic C++ by resorting to equivalent binary boolean operations. * Source/JavaScriptCore/assembler/CPU.cpp: (JSC::isARM64E_FPAC): * Source/JavaScriptCore/bytecode/DeleteByStatus.cpp: (JSC::DeleteByStatus::computeForStubInfoWithoutExitSiteFeedback): * Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitGenericEnumeration): * Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp: (JSC::ShortCircuitReadModifyResolveNode::emitBytecode): * Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleIntrinsicCall): * Source/JavaScriptCore/parser/Nodes.cpp: (JSC::BlockNode::hasCompletionValue const): (JSC::BlockNode::hasEarlyBreakOrContinue const): (JSC::ScopeNode::hasCompletionValue const): (JSC::ScopeNode::hasEarlyBreakOrContinue const): * Source/JavaScriptCore/parser/Nodes.h: * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionBody): * Source/JavaScriptCore/runtime/Butterfly.h: (JSC::Butterfly::totalSize): * Source/JavaScriptCore/runtime/LiteralParser.cpp: (JSC::requires): (JSC::reviverMode>::parse): * Source/JavaScriptCore/runtime/Options.cpp: (JSC::OptionRange::isInRange const): * Source/JavaScriptCore/runtime/VMManager.h: (JSC::VMManager::isValidVM): Canonical link: https://commits.webkit.org/306188@main
1 parent 8cfc642 commit c4e25ac

File tree

12 files changed

+20
-20
lines changed

12 files changed

+20
-20
lines changed

Source/JavaScriptCore/assembler/CPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bool isARM64E_FPAC()
125125
uint32_t val = 0;
126126
size_t valSize = sizeof(val);
127127
int rc = sysctlbyname("hw.optional.arm.FEAT_FPAC", &val, &valSize, nullptr, 0);
128-
g_jscConfig.canUseFPAC = rc < 0 ? false : !!val;
128+
g_jscConfig.canUseFPAC = rc >= 0 && val;
129129
});
130130
return g_jscConfig.canUseFPAC;
131131
#else

Source/JavaScriptCore/bytecode/DeleteByStatus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ DeleteByStatus DeleteByStatus::computeForStubInfoWithoutExitSiteFeedback(const C
113113
switch (access.type()) {
114114
case AccessCase::DeleteMiss:
115115
case AccessCase::DeleteNonConfigurable: {
116-
DeleteByVariant variant(access.identifier(), access.type() == AccessCase::DeleteMiss ? true : false, structure, nullptr, invalidOffset);
116+
DeleteByVariant variant(access.identifier(), access.type() == AccessCase::DeleteMiss, structure, nullptr, invalidOffset);
117117
if (!result.appendVariant(variant))
118118
return DeleteByStatus(JSC::slowVersion(summary), *stubInfo);
119119
break;

Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4660,7 +4660,7 @@ void BytecodeGenerator::emitTryWithFinallyThatDoesNotShadowException(FinallyCont
46604660

46614661
void BytecodeGenerator::emitGenericEnumeration(ThrowableExpressionData* node, ExpressionNode* subjectNode, const ScopedLambda<void(BytecodeGenerator&, RegisterID*)>& callBack, ForOfNode* forLoopNode, RegisterID* forLoopSymbolTable)
46624662
{
4663-
bool isForAwait = forLoopNode ? forLoopNode->isForAwait() : false;
4663+
bool isForAwait = forLoopNode && forLoopNode->isForAwait();
46644664
auto shouldEmitAwait = isForAwait ? EmitAwait::Yes : EmitAwait::No;
46654665
ASSERT(!isForAwait || (isAsyncFunctionParseMode(parseMode()) || isModuleParseMode(parseMode())));
46664666

Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4093,7 +4093,7 @@ RegisterID* ShortCircuitReadModifyResolveNode::emitBytecode(BytecodeGenerator& g
40934093

40944094
generator.emitNode(uncheckedResult.get(), m_right); // Execute side effects first.
40954095

4096-
bool threwException = isReadOnly ? generator.emitReadOnlyExceptionIfNeeded(var) : false;
4096+
bool threwException = isReadOnly && generator.emitReadOnlyExceptionIfNeeded(var);
40974097

40984098
if (!threwException)
40994099
generator.emitExpressionInfo(divot(), divotStart(), divotEnd());

Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3591,7 +3591,7 @@ auto ByteCodeParser::handleIntrinsicCall(Node* callee, Operand resultOperand, Ca
35913591

35923592
case IsFinalTierIntrinsic: {
35933593
insertChecks();
3594-
setResult(jsConstant(jsBoolean(Options::useFTLJIT() ? m_graph.m_plan.isFTL() : true)));
3594+
setResult(jsConstant(jsBoolean(!Options::useFTLJIT() || m_graph.m_plan.isFTL())));
35953595
return CallOptimizationResult::Inlined;
35963596
}
35973597

Source/JavaScriptCore/parser/Nodes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ StatementNode* BlockNode::singleStatement() const
107107

108108
bool BlockNode::hasCompletionValue() const
109109
{
110-
return m_statements ? m_statements->hasCompletionValue() : false;
110+
return m_statements && m_statements->hasCompletionValue();
111111
}
112112

113113
bool BlockNode::hasEarlyBreakOrContinue() const
114114
{
115-
return m_statements ? m_statements->hasEarlyBreakOrContinue() : false;
115+
return m_statements && m_statements->hasEarlyBreakOrContinue();
116116
}
117117

118118
// ------------------------------ ScopeNode -----------------------------
@@ -155,12 +155,12 @@ StatementNode* ScopeNode::singleStatement() const
155155

156156
bool ScopeNode::hasCompletionValue() const
157157
{
158-
return m_statements ? m_statements->hasCompletionValue() : false;
158+
return m_statements && m_statements->hasCompletionValue();
159159
}
160160

161161
bool ScopeNode::hasEarlyBreakOrContinue() const
162162
{
163-
return m_statements ? m_statements->hasEarlyBreakOrContinue() : false;
163+
return m_statements && m_statements->hasEarlyBreakOrContinue();
164164
}
165165

166166
// ------------------------------ ProgramNode -----------------------------

Source/JavaScriptCore/parser/Nodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,8 +2456,8 @@ namespace JSC {
24562456
const Identifier& ecmaName() { return m_ecmaName ? *m_ecmaName : m_name; }
24572457
void setEcmaName(const Identifier& name) { m_ecmaName = m_name.isNull() ? &name : &m_name; }
24582458

2459-
bool hasStaticProperty(const Identifier& propName) { return m_classElements ? m_classElements->hasStaticallyNamedProperty(propName) : false; }
2460-
bool hasInstanceFields() const { return m_classElements ? m_classElements->hasInstanceFields() : false; }
2459+
bool hasStaticProperty(const Identifier& propName) { return m_classElements && m_classElements->hasStaticallyNamedProperty(propName); }
2460+
bool hasInstanceFields() const { return m_classElements && m_classElements->hasInstanceFields(); }
24612461

24622462
private:
24632463
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;

Source/JavaScriptCore/parser/Parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,8 +2244,8 @@ template <class TreeBuilder> TreeFunctionBody Parser<LexerType>::parseFunctionBo
22442244
TreeBuilder& context, SyntaxChecker& syntaxChecker, const JSTokenLocation& startLocation, int startColumn, unsigned functionStart, int functionNameStart, int parametersStart,
22452245
ConstructorKind constructorKind, SuperBinding superBinding, FunctionBodyType bodyType, unsigned parameterCount)
22462246
{
2247-
SetForScope overrideParsingClassFieldInitializer(m_parserState.isParsingClassFieldInitializer, bodyType == StandardFunctionBodyBlock ? false : m_parserState.isParsingClassFieldInitializer);
2248-
SetForScope maybeUnmaskAsync(m_parserState.classFieldInitMasksAsync, isAsyncFunctionParseMode(m_parseMode) ? false : m_parserState.classFieldInitMasksAsync);
2247+
SetForScope overrideParsingClassFieldInitializer(m_parserState.isParsingClassFieldInitializer, bodyType != StandardFunctionBodyBlock && m_parserState.isParsingClassFieldInitializer);
2248+
SetForScope maybeUnmaskAsync(m_parserState.classFieldInitMasksAsync, !isAsyncFunctionParseMode(m_parseMode) && m_parserState.classFieldInitMasksAsync);
22492249
bool isArrowFunctionBodyExpression = bodyType == ArrowFunctionBodyExpression;
22502250
if (!isArrowFunctionBodyExpression) {
22512251
next();

Source/JavaScriptCore/runtime/Butterfly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class Butterfly {
140140

141141
static size_t totalSize(size_t preCapacity, size_t propertyCapacity, bool hasIndexingHeader, size_t indexingPayloadSizeInBytes)
142142
{
143-
ASSERT(indexingPayloadSizeInBytes ? hasIndexingHeader : true);
143+
ASSERT(!indexingPayloadSizeInBytes || hasIndexingHeader);
144144
ASSERT(sizeof(EncodedJSValue) == sizeof(IndexingHeader));
145145
return (preCapacity + propertyCapacity) * sizeof(EncodedJSValue) + (hasIndexingHeader ? sizeof(IndexingHeader) : 0) + indexingPayloadSizeInBytes;
146146
}

Source/JavaScriptCore/runtime/LiteralParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ JSValue LiteralParser<CharType, reviverMode>::parseRecursively(VM& vm, uint8_t*
14941494
m_parseErrorMessage = "Attempted to redefine __proto__ property"_s;
14951495
return { };
14961496
}
1497-
PutPropertySlot slot(object, m_nullOrCodeBlock ? m_nullOrCodeBlock->ownerExecutable()->isInStrictContext() : false);
1497+
PutPropertySlot slot(object, m_nullOrCodeBlock && m_nullOrCodeBlock->ownerExecutable()->isInStrictContext());
14981498
JSValue(object).put(m_globalObject, ident, value, slot);
14991499
RETURN_IF_EXCEPTION(scope, { });
15001500
} else if (std::optional<uint32_t> index = parseIndex(ident)) {
@@ -1672,7 +1672,7 @@ JSValue LiteralParser<CharType, reviverMode>::parse(VM& vm, ParserState initialS
16721672
m_parseErrorMessage = "Attempted to redefine __proto__ property"_s;
16731673
return { };
16741674
}
1675-
PutPropertySlot slot(object, m_nullOrCodeBlock ? m_nullOrCodeBlock->ownerExecutable()->isInStrictContext() : false);
1675+
PutPropertySlot slot(object, m_nullOrCodeBlock && m_nullOrCodeBlock->ownerExecutable()->isInStrictContext());
16761676
JSValue(object).put(m_globalObject, ident, primitive, slot);
16771677
RETURN_IF_EXCEPTION(scope, { });
16781678
} else {
@@ -1767,7 +1767,7 @@ JSValue LiteralParser<CharType, reviverMode>::parse(VM& vm, ParserState initialS
17671767
m_parseErrorMessage = "Attempted to redefine __proto__ property"_s;
17681768
return { };
17691769
}
1770-
PutPropertySlot slot(object, m_nullOrCodeBlock ? m_nullOrCodeBlock->ownerExecutable()->isInStrictContext() : false);
1770+
PutPropertySlot slot(object, m_nullOrCodeBlock && m_nullOrCodeBlock->ownerExecutable()->isInStrictContext());
17711771
JSValue(object).put(m_globalObject, ident, lastValue, slot);
17721772
RETURN_IF_EXCEPTION(scope, { });
17731773
} else {

0 commit comments

Comments
 (0)