Commit 740d94be authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[compiler] Make StringRef::GetFirstChar() return an optional value

Follow-up that continues to make StringRefs's methods return optional
values.

Bug: v8:7790
Change-Id: I34f907810747216b047a3da8db035cf4f62728c3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2615162Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71982}
parent c27c167c
......@@ -835,7 +835,7 @@ class StringRef : public NameRef {
Handle<String> object() const;
base::Optional<int> length() const;
uint16_t GetFirstChar();
base::Optional<uint16_t> GetFirstChar();
base::Optional<double> ToNumber();
bool IsSeqString() const;
bool IsExternalString() const;
......
......@@ -6040,7 +6040,7 @@ Reduction JSCallReducer::ReduceStringPrototypeStartsWith(Node* node) {
graph()->NewNode(simplified()->StringCharCodeAt(), receiver,
masked_position, etrue, if_true);
Node* search_first = jsgraph()->Constant(str.GetFirstChar());
Node* search_first = jsgraph()->Constant(str.GetFirstChar().value());
vtrue = graph()->NewNode(simplified()->NumberEqual(), string_first,
search_first);
}
......
......@@ -3079,8 +3079,16 @@ base::Optional<int> StringRef::length() const {
return data()->AsString()->length();
}
uint16_t StringRef::GetFirstChar() {
base::Optional<uint16_t> StringRef::GetFirstChar() {
if (data_->should_access_heap()) {
if (data_->kind() == kNeverSerializedHeapObject &&
!this->IsInternalizedString()) {
TRACE_BROKER_MISSING(
broker(),
"first char for kNeverSerialized non-internalized string " << *this);
return base::nullopt;
}
if (broker()->local_isolate()) {
return object()->Get(0, broker()->local_isolate());
} else {
......
......@@ -482,7 +482,8 @@ TypedOptimization::TryReduceStringComparisonOfStringFromSingleCharCode(
simplified()->NumberBitwiseAnd(), from_char_code_repl,
jsgraph()->Constant(std::numeric_limits<uint16_t>::max()));
}
Node* constant_repl = jsgraph()->Constant(string.GetFirstChar());
if (!string.GetFirstChar().has_value()) return NoChange();
Node* constant_repl = jsgraph()->Constant(string.GetFirstChar().value());
Node* number_comparison = nullptr;
if (inverted) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment