Skip to content

Commit 0f581e4

Browse files
jakobkummerowCommit Bot
authored andcommitted
[ubsan] Port Name/String/Symbol to the new design
Bug: v8:3770 Change-Id: I4da6404aa968adca1fbb49029fc304622101d6c3 Reviewed-on: https://chromium-review.googlesource.com/c/1349112 Commit-Queue: Jakob Kummerow <[email protected]> Reviewed-by: Yang Guo <[email protected]> Reviewed-by: Toon Verwaest <[email protected]> Reviewed-by: Michael Starzinger <[email protected]> Cr-Commit-Position: refs/heads/master@{#57853}
1 parent fe0d265 commit 0f581e4

File tree

158 files changed

+1043
-1001
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+1043
-1001
lines changed

src/api.cc

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,9 +2411,9 @@ class IsIdentifierHelper {
24112411
public:
24122412
IsIdentifierHelper() : is_identifier_(false), first_char_(true) {}
24132413

2414-
bool Check(i::String* string) {
2415-
i::ConsString* cons_string = i::String::VisitFlat(this, string, 0);
2416-
if (cons_string == nullptr) return is_identifier_;
2414+
bool Check(i::String string) {
2415+
i::ConsString cons_string = i::String::VisitFlat(this, string, 0);
2416+
if (cons_string.is_null()) return is_identifier_;
24172417
// We don't support cons strings here.
24182418
return false;
24192419
}
@@ -5203,9 +5203,9 @@ static inline const uint16_t* Align(const uint16_t* chars) {
52035203
class ContainsOnlyOneByteHelper {
52045204
public:
52055205
ContainsOnlyOneByteHelper() : is_one_byte_(true) {}
5206-
bool Check(i::String* string) {
5207-
i::ConsString* cons_string = i::String::VisitFlat(this, string, 0);
5208-
if (cons_string == nullptr) return is_one_byte_;
5206+
bool Check(i::String string) {
5207+
i::ConsString cons_string = i::String::VisitFlat(this, string, 0);
5208+
if (cons_string.is_null()) return is_one_byte_;
52095209
return CheckCons(cons_string);
52105210
}
52115211
void VisitOneByteString(const uint8_t* chars, int length) {
@@ -5244,20 +5244,18 @@ class ContainsOnlyOneByteHelper {
52445244
}
52455245

52465246
private:
5247-
bool CheckCons(i::ConsString* cons_string) {
5247+
bool CheckCons(i::ConsString cons_string) {
52485248
while (true) {
52495249
// Check left side if flat.
5250-
i::String* left = cons_string->first();
5251-
i::ConsString* left_as_cons =
5252-
i::String::VisitFlat(this, left, 0);
5250+
i::String left = cons_string->first();
5251+
i::ConsString left_as_cons = i::String::VisitFlat(this, left, 0);
52535252
if (!is_one_byte_) return false;
52545253
// Check right side if flat.
5255-
i::String* right = cons_string->second();
5256-
i::ConsString* right_as_cons =
5257-
i::String::VisitFlat(this, right, 0);
5254+
i::String right = cons_string->second();
5255+
i::ConsString right_as_cons = i::String::VisitFlat(this, right, 0);
52585256
if (!is_one_byte_) return false;
52595257
// Standard recurse/iterate trick.
5260-
if (left_as_cons != nullptr && right_as_cons != nullptr) {
5258+
if (!left_as_cons.is_null() && !right_as_cons.is_null()) {
52615259
if (left->length() < right->length()) {
52625260
CheckCons(left_as_cons);
52635261
cons_string = right_as_cons;
@@ -5270,12 +5268,12 @@ class ContainsOnlyOneByteHelper {
52705268
continue;
52715269
}
52725270
// Descend left in place.
5273-
if (left_as_cons != nullptr) {
5271+
if (!left_as_cons.is_null()) {
52745272
cons_string = left_as_cons;
52755273
continue;
52765274
}
52775275
// Descend right in place.
5278-
if (right_as_cons != nullptr) {
5276+
if (!right_as_cons.is_null()) {
52795277
cons_string = right_as_cons;
52805278
continue;
52815279
}
@@ -5499,16 +5497,16 @@ class Utf8WriterVisitor {
54995497
DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8WriterVisitor);
55005498
};
55015499

5502-
5503-
static bool RecursivelySerializeToUtf8(i::String* current,
5500+
// TODO(yangguo): Simplify this. We can now expect the string to be flat.
5501+
static bool RecursivelySerializeToUtf8(i::String current,
55045502
Utf8WriterVisitor* writer,
55055503
int recursion_budget) {
55065504
while (!writer->IsDone()) {
5507-
i::ConsString* cons_string = i::String::VisitFlat(writer, current);
5508-
if (cons_string == nullptr) return true; // Leaf node.
5505+
i::ConsString cons_string = i::String::VisitFlat(writer, current);
5506+
if (cons_string.is_null()) return true; // Leaf node.
55095507
if (recursion_budget <= 0) return false;
55105508
// Must write the left branch first.
5511-
i::String* first = cons_string->first();
5509+
i::String first = cons_string->first();
55125510
bool success = RecursivelySerializeToUtf8(first,
55135511
writer,
55145512
recursion_budget - 1);
@@ -5615,7 +5613,7 @@ bool v8::String::IsExternalOneByte() const {
56155613
void v8::String::VerifyExternalStringResource(
56165614
v8::String::ExternalStringResource* value) const {
56175615
i::DisallowHeapAllocation no_allocation;
5618-
i::String* str = *Utils::OpenHandle(this);
5616+
i::String str = *Utils::OpenHandle(this);
56195617
const v8::String::ExternalStringResource* expected;
56205618

56215619
if (str->IsThinString()) {
@@ -5634,7 +5632,7 @@ void v8::String::VerifyExternalStringResource(
56345632
void v8::String::VerifyExternalStringResourceBase(
56355633
v8::String::ExternalStringResourceBase* value, Encoding encoding) const {
56365634
i::DisallowHeapAllocation no_allocation;
5637-
i::String* str = *Utils::OpenHandle(this);
5635+
i::String str = *Utils::OpenHandle(this);
56385636
const v8::String::ExternalStringResourceBase* expected;
56395637
Encoding expectedEncoding;
56405638

@@ -5662,15 +5660,14 @@ void v8::String::VerifyExternalStringResourceBase(
56625660
String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
56635661
i::DisallowHeapAllocation no_allocation;
56645662
typedef internal::Internals I;
5665-
i::String* str = *Utils::OpenHandle(this);
5663+
i::String str = *Utils::OpenHandle(this);
56665664

56675665
if (str->IsThinString()) {
56685666
str = i::ThinString::cast(str)->actual();
56695667
}
56705668

56715669
if (i::StringShape(str).IsExternalTwoByte()) {
5672-
void* value = I::ReadField<void*>(reinterpret_cast<i::Address>(str),
5673-
I::kStringResourceOffset);
5670+
void* value = I::ReadField<void*>(str.ptr(), I::kStringResourceOffset);
56745671
return reinterpret_cast<String::ExternalStringResource*>(value);
56755672
}
56765673
return nullptr;
@@ -5681,13 +5678,13 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
56815678
i::DisallowHeapAllocation no_allocation;
56825679
typedef internal::Internals I;
56835680
ExternalStringResourceBase* resource = nullptr;
5684-
i::String* str = *Utils::OpenHandle(this);
5681+
i::String str = *Utils::OpenHandle(this);
56855682

56865683
if (str->IsThinString()) {
56875684
str = i::ThinString::cast(str)->actual();
56885685
}
56895686

5690-
internal::Address string = reinterpret_cast<internal::Address>(str);
5687+
internal::Address string = str.ptr();
56915688
int type = I::GetInstanceType(string) & I::kFullStringRepresentationMask;
56925689
*encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
56935690
if (i::StringShape(str).IsExternalOneByte() ||
@@ -5701,7 +5698,7 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
57015698
const v8::String::ExternalOneByteStringResource*
57025699
v8::String::GetExternalOneByteStringResource() const {
57035700
i::DisallowHeapAllocation no_allocation;
5704-
i::String* str = *Utils::OpenHandle(this);
5701+
i::String str = *Utils::OpenHandle(this);
57055702
if (i::StringShape(str).IsExternalOneByte()) {
57065703
return i::ExternalOneByteString::cast(str)->resource();
57075704
} else if (str->IsThinString()) {
@@ -6620,7 +6617,7 @@ Local<String> v8::String::NewExternal(
66206617
bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
66216618
i::DisallowHeapAllocation no_allocation;
66226619

6623-
i::String* obj = *Utils::OpenHandle(this);
6620+
i::String obj = *Utils::OpenHandle(this);
66246621

66256622
if (obj->IsThinString()) {
66266623
obj = i::ThinString::cast(obj)->actual();
@@ -6649,7 +6646,7 @@ bool v8::String::MakeExternal(
66496646
v8::String::ExternalOneByteStringResource* resource) {
66506647
i::DisallowHeapAllocation no_allocation;
66516648

6652-
i::String* obj = *Utils::OpenHandle(this);
6649+
i::String obj = *Utils::OpenHandle(this);
66536650

66546651
if (obj->IsThinString()) {
66556652
obj = i::ThinString::cast(obj)->actual();
@@ -6676,7 +6673,7 @@ bool v8::String::MakeExternal(
66766673

66776674
bool v8::String::CanMakeExternal() {
66786675
i::DisallowHeapAllocation no_allocation;
6679-
i::String* obj = *Utils::OpenHandle(this);
6676+
i::String obj = *Utils::OpenHandle(this);
66806677

66816678
if (obj->IsThinString()) {
66826679
obj = i::ThinString::cast(obj)->actual();
@@ -9762,7 +9759,7 @@ void debug::GlobalLexicalScopeNames(
97629759
i::Handle<i::ScopeInfo> scope_info(context->scope_info(), isolate);
97639760
int local_count = scope_info->ContextLocalCount();
97649761
for (int j = 0; j < local_count; ++j) {
9765-
i::String* name = scope_info->ContextLocalName(j);
9762+
i::String name = scope_info->ContextLocalName(j);
97669763
if (i::ScopeInfo::VariableIsSynthetic(name)) continue;
97679764
names->Append(Utils::ToLocal(handle(name, isolate)));
97689765
}

src/ast/scopes.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
430430
DCHECK_EQ(scope_info->ContextLocalCount(), 1);
431431
DCHECK_EQ(scope_info->ContextLocalMode(0), VariableMode::kVar);
432432
DCHECK_EQ(scope_info->ContextLocalInitFlag(0), kCreatedInitialized);
433-
String* name = scope_info->ContextLocalName(0);
433+
String name = scope_info->ContextLocalName(0);
434434
MaybeAssignedFlag maybe_assigned =
435435
scope_info->ContextLocalMaybeAssignedFlag(0);
436436
outer_scope = new (zone)

src/bootstrapper.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void SourceCodeCache::Iterate(RootVisitor* v) {
6868
bool SourceCodeCache::Lookup(Isolate* isolate, Vector<const char> name,
6969
Handle<SharedFunctionInfo>* handle) {
7070
for (int i = 0; i < cache_->length(); i += 2) {
71-
SeqOneByteString* str = SeqOneByteString::cast(cache_->get(i));
71+
SeqOneByteString str = SeqOneByteString::cast(cache_->get(i));
7272
if (str->IsUtf8EqualTo(name)) {
7373
*handle = Handle<SharedFunctionInfo>(
7474
SharedFunctionInfo::cast(cache_->get(i + 1)), isolate);

src/bootstrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace v8 {
1616
namespace internal {
1717

1818
// A SourceCodeCache uses a FixedArray to store pairs of
19-
// (OneByteString*, JSFunction*), mapping names of native code files
19+
// (OneByteString, JSFunction*), mapping names of native code files
2020
// (array.js, etc.) to precompiled functions. Instead of mapping
2121
// names to functions it might make sense to let the JS2C tool
2222
// generate an index for each native JS file.

src/builtins/builtins-array-gen.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ class ArrayBuiltinsAssembler : public CodeStubAssembler {
8080
TNode<ExternalReference> isolate_ptr =
8181
ExternalConstant(ExternalReference::isolate_address(isolate()));
8282
return UncheckedCast<String>(
83-
CallCFunction5(MachineType::AnyTagged(), // <return> String*
83+
CallCFunction5(MachineType::AnyTagged(), // <return> String
8484
MachineType::Pointer(), // Isolate*
8585
MachineType::AnyTagged(), // FixedArray fixed_array
8686
MachineType::IntPtr(), // intptr_t length
87-
MachineType::AnyTagged(), // String* sep
88-
MachineType::AnyTagged(), // String* dest
87+
MachineType::AnyTagged(), // String sep
88+
MachineType::AnyTagged(), // String dest
8989
func, isolate_ptr, fixed_array, length, sep, dest));
9090
}
9191

src/builtins/builtins-intl-gen.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,18 @@ TF_BUILTIN(StringToLowerCaseIntl, IntlBuiltinsAssembler) {
103103
}
104104

105105
// Call into C for case conversion. The signature is:
106-
// Object* ConvertOneByteToLower(String* src, String* dst, Isolate* isolate);
106+
// String ConvertOneByteToLower(String src, String dst);
107107
BIND(&call_c);
108108
{
109109
Node* const src = to_direct.string();
110110

111111
Node* const function_addr =
112112
ExternalConstant(ExternalReference::intl_convert_one_byte_to_lower());
113-
Node* const isolate_ptr =
114-
ExternalConstant(ExternalReference::isolate_address(isolate()));
115113

116-
MachineType type_ptr = MachineType::Pointer();
117114
MachineType type_tagged = MachineType::AnyTagged();
118115

119-
Node* const result =
120-
CallCFunction3(type_tagged, type_tagged, type_tagged, type_ptr,
121-
function_addr, src, dst, isolate_ptr);
116+
Node* const result = CallCFunction2(type_tagged, type_tagged, type_tagged,
117+
function_addr, src, dst);
122118

123119
Return(result);
124120
}

src/builtins/builtins-string.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ inline bool ToUpperOverflows(uc32 character) {
350350

351351
template <class Converter>
352352
V8_WARN_UNUSED_RESULT static Object* ConvertCaseHelper(
353-
Isolate* isolate, String* string, SeqString* result, int result_length,
353+
Isolate* isolate, String string, SeqString result, int result_length,
354354
unibrow::Mapping<Converter, 128>* mapping) {
355355
DisallowHeapAllocation no_gc;
356356
// We try this twice, once with the assumption that the result is no longer

src/code-events.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "src/base/platform/mutex.h"
1111
#include "src/globals.h"
1212
#include "src/objects/code.h"
13+
#include "src/objects/name.h"
14+
#include "src/objects/string.h"
1315
#include "src/vector.h"
1416

1517
namespace v8 {
@@ -72,18 +74,18 @@ class CodeEventListener {
7274
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
7375
const char* comment) = 0;
7476
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
75-
Name* name) = 0;
77+
Name name) = 0;
7678
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
77-
SharedFunctionInfo* shared, Name* source) = 0;
79+
SharedFunctionInfo* shared, Name source) = 0;
7880
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
79-
SharedFunctionInfo* shared, Name* source,
81+
SharedFunctionInfo* shared, Name source,
8082
int line, int column) = 0;
8183
virtual void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
8284
wasm::WasmName name) = 0;
83-
virtual void CallbackEvent(Name* name, Address entry_point) = 0;
84-
virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0;
85-
virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0;
86-
virtual void RegExpCodeCreateEvent(AbstractCode code, String* source) = 0;
85+
virtual void CallbackEvent(Name name, Address entry_point) = 0;
86+
virtual void GetterCallbackEvent(Name name, Address entry_point) = 0;
87+
virtual void SetterCallbackEvent(Name name, Address entry_point) = 0;
88+
virtual void RegExpCodeCreateEvent(AbstractCode code, String source) = 0;
8789
virtual void CodeMoveEvent(AbstractCode from, AbstractCode to) = 0;
8890
virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
8991
virtual void CodeMovingGCEvent() = 0;
@@ -126,15 +128,15 @@ class CodeEventDispatcher {
126128
const char* comment) {
127129
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, comment));
128130
}
129-
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code, Name* name) {
131+
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code, Name name) {
130132
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name));
131133
}
132134
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
133-
SharedFunctionInfo* shared, Name* name) {
135+
SharedFunctionInfo* shared, Name name) {
134136
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, shared, name));
135137
}
136138
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
137-
SharedFunctionInfo* shared, Name* source, int line,
139+
SharedFunctionInfo* shared, Name source, int line,
138140
int column) {
139141
CODE_EVENT_DISPATCH(
140142
CodeCreateEvent(tag, code, shared, source, line, column));
@@ -143,16 +145,16 @@ class CodeEventDispatcher {
143145
wasm::WasmName name) {
144146
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name));
145147
}
146-
void CallbackEvent(Name* name, Address entry_point) {
148+
void CallbackEvent(Name name, Address entry_point) {
147149
CODE_EVENT_DISPATCH(CallbackEvent(name, entry_point));
148150
}
149-
void GetterCallbackEvent(Name* name, Address entry_point) {
151+
void GetterCallbackEvent(Name name, Address entry_point) {
150152
CODE_EVENT_DISPATCH(GetterCallbackEvent(name, entry_point));
151153
}
152-
void SetterCallbackEvent(Name* name, Address entry_point) {
154+
void SetterCallbackEvent(Name name, Address entry_point) {
153155
CODE_EVENT_DISPATCH(SetterCallbackEvent(name, entry_point));
154156
}
155-
void RegExpCodeCreateEvent(AbstractCode code, String* source) {
157+
void RegExpCodeCreateEvent(AbstractCode code, String source) {
156158
CODE_EVENT_DISPATCH(RegExpCodeCreateEvent(code, source));
157159
}
158160
void CodeMoveEvent(AbstractCode from, AbstractCode to) {

src/compiler.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ void LogFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
9191

9292
int line_num = Script::GetLineNumber(script, shared->StartPosition()) + 1;
9393
int column_num = Script::GetColumnNumber(script, shared->StartPosition()) + 1;
94-
String* script_name = script->name()->IsString()
95-
? String::cast(script->name())
96-
: ReadOnlyRoots(isolate).empty_string();
94+
String script_name = script->name()->IsString()
95+
? String::cast(script->name())
96+
: ReadOnlyRoots(isolate).empty_string();
9797
CodeEventListener::LogEventsAndTags log_tag =
9898
Logger::ToNativeByScript(tag, *script);
9999
PROFILE(isolate, CodeCreateEvent(log_tag, *abstract_code, *shared,
@@ -331,9 +331,9 @@ void InstallBytecodeArray(Handle<BytecodeArray> bytecode_array,
331331
Script::GetLineNumber(script, shared_info->StartPosition()) + 1;
332332
int column_num =
333333
Script::GetColumnNumber(script, shared_info->StartPosition()) + 1;
334-
String* script_name = script->name()->IsString()
335-
? String::cast(script->name())
336-
: ReadOnlyRoots(isolate).empty_string();
334+
String script_name = script->name()->IsString()
335+
? String::cast(script->name())
336+
: ReadOnlyRoots(isolate).empty_string();
337337
CodeEventListener::LogEventsAndTags log_tag = Logger::ToNativeByScript(
338338
CodeEventListener::INTERPRETED_FUNCTION_TAG, *script);
339339
PROFILE(isolate, CodeCreateEvent(log_tag, *abstract_code, *shared_info,

src/compiler/code-assembler.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1930,9 +1930,10 @@ CodeAssemblerScopedExceptionHandler::~CodeAssemblerScopedExceptionHandler() {
19301930

19311931
} // namespace compiler
19321932

1933-
Address CheckObjectType(Object* value, Address raw_type, String* location) {
1933+
Address CheckObjectType(Object* value, Address raw_type, Address raw_location) {
19341934
#ifdef DEBUG
19351935
Smi type(raw_type);
1936+
String location = String::cast(ObjectPtr(raw_location));
19361937
const char* expected;
19371938
switch (static_cast<ObjectType>(type->value())) {
19381939
#define TYPE_CASE(Name) \

0 commit comments

Comments
 (0)