[base] Remove StaticCharVector, CStrVector, and StrVector

Finish migrating base::Vector<const char> string APIs to
std::string_view and remove the legacy char-vector helpers from
src/base/vector.h.

TAG=agy
CONV=2767341c-6359-48bb-9eb0-79b64ed5d866

Bug: 568729129
Change-Id: Ia0630543dc7dd20701e3b6a358d8f5c937681d21
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8579388
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#111099}
This commit is contained in:
Michael Lippautz authored and v8-scoped@luci-project-accounts.iam.gserviceaccount.com committed 2026-10-23 02:23:00 -07:00
1 parent e19035b316
commit 646da9f19a
82 files changed
+412 -571

No files matched your search

+7 -9
View File
@@ -7724,7 +7724,7 @@ inline int StringLength(const uint16_t* string) {
V8_WARN_UNUSED_RESULT
inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
NewStringType type,
base::Vector<const char> string) {
std::string_view string) {
if (type == NewStringType::kInternalized) {
return factory->InternalizeUtf8String(string);
}
@@ -7772,7 +7772,7 @@ static_assert(v8::String::kMaxLength == i::String::kMaxLength);
if (length < 0) length = StringLength(data); \
i::DirectHandle<i::String> handle_result = \
NewString(i_isolate->factory(), type, \
base::Vector<const Char>(data, length)) \
{data, static_cast<size_t>(length)}) \
.ToHandleChecked(); \
result = Utils::ToLocal(handle_result); \
}
@@ -7787,7 +7787,7 @@ Local<String> String::NewFromUtf8Literal(Isolate* v8_isolate,
RCCId::kAPI_String_NewFromUtf8Literal);
i::DirectHandle<i::String> handle_result =
NewString(i_isolate->factory(), type,
base::Vector<const char>(literal, length))
{literal, static_cast<size_t>(length)})
.ToHandleChecked();
return Utils::ToLocal(handle_result);
}
@@ -8206,7 +8206,7 @@ v8::Local<v8::String> v8::Date::ToISOString() const {
i::ToDateStringMode::kISODateAndTime);
i::DirectHandle<i::String> str =
i_isolate->factory()
->NewStringFromUtf8(base::VectorOf(buffer))
->NewStringFromUtf8({buffer.data(), buffer.size()})
.ToHandleChecked();
return Utils::ToLocal(str);
}
@@ -8220,7 +8220,7 @@ v8::Local<v8::String> v8::Date::ToUTCString() const {
i::ToDateStringMode::kUTCDateAndTime);
i::DirectHandle<i::String> str =
i_isolate->factory()
->NewStringFromUtf8(base::VectorOf(buffer))
->NewStringFromUtf8({buffer.data(), buffer.size()})
.ToHandleChecked();
return Utils::ToLocal(str);
}
@@ -9112,7 +9112,7 @@ MaybeLocal<WasmModuleObject> WasmModuleObject::FromCompiledModule(
i::DirectHandle<i::WasmModuleObject> module_object =
i::wasm::GetWasmEngine()->ImportNativeModule(
i_isolate, compiled_module.native_module_,
base::VectorOf(compiled_module.source_url()));
compiled_module.source_url());
return Utils::ToLocal(module_object);
#else
UNREACHABLE();
@@ -9142,9 +9142,7 @@ MaybeLocal<WasmModuleObject> WasmModuleObject::Compile(
i::wasm::WasmEnabledFeatures::FromIsolate(i_isolate);
maybe_compiled = i::wasm::GetWasmEngine()->SyncCompile(
i_isolate, enabled_features, std::move(compile_imports), &thrower,
std::move(bytes),
base::Vector<const char>(options.source_url.data(),
options.source_url.size()));
std::move(bytes), options.source_url);
}
CHECK_EQ(maybe_compiled.is_null(), i_isolate->has_exception());
if (maybe_compiled.is_null()) return {};
+2 -19
View File
@@ -216,26 +216,10 @@ V8_INLINE size_t hash_value(base::Vector<T> v) {
return hash_range(v.begin(), v.end());
}
// The vectors returned by {StaticCharVector}, {CStrVector}, or {OneByteVector}
// do not contain a null-termination byte. If you want the null byte, use
// The vectors returned by {OneByteVector} or {StaticOneByteVector} do not
// contain a null-termination byte. If you want the null byte, use
// {ArrayVector}.
// Known length, constexpr.
template <size_t N>
constexpr Vector<const char> StaticCharVector(
const char (&array V8_LIFETIME_BOUND)[N]) {
return {array, N - 1};
}
// Unknown length, not constexpr.
inline Vector<const char> CStrVector(const char* data V8_LIFETIME_BOUND) {
return {data, strlen(data)};
}
inline Vector<const char> StrVector(std::string_view str V8_LIFETIME_BOUND) {
return {str.data(), str.size()};
}
// OneByteVector is never constexpr because the data pointer is
// {reinterpret_cast}ed.
inline Vector<const uint8_t> OneByteVector(const char* data V8_LIFETIME_BOUND,
@@ -255,7 +239,6 @@ Vector<const uint8_t> StaticOneByteVector(
// For string literals, ArrayVector("foo") returns a vector ['f', 'o', 'o', \0]
// with length 4 and null-termination.
// If you want ['f', 'o', 'o'], use CStrVector("foo").
template <typename T, size_t N>
inline constexpr Vector<T> ArrayVector(T (&arr V8_LIFETIME_BOUND)[N]) {
return {arr, N};
+12 -12
View File
@@ -63,8 +63,8 @@ BUILTIN(DateConstructor) {
static_cast<double>(JSDate::CurrentTimeValue(isolate));
DateBuffer buffer = ToDateString(time_val, isolate->date_cache(),
ToDateStringMode::kLocalDateAndTime);
RETURN_RESULT_OR_FAILURE(
isolate, isolate->factory()->NewStringFromUtf8(base::VectorOf(buffer)));
RETURN_RESULT_OR_FAILURE(isolate, isolate->factory()->NewStringFromUtf8(
{buffer.data(), buffer.size()}));
}
// [Construct]
int const argc = args.length() - 1;
@@ -739,8 +739,8 @@ BUILTIN(DatePrototypeToDateString) {
CHECK_RECEIVER(JSDate, date, "Date.prototype.toDateString");
DateBuffer buffer = ToDateString(date->value(), isolate->date_cache(),
ToDateStringMode::kLocalDate);
RETURN_RESULT_OR_FAILURE(
isolate, isolate->factory()->NewStringFromUtf8(base::VectorOf(buffer)));
RETURN_RESULT_OR_FAILURE(isolate, isolate->factory()->NewStringFromUtf8(
{buffer.data(), buffer.size()}));
}
// ES6 section 20.3.4.36 Date.prototype.toISOString ( )
@@ -754,8 +754,8 @@ BUILTIN(DatePrototypeToISOString) {
}
DateBuffer buffer = ToDateString(time_val, isolate->date_cache(),
ToDateStringMode::kISODateAndTime);
RETURN_RESULT_OR_FAILURE(
isolate, isolate->factory()->NewStringFromUtf8(base::VectorOf(buffer)));
RETURN_RESULT_OR_FAILURE(isolate, isolate->factory()->NewStringFromUtf8(
{buffer.data(), buffer.size()}));
}
// ES6 section 20.3.4.41 Date.prototype.toString ( )
@@ -764,8 +764,8 @@ BUILTIN(DatePrototypeToString) {
CHECK_RECEIVER(JSDate, date, "Date.prototype.toString");
DateBuffer buffer = ToDateString(date->value(), isolate->date_cache(),
ToDateStringMode::kLocalDateAndTime);
RETURN_RESULT_OR_FAILURE(
isolate, isolate->factory()->NewStringFromUtf8(base::VectorOf(buffer)));
RETURN_RESULT_OR_FAILURE(isolate, isolate->factory()->NewStringFromUtf8(
{buffer.data(), buffer.size()}));
}
// ES6 section 20.3.4.42 Date.prototype.toTimeString ( )
@@ -774,8 +774,8 @@ BUILTIN(DatePrototypeToTimeString) {
CHECK_RECEIVER(JSDate, date, "Date.prototype.toTimeString");
DateBuffer buffer = ToDateString(date->value(), isolate->date_cache(),
ToDateStringMode::kLocalTime);
RETURN_RESULT_OR_FAILURE(
isolate, isolate->factory()->NewStringFromUtf8(base::VectorOf(buffer)));
RETURN_RESULT_OR_FAILURE(isolate, isolate->factory()->NewStringFromUtf8(
{buffer.data(), buffer.size()}));
}
#ifdef V8_INTL_SUPPORT
@@ -846,8 +846,8 @@ BUILTIN(DatePrototypeToUTCString) {
CHECK_RECEIVER(JSDate, date, "Date.prototype.toUTCString");
DateBuffer buffer = ToDateString(date->value(), isolate->date_cache(),
ToDateStringMode::kUTCDateAndTime);
RETURN_RESULT_OR_FAILURE(
isolate, isolate->factory()->NewStringFromUtf8(base::VectorOf(buffer)));
RETURN_RESULT_OR_FAILURE(isolate, isolate->factory()->NewStringFromUtf8(
{buffer.data(), buffer.size()}));
}
// ES6 section B.2.4.1 Date.prototype.getYear ( )
@@ -1043,8 +1043,7 @@ class BuiltinsReducer : public Next {
}
V<String> StringConstant(const char* str) {
Handle<String> internalized_string =
factory()->InternalizeString(base::OneByteVector(str));
Handle<String> internalized_string = factory()->InternalizeString(str);
__ CanonicalizeEmbeddedBuiltinsConstantIfNeeded(internalized_string);
return V<String>::Cast(__ HeapConstantNoHole(internalized_string));
}
+1 -2
View File
@@ -389,8 +389,7 @@ TNode<HeapObject> CodeAssembler::UntypedHeapConstantHole(
}
TNode<String> CodeAssembler::StringConstant(const char* str) {
Handle<String> internalized_string =
factory()->InternalizeString(base::OneByteVector(str));
Handle<String> internalized_string = factory()->InternalizeString(str);
CanonicalizeEmbeddedBuiltinsConstantIfNeeded(internalized_string);
return UncheckedCast<String>(HeapConstantNoHole(internalized_string));
}
+6 -10
View File
@@ -4414,8 +4414,8 @@ class AssemblerOpInterface : public Next {
DCHECK_NOT_NULL(isolate);
DCHECK_EQ(ThreadId::Current(), isolate->thread_id());
const std::string str = stream.str();
Handle<String> internalized_string = isolate->factory()->InternalizeString(
base::OneByteVector(str.c_str(), str.length()));
Handle<String> internalized_string =
isolate->factory()->InternalizeString(str);
CanonicalizeEmbeddedBuiltinsConstantIfNeeded(internalized_string);
V<String> string_constant = __ HeapConstantNoHole(internalized_string);
@@ -4658,8 +4658,7 @@ class AssemblerOpInterface : public Next {
if (broker) {
UnparkedScopeIfNeeded scope(broker);
LocalIsolate* isolate = broker->local_isolate_or_isolate();
internalized_string = isolate->factory()->InternalizeString(
base::OneByteVector(label.c_str(), label.length()));
internalized_string = isolate->factory()->InternalizeString(label);
internalized_string =
broker->CanonicalPersistentHandle(internalized_string);
} else {
@@ -4667,8 +4666,7 @@ class AssemblerOpInterface : public Next {
// If we don't have a broker, we can only allocate the string on the
// main thread.
DCHECK_EQ(ThreadId::Current(), isolate->thread_id());
internalized_string = isolate->factory()->InternalizeString(
base::OneByteVector(label.c_str(), label.length()));
internalized_string = isolate->factory()->InternalizeString(label);
CanonicalizeEmbeddedBuiltinsConstantIfNeeded(internalized_string);
}
label_string = __ HeapConstantNoHole(internalized_string);
@@ -4686,8 +4684,7 @@ class AssemblerOpInterface : public Next {
if (broker) {
UnparkedScopeIfNeeded scope(broker);
LocalIsolate* isolate = broker->local_isolate_or_isolate();
internalized_string = isolate->factory()->InternalizeString(
base::OneByteVector(str.c_str(), str.length()));
internalized_string = isolate->factory()->InternalizeString(str);
internalized_string =
broker->CanonicalPersistentHandle(internalized_string);
} else {
@@ -4695,8 +4692,7 @@ class AssemblerOpInterface : public Next {
// If we don't have a broker, we can only allocate the string on the main
// thread.
DCHECK_EQ(ThreadId::Current(), isolate->thread_id());
internalized_string = isolate->factory()->InternalizeString(
base::OneByteVector(str.c_str(), str.length()));
internalized_string = isolate->factory()->InternalizeString(str);
CanonicalizeEmbeddedBuiltinsConstantIfNeeded(internalized_string);
}
V<String> string_constant = __ HeapConstantNoHole(internalized_string);
+1 -1
View File
@@ -141,7 +141,7 @@ Local<String> GetDateDescription(Local<Date> date) {
auto buffer = i::ToDateString(jsdate->value(), i_isolate->date_cache(),
i::ToDateStringMode::kLocalDateAndTime);
return Utils::ToLocal(i_isolate->factory()
->NewStringFromUtf8(base::VectorOf(buffer))
->NewStringFromUtf8({buffer.data(), buffer.size()})
.ToHandleChecked());
}
+16 -20
View File
@@ -33,7 +33,7 @@ namespace {
using StringBuilder = wasm::StringBuilder;
DirectHandle<String> ToInternalString(StringBuilder& sb, Isolate* isolate) {
return isolate->factory()->InternalizeString(
base::VectorOf(sb.start(), sb.length()));
{sb.start(), static_cast<size_t>(sb.length())});
}
Address GetDebugBreakFp(WasmFrame* frame) {
@@ -901,18 +901,15 @@ DirectHandle<WasmValueObject> WasmValueObject::New(Isolate* isolate,
map->SetConstructor(*isolate->object_function());
{ // type
Descriptor d = Descriptor::DataField(
isolate,
isolate->factory()->InternalizeString(base::StaticCharVector("type")),
isolate, isolate->factory()->InternalizeString("type"),
WasmValueObject::kTypeOffset, FROZEN, Representation::Tagged(), true);
map->AppendDescriptor(isolate, &d);
}
{ // value
Descriptor d =
Descriptor::DataField(isolate,
isolate->factory()->InternalizeString(
base::StaticCharVector("value")),
WasmValueObject::kValueOffset, FROZEN,
Representation::Tagged(), true);
Descriptor d = Descriptor::DataField(
isolate, isolate->factory()->InternalizeString("value"),
WasmValueObject::kValueOffset, FROZEN, Representation::Tagged(),
true);
map->AppendDescriptor(isolate, &d);
}
map->set_is_extensible(false);
@@ -1011,46 +1008,46 @@ DirectHandle<WasmValueObject> WasmValueObject::New(
case wasm::kI8: {
// This can't be reached for most "top-level" things, only via nested
// calls for struct/array fields.
t = isolate->factory()->InternalizeString(base::StaticCharVector("i8"));
t = isolate->factory()->InternalizeString("i8");
v = isolate->factory()->NewNumber(value.to_i8_unchecked());
break;
}
case wasm::kI16: {
// This can't be reached for most "top-level" things, only via nested
// calls for struct/array fields.
t = isolate->factory()->InternalizeString(base::StaticCharVector("i16"));
t = isolate->factory()->InternalizeString("i16");
v = isolate->factory()->NewNumber(value.to_i16_unchecked());
break;
}
case wasm::kI32: {
t = isolate->factory()->InternalizeString(base::StaticCharVector("i32"));
t = isolate->factory()->InternalizeString("i32");
v = isolate->factory()->NewNumberFromInt(value.to_i32_unchecked());
break;
}
case wasm::kI64: {
t = isolate->factory()->InternalizeString(base::StaticCharVector("i64"));
t = isolate->factory()->InternalizeString("i64");
v = BigInt::FromInt64(isolate, value.to_i64_unchecked());
break;
}
case wasm::kF16: {
// This can't be reached for most "top-level" things, only via nested
// calls for struct/array fields.
t = isolate->factory()->InternalizeString(base::StaticCharVector("f16"));
t = isolate->factory()->InternalizeString("f16");
v = isolate->factory()->NewNumber(value.to_f16_unchecked());
break;
}
case wasm::kF32: {
t = isolate->factory()->InternalizeString(base::StaticCharVector("f32"));
t = isolate->factory()->InternalizeString("f32");
v = isolate->factory()->NewNumber(value.to_f32_unchecked());
break;
}
case wasm::kF64: {
t = isolate->factory()->InternalizeString(base::StaticCharVector("f64"));
t = isolate->factory()->InternalizeString("f64");
v = isolate->factory()->NewNumber(value.to_f64_unchecked());
break;
}
case wasm::kS128: {
t = isolate->factory()->InternalizeString(base::StaticCharVector("v128"));
t = isolate->factory()->InternalizeString("v128");
v = WasmSimd128ToString(isolate, value.to_s128_unchecked());
break;
}
@@ -1064,8 +1061,7 @@ DirectHandle<WasmValueObject> WasmValueObject::New(
}
#endif
if (value.type().is_reference_to(wasm::GenericKind::kExn)) {
t = isolate->factory()->InternalizeString(
base::StaticCharVector("exnref"));
t = isolate->factory()->InternalizeString("exnref");
v = ref;
} else if (IsWasmNull(*ref)) {
v = isolate->factory()->null_value();
@@ -1104,7 +1100,7 @@ DirectHandle<WasmValueObject> WasmValueObject::New(
Cast<HeapObject>(*ref)->map()->instance_type());
t = GetRefTypeName(isolate, value.type());
v = isolate->factory()->InternalizeString(
base::VectorOf(error).SubVector(0, len));
{error.data(), static_cast<size_t>(len)});
}
break;
}
+1 -2
View File
@@ -422,8 +422,7 @@ DirectHandle<String> MessageFormatter::Format(
Handle<String> result_string;
if (!maybe_result_string.ToHandle(&result_string)) {
DCHECK(isolate->has_exception());
return isolate->factory()->InternalizeString(
base::StaticCharVector("<error>"));
return isolate->factory()->InternalizeString("<error>");
}
// A string that has been obtained from JS code in this way is
// likely to be a complicated ConsString of some sort. We flatten it
+9
View File
@@ -5,6 +5,7 @@
#ifndef V8_HEAP_FACTORY_BASE_H_
#define V8_HEAP_FACTORY_BASE_H_
#include <algorithm>
#include <string_view>
#include "src/base/export-template.h"
@@ -309,6 +310,14 @@ class FactoryBase {
base::Vector<const uint8_t> string, bool convert_encoding = false);
Handle<InternalizedString> InternalizeString(
base::Vector<const uint16_t> string, bool convert_encoding = false);
Handle<InternalizedString> InternalizeString(std::string_view str,
bool convert_encoding = false) {
DCHECK(std::all_of(str.begin(), str.end(), [](char c) {
return static_cast<unsigned char>(c) <= 0x7f;
}));
return InternalizeString(base::OneByteVector(str.data(), str.size()),
convert_encoding);
}
template <class StringTableKey>
Handle<InternalizedString> InternalizeStringWithKey(StringTableKey* key);
+5 -6
View File
@@ -759,9 +759,9 @@ Factory::CreateCanonicalEmptySwissNameDictionary() {
}
// Internalized strings are created in the old generation (data space).
Handle<String> Factory::InternalizeUtf8String(base::Vector<const char> string) {
Handle<String> Factory::InternalizeUtf8String(std::string_view str) {
base::Vector<const uint8_t> utf8_data =
base::Vector<const uint8_t>::cast(string);
base::OneByteVector(str.data(), str.size());
Utf8Decoder decoder(utf8_data);
if (decoder.is_ascii()) return InternalizeString(utf8_data);
if (decoder.is_one_byte()) {
@@ -989,11 +989,10 @@ MaybeHandle<String> Factory::NewStringFromUtf8(
StringBuilder{}, allocation);
}
MaybeHandle<String> Factory::NewStringFromUtf8(base::Vector<const char> string,
MaybeHandle<String> Factory::NewStringFromUtf8(std::string_view str,
AllocationType allocation) {
return NewStringFromUtf8(base::Vector<const uint8_t>::cast(string),
UnicodeConfig(unibrow::Utf8Variant::kLossyUtf8),
allocation);
return NewStringFromUtf8(base::OneByteVector(str.data(), str.size()),
unibrow::Utf8Variant::kLossyUtf8, allocation);
}
#if V8_ENABLE_WEBASSEMBLY
+2 -23
View File
@@ -275,25 +275,11 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
// Finds the internalized copy for string in the string table.
// If not found, a new string is added to the table and returned.
Handle<String> InternalizeUtf8String(base::Vector<const char> str);
Handle<String> InternalizeUtf8String(const char* str) {
return InternalizeUtf8String(base::CStrVector(str));
}
Handle<String> InternalizeUtf8String(std::string_view str);
// Import InternalizeString overloads from base class.
using FactoryBase::InternalizeString;
Handle<InternalizedString> InternalizeString(base::Vector<const char> str,
bool convert_encoding = false) {
return InternalizeString(base::Vector<const uint8_t>::cast(str),
convert_encoding);
}
Handle<InternalizedString> InternalizeString(const char* str,
bool convert_encoding = false) {
return InternalizeString(base::OneByteVector(str), convert_encoding);
}
template <typename SeqString, template <typename> typename HandleType>
requires(
std::is_convertible_v<HandleType<SeqString>, DirectHandle<SeqString>>)
@@ -353,14 +339,7 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
// UTF8 strings are pretenured when used for regexp literal patterns and
// flags in the parser.
V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromUtf8(
base::Vector<const char> str,
AllocationType allocation = AllocationType::kYoung);
V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromUtf8(
std::string_view str,
AllocationType allocation = AllocationType::kYoung) {
return NewStringFromUtf8(base::StrVector(str), allocation);
}
std::string_view str, AllocationType allocation = AllocationType::kYoung);
V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromUtf8(
base::Vector<const uint8_t> str, UnicodeConfig config,
+6 -5
View File
@@ -107,7 +107,7 @@ bool IsMutableMap(InstanceType instance_type, ElementsKind elements_kind) {
#endif
struct ConstantStringInit {
base::Vector<const char> contents;
std::string_view contents;
RootIndex index;
};
@@ -970,7 +970,8 @@ bool Heap::CreateImportantReadOnlyObjects() {
// the initial section.
isolate()->string_table()->InsertEmptyStringForBootstrapping(isolate());
} else {
DirectHandle<String> str = factory->InternalizeString(entry.contents);
DirectHandle<String> str = factory->InternalizeString(
base::OneByteVector(entry.contents.data(), entry.contents.size()));
roots_table()[entry.index] = str->ptr();
}
}
@@ -1149,7 +1150,8 @@ bool Heap::CreateReadOnlyObjects() {
Context::BIGINT_FUNCTION_INDEX);
for (const ConstantStringInit& entry : kNotImportantConstantStringTable) {
DirectHandle<String> str = factory->InternalizeString(entry.contents);
DirectHandle<String> str = factory->InternalizeString(
base::OneByteVector(entry.contents.data(), entry.contents.size()));
roots_table()[entry.index] = str->ptr();
}
@@ -1321,8 +1323,7 @@ bool Heap::CreateReadOnlyObjects() {
// This code duplicates FactoryBase::SmiToNumber.
for (uint32_t i = 10; i < kPreallocatedNumberStringTableSize; ++i) {
std::string_view string = IntToStringView(i, buffer);
Handle<String> str = factory->InternalizeString(
base::OneByteVector(string.data(), string.length()));
Handle<String> str = factory->InternalizeString(string);
DCHECK(ReadOnlyHeap::Contains(*str));
preallocated_number_string_table->set(i, *str);
+1 -1
View File
@@ -943,7 +943,7 @@ double InternalStringToDouble(const Char* current, const Char* end,
double StringToDouble(const char* str, ConversionFlag flags,
double empty_string_val) {
// We use {base::OneByteVector} instead of {base::CStrVector} to avoid
// We use {base::OneByteVector} instead of {std::string_view} to avoid
// instantiating the InternalStringToDouble() template for {const char*} as
// well.
return StringToDouble(base::OneByteVector(str), flags, empty_string_val);
+1 -2
View File
@@ -2179,8 +2179,7 @@ MaybeDirectHandle<JSArray> CreateArrayFromList(
// a. Let status be CreateDataProperty(array, ! ToString(n), e).
const std::string& part = elements[i];
DirectHandle<String> value =
factory->NewStringFromUtf8(base::CStrVector(part.c_str()))
.ToHandleChecked();
factory->NewStringFromUtf8(part).ToHandleChecked();
MAYBE_RETURN(JSObject::AddDataElement(isolate, array, i, value, attr), {});
}
// 5. Return array.
+1 -1
View File
@@ -331,7 +331,7 @@ Handle<String> SharedFunctionInfo::DebugName(
#if V8_ENABLE_WEBASSEMBLY
if (shared->HasWasmExportedFunctionData(isolate) && allow_allocation) {
return isolate->factory()
->NewStringFromUtf8(base::CStrVector(shared->DebugNameCStr().get()))
->NewStringFromUtf8(shared->DebugNameCStr().get())
.ToHandleChecked();
}
#endif // V8_ENABLE_WEBASSEMBLY
+1 -2
View File
@@ -204,8 +204,7 @@ DirectHandle<DictionaryTemplateInfo> DictionaryTemplateInfo::Create(
uint32_t unused_array_index;
for (const std::string_view& name : names) {
DirectHandle<String> internalized_name =
isolate->factory()->InternalizeString(
base::Vector<const char>(name.data(), name.length()));
isolate->factory()->InternalizeString(name);
// Check that property name cannot be used as index.
CHECK(!internalized_name->AsArrayIndex(&unused_array_index));
property_names->set(index, *internalized_name);
+1 -1
View File
@@ -1845,7 +1845,7 @@ MaybeDirectHandle<String> ValueDeserializer::ReadUtf8String(
base::Vector<const uint8_t> utf8_bytes;
if (!ReadRawBytes(utf8_length).To(&utf8_bytes)) return {};
return isolate_->factory()->NewStringFromUtf8(
base::Vector<const char>::cast(utf8_bytes), allocation);
utf8_bytes, unibrow::Utf8Variant::kLossyUtf8, allocation);
}
MaybeDirectHandle<String> ValueDeserializer::ReadOneByteString(
@@ -64,8 +64,7 @@ DirectHandle<String> PendingCompilationErrorHandler::MessageDetails::ArgString(
return Handle<String>::null();
case kConstCharString:
return isolate->factory()
->NewStringFromUtf8(base::CStrVector(args_[index].c_string),
AllocationType::kOld)
->NewStringFromUtf8(args_[index].c_string, AllocationType::kOld)
.ToHandleChecked();
case kAstRawString:
UNREACHABLE();
+1 -5
View File
@@ -167,12 +167,8 @@ MaybeDirectHandle<Object> RegExp::ThrowRegExpException(
regexp::ErrorIsStackOverflow(error))) {
FATAL("Aborting on stack overflow");
}
base::Vector<const char> error_data =
base::CStrVector(regexp::ErrorString(error));
DirectHandle<String> error_text =
isolate->factory()
->NewStringFromOneByte(base::Vector<const uint8_t>::cast(error_data))
.ToHandleChecked();
isolate->factory()->NewStringFromAsciiChecked(regexp::ErrorString(error));
DirectHandle<String> flag_string =
JSRegExp::StringFromFlags(isolate, JSRegExp::AsJSRegExpFlags(flags));
THROW_NEW_ERROR(isolate,
+4 -5
View File
@@ -1755,11 +1755,10 @@ class PrototypesSetup : public wasm::Decoder {
if (HasMorePrototypes()) error("unconsumed prototypes");
if (more()) error("unconsumed data");
if (!ok()) {
DirectHandle<String> message =
isolate()
->factory()
->NewStringFromUtf8(base::VectorOf(error().message()))
.ToHandleChecked();
DirectHandle<String> message = isolate()
->factory()
->NewStringFromUtf8(error().message())
.ToHandleChecked();
DirectHandle<JSObject> error = isolate()->factory()->NewError(
isolate()->wasm_runtime_error_function(), message);
return isolate()->Throw(*error);
+6 -7
View File
@@ -88,14 +88,13 @@ static bool IsControlChar(char c) {
}
}
void StringStream::Add(base::Vector<const char> format,
base::Vector<FmtElm> elms) {
void StringStream::Add(std::string_view format, std::span<const FmtElm> elms) {
// If we already ran out of space then return immediately.
if (full()) return;
int offset = 0;
int elm = 0;
size_t offset = 0;
size_t elm = 0;
while (offset < format.length()) {
if (format[offset] != '%' || elm == elms.length()) {
if (format[offset] != '%' || elm == elms.size()) {
Put(format[offset]);
offset++;
continue;
@@ -157,7 +156,7 @@ void StringStream::Add(base::Vector<const char> format,
int value = current.data_.u_int_;
std::array<char, 24> formatted;
int length = base::SNPrintF(formatted, temp.data(), value);
Add(base::Vector<const char>(formatted.data(), length));
Add(std::string_view(formatted.data(), length));
break;
}
case 'f':
@@ -251,7 +250,7 @@ void StringStream::OutputToFile(FILE* out) {
DirectHandle<String> StringStream::ToString(Isolate* isolate) {
return isolate->factory()
->NewStringFromUtf8(base::Vector<const char>(buffer_, length_))
->NewStringFromUtf8(std::string_view(buffer_, length_))
.ToHandleChecked();
}
+6 -12
View File
@@ -6,6 +6,8 @@
#define V8_STRINGS_STRING_STREAM_H_
#include <memory>
#include <span>
#include <string_view>
#include "src/base/small-vector.h"
#include "src/base/strings.h"
@@ -153,20 +155,12 @@ class StringStream final {
bool Put(char c);
bool Put(Tagged<String> str);
bool Put(Tagged<String> str, int start, int end);
void Add(const char* format) { Add(base::CStrVector(format)); }
void Add(base::Vector<const char> format) {
Add(format, base::Vector<FmtElm>());
}
void Add(std::string_view format) { Add(format, std::span<const FmtElm>{}); }
template <typename... Args>
void Add(const char* format, Args... args) {
Add(base::CStrVector(format), args...);
}
template <typename... Args>
void Add(base::Vector<const char> format, Args... args) {
void Add(std::string_view format, Args... args) {
FmtElm elems[]{args...};
Add(format, base::ArrayVector(elems));
Add(format, std::span<const FmtElm>(elems));
}
// Getting the message out.
@@ -205,7 +199,7 @@ class StringStream final {
static const int kInitialCapacity = 16;
private:
void Add(base::Vector<const char> format, base::Vector<FmtElm> elms);
void Add(std::string_view format, std::span<const FmtElm> elms);
void PrintObject(Tagged<Object> obj);
StringAllocator* allocator_;
+3 -3
View File
@@ -31,7 +31,7 @@ void EmitCompilationHintsToBuffer(ZoneBuffer& buffer,
buffer.write_u8(kUnknownSectionCode);
size_t section_size_offset = buffer.reserve_u32v();
size_t section_body_begin = buffer.offset();
buffer.write_string(base::StaticCharVector(kCompilationPriorityString));
buffer.write_string(kCompilationPriorityString);
uint32_t num_functions = 0;
size_t num_functions_offset = buffer.reserve_u32v();
for (uint32_t func_index = module->num_imported_functions;
@@ -76,7 +76,7 @@ void EmitCompilationHintsToBuffer(ZoneBuffer& buffer,
buffer.write_u8(kUnknownSectionCode);
size_t section_size_offset = buffer.reserve_u32v();
size_t section_body_begin = buffer.offset();
buffer.write_string(base::StaticCharVector(kInstructionFrequenciesString));
buffer.write_string(kInstructionFrequenciesString);
uint32_t num_functions = 0;
size_t num_functions_offset = buffer.reserve_u32v();
@@ -135,7 +135,7 @@ void EmitCompilationHintsToBuffer(ZoneBuffer& buffer,
buffer.write_u8(kUnknownSectionCode);
size_t section_size_offset = buffer.reserve_u32v();
size_t section_body_begin = buffer.offset();
buffer.write_string(base::StaticCharVector(kCallTargetsString));
buffer.write_string(kCallTargetsString);
uint32_t num_functions = 0;
size_t num_functions_offset = buffer.reserve_u32v();
+11 -17
View File
@@ -4693,8 +4693,7 @@ class ModuleGen {
for (auto& import : *imports) {
import.sig_index = builder_->ForceAddSignature(import.sig, kIsFinal);
uint32_t index =
builder_->AddImport(base::VectorOf(import.name), import.sig,
base::VectorOf(import.module_name));
builder_->AddImport(import.name, import.sig, import.module_name);
import.index = index;
}
imports_ = imports;
@@ -4750,20 +4749,16 @@ class ModuleGen {
static constexpr FunctionSig kSig_into_a8(1, 3, kReps_into_a8);
static constexpr FunctionSig kSig_to_a8(1, 1, kReps_to_a8);
static constexpr base::Vector<const char> kJsString =
base::StaticCharVector("wasm:js-string");
static constexpr base::Vector<const char> kTextDecoder =
base::StaticCharVector("wasm:text-decoder");
static constexpr base::Vector<const char> kTextEncoder =
base::StaticCharVector("wasm:text-encoder");
static constexpr std::string_view kJsString = "wasm:js-string";
static constexpr std::string_view kTextDecoder = "wasm:text-decoder";
static constexpr std::string_view kTextEncoder = "wasm:text-encoder";
// The signatures of compile-time imports must be defined in singleton
// recgroups, so we can't allow them to get deduplicated against existing
// signatures that might be in nontrivial recgroups.
static constexpr bool kForceNewSig = true;
#define STRINGFUNC(name, sig, group) \
strings.name = \
builder_->AddImport(base::CStrVector(#name), &sig, group, kForceNewSig)
strings.name = builder_->AddImport(#name, &sig, group, kForceNewSig)
STRINGFUNC(cast, kSig_e_r, kJsString);
STRINGFUNC(test, kSig_i_r, kJsString);
@@ -5347,9 +5342,9 @@ base::Vector<uint8_t> GenerateRandomWasmModule(
gen_body.Generate(return_types, &function_range);
f->Emit(kExprEnd);
if (module_exports) {
builder.AddExport(base::CStrVector((*module_exports)[i].name.c_str()), f);
builder.AddExport((*module_exports)[i].name, f);
} else if (i == 0) {
builder.AddExport(base::CStrVector("main"), f);
builder.AddExport("main", f);
}
}
@@ -5782,9 +5777,8 @@ base::Vector<uint8_t> GenerateWasmModuleForDeopt(
// Create global for call target index.
// Simplification: This global is used to specify the call target at the deopt
// point instead of passing the call target around dynamically.
uint32_t global_index =
builder.AddExportedGlobal(kWasmI32, true, WasmInitExpr(0),
base::StaticCharVector("call_target_index"));
uint32_t global_index = builder.AddExportedGlobal(
kWasmI32, true, WasmInitExpr(0), "call_target_index");
// Create inlinee bodies.
for (int i = 0; i < num_inlinees; ++i) {
@@ -5839,7 +5833,7 @@ base::Vector<uint8_t> GenerateWasmModuleForDeopt(
}
f->Emit(kExprEnd);
builder.AddExport(base::StaticCharVector("main"), f);
builder.AddExport("main", f);
}
// Create call target bodies.
@@ -6083,7 +6077,7 @@ base::Vector<uint8_t> GenerateWasmModuleForRevec(
}
f->Emit(kExprEnd);
if (i == 0) builder.AddExport(base::CStrVector("main"), f);
if (i == 0) builder.AddExport("main", f);
}
ZoneBuffer buffer{zone};
+6 -5
View File
@@ -2564,8 +2564,8 @@ void AsyncCompileJob::FinishCompile(
bool is_after_deserialization = !deserialized_module_object.is_null();
if (!is_after_deserialization) {
// Prepare runtime objects.
auto source_url =
stream_ ? base::VectorOf(stream_->url()) : base::Vector<const char>();
std::string_view source_url =
stream_ ? std::string_view(stream_->url()) : std::string_view();
auto script =
GetWasmEngine()->GetOrCreateScript(isolate, native_module, source_url);
module_object = WasmModuleObject::New(isolate, script);
@@ -2628,10 +2628,11 @@ void AsyncCompileJob::FinishCompile(
if (sourcemap_symbol.type != WasmDebugSymbols::Type::None &&
!sourcemap_symbol.external_url.is_empty()) {
ModuleWireBytes wire_bytes(native_module->wire_bytes());
WasmName external_url =
wire_bytes.GetNameOrNull(sourcemap_symbol.external_url);
MaybeDirectHandle<String> src_map_str =
isolate->factory()->NewStringFromUtf8(
wire_bytes.GetNameOrNull(sourcemap_symbol.external_url),
AllocationType::kOld);
{external_url.data(), external_url.size()}, AllocationType::kOld);
script->set_source_mapping_url(*src_map_str.ToHandleChecked());
}
{
@@ -3390,7 +3391,7 @@ bool AsyncStreamingProcessor::Deserialize(
DirectHandle<WasmModuleObject> module_object;
if (!DeserializeNativeModule(isolate, job_->enabled_features_, module_bytes,
wire_bytes, job_->compile_imports_,
base::VectorOf(job_->stream_->url()))
job_->stream_->url())
.ToHandle(&module_object)) {
return false;
}
+13 -17
View File
@@ -136,25 +136,21 @@ inline SectionCode IdentifyUnknownSectionInternal(Decoder* decoder,
static_cast<int>(section_name_start - decoder->start()),
string.length() < 20 ? string.length() : 20, section_name_start);
using SpecialSectionPair = std::pair<base::Vector<const char>, SectionCode>;
using SpecialSectionPair = std::pair<std::string_view, SectionCode>;
static constexpr SpecialSectionPair kSpecialSections[]{
{base::StaticCharVector(kNameString), kNameSectionCode},
{base::StaticCharVector(kSourceMappingURLString),
kSourceMappingURLSectionCode},
{base::StaticCharVector(kInstTraceString), kInstTraceSectionCode},
{base::StaticCharVector(kBranchHintsString), kBranchHintsSectionCode},
{base::StaticCharVector(kCompilationPriorityString),
kCompilationPrioritySectionCode},
{base::StaticCharVector(kInstructionFrequenciesString),
kInstFrequenciesSectionCode},
{base::StaticCharVector(kCallTargetsString), kCallTargetsSectionCode},
{base::StaticCharVector(kDebugInfoString), kDebugInfoSectionCode},
{base::StaticCharVector(kExternalDebugInfoString),
kExternalDebugInfoSectionCode},
{base::StaticCharVector(kBuildIdString), kBuildIdSectionCode}};
{kNameString, kNameSectionCode},
{kSourceMappingURLString, kSourceMappingURLSectionCode},
{kInstTraceString, kInstTraceSectionCode},
{kBranchHintsString, kBranchHintsSectionCode},
{kCompilationPriorityString, kCompilationPrioritySectionCode},
{kInstructionFrequenciesString, kInstFrequenciesSectionCode},
{kCallTargetsString, kCallTargetsSectionCode},
{kDebugInfoString, kDebugInfoSectionCode},
{kExternalDebugInfoString, kExternalDebugInfoSectionCode},
{kBuildIdString, kBuildIdSectionCode}};
auto name_vec = base::Vector<const char>::cast(
base::VectorOf(section_name_start, string.length()));
std::string_view name_vec(reinterpret_cast<const char*>(section_name_start),
string.length());
for (auto& special_section : kSpecialSections) {
if (name_vec == special_section.first) return special_section.second;
}
+3 -2
View File
@@ -10,6 +10,7 @@
#endif // !V8_ENABLE_WEBASSEMBLY
#include <memory>
#include <string_view>
#include <vector>
#include "include/v8-wasm.h" // For WasmStreaming::ModuleCachingInterface.
@@ -125,7 +126,7 @@ class V8_EXPORT_PRIVATE StreamingDecoder {
const std::string& url() const { return *url_; }
std::shared_ptr<const std::string> shared_url() const { return url_; }
void SetUrl(base::Vector<const char> url) {
void SetUrl(std::string_view url) {
// We shouldn't modify {url_} while it is being read. The API contract
// hence states that {SetUrl()} must be called early.
// Enforcing this with a CHECK is possibly racy when an attacker with an
@@ -133,7 +134,7 @@ class V8_EXPORT_PRIVATE StreamingDecoder {
// becomes a problem, we can add a lock. As an attack mitigation, a CHECK
// that fails most of the time is probably good enough.
SBXCHECK_EQ(stream_state_, kReceivingBytes);
url_->assign(url.begin(), url.size());
url_->assign(url);
// Safely crash if a race did happen:
SBXCHECK_EQ(stream_state_, kReceivingBytes);
}
+11 -11
View File
@@ -291,9 +291,9 @@ class WeakScriptHandle {
return source_url_;
}
bool MatchesSourceUrl(base::Vector<const char> source_url) const {
bool MatchesSourceUrl(std::string_view source_url) const {
if (source_url.empty()) return is_default_url_;
return base::CStrVector(source_url_.get()) == source_url;
return source_url_.get() == source_url;
}
private:
@@ -650,8 +650,7 @@ bool WasmEngine::SyncValidate(Isolate* isolate, WasmEnabledFeatures enabled,
MaybeDirectHandle<WasmModuleObject> WasmEngine::SyncCompile(
Isolate* isolate, WasmEnabledFeatures enabled_features,
CompileTimeImports compile_imports, ErrorThrower* thrower,
base::UniqueArray<const uint8_t> bytes,
base::Vector<const char> source_url) {
base::UniqueArray<const uint8_t> bytes, std::string_view source_url) {
int compilation_id = next_compilation_id_.fetch_add(1);
TRACE_EVENT("v8.wasm", "wasm.SyncCompile", "id", compilation_id);
v8::metrics::Recorder::ContextId context_id =
@@ -927,7 +926,7 @@ void WasmEngine::LeaveDebuggingForIsolate(Isolate* isolate) {
namespace {
DirectHandle<Script> CreateWasmScript(
Isolate* isolate, std::shared_ptr<NativeModule> native_module,
base::Vector<const char> source_url) {
std::string_view source_url) {
base::Vector<const uint8_t> wire_bytes = native_module->wire_bytes();
// The source URL of the script is
@@ -950,7 +949,7 @@ DirectHandle<Script> CreateWasmScript(
DCHECK(url_len >= 0 && static_cast<size_t>(url_len) < buffer.size());
url_str =
isolate->factory()
->NewStringFromUtf8(base::VectorOf(buffer).SubVector(0, url_len),
->NewStringFromUtf8({buffer.data(), static_cast<size_t>(url_len)},
AllocationType::kOld)
.ToHandleChecked();
} else {
@@ -964,7 +963,8 @@ DirectHandle<Script> CreateWasmScript(
isolate, wire_bytes, module->name, kNoInternalize);
DirectHandle<String> hash_str =
isolate->factory()
->NewStringFromUtf8(base::VectorOf(buffer).SubVector(0, hash_len))
->NewStringFromUtf8(
{buffer.data(), static_cast<size_t>(hash_len)})
.ToHandleChecked();
// Concatenate the three parts.
url_str = isolate->factory()
@@ -985,8 +985,8 @@ DirectHandle<Script> CreateWasmScript(
ModuleWireBytes(wire_bytes)
.GetNameOrNull(source_map_symbols.external_url);
MaybeDirectHandle<String> src_map_str =
isolate->factory()->NewStringFromUtf8(external_url,
AllocationType::kOld);
isolate->factory()->NewStringFromUtf8(
{external_url.data(), external_url.size()}, AllocationType::kOld);
source_map_url = src_map_str.ToHandleChecked();
}
@@ -1038,7 +1038,7 @@ DirectHandle<Script> CreateWasmScript(
DirectHandle<WasmModuleObject> WasmEngine::ImportNativeModule(
Isolate* isolate, std::shared_ptr<NativeModule> shared_native_module,
base::Vector<const char> source_url) {
std::string_view source_url) {
NativeModule* native_module = shared_native_module.get();
ModuleWireBytes wire_bytes(native_module->wire_bytes());
DirectHandle<Script> script =
@@ -1894,7 +1894,7 @@ void WasmEngine::FreeDeadCodeLocked(
DirectHandle<Script> WasmEngine::GetOrCreateScript(
Isolate* isolate, const std::shared_ptr<NativeModule>& native_module,
base::Vector<const char> source_url) {
std::string_view source_url) {
{
base::MutexGuard guard(&mutex_);
DCHECK(isolates_.contains(isolate));
+4 -3
View File
@@ -13,6 +13,7 @@
#include <map>
#include <memory>
#include <optional>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
@@ -197,7 +198,7 @@ class V8_EXPORT_PRIVATE WasmEngine {
base::UniqueArray<const uint8_t> bytes,
// Optional source URL; needed when recompiling on flags mismatch
// to preserve the original URL.
base::Vector<const char> source_url = {});
std::string_view source_url = {});
// Synchronously instantiate the given Wasm module with the given imports.
MaybeDirectHandle<WasmInstanceObject> SyncInstantiate(
@@ -238,7 +239,7 @@ class V8_EXPORT_PRIVATE WasmEngine {
// recreating a full module object in the given Isolate.
DirectHandle<WasmModuleObject> ImportNativeModule(
Isolate* isolate, std::shared_ptr<NativeModule> shared_module,
base::Vector<const char> source_url);
std::string_view source_url);
// Flushes all Liftoff code in all NativeModules.
void FlushLiftoffCode();
@@ -402,7 +403,7 @@ class V8_EXPORT_PRIVATE WasmEngine {
DirectHandle<Script> GetOrCreateScript(Isolate*,
const std::shared_ptr<NativeModule>&,
base::Vector<const char> source_url);
std::string_view source_url);
// Returns a barrier allowing background compile operations if valid and
// preventing this object from being destroyed.
+5 -6
View File
@@ -110,7 +110,7 @@ class WasmStreaming::WasmStreamingImpl {
streaming_decoder_->SetHasCompiledModuleBytes();
}
void SetUrl(base::Vector<const char> url) { streaming_decoder_->SetUrl(url); }
void SetUrl(std::string_view url) { streaming_decoder_->SetUrl(url); }
private:
i::Isolate* const i_isolate_;
@@ -160,7 +160,7 @@ void WasmStreaming::SetMoreFunctionsCanBeSerializedCallback(
void WasmStreaming::SetUrl(const char* url, size_t length) {
DCHECK_EQ('\0', url[length]); // {url} is null-terminated.
TRACE_EVENT("v8.wasm", "wasm.SetUrl", "url", url);
impl_->SetUrl(base::VectorOf(url, length));
impl_->SetUrl(std::string_view(url, length));
}
// static
@@ -213,7 +213,7 @@ class WasmModuleCompilation::Impl {
streaming_decoder_->SetHasCompiledModuleBytes();
}
void SetUrl(base::Vector<const char> url) { streaming_decoder_->SetUrl(url); }
void SetUrl(std::string_view url) { streaming_decoder_->SetUrl(url); }
private:
class Resolver final : public i::wasm::CompilationResultResolver {
@@ -246,8 +246,7 @@ WasmModuleCompilation::WasmModuleCompilation(const CompileOptions& options)
i::wasm::CompileTimeImportsFromOptions(options))) {
TRACE_EVENT("v8.wasm", "wasm.ModuleCompilation");
if (!options.source_url.empty()) {
impl_->SetUrl(
base::VectorOf(options.source_url.data(), options.source_url.size()));
impl_->SetUrl(options.source_url);
}
}
@@ -283,7 +282,7 @@ void WasmModuleCompilation::SetMoreFunctionsCanBeSerializedCallback(
void WasmModuleCompilation::SetUrl(const char* url, size_t length) {
DCHECK_EQ('\0', url[length]); // {url} is null-terminated.
TRACE_EVENT("v8.wasm", "wasm.SetUrl", "url", url);
impl_->SetUrl(base::VectorOf(url, length));
impl_->SetUrl(std::string_view(url, length));
}
namespace {
+9 -11
View File
@@ -349,9 +349,7 @@ void WasmFunctionBuilder::EmitFromInitializerExpression(
WriteInitializerExpression(&body_, init_expr);
}
void WasmFunctionBuilder::SetName(base::Vector<const char> name) {
name_ = name;
}
void WasmFunctionBuilder::SetName(std::string_view name) { name_ = name; }
void WasmFunctionBuilder::DeleteCodeAfter(size_t position) {
DCHECK_LE(position, body_.size());
@@ -552,9 +550,9 @@ void WasmModuleBuilder::SetIndirectFunction(uint32_t table_index,
AddElementSegment(std::move(segment));
}
uint32_t WasmModuleBuilder::AddImport(base::Vector<const char> name,
uint32_t WasmModuleBuilder::AddImport(std::string_view name,
const FunctionSig* sig,
base::Vector<const char> module,
std::string_view module,
bool force_new_sig) {
DCHECK(adding_imports_allowed_);
ModuleTypeIndex sig_index =
@@ -564,9 +562,9 @@ uint32_t WasmModuleBuilder::AddImport(base::Vector<const char> name,
return static_cast<uint32_t>(function_imports_.size() - 1);
}
uint32_t WasmModuleBuilder::AddGlobalImport(base::Vector<const char> name,
uint32_t WasmModuleBuilder::AddGlobalImport(std::string_view name,
ValueType type, bool mutability,
base::Vector<const char> module) {
std::string_view module) {
global_imports_.push_back({.module = module,
.name = name,
.type_code = type.value_type_code(),
@@ -578,7 +576,7 @@ void WasmModuleBuilder::MarkStartFunction(WasmFunctionBuilder* function) {
start_function_index_ = function->func_index();
}
void WasmModuleBuilder::AddExport(base::Vector<const char> name,
void WasmModuleBuilder::AddExport(std::string_view name,
ImportExportKindCode kind, uint32_t index) {
DCHECK_LE(index, std::numeric_limits<int>::max());
exports_.push_back(
@@ -587,13 +585,13 @@ void WasmModuleBuilder::AddExport(base::Vector<const char> name,
uint32_t WasmModuleBuilder::AddExportedGlobal(ValueType type, bool mutability,
WasmInitExpr init,
base::Vector<const char> name) {
std::string_view name) {
uint32_t index = AddGlobal(type, mutability, init);
AddExport(name, kExternalGlobal, index);
return index;
}
void WasmModuleBuilder::ExportImportedFunction(base::Vector<const char> name,
void WasmModuleBuilder::ExportImportedFunction(std::string_view name,
int import_index) {
#if DEBUG
// The size of function_imports_ must not change any more.
@@ -942,7 +940,7 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer* buffer) const {
// Emit a placeholder for the length.
size_t start = buffer->reserve_u32v();
// Emit the section string.
buffer->write_string(base::CStrVector("name"));
buffer->write_string("name");
// Emit a subsection for the function names.
buffer->write_u8(NameSectionKindCode::kFunctionCode);
// Emit a placeholder for the subsection length.
+18 -19
View File
@@ -10,6 +10,7 @@
#endif // !V8_ENABLE_WEBASSEMBLY
#include <optional>
#include <string_view>
#include "src/base/memory.h"
#include "src/base/numerics/safe_conversions.h"
@@ -95,9 +96,9 @@ class ZoneBuffer : public ZoneObject {
pos_ += size;
}
void write_string(base::Vector<const char> name) {
void write_string(std::string_view name) {
write_size(name.size());
write(reinterpret_cast<const uint8_t*>(name.begin()), name.size());
write(reinterpret_cast<const uint8_t*>(name.data()), name.size());
}
size_t reserve_u32v() {
@@ -197,7 +198,7 @@ class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject {
void EmitValueType(ValueType type);
void EmitDirectCallIndex(uint32_t index);
void EmitFromInitializerExpression(const WasmInitExpr& init_expr);
void SetName(base::Vector<const char> name);
void SetName(std::string_view name);
size_t GetPosition() const { return body_.size(); }
void FixupByte(size_t position, uint8_t value) {
@@ -228,7 +229,7 @@ class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject {
ModuleTypeIndex signature_index_;
uint32_t func_index_;
ZoneBuffer body_;
base::Vector<const char> name_;
std::string_view name_;
ZoneVector<uint32_t> i32_temps_;
ZoneVector<uint32_t> i64_temps_;
ZoneVector<uint32_t> f32_temps_;
@@ -302,15 +303,13 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
};
// Building methods.
uint32_t AddImport(base::Vector<const char> name, const FunctionSig* sig,
base::Vector<const char> module = {},
bool force_new_sig = false);
uint32_t AddImport(std::string_view name, const FunctionSig* sig,
std::string_view module = {}, bool force_new_sig = false);
WasmFunctionBuilder* AddFunction(const FunctionSig* sig = nullptr);
WasmFunctionBuilder* AddFunction(ModuleTypeIndex sig_index);
uint32_t AddGlobal(ValueType type, bool mutability, WasmInitExpr init);
uint32_t AddGlobalImport(base::Vector<const char> name, ValueType type,
bool mutability,
base::Vector<const char> module = {});
uint32_t AddGlobalImport(std::string_view name, ValueType type,
bool mutability, std::string_view module = {});
void AddDataSegment(const uint8_t* data, uint32_t size, uint32_t dest);
void AddPassiveDataSegment(const uint8_t* data, uint32_t size);
// Add an element segment to this {WasmModuleBuilder}. {segment}'s enties
@@ -347,14 +346,14 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
uint32_t AddMemory64(uint32_t min_pages);
uint32_t AddMemory64(uint32_t min_pages, uint32_t max_pages);
void MarkStartFunction(WasmFunctionBuilder* builder);
void AddExport(base::Vector<const char> name, ImportExportKindCode kind,
void AddExport(std::string_view name, ImportExportKindCode kind,
uint32_t index);
void AddExport(base::Vector<const char> name, WasmFunctionBuilder* builder) {
void AddExport(std::string_view name, WasmFunctionBuilder* builder) {
AddExport(name, kExternalFunction, builder->func_index());
}
uint32_t AddExportedGlobal(ValueType type, bool mutability, WasmInitExpr init,
base::Vector<const char> name);
void ExportImportedFunction(base::Vector<const char> name, int import_index);
std::string_view name);
void ExportImportedFunction(std::string_view name, int import_index);
// Start a recursive type group; must be followed by `EndRecursiveTypeGroup()`
// after adding all types of the recursion group.
@@ -477,21 +476,21 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
private:
struct WasmFunctionImport {
base::Vector<const char> module;
base::Vector<const char> name;
std::string_view module;
std::string_view name;
ModuleTypeIndex sig_index;
};
struct WasmGlobalImport {
base::Vector<const char> module;
base::Vector<const char> name;
std::string_view module;
std::string_view name;
// TODO(manoskouk): Extend to full value type.
ValueTypeCode type_code;
bool mutability;
};
struct WasmExport {
base::Vector<const char> name;
std::string_view name;
ImportExportKindCode kind;
int index; // Can be negative for re-exported imports.
};
+2 -3
View File
@@ -220,7 +220,7 @@ namespace {
// Converts the given {type} into a string representation that can be used in
// reflective functions. Should be kept in sync with the {GetValueType} helper.
DirectHandle<String> ToValueTypeString(Isolate* isolate, ValueType type) {
return isolate->factory()->InternalizeUtf8String(base::VectorOf(type.name()));
return isolate->factory()->InternalizeUtf8String(type.name());
}
} // namespace
@@ -329,8 +329,7 @@ DirectHandle<JSObject> GetTypeForTable(Isolate* isolate, ValueType type,
AddressType address_type) {
Factory* factory = isolate->factory();
DirectHandle<String> element =
factory->InternalizeUtf8String(base::VectorOf(type.name()));
DirectHandle<String> element = factory->InternalizeUtf8String(type.name());
DirectHandle<JSFunction> object_function = isolate->object_function();
DirectHandle<JSObject> object = factory->NewJSObject(object_function);
+2 -1
View File
@@ -140,7 +140,8 @@ DirectHandle<String> WasmModuleObject::ExtractUtf8StringFromModuleBytes(
DCHECK_IMPLIES(shared, !internalize);
return internalize
? factory->InternalizeUtf8String(
base::Vector<const char>::cast(name_vec))
{reinterpret_cast<const char*>(name_vec.begin()),
name_vec.size()})
: factory
->NewStringFromUtf8(
name_vec, UnicodeConfig(unibrow::Utf8Variant::kLossyUtf8,
+1 -3
View File
@@ -128,9 +128,7 @@ DirectHandle<JSObject> ErrorThrower::Reify() {
break;
}
DirectHandle<String> message =
isolate_->factory()
->NewStringFromUtf8(base::VectorOf(error_msg_))
.ToHandleChecked();
isolate_->factory()->NewStringFromUtf8(error_msg_).ToHandleChecked();
Reset();
return isolate_->factory()->NewError(constructor, message);
}
+1 -2
View File
@@ -1208,8 +1208,7 @@ MaybeDirectHandle<WasmModuleObject> DeserializeNativeModule(
Isolate* isolate, WasmEnabledFeatures enabled_features,
base::Vector<const uint8_t> data,
base::UniqueArray<const uint8_t>& wire_bytes_vec,
const CompileTimeImports& compile_imports,
base::Vector<const char> source_url) {
const CompileTimeImports& compile_imports, std::string_view source_url) {
if (!IsWasmCodegenAllowed(isolate, isolate->native_context())) return {};
if (!HeaderMatches(data, enabled_features, compile_imports)) return {};
+3 -2
View File
@@ -9,6 +9,8 @@
#error This header should only be included if WebAssembly is enabled.
#endif // !V8_ENABLE_WEBASSEMBLY
#include <string_view>
#include "src/base/unique-array.h"
#include "src/wasm/wasm-code-manager.h"
@@ -53,8 +55,7 @@ class V8_EXPORT_PRIVATE WasmSerializer {
V8_EXPORT_PRIVATE MaybeDirectHandle<WasmModuleObject> DeserializeNativeModule(
Isolate*, WasmEnabledFeatures, base::Vector<const uint8_t> data,
base::UniqueArray<const uint8_t>& wire_bytes,
const CompileTimeImports& compile_imports,
base::Vector<const char> source_url);
const CompileTimeImports& compile_imports, std::string_view source_url);
} // namespace v8::internal::wasm
+2 -2
View File
@@ -16318,8 +16318,8 @@ TEST(ErrorLevelWarning) {
v8::Isolate::kMessageAll);
for (size_t i = 0; i < arraysize(levels); i++) {
i::MessageLocation location(script, 0, 0);
i::DirectHandle<i::String> msg(i_isolate->factory()->InternalizeString(
v8::base::StaticCharVector("test")));
i::DirectHandle<i::String> msg(
i_isolate->factory()->InternalizeString("test"));
i::DirectHandle<i::JSMessageObject> message =
i::MessageHandler::MakeMessageObject(
i_isolate, i::MessageTemplate::kDataCloneError, &location, msg);
-1
View File
@@ -33,7 +33,6 @@
#include "src/strings/string-search.h"
#include "test/cctest/cctest.h"
using ::v8::base::CStrVector;
using ::v8::base::Vector;
using ::v8::internal::DirectHandle;
using ::v8::internal::Factory;
+3 -4
View File
@@ -298,8 +298,7 @@ class FastJSWasmCallTester {
void DeclareCallback(const char* name, FunctionSig* signature,
const char* module) {
builder_->AddImport(base::CStrVector(name), signature,
base::CStrVector(module));
builder_->AddImport(name, signature, module);
}
void AddExportedFunction(const ExportedFunction& exported_func) {
@@ -308,8 +307,8 @@ class FastJSWasmCallTester {
func->EmitCode(exported_func.code.data(),
static_cast<uint32_t>(exported_func.code.size()));
func->Emit(kExprEnd);
builder_->AddExport(base::CStrVector(exported_func.name.c_str()),
kExternalFunction, func->func_index());
builder_->AddExport(exported_func.name, kExternalFunction,
func->func_index());
// JS-to-Wasm inlining is disabled when targeting 32 bits if the Wasm
// function signature contains an I64.
+55 -87
View File
@@ -223,19 +223,15 @@ StartupBlobs Serialize(v8::Isolate* isolate) {
WritePayload(shared_space_snapshot.RawData())};
}
base::UniqueArray<const char> ConstructSource(base::Vector<const char> head,
base::Vector<const char> body,
base::Vector<const char> tail,
int repeats) {
size_t source_length = head.size() + body.size() * repeats + tail.size();
auto source = base::UniqueArray<char>::NewForOverwrite(source_length);
CopyChars(source.begin(), head.begin(), head.length());
std::string ConstructSource(std::string_view head, std::string_view body,
std::string_view tail, int repeats) {
std::string source;
source.reserve(head.size() + body.size() * repeats + tail.size());
source.append(head);
for (int i = 0; i < repeats; i++) {
CopyChars(source.begin() + head.length() + i * body.length(), body.begin(),
body.length());
source.append(body);
}
CopyChars(source.begin() + head.length() + repeats * body.length(),
tail.begin(), tail.length());
source.append(tail);
return source;
}
@@ -253,7 +249,7 @@ void SanityCheck(v8::Isolate* v8_isolate) {
#endif
CHECK(IsJSObject(*isolate->global_object()));
CHECK(IsContext(*isolate->native_context()));
isolate->factory()->InternalizeString(base::StaticCharVector("Empty"));
isolate->factory()->InternalizeString("Empty");
}
void TestStartupSerializerOnceImpl() {
@@ -550,12 +546,11 @@ static void SerializeCustomContext(
"var p = 0;"
"(async ()=>{ p = await 42; })();");
base::UniqueArray<const char> source = ConstructSource(
base::StaticCharVector("function g() { return [,"),
base::StaticCharVector("1,"),
base::StaticCharVector("];} a = g(); b = g(); b.push(1);"), 100000);
std::string source =
ConstructSource("function g() { return [,", "1,",
"];} a = g(); b = g(); b.push(1);", 100000);
v8::MaybeLocal<v8::String> source_str = v8::String::NewFromUtf8(
isolate, source.begin(), v8::NewStringType::kNormal,
isolate, source.data(), v8::NewStringType::kNormal,
static_cast<int>(source.size()));
CompileRun(source_str.ToLocalChecked());
}
@@ -1818,13 +1813,11 @@ UNINITIALIZED_TEST(CustomSnapshotDataBlobImmortalImmovableRoots) {
// Flood the startup snapshot with shared function infos. If they are
// serialized before the immortal immovable root, the root will no longer end
// up on the first page.
base::UniqueArray<const char> source =
ConstructSource(base::StaticCharVector("var a = [];"),
base::StaticCharVector("a.push(function() {return 7});"),
base::StaticCharVector("\0"), 10000);
std::string source = ConstructSource(
"var a = [];", "a.push(function() {return 7});", "", 10000);
DisableEmbeddedBlobRefcounting();
v8::StartupData data = CreateSnapshotDataBlob(source.begin());
v8::StartupData data = CreateSnapshotDataBlob(source.c_str());
v8::Isolate::CreateParams params;
params.snapshot_blob = &data;
@@ -1920,12 +1913,10 @@ TEST(CodeSerializerWithProfiler) {
const char* source = "1 + 1";
Handle<String> orig_source = isolate->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
Handle<String> copy_source = isolate->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
Handle<String> orig_source =
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
Handle<String> copy_source =
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
CHECK(!orig_source.is_identical_to(copy_source));
CHECK(orig_source->Equals(*copy_source));
@@ -1963,12 +1954,10 @@ void TestCodeSerializerOnePlusOneImpl(bool verify_builtins_count = true) {
const char* source = "1 + 1";
Handle<String> orig_source = isolate->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
Handle<String> copy_source = isolate->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
Handle<String> orig_source =
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
Handle<String> copy_source =
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
CHECK(!orig_source.is_identical_to(copy_source));
CHECK(orig_source->Equals(*copy_source));
@@ -2460,12 +2449,10 @@ TEST(CodeSerializerInternalizedString) {
const char* source = "'string1'";
Handle<String> orig_source = isolate->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
Handle<String> copy_source = isolate->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
Handle<String> orig_source =
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
Handle<String> copy_source =
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
CHECK(!orig_source.is_identical_to(copy_source));
CHECK(orig_source->Equals(*copy_source));
@@ -2522,13 +2509,12 @@ TEST(CodeSerializerLargeCodeObject) {
v8::HandleScope scope(CcTest::isolate());
base::UniqueArray<const char> source = ConstructSource(
base::StaticCharVector("var j=1; if (j == 0) {"),
base::StaticCharVector(
"for (let i of Object.prototype) for (let k = 0; k < 0; ++k);"),
base::StaticCharVector("} j=7; j"), 2000);
std::string source = ConstructSource(
"var j=1; if (j == 0) {",
"for (let i of Object.prototype) for (let k = 0; k < 0; ++k);",
"} j=7; j", 2000);
Handle<String> source_str =
isolate->factory()->NewStringFromUtf8(source.as_span()).ToHandleChecked();
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
DirectHandle<JSObject> global(isolate->context()->global_object(), isolate);
AlignedCachedData* cache = nullptr;
@@ -2583,12 +2569,11 @@ TEST(CodeSerializerLargeCodeObjectWithIncrementalMarking) {
v8::HandleScope scope(CcTest::isolate());
base::UniqueArray<const char> source = ConstructSource(
base::StaticCharVector("var j=1; if (j == 0) {"),
base::StaticCharVector("for (var i = 0; i < Object.prototype; i++);"),
base::StaticCharVector("} j=7; var s = 'happy_hippo'; j"), 20000);
std::string source = ConstructSource(
"var j=1; if (j == 0) {", "for (var i = 0; i < Object.prototype; i++);",
"} j=7; var s = 'happy_hippo'; j", 20000);
Handle<String> source_str =
isolate->factory()->NewStringFromUtf8(source.as_span()).ToHandleChecked();
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
// Create a string on an evacuation candidate in old space.
DirectHandle<String> moving_object;
@@ -2659,16 +2644,13 @@ TEST(CodeSerializerLargeStrings) {
v8::HandleScope scope(CcTest::isolate());
base::UniqueArray<const char> source_s = ConstructSource(
base::StaticCharVector("var s = \""), base::StaticCharVector("abcdef"),
base::StaticCharVector("\";"), 1000000);
base::UniqueArray<const char> source_t = ConstructSource(
base::StaticCharVector("var t = \""), base::StaticCharVector("uvwxyz"),
base::StaticCharVector("\"; s + t"), 999999);
std::string source_s =
ConstructSource("var s = \"", "abcdef", "\";", 1000000);
std::string source_t =
ConstructSource("var t = \"", "uvwxyz", "\"; s + t", 999999);
Handle<String> source_str =
f->NewConsString(
f->NewStringFromUtf8(source_s.as_span()).ToHandleChecked(),
f->NewStringFromUtf8(source_t.as_span()).ToHandleChecked())
f->NewConsString(f->NewStringFromUtf8(source_s).ToHandleChecked(),
f->NewStringFromUtf8(source_t).ToHandleChecked())
.ToHandleChecked();
DirectHandle<JSObject> global(isolate->context()->global_object(), isolate);
@@ -2726,23 +2708,17 @@ TEST(CodeSerializerThreeBigStrings) {
const int32_t length_of_b = kMaxRegularHeapObjectSize / 2;
const int32_t length_of_c = kMaxRegularHeapObjectSize / 2;
base::UniqueArray<const char> source_a = ConstructSource(
base::StaticCharVector("var a = \""), base::StaticCharVector("a"),
base::StaticCharVector("\";"), length_of_a);
std::string source_a = ConstructSource("var a = \"", "a", "\";", length_of_a);
Handle<String> source_a_str =
f->NewStringFromUtf8(source_a.as_span()).ToHandleChecked();
f->NewStringFromUtf8(source_a).ToHandleChecked();
base::UniqueArray<const char> source_b = ConstructSource(
base::StaticCharVector("var b = \""), base::StaticCharVector("b"),
base::StaticCharVector("\";"), length_of_b);
std::string source_b = ConstructSource("var b = \"", "b", "\";", length_of_b);
Handle<String> source_b_str =
f->NewStringFromUtf8(source_b.as_span()).ToHandleChecked();
f->NewStringFromUtf8(source_b).ToHandleChecked();
base::UniqueArray<const char> source_c = ConstructSource(
base::StaticCharVector("var c = \""), base::StaticCharVector("c"),
base::StaticCharVector("\";"), length_of_c);
std::string source_c = ConstructSource("var c = \"", "c", "\";", length_of_c);
Handle<String> source_c_str =
f->NewStringFromUtf8(source_c.as_span()).ToHandleChecked();
f->NewStringFromUtf8(source_c).ToHandleChecked();
Handle<String> source_str =
f->NewConsString(
@@ -2867,9 +2843,7 @@ TEST(CodeSerializerExternalString) {
"o.two_byte = 8; \n"
"o.one_byte + o.two_byte; \n";
Handle<String> source_string =
isolate->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
DirectHandle<JSObject> global(isolate->context()->global_object(), isolate);
AlignedCachedData* cache = nullptr;
@@ -3047,13 +3021,9 @@ TEST(CodeSerializerLargeExternalString) {
v8::HandleScope scope(CcTest::isolate());
// Create a huge external internalized string to use as variable name.
base::UniqueArray<const char> string = ConstructSource(
base::StaticCharVector(""), base::StaticCharVector("abcdef"),
base::StaticCharVector(""), 999999);
Handle<String> name =
f->NewStringFromUtf8(string.as_span()).ToHandleChecked();
SerializerOneByteResource one_byte_resource(
reinterpret_cast<const char*>(string.begin()), string.size());
std::string string = ConstructSource("", "abcdef", "", 999999);
Handle<String> name = f->NewStringFromUtf8(string).ToHandleChecked();
SerializerOneByteResource one_byte_resource(string.data(), string.size());
name = f->InternalizeString(name);
name->MakeExternal(isolate, &one_byte_resource);
CHECK(IsExternalOneByteString(*name));
@@ -3114,8 +3084,7 @@ TEST(CodeSerializerExternalScriptName) {
"var a = [1, 2, 3, 4];"
"a.reduce(function(x, y) { return x + y }, 0)";
Handle<String> source_string =
f->NewStringFromUtf8(base::CStrVector(source)).ToHandleChecked();
Handle<String> source_string = f->NewStringFromUtf8(source).ToHandleChecked();
const SerializerOneByteResource one_byte_resource("one_byte", 8);
Handle<String> name =
@@ -6553,9 +6522,8 @@ TEST(WeakArraySerializationInCodeCache) {
const char* source = "function foo() { }";
Handle<String> src = isolate->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
Handle<String> src =
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
AlignedCachedData* cache = nullptr;
ScriptDetails script_details(src);
+14 -14
View File
@@ -1716,20 +1716,20 @@ TEST(InvalidExternalString) {
}
}
#define INVALID_STRING_TEST(FUN, TYPE) \
TEST(StringOOM##FUN) { \
CcTest::InitializeVM(); \
LocalContext context; \
Isolate* isolate = CcTest::i_isolate(); \
static_assert(String::kMaxLength < kMaxInt); \
static const int invalid = String::kMaxLength + 1; \
HandleScope scope(isolate); \
auto dummy = v8::base::UniqueArray<TYPE>::NewForOverwrite(invalid); \
memset(dummy.begin(), 0x0, dummy.size() * sizeof(TYPE)); \
CHECK(isolate->factory()->FUN(dummy.as_span()).is_null()); \
memset(dummy.begin(), 0x20, dummy.size() * sizeof(TYPE)); \
CHECK(isolate->has_exception()); \
isolate->clear_exception(); \
#define INVALID_STRING_TEST(FUN, TYPE) \
TEST(StringOOM##FUN) { \
CcTest::InitializeVM(); \
LocalContext context; \
Isolate* isolate = CcTest::i_isolate(); \
static_assert(String::kMaxLength < kMaxInt); \
static const int invalid = String::kMaxLength + 1; \
HandleScope scope(isolate); \
auto dummy = v8::base::UniqueArray<TYPE>::NewForOverwrite(invalid); \
memset(dummy.begin(), 0x0, dummy.size() * sizeof(TYPE)); \
CHECK(isolate->factory()->FUN({dummy.begin(), dummy.size()}).is_null()); \
memset(dummy.begin(), 0x20, dummy.size() * sizeof(TYPE)); \
CHECK(isolate->has_exception()); \
isolate->clear_exception(); \
}
INVALID_STRING_TEST(NewStringFromUtf8, char)
+1 -1
View File
@@ -69,7 +69,7 @@ class WasmGCTester {
std::initializer_list<const uint8_t> code) {
WasmFunctionBuilder* fun = builder_.AddFunction(sig);
fun->EmitCode(code);
builder_.AddExport(base::CStrVector(name), fun);
builder_.AddExport(name, fun);
}
MaybeDirectHandle<Object> CallExportedFunction(
+1 -1
View File
@@ -23,7 +23,7 @@ using v8::internal::testing::ManuallyExternalizedBuffer;
namespace {
void ExportAsMain(WasmFunctionBuilder* f) {
f->builder()->AddExport(base::CStrVector("main"), f);
f->builder()->AddExport("main", f);
}
void Cleanup(Isolate* isolate = CcTest::InitIsolateOnce()) {
+1 -1
View File
@@ -66,7 +66,7 @@ void TestModuleException(Zone* zone, WasmModuleBuilder* builder) {
}
void ExportAsMain(WasmFunctionBuilder* f) {
f->builder()->AddExport(base::CStrVector("main"), f);
f->builder()->AddExport("main", f);
}
#define EMIT_CODE_WITH_END(f, code) \
+7 -7
View File
@@ -116,7 +116,7 @@ TEST(WrapperBudget) {
// Define the Wasm function.
TestSignatures sigs;
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_ii());
f->builder()->AddExport(base::CStrVector("main"), f);
f->builder()->AddExport("main", f);
f->EmitCode({WASM_I32_MUL(WASM_LOCAL_GET(0), WASM_LOCAL_GET(1)), WASM_END});
// Compile the module.
@@ -164,7 +164,7 @@ TEST(WrapperReplacement) {
// Define the Wasm function.
TestSignatures sigs;
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
f->builder()->AddExport(base::CStrVector("main"), f);
f->builder()->AddExport("main", f);
f->EmitCode({WASM_LOCAL_GET(0), WASM_END});
// Compile the module.
@@ -240,15 +240,15 @@ TEST(EagerWrapperReplacement) {
// while the other one (id) won't.
TestSignatures sigs;
WasmFunctionBuilder* add = builder->AddFunction(sigs.i_ii());
add->builder()->AddExport(base::CStrVector("add"), add);
add->builder()->AddExport("add", add);
add->EmitCode(
{WASM_I32_ADD(WASM_LOCAL_GET(0), WASM_LOCAL_GET(1)), WASM_END});
WasmFunctionBuilder* mult = builder->AddFunction(sigs.i_ii());
mult->builder()->AddExport(base::CStrVector("mult"), mult);
mult->builder()->AddExport("mult", mult);
mult->EmitCode(
{WASM_I32_MUL(WASM_LOCAL_GET(0), WASM_LOCAL_GET(1)), WASM_END});
WasmFunctionBuilder* id = builder->AddFunction(sigs.i_i());
id->builder()->AddExport(base::CStrVector("id"), id);
id->builder()->AddExport("id", id);
id->EmitCode({WASM_LOCAL_GET(0), WASM_END});
// Compile the module.
@@ -354,7 +354,7 @@ TEST(WrapperReplacement_IndirectExport) {
const uint32_t table_size = 2;
const uint32_t table_index =
builder->AddTable(kWasmFuncRef, table_size, table_size);
builder->AddExport(base::CStrVector("exported_table"), kExternalTable, 0);
builder->AddExport("exported_table", kExternalTable, 0);
// Point from the exported table to the Wasm function.
builder->SetIndirectFunction(table_index, 0, function_index);
@@ -415,7 +415,7 @@ TEST(JSToWasmWrapperGarbageCollection) {
// Define an exported Wasm function.
TestSignatures sigs;
WasmFunctionBuilder* f = builder.AddFunction(sigs.i_v());
builder.AddExport(base::CStrVector("main"), f);
builder.AddExport("main", f);
f->EmitCode({WASM_ONE, WASM_END});
// Before compilation there should be no compiled wrappers.
@@ -315,7 +315,7 @@ ZoneBuffer GetValidModuleBytes(Zone* zone) {
WasmFunctionBuilder* f = builder.AddFunction(sigs.i_iii());
f->EmitCode({kExprLocalGet, i, kExprEnd});
CHECK_GE(3, ++i);
builder.AddExport(base::CStrVector(export_name), f);
builder.AddExport(export_name, f);
}
builder.WriteTo(&buffer);
return buffer;
@@ -1212,7 +1212,7 @@ STREAM_TEST(TestModuleWithImportedFunction) {
ZoneBuffer buffer(tester.zone());
TestSignatures sigs;
WasmModuleBuilder builder(tester.zone());
builder.AddImport(base::ArrayVector("Test"), sigs.i_iii());
builder.AddImport("Test", sigs.i_iii());
{
WasmFunctionBuilder* f = builder.AddFunction(sigs.i_iii());
f->EmitCode({kExprLocalGet, 0, kExprEnd});
@@ -1246,8 +1246,7 @@ STREAM_TEST(TestIncrementalCaching) {
WasmModuleBuilder builder(tester.zone());
builder.AddMemory(1);
base::Vector<const char> function_names[] = {
base::CStrVector("f0"), base::CStrVector("f1"), base::CStrVector("f2")};
std::string_view function_names[] = {"f0", "f1", "f2"};
for (int i = 0; i < 3; ++i) {
WasmFunctionBuilder* f = builder.AddFunction(sigs.v_v());
@@ -1274,7 +1273,7 @@ STREAM_TEST(TestIncrementalCaching) {
tester.RunCompilerTasks();
CHECK(tester.IsPromiseFulfilled());
tester.native_module();
constexpr base::Vector<const char> kNoSourceUrl{"", 0};
constexpr std::string_view kNoSourceUrl{"", 0};
Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
IndirectHandle<WasmInstanceObject> instance;
{
@@ -1963,7 +1962,7 @@ STREAM_TEST(TestProfilingMidStreaming) {
WasmModuleBuilder builder(zone);
WasmFunctionBuilder* f = builder.AddFunction(sigs.v_v());
f->EmitCode({kExprEnd});
builder.AddExport(base::VectorOf("foo", 3), f);
builder.AddExport("foo", f);
builder.WriteTo(&buffer);
}
+1 -1
View File
@@ -595,7 +595,7 @@ WASM_COMPILED_EXEC_TEST(WasmBreakpointMultipleScripts) {
std::shared_ptr<NativeModule> native_module =
module_object->managed_native_module()->get();
DirectHandle<Script> script2 = GetWasmEngine()->GetOrCreateScript(
isolate, native_module, base::CStrVector("custom://other-url.wasm"));
isolate, native_module, "custom://other-url.wasm");
CHECK_NE(*script1, *script2);
int func_offset =
+1 -1
View File
@@ -281,7 +281,7 @@ COMPILE_TEST(TestEventMetrics) {
WasmModuleBuilder* builder = zone.New<WasmModuleBuilder>(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
f->builder()->AddExport(base::CStrVector("main"), f);
f->builder()->AddExport("main", f);
f->EmitCode({WASM_I32V_2(0), WASM_END});
ZoneBuffer buffer(&zone);
builder->WriteTo(&buffer);
+8 -8
View File
@@ -54,7 +54,7 @@ class WasmSerializationTest {
f = builder->AddFunction(sigs.i_i());
f->EmitCode({WASM_LOCAL_GET(0), kExprI32Const, 1, kExprI32Add, kExprEnd});
}
builder->AddExport(base::CStrVector(kFunctionName), f);
builder->AddExport(kFunctionName, f);
builder->WriteTo(buffer);
}
@@ -73,7 +73,7 @@ class WasmSerializationTest {
}
MaybeDirectHandle<WasmModuleObject> Deserialize(
base::Vector<const char> source_url = {}) {
std::string_view source_url = {}) {
// Create a separate copy because some tests want to deserialize multiple
// times.
base::UniqueArray<const uint8_t> wire_bytes_copy =
@@ -238,7 +238,7 @@ TEST(DeserializeWithSourceUrl) {
HandleScope scope(CcTest::i_isolate());
const std::string url = "http://example.com/example.wasm";
DirectHandle<WasmModuleObject> module_object;
CHECK(test.Deserialize(base::VectorOf(url)).ToHandle(&module_object));
CHECK(test.Deserialize(url).ToHandle(&module_object));
Tagged<String> url_str = Cast<String>(module_object->script()->name());
CHECK_EQ(url, url_str->ToCString().get());
}
@@ -576,7 +576,7 @@ TEST(DeserializeIndirectCallWithDifferentCanonicalId) {
// if_false:
WASM_I32V_1(42)),
WASM_END});
builder.AddExport(base::CStrVector("call_indirect"), f);
builder.AddExport("call_indirect", f);
// Add a function table.
uint32_t table_id = builder.AddTable(kWasmFuncRef, 1);
builder.SetIndirectFunction(table_id, 0, f->func_index());
@@ -681,7 +681,7 @@ TEST(DeserializeIndirectCallWithDifferentCanonicalId) {
v8::Context::New(CcTest::isolate());
deserialization_context->Enter();
ErrorThrower thrower(i_isolate, "");
base::Vector<const char> kNoSourceUrl;
std::string_view kNoSourceUrl;
base::UniqueArray<const uint8_t> wire_bytes_copy =
base::UniqueCopyOf(zone_buffer);
DirectHandle<WasmModuleObject> module_object =
@@ -750,11 +750,11 @@ TEST(SerializeDetectedFeatures) {
ModuleTypeIndex sig_i_v = builder.AddSignature(TestSignatures::i_v(), true);
WasmFunctionBuilder* a = builder.AddFunction(sig_i_v);
a->EmitCode({WASM_I32V_1(11), WASM_END});
builder.AddExport(base::CStrVector("a"), a);
builder.AddExport("a", a);
// Add the function which tail-calls the first one.
WasmFunctionBuilder* b = builder.AddFunction(sig_i_v);
b->EmitCode({WASM_RETURN_CALL_FUNCTION0(a->func_index()), WASM_END});
builder.AddExport(base::CStrVector("b"), b);
builder.AddExport("b", b);
// Write the final module into {buffer}.
builder.WriteTo(&buffer);
}
@@ -838,7 +838,7 @@ TEST(SerializeDetectedFeatures) {
v8::Context::New(CcTest::isolate());
deserialization_context->Enter();
ErrorThrower thrower(i_isolate, "");
base::Vector<const char> kNoSourceUrl;
std::string_view kNoSourceUrl;
base::UniqueArray<const uint8_t> wire_bytes_copy =
base::UniqueCopyOf(buffer);
DirectHandle<WasmModuleObject> module_object =
+1 -1
View File
@@ -103,7 +103,7 @@ ZoneBuffer* BuildReturnConstantModule(Zone* zone, int constant) {
ZoneBuffer* buffer = zone->New<ZoneBuffer>(zone);
WasmModuleBuilder* builder = zone->New<WasmModuleBuilder>(zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
f->builder()->AddExport(base::CStrVector("main"), f);
f->builder()->AddExport("main", f);
f->EmitCode({WASM_I32V_2(constant), WASM_END});
builder->WriteTo(buffer);
return buffer;
+5 -5
View File
@@ -494,7 +494,7 @@ MaybeDirectHandle<WasmModuleObject> CompileReferenceModule(
}
// Create the module object.
constexpr base::Vector<const char> kNoSourceUrl;
constexpr std::string_view kNoSourceUrl;
DirectHandle<Script> script =
GetWasmEngine()->GetOrCreateScript(isolate, native_module, kNoSourceUrl);
TypeCanonicalizer::PrepareForCanonicalTypeId(
@@ -684,12 +684,12 @@ static std::optional<ExecutionResult> ExecuteNonReferenceRun(
int FindExportedMainFunction(const WasmModule* module,
base::Vector<const uint8_t> wire_bytes) {
constexpr base::Vector<const char> kMainName = base::StaticCharVector("main");
for (const WasmExport& exp : module->export_table) {
if (exp.kind != ImportExportKindCode::kExternalFunction) continue;
base::Vector<const uint8_t> name =
wire_bytes.SubVector(exp.name.offset(), exp.name.end_offset());
if (base::Vector<const char>::cast(name) != kMainName) continue;
std::string_view name(
reinterpret_cast<const char*>(wire_bytes.begin() + exp.name.offset()),
exp.name.length());
if (name != "main") continue;
return exp.index;
}
return -1;
+2 -3
View File
@@ -269,8 +269,7 @@ uint32_t TestingModuleBuilder::AddFunction(const FunctionSig* sig,
DCHECK_EQ(module_->functions.size(),
module_->num_imported_functions + module_->num_declared_functions);
if (name) {
base::Vector<const uint8_t> name_vec =
base::Vector<const uint8_t>::cast(base::CStrVector(name));
base::Vector<const uint8_t> name_vec = base::OneByteVector(name);
module_->lazily_generated_names.AddForTesting(
index, {AddBytes(name_vec), static_cast<uint32_t>(name_vec.size())});
}
@@ -494,7 +493,7 @@ DirectHandle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
module_->num_declared_functions = 0;
native_module->SetWireBytes(base::UniqueArray<const uint8_t>());
native_module->compilation_state()->set_compilation_id(0);
constexpr base::Vector<const char> kNoSourceUrl{"", 0};
constexpr std::string_view kNoSourceUrl{"", 0};
DirectHandle<Script> script =
GetWasmEngine()->GetOrCreateScript(isolate_, native_module, kNoSourceUrl);
+1 -1
View File
@@ -22,7 +22,7 @@ class WasmCodeFuzzer : public WasmExecutionFuzzer {
WasmFunctionBuilder* f = builder.AddFunction(sigs.i_iii());
f->EmitCode(data.begin(), static_cast<uint32_t>(data.size()));
f->Emit(kExprEnd);
builder.AddExport(base::CStrVector("main"), f);
builder.AddExport("main", f);
builder.AddMemory(0, 32);
builder.WriteTo(buffer);
@@ -18,7 +18,7 @@ bool GenerateModule(Isolate* isolate, Zone* zone,
WasmFunctionBuilder* f = builder.AddFunction(&sig_i_iii);
f->EmitCode(data.begin(), static_cast<uint32_t>(data.size()));
f->Emit(kExprEnd);
builder.AddExport(base::CStrVector("main"), f);
builder.AddExport("main", f);
builder.AddMemory(0, 32);
builder.WriteTo(buffer);
@@ -216,7 +216,7 @@ Handle<String> ExtractUtf8StringFromModuleBytes(
base::Vector<const uint8_t> name_vec =
wire_bytes.SubVector(ref.offset(), ref.end_offset());
return isolate->factory()->InternalizeUtf8String(
base::Vector<const char>::cast(name_vec));
{reinterpret_cast<const char*>(name_vec.begin()), name_vec.size()});
}
Handle<JSObject> CreateImportObjectInternal(
+12 -13
View File
@@ -12,28 +12,32 @@ namespace v8 {
namespace base {
TEST(VectorTest, Factories) {
auto vec = base::CStrVector("foo");
auto vec = base::OneByteVector("foo");
EXPECT_EQ(3u, vec.size());
EXPECT_EQ(0, memcmp(vec.begin(), "foo", 3));
vec = base::ArrayVector("foo");
EXPECT_EQ(4u, vec.size());
EXPECT_EQ(0, memcmp(vec.begin(), "foo\0", 4));
auto char_vec = base::ArrayVector("foo");
EXPECT_EQ(4u, char_vec.size());
EXPECT_EQ(0, memcmp(char_vec.begin(), "foo\0", 4));
vec = base::CStrVector("foo\0\0");
vec = base::OneByteVector("foo\0\0");
EXPECT_EQ(3u, vec.size());
EXPECT_EQ(0, memcmp(vec.begin(), "foo", 3));
vec = base::CStrVector("");
vec = base::OneByteVector("");
EXPECT_EQ(0u, vec.size());
vec = base::CStrVector("\0");
vec = base::OneByteVector("\0");
EXPECT_EQ(0u, vec.size());
vec = base::StaticOneByteVector("foo\0\0");
EXPECT_EQ(5u, vec.size());
EXPECT_EQ(0, memcmp(vec.begin(), "foo\0\0", 5));
}
// Test operator== and operator!= on different Vector types.
TEST(VectorTest, Equals) {
auto foo1 = base::CStrVector("foo");
auto foo1 = base::VectorOf("foo", 3);
auto foo2 = base::ArrayVector("ffoo") + 1;
EXPECT_EQ(4u, foo2.size()); // Includes trailing '\0'.
foo2.Truncate(foo2.size() - 1);
@@ -70,11 +74,6 @@ TEST(VectorTest, ConstexprFactories) {
static constexpr auto kVec2 = base::VectorOf(kInit1, 2);
static_assert(kVec2.size() == 2);
EXPECT_THAT(kVec2, testing::ElementsAre(4, 11));
static constexpr const char kInit3[] = "foobar";
static constexpr auto kVec3 = base::StaticCharVector(kInit3);
static_assert(kVec3.size() == 6);
EXPECT_THAT(kVec3, testing::ElementsAreArray(kInit3, kInit3 + 6));
}
TEST(VectorTest, SpanConversion) {
+5 -12
View File
@@ -51,9 +51,8 @@ static void SetGlobalProperty(const char* name, Tagged<Object> value) {
static DirectHandle<JSFunction> Compile(const char* source) {
Isolate* isolate = reinterpret_cast<i::Isolate*>(v8::Isolate::GetCurrent());
Handle<String> source_code = isolate->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
Handle<String> source_code =
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
ScriptCompiler::CompilationDetails compilation_details;
DirectHandle<SharedFunctionInfo> shared =
Compiler::GetSharedFunctionInfoForScript(
@@ -242,7 +241,7 @@ TEST_F(CompilerTestWithPrintExtension, C2JSFrames) {
EXPECT_TRUE(IsJSFunction(*fun1));
DirectHandle<Object> args[] = {
isolate->factory()->InternalizeString(base::StaticCharVector("hello"))};
isolate->factory()->InternalizeString("hello")};
Execution::Call(isolate, Cast<JSFunction>(fun1), global, base::VectorOf(args))
.Check();
}
@@ -956,10 +955,7 @@ TEST_F(BackgroundMergeTest, GCDuringMerge) {
" }"
"})";
IndirectHandle<String> source_string =
isolate()
->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
isolate()->factory()->NewStringFromUtf8(source).ToHandleChecked();
const int kTopLevelId = 0;
const int kFId = 1;
@@ -1162,10 +1158,7 @@ TEST_F(BackgroundMergeTest, MergeWithEval) {
" return eval('1');"
"};";
IndirectHandle<String> source_string =
isolate()
->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
isolate()->factory()->NewStringFromUtf8(source).ToHandleChecked();
ScriptCompiler::CompilationDetails compilation_details;
DirectHandle<SharedFunctionInfo> top_level_sfi =
+2 -4
View File
@@ -50,10 +50,8 @@ static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite,
// So we can get a real JS function.
static Handle<JSFunction> Compile(Isolate* isolate, std::string_view source) {
Handle<String> source_code = isolate->factory()
->NewStringFromUtf8(base::Vector<const char>(
source.data(), source.length()))
.ToHandleChecked();
Handle<String> source_code =
isolate->factory()->NewStringFromUtf8(source).ToHandleChecked();
ScriptCompiler::CompilationDetails compilation_details;
DirectHandle<SharedFunctionInfo> shared =
Compiler::GetSharedFunctionInfoForScript(
@@ -69,9 +69,7 @@ class LocalFactoryTest : public TestWithIsolateAndZone {
// Normally this would be an external string or whatever, we don't have to
// worry about it for now.
source_string_ = factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
source_string_ = factory()->NewStringFromUtf8(source).ToHandleChecked();
script_ = parse_info_.CreateScript(local_isolate(),
local_factory()->empty_string(),
@@ -67,12 +67,12 @@ TEST_F(StringTableTest, InternalizeUtf8String) {
const char* string = *ptr;
HandleScope scope(isolate());
DirectHandle<String> a =
factory()->InternalizeUtf8String(base::CStrVector(string));
factory()->InternalizeUtf8String(std::string_view(string));
EXPECT_TRUE(IsInternalizedString(*a));
DirectHandle<String> b = factory()->InternalizeUtf8String(string);
EXPECT_EQ(*b, *a);
EXPECT_TRUE(b->IsOneByteEqualTo(string));
b = factory()->InternalizeUtf8String(base::CStrVector(string));
b = factory()->InternalizeUtf8String(std::string_view(string));
EXPECT_EQ(*b, *a);
EXPECT_TRUE(b->IsOneByteEqualTo(string));
}
+7 -13
View File
@@ -190,8 +190,7 @@ class ParsingTest : public TestWithContextAndZone {
full_source += "; }";
i::DirectHandle<i::String> source_code =
factory->NewStringFromUtf8(base::CStrVector(full_source.c_str()))
.ToHandleChecked();
factory->NewStringFromUtf8(full_source).ToHandleChecked();
i::Handle<i::Script> script = factory->NewScript(source_code);
@@ -348,11 +347,8 @@ class ParsingTest : public TestWithContextAndZone {
size_t always_false_flags_length = 0,
bool is_module = false, bool test_preparser = true,
bool ignore_error_msg = false) {
i::Handle<i::String> str = i_isolate()
->factory()
->NewStringFromUtf8(base::Vector<const char>(
source, strlen(source)))
.ToHandleChecked();
i::Handle<i::String> str =
i_isolate()->factory()->NewStringFromUtf8(source).ToHandleChecked();
for (int bits = 0; bits < (1 << varying_flags_length); bits++) {
base::EnumSet<ParserFlag> flags;
for (size_t flag_index = 0; flag_index < varying_flags_length;
@@ -1425,8 +1421,7 @@ TEST_F(ParsingTest, ScopeUsesArgumentsSuperThis) {
base::SNPrintF(program.as_span(), "%s%s%s", surroundings[j].prefix,
source_data[i].body, surroundings[j].suffix);
i::DirectHandle<i::String> source =
factory->NewStringFromUtf8(base::CStrVector(program.begin()))
.ToHandleChecked();
factory->NewStringFromUtf8(program.begin()).ToHandleChecked();
i::Handle<i::Script> script = factory->NewScript(source);
i::UnoptimizedCompileState compile_state;
i::ReusableUnoptimizedCompileState reusable_state(isolate);
@@ -1758,8 +1753,7 @@ TEST_F(ParsingTest, ScopePositions) {
// Parse program source.
i::DirectHandle<i::String> source =
factory->NewStringFromUtf8(base::CStrVector(program.begin()))
.ToHandleChecked();
factory->NewStringFromUtf8(program.begin()).ToHandleChecked();
CHECK_EQ(source->length(), kProgramSize);
i::Handle<i::Script> script = factory->NewScript(source);
@@ -1808,7 +1802,7 @@ TEST_F(ParsingTest, DiscardFunctionBody) {
for (int i = 0; discard_sources[i]; i++) {
const char* source = discard_sources[i];
i::DirectHandle<i::String> source_code =
factory->NewStringFromUtf8(base::CStrVector(source)).ToHandleChecked();
factory->NewStringFromUtf8(source).ToHandleChecked();
i::Handle<i::Script> script = factory->NewScript(source_code);
i::UnoptimizedCompileState compile_state;
i::ReusableUnoptimizedCompileState reusable_state(isolate);
@@ -12974,7 +12968,7 @@ TEST_F(ParsingTest, LexicalLoopVariable) {
auto TestProgram = [isolate](const char* program, TestCB test) {
i::Factory* const factory = isolate->factory();
i::DirectHandle<i::String> source =
factory->NewStringFromUtf8(base::CStrVector(program)).ToHandleChecked();
factory->NewStringFromUtf8(program).ToHandleChecked();
i::Handle<i::Script> script = factory->NewScript(source);
i::UnoptimizedCompileState compile_state;
i::ReusableUnoptimizedCompileState reusable_state(isolate);
+1 -1
View File
@@ -116,7 +116,7 @@ void RegExpTest<T>::RunRegExp(const std::string& regexp_input,
// Convert input string.
i::MaybeDirectHandle<i::String> maybe_source =
factory_->NewStringFromUtf8(v8::base::CStrVector(regexp_input.c_str()));
factory_->NewStringFromUtf8(regexp_input);
i::DirectHandle<i::String> source;
if (!maybe_source.ToHandle(&source)) {
i_isolate_->clear_exception();
+2 -6
View File
@@ -595,13 +595,9 @@ static regexp::Node* Compile(const char* input, bool multiline, bool unicode,
return nullptr;
}
DirectHandle<String> pattern =
isolate->factory()
->NewStringFromUtf8(base::CStrVector(input))
.ToHandleChecked();
isolate->factory()->NewStringFromUtf8(input).ToHandleChecked();
DirectHandle<String> sample_subject =
isolate->factory()
->NewStringFromUtf8(base::CStrVector(""))
.ToHandleChecked();
isolate->factory()->NewStringFromUtf8("").ToHandleChecked();
DirectHandle<IrRegExpData> re_data =
TrustedCast<IrRegExpData>(isolate->factory()->NewIrRegExpData(
pattern, pattern, JSRegExp::AsJSRegExpFlags(flags),
+2 -2
View File
@@ -138,9 +138,9 @@ TEST(UtilsTest, PassesFilterTest) {
// which are hidden when the string literal is embedded into the binary
// and hence always null-terminated.
base::UniqueArray<const char> name =
base::UniqueCopyOf(base::CStrVector("abcdefgh"));
base::UniqueCopyOf(std::string_view("abcdefgh"));
base::UniqueArray<const char> filter =
base::UniqueCopyOf(base::CStrVector("abcdefgh*"));
base::UniqueCopyOf(std::string_view("abcdefgh*"));
EXPECT_TRUE(PassesFilter({name.begin(), name.size()},
{filter.begin(), filter.size()}));
}
@@ -46,7 +46,7 @@ class WasmCompilationHintsBuilder {
}
void AddExport(const char* name, uint32_t index) {
builder_.AddExport(base::CStrVector(name), kExternalFunction, index);
builder_.AddExport(name, kExternalFunction, index);
}
void CompileModule() {
+1 -1
View File
@@ -133,7 +133,7 @@ class WasmTracingTest : public TestWithContextAndZone {
WasmFunctionBuilder* f = builder.AddFunction(sig);
f->AddLocal(ValueType::Primitive(kI32));
f->builder()->AddExport(base::CStrVector("main"), f);
f->builder()->AddExport("main", f);
f->EmitCode(code.data(), static_cast<uint32_t>(code.size()));
+13 -16
View File
@@ -40,16 +40,15 @@ class WasmCapiCallbacksTest : public WasmCapiTest {
WasmCapiCallbacksTest() : WasmCapiTest() {
// Build the following function:
// int32 stage1(int32 arg0) { return stage2(arg0); }
uint32_t stage2_index =
builder()->AddImport(base::CStrVector("stage2"), wasm_i_i_sig());
uint32_t stage2_index = builder()->AddImport("stage2", wasm_i_i_sig());
uint8_t code[] = {WASM_CALL_FUNCTION(stage2_index, WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("stage1"), code, sizeof(code));
AddExportedFunction("stage1", code, sizeof(code));
stage2_ = Func::make(store(), cpp_i_i_sig(), Stage2, this);
}
Func* stage2() { return stage2_.get(); }
void AddExportedFunction(base::Vector<const char> name, uint8_t code[],
void AddExportedFunction(std::string_view name, uint8_t code[],
size_t code_size) {
WasmCapiTest::AddExportedFunction(name, code, code_size, wasm_i_i_sig());
}
@@ -64,7 +63,7 @@ TEST_F(WasmCapiCallbacksTest, Trap) {
// Build the following function:
// int32 stage3_trap(int32 arg0) { unreachable(); }
uint8_t code[] = {WASM_UNREACHABLE};
AddExportedFunction(base::CStrVector("stage3_trap"), code, sizeof(code));
AddExportedFunction("stage3_trap", code, sizeof(code));
vec<Extern*> imports = vec<Extern*>::make(stage2());
Instantiate(imports);
@@ -78,10 +77,9 @@ TEST_F(WasmCapiCallbacksTest, Trap) {
TEST_F(WasmCapiCallbacksTest, GC) {
// Build the following function:
// int32 stage3_to4(int32 arg0) { return stage4(arg0); }
uint32_t stage4_index =
builder()->AddImport(base::CStrVector("stage4"), wasm_i_i_sig());
uint32_t stage4_index = builder()->AddImport("stage4", wasm_i_i_sig());
uint8_t code[] = {WASM_CALL_FUNCTION(stage4_index, WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("stage3_to4"), code, sizeof(code));
AddExportedFunction("stage3_to4", code, sizeof(code));
i::Isolate* isolate =
reinterpret_cast<::wasm::StoreImpl*>(store())->i_isolate();
@@ -131,8 +129,7 @@ TEST_F(WasmCapiTest, Recursion) {
// if (arg0 == 1) return 1;
// return fibonacci_c(arg0 - 1) + fibonacci_c(arg0 - 2);
// }
uint32_t fibo_c_index =
builder()->AddImport(base::CStrVector("fibonacci_c"), wasm_i_i_sig());
uint32_t fibo_c_index = builder()->AddImport("fibonacci_c", wasm_i_i_sig());
uint8_t code_fibo[] = {
WASM_IF(WASM_I32_EQ(WASM_LOCAL_GET(0), WASM_ZERO),
WASM_RETURN(WASM_ZERO)),
@@ -143,8 +140,8 @@ TEST_F(WasmCapiTest, Recursion) {
WASM_CALL_FUNCTION(fibo_c_index, WASM_LOCAL_GET(0)),
WASM_CALL_FUNCTION(fibo_c_index,
WASM_I32_SUB(WASM_LOCAL_GET(0), WASM_ONE))))};
AddExportedFunction(base::CStrVector("fibonacci_wasm"), code_fibo,
sizeof(code_fibo), wasm_i_i_sig());
AddExportedFunction("fibonacci_wasm", code_fibo, sizeof(code_fibo),
wasm_i_i_sig());
own<Func> fibonacci = Func::make(store(), cpp_i_i_sig(), FibonacciC, this);
vec<Extern*> imports = vec<Extern*>::make(fibonacci.get());
@@ -222,8 +219,8 @@ TEST_F(WasmCapiTest, DirectCallCapiFunction) {
kWasmExternRef, kWasmI32, kWasmI64, kWasmF32,
kWasmF64, kWasmExternRef};
FunctionSig wasm_sig(5, 5, wasm_types);
int func_index = builder()->AddImport(base::CStrVector("func"), &wasm_sig);
builder()->ExportImportedFunction(base::CStrVector("func"), func_index);
int func_index = builder()->AddImport("func", &wasm_sig);
builder()->ExportImportedFunction("func", func_index);
Instantiate(imports);
int32_t a0 = 42;
int64_t a1 = 0x1234c0ffee;
@@ -292,8 +289,8 @@ TEST_F(WasmCapiTest, DirectCallCapiFunctionWithManyArgs) {
kWasmExternRef, kWasmI32, kWasmI64, kWasmF32, kWasmF64, kWasmI32,
kWasmI64, kWasmF32, kWasmF64, kWasmI32};
FunctionSig wasm_sig(14, 14, wasm_types);
int func_index = builder()->AddImport(base::CStrVector("func"), &wasm_sig);
builder()->ExportImportedFunction(base::CStrVector("func"), func_index);
int func_index = builder()->AddImport("func", &wasm_sig);
builder()->ExportImportedFunction("func", func_index);
Instantiate(imports);
int32_t a0 = 42;
int64_t a1 = 0x1234c0ffee;
+3 -5
View File
@@ -69,8 +69,7 @@ void RunInStore(Store* store, base::Vector<const uint8_t> wire_bytes,
TEST_F(WasmCapiTest, InstanceFinalization) {
// Add a dummy function: f(x) { return x; }
uint8_t code[] = {WASM_RETURN(WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("f"), code, sizeof(code),
wasm_i_i_sig());
AddExportedFunction("f", code, sizeof(code), wasm_i_i_sig());
Compile();
g_instances_finalized = 0;
g_functions_finalized = 0;
@@ -121,9 +120,8 @@ void FinalizeHostData(void* data) {
} // namespace
TEST_F(WasmCapiTest, CapiFunctionLifetimes) {
uint32_t func_index =
builder()->AddImport(base::CStrVector("f"), wasm_i_i_sig());
builder()->ExportImportedFunction(base::CStrVector("f"), func_index);
uint32_t func_index = builder()->AddImport("f", wasm_i_i_sig());
builder()->ExportImportedFunction("f", func_index);
Compile();
own<Instance> instance;
void* kHostData = reinterpret_cast<void*>(1234);
+27 -41
View File
@@ -15,32 +15,30 @@ TEST_F(WasmCapiTest, Globals) {
const bool kImmutable = false;
// Define imported and exported globals in the module.
const uint32_t cfi_index = builder()->AddGlobalImport(
base::CStrVector("const f32"), kWasmF32, kImmutable);
const uint32_t cii_index = builder()->AddGlobalImport(
base::CStrVector("const i64"), kWasmI64, kImmutable);
const uint32_t vfi_index = builder()->AddGlobalImport(
base::CStrVector("var f32"), kWasmF32, kMutable);
const uint32_t vii_index = builder()->AddGlobalImport(
base::CStrVector("var i64"), kWasmI64, kMutable);
const uint32_t cfi_index =
builder()->AddGlobalImport("const f32", kWasmF32, kImmutable);
const uint32_t cii_index =
builder()->AddGlobalImport("const i64", kWasmI64, kImmutable);
const uint32_t vfi_index =
builder()->AddGlobalImport("var f32", kWasmF32, kMutable);
const uint32_t vii_index =
builder()->AddGlobalImport("var i64", kWasmI64, kMutable);
const int kNumImported = 4;
const uint32_t cfe_index =
kNumImported +
builder()->AddExportedGlobal(kWasmF32, kImmutable, WasmInitExpr(5.f),
base::CStrVector("const f32"));
const uint32_t cie_index =
kNumImported + builder()->AddExportedGlobal(
kWasmI64, kImmutable, WasmInitExpr(int64_t{6}),
base::CStrVector("const i64"));
kWasmF32, kImmutable, WasmInitExpr(5.f), "const f32");
const uint32_t cie_index =
kNumImported + builder()->AddExportedGlobal(kWasmI64, kImmutable,
WasmInitExpr(int64_t{6}),
"const i64");
const uint32_t vfe_index =
kNumImported + builder()->AddExportedGlobal(kWasmF32, kMutable,
WasmInitExpr(7.f),
base::CStrVector("var f32"));
WasmInitExpr(7.f), "var f32");
const uint32_t vie_index =
kNumImported + builder()->AddExportedGlobal(kWasmI64, kMutable,
WasmInitExpr(int64_t{8}),
base::CStrVector("var i64"));
"var i64");
// Define functions for inspecting globals.
ValueType f32_type[] = {kWasmF32};
@@ -48,46 +46,34 @@ TEST_F(WasmCapiTest, Globals) {
FunctionSig return_f32(1, 0, f32_type);
FunctionSig return_i64(1, 0, i64_type);
uint8_t gcfi[] = {WASM_GLOBAL_GET(cfi_index)};
AddExportedFunction(base::CStrVector("get const f32 import"), gcfi,
sizeof(gcfi), &return_f32);
AddExportedFunction("get const f32 import", gcfi, sizeof(gcfi), &return_f32);
uint8_t gcii[] = {WASM_GLOBAL_GET(cii_index)};
AddExportedFunction(base::CStrVector("get const i64 import"), gcii,
sizeof(gcii), &return_i64);
AddExportedFunction("get const i64 import", gcii, sizeof(gcii), &return_i64);
uint8_t gvfi[] = {WASM_GLOBAL_GET(vfi_index)};
AddExportedFunction(base::CStrVector("get var f32 import"), gvfi,
sizeof(gvfi), &return_f32);
AddExportedFunction("get var f32 import", gvfi, sizeof(gvfi), &return_f32);
uint8_t gvii[] = {WASM_GLOBAL_GET(vii_index)};
AddExportedFunction(base::CStrVector("get var i64 import"), gvii,
sizeof(gvii), &return_i64);
AddExportedFunction("get var i64 import", gvii, sizeof(gvii), &return_i64);
uint8_t gcfe[] = {WASM_GLOBAL_GET(cfe_index)};
AddExportedFunction(base::CStrVector("get const f32 export"), gcfe,
sizeof(gcfe), &return_f32);
AddExportedFunction("get const f32 export", gcfe, sizeof(gcfe), &return_f32);
uint8_t gcie[] = {WASM_GLOBAL_GET(cie_index)};
AddExportedFunction(base::CStrVector("get const i64 export"), gcie,
sizeof(gcie), &return_i64);
AddExportedFunction("get const i64 export", gcie, sizeof(gcie), &return_i64);
uint8_t gvfe[] = {WASM_GLOBAL_GET(vfe_index)};
AddExportedFunction(base::CStrVector("get var f32 export"), gvfe,
sizeof(gvfe), &return_f32);
AddExportedFunction("get var f32 export", gvfe, sizeof(gvfe), &return_f32);
uint8_t gvie[] = {WASM_GLOBAL_GET(vie_index)};
AddExportedFunction(base::CStrVector("get var i64 export"), gvie,
sizeof(gvie), &return_i64);
AddExportedFunction("get var i64 export", gvie, sizeof(gvie), &return_i64);
// Define functions for manipulating globals.
FunctionSig param_f32(0, 1, f32_type);
FunctionSig param_i64(0, 1, i64_type);
uint8_t svfi[] = {WASM_GLOBAL_SET(vfi_index, WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("set var f32 import"), svfi,
sizeof(svfi), &param_f32);
AddExportedFunction("set var f32 import", svfi, sizeof(svfi), &param_f32);
uint8_t svii[] = {WASM_GLOBAL_SET(vii_index, WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("set var i64 import"), svii,
sizeof(svii), &param_i64);
AddExportedFunction("set var i64 import", svii, sizeof(svii), &param_i64);
uint8_t svfe[] = {WASM_GLOBAL_SET(vfe_index, WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("set var f32 export"), svfe,
sizeof(svfe), &param_f32);
AddExportedFunction("set var f32 export", svfe, sizeof(svfe), &param_f32);
uint8_t svie[] = {WASM_GLOBAL_SET(vie_index, WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("set var i64 export"), svie,
sizeof(svie), &param_i64);
AddExportedFunction("set var i64 export", svie, sizeof(svie), &param_i64);
// Create imported globals.
own<GlobalType> const_f32_type = GlobalType::make(
+13 -13
View File
@@ -32,31 +32,31 @@ TEST_F(WasmCapiTest, HostRef) {
FunctionSig r_v_sig(1, 0, rr_reps);
FunctionSig v_ir_sig(0, 2, ir_reps);
FunctionSig r_i_sig(1, 1, ri_reps);
uint32_t func_index = builder()->AddImport(base::CStrVector("f"), &r_r_sig);
uint32_t func_index = builder()->AddImport("f", &r_r_sig);
const bool kMutable = true;
uint32_t global_index = builder()->AddExportedGlobal(
kWasmExternRef, kMutable, WasmInitExpr::RefNullConst(kWasmExternRef),
base::CStrVector("global"));
"global");
uint32_t table_index = builder()->AddTable(kWasmExternRef, 10);
builder()->AddExport(base::CStrVector("table"), kExternalTable, table_index);
builder()->AddExport("table", kExternalTable, table_index);
uint8_t global_set_code[] = {
WASM_GLOBAL_SET(global_index, WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("global.set"), global_set_code,
sizeof(global_set_code), &v_r_sig);
AddExportedFunction("global.set", global_set_code, sizeof(global_set_code),
&v_r_sig);
uint8_t global_get_code[] = {WASM_GLOBAL_GET(global_index)};
AddExportedFunction(base::CStrVector("global.get"), global_get_code,
sizeof(global_get_code), &r_v_sig);
AddExportedFunction("global.get", global_get_code, sizeof(global_get_code),
&r_v_sig);
uint8_t table_set_code[] = {
WASM_TABLE_SET(table_index, WASM_LOCAL_GET(0), WASM_LOCAL_GET(1))};
AddExportedFunction(base::CStrVector("table.set"), table_set_code,
sizeof(table_set_code), &v_ir_sig);
AddExportedFunction("table.set", table_set_code, sizeof(table_set_code),
&v_ir_sig);
uint8_t table_get_code[] = {WASM_TABLE_GET(table_index, WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("table.get"), table_get_code,
sizeof(table_get_code), &r_i_sig);
AddExportedFunction("table.get", table_get_code, sizeof(table_get_code),
&r_i_sig);
uint8_t func_call_code[] = {
WASM_CALL_FUNCTION(func_index, WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("func.call"), func_call_code,
sizeof(func_call_code), &r_r_sig);
AddExportedFunction("func.call", func_call_code, sizeof(func_call_code),
&r_r_sig);
own<FuncType> func_type = FuncType::make(
ownvec<ValType>::make(ValType::make(::wasm::ValKind::EXTERNREF)),
+4 -6
View File
@@ -13,22 +13,20 @@ using ::wasm::MemoryType;
TEST_F(WasmCapiTest, Memory) {
builder()->AddMemory(2, 3);
builder()->AddExport(base::CStrVector("memory"), kExternalMemory, 0);
builder()->AddExport("memory", kExternalMemory, 0);
ValueType i32_type[] = {kWasmI32, kWasmI32};
FunctionSig return_i32(1, 0, i32_type);
FunctionSig param_i32_return_i32(1, 1, i32_type);
FunctionSig param_i32_i32(0, 2, i32_type);
uint8_t size_code[] = {WASM_MEMORY_SIZE};
AddExportedFunction(base::CStrVector("size"), size_code, sizeof(size_code),
&return_i32);
AddExportedFunction("size", size_code, sizeof(size_code), &return_i32);
uint8_t load_code[] = {WASM_LOAD_MEM(MachineType::Int8(), WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("load"), load_code, sizeof(load_code),
AddExportedFunction("load", load_code, sizeof(load_code),
&param_i32_return_i32);
uint8_t store_code[] = {WASM_STORE_MEM(MachineType::Int8(), WASM_LOCAL_GET(0),
WASM_LOCAL_GET(1))};
AddExportedFunction(base::CStrVector("store"), store_code, sizeof(store_code),
&param_i32_i32);
AddExportedFunction("store", store_code, sizeof(store_code), &param_i32_i32);
uint8_t data[] = {0x1, 0x2, 0x3, 0x4};
builder()->AddDataSegment(data, sizeof(data), 0x1000);
+2 -2
View File
@@ -27,11 +27,11 @@ TEST_F(WasmCapiTest, MultiReturn) {
ValueType reps[] = {kWasmI32, kWasmI64, kWasmI64, kWasmI32,
kWasmI32, kWasmI64, kWasmI64, kWasmI32};
FunctionSig sig(4, 4, reps);
uint32_t func_index = builder()->AddImport(base::CStrVector("f"), &sig);
uint32_t func_index = builder()->AddImport("f", &sig);
uint8_t code[] = {WASM_CALL_FUNCTION(func_index, WASM_LOCAL_GET(0),
WASM_LOCAL_GET(2), WASM_LOCAL_GET(1),
WASM_LOCAL_GET(3))};
AddExportedFunction(base::CStrVector("g"), code, sizeof(code), &sig);
AddExportedFunction("g", code, sizeof(code), &sig);
ownvec<ValType> types =
ownvec<ValType>::make(ValType::make(I32), ValType::make(I64),
+4 -5
View File
@@ -39,16 +39,15 @@ TEST_F(WasmCapiTest, Reflect) {
ValueType types[] = {kWasmI32, kWasmExternRef, kWasmI32,
kWasmI64, kWasmF32, kWasmF64};
FunctionSig sig(2, 4, types);
AddExportedFunction(base::CStrVector(kFuncName), code, sizeof(code), &sig);
AddExportedFunction(kFuncName, code, sizeof(code), &sig);
builder()->AddExportedGlobal(kWasmF64, false, WasmInitExpr(0.0),
base::CStrVector(kGlobalName));
builder()->AddExportedGlobal(kWasmF64, false, WasmInitExpr(0.0), kGlobalName);
builder()->AddTable(kWasmFuncRef, 12, 12);
builder()->AddExport(base::CStrVector(kTableName), kExternalTable, 0);
builder()->AddExport(kTableName, kExternalTable, 0);
builder()->AddMemory(1);
builder()->AddExport(base::CStrVector(kMemoryName), kExternalMemory, 0);
builder()->AddExport(kMemoryName, kExternalMemory, 0);
vec<Extern*> imports = vec<Extern*>::make_uninitialized();
Instantiate(imports);
+1 -1
View File
@@ -13,7 +13,7 @@ TEST_F(WasmCapiTest, Regressions) {
WasmFunctionBuilder* start_func = builder()->AddFunction(&sig);
start_func->EmitCode({WASM_UNREACHABLE, WASM_END});
builder()->MarkStartFunction(start_func);
builder()->AddImport(base::CStrVector("dummy"), &sig);
builder()->AddImport("dummy", &sig);
// Ensure we can validate.
bool valid = Validate();
+2 -3
View File
@@ -24,10 +24,9 @@ own<Trap> Callback(const vec<Val>& args, vec<Val>& results) {
TEST_F(WasmCapiTest, Serialize) {
FunctionSig sig(0, 0, nullptr);
uint32_t callback_index =
builder()->AddImport(base::CStrVector("callback"), &sig);
uint32_t callback_index = builder()->AddImport("callback", &sig);
uint8_t code[] = {WASM_CALL_FUNCTION0(callback_index)};
AddExportedFunction(base::CStrVector("run"), code, sizeof(code), &sig);
AddExportedFunction("run", code, sizeof(code), &sig);
Compile();
vec<byte_t> serialized = module()->serialize();
+1 -1
View File
@@ -21,7 +21,7 @@ TEST_F(WasmCapiTest, StartupErrors) {
WasmFunctionBuilder* start_func = builder()->AddFunction(&sig);
start_func->EmitCode({WASM_UNREACHABLE, WASM_END});
builder()->MarkStartFunction(start_func);
builder()->AddImport(base::CStrVector("dummy"), &sig);
builder()->AddImport("dummy", &sig);
Compile();
own<Trap> trap;
+4 -7
View File
@@ -39,21 +39,18 @@ void ExpectResult(int expected, const Func* func, int arg1, int arg2) {
TEST_F(WasmCapiTest, Table) {
const uint32_t table_index = builder()->AddTable(kWasmFuncRef, 2, 10);
builder()->AddExport(base::CStrVector("table"), kExternalTable, table_index);
builder()->AddExport("table", kExternalTable, table_index);
const ModuleTypeIndex sig_i_i_index =
builder()->AddSignature(wasm_i_i_sig(), true);
ValueType reps[] = {kWasmI32, kWasmI32, kWasmI32};
FunctionSig call_sig(1, 2, reps);
uint8_t call_code[] = {
WASM_CALL_INDIRECT(sig_i_i_index, WASM_LOCAL_GET(0), WASM_LOCAL_GET(1))};
AddExportedFunction(base::CStrVector("call_indirect"), call_code,
sizeof(call_code), &call_sig);
AddExportedFunction("call_indirect", call_code, sizeof(call_code), &call_sig);
uint8_t f_code[] = {WASM_LOCAL_GET(0)};
AddExportedFunction(base::CStrVector("f"), f_code, sizeof(f_code),
wasm_i_i_sig());
AddExportedFunction("f", f_code, sizeof(f_code), wasm_i_i_sig());
uint8_t g_code[] = {WASM_I32V_1(42)};
AddExportedFunction(base::CStrVector("g"), g_code, sizeof(g_code),
wasm_i_i_sig());
AddExportedFunction("g", g_code, sizeof(g_code), wasm_i_i_sig());
// Set table[1] to {f}, which has function index 1.
builder()->SetIndirectFunction(table_index, 1, 1);
+3 -5
View File
@@ -75,15 +75,13 @@ TEST_F(WasmCapiTest, Threads) {
// Create module.
ValueType i32_type[] = {kWasmI32};
FunctionSig param_i32(0, 1, i32_type);
uint32_t callback_index =
builder()->AddImport(base::CStrVector("callback"), &param_i32);
uint32_t global_index =
builder()->AddGlobalImport(base::CStrVector("id"), kWasmI32, false);
uint32_t callback_index = builder()->AddImport("callback", &param_i32);
uint32_t global_index = builder()->AddGlobalImport("id", kWasmI32, false);
uint8_t code[] = {
WASM_CALL_FUNCTION(callback_index, WASM_GLOBAL_GET(global_index))};
FunctionSig empty_sig(0, 0, nullptr);
AddExportedFunction(base::CStrVector("run"), code, sizeof(code), &empty_sig);
AddExportedFunction("run", code, sizeof(code), &empty_sig);
Compile();
own<Shared<Module>> shared = module()->share();
+4 -7
View File
@@ -36,14 +36,12 @@ void ExpectMessage(const char* expected, const Message& message) {
TEST_F(WasmCapiTest, Traps) {
ValueType i32_type[] = {kWasmI32};
FunctionSig sig(1, 0, i32_type);
uint32_t callback_index =
builder()->AddImport(base::CStrVector("callback"), &sig);
uint32_t callback_index = builder()->AddImport("callback", &sig);
uint8_t code[] = {WASM_CALL_FUNCTION0(callback_index)};
AddExportedFunction(base::CStrVector("callback"), code, sizeof(code), &sig);
AddExportedFunction("callback", code, sizeof(code), &sig);
uint8_t code2[] = {WASM_CALL_FUNCTION0(3)};
AddExportedFunction(base::CStrVector("unreachable"), code2, sizeof(code2),
&sig);
AddExportedFunction("unreachable", code2, sizeof(code2), &sig);
// The first constant is a 4-byte dummy so that the {unreachable} trap
// has a more interesting offset. This is called by code2.
uint8_t code3[] = {WASM_I32V_3(0), WASM_UNREACHABLE, WASM_I32V_1(1)};
@@ -52,8 +50,7 @@ TEST_F(WasmCapiTest, Traps) {
// Check that traps returned from a C callback are uncatchable in Wasm.
uint8_t code4[] = {WASM_TRY_CATCH_ALL_T(
kWasmI32, WASM_CALL_FUNCTION0(callback_index), WASM_I32V(42))};
AddExportedFunction(base::CStrVector("uncatchable"), code4, sizeof(code4),
&sig);
AddExportedFunction("uncatchable", code4, sizeof(code4), &sig);
own<FuncType> func_type = FuncType::make(
ownvec<ValType>::make(),
+1 -1
View File
@@ -88,7 +88,7 @@ class WasmCapiTest : public ::testing::Test {
exports_ = instance_->exports();
}
void AddExportedFunction(base::Vector<const char> name, uint8_t code[],
void AddExportedFunction(std::string_view name, uint8_t code[],
size_t code_size, FunctionSig* sig) {
WasmFunctionBuilder* fun = builder()->AddFunction(sig);
fun->EmitCode(code, static_cast<uint32_t>(code_size));