[wasm] Clean up decoder constructor(s)

1) Pass {WasmFeatures} by value, it's a single word.
2) Pass a {base::Vector} instead of {start} and {end} pair.
3) Remove a redundant constructor (just pass an empty wire bytes vector
   instead).

R=thibaudm@chromium.org

Change-Id: I337c3c86960505ae23c88cb6adc5646a61111f76
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4030434
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Thibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/main@{#84382}
This commit is contained in:
Clemens Backes 2022-11-18 16:53:15 +01:00 committed by V8 LUCI CQ
parent ced7875a08
commit 6aaab3291b
19 changed files with 261 additions and 286 deletions

View File

@ -805,7 +805,7 @@ bool BackgroundCompileScope::cancelled() const {
Impl(native_module_->compilation_state())->cancelled();
}
void UpdateFeatureUseCounts(Isolate* isolate, const WasmFeatures& detected) {
void UpdateFeatureUseCounts(Isolate* isolate, WasmFeatures detected) {
using Feature = v8::Isolate::UseCounterFeature;
constexpr static std::pair<WasmFeature, Feature> kUseCounters[] = {
{kFeature_reftypes, Feature::kWasmRefTypes},
@ -920,7 +920,7 @@ const WasmCompilationHint* GetCompilationHint(const WasmModule* module,
}
CompileStrategy GetCompileStrategy(const WasmModule* module,
const WasmFeatures& enabled_features,
WasmFeatures enabled_features,
uint32_t func_index, bool lazy_module) {
if (lazy_module) return CompileStrategy::kLazy;
if (!enabled_features.has_compilation_hints()) {
@ -1762,7 +1762,7 @@ std::unique_ptr<CompilationUnitBuilder> InitializeCompilation(
}
bool MayCompriseLazyFunctions(const WasmModule* module,
const WasmFeatures& enabled_features) {
WasmFeatures enabled_features) {
if (IsLazyModule(module)) return true;
if (enabled_features.has_compilation_hints()) return true;
#ifdef ENABLE_SLOW_DCHECKS
@ -1983,7 +1983,7 @@ class BackgroundCompileJob final : public JobTask {
} // namespace
std::shared_ptr<NativeModule> CompileToNativeModule(
Isolate* isolate, const WasmFeatures& enabled, ErrorThrower* thrower,
Isolate* isolate, WasmFeatures enabled_features, ErrorThrower* thrower,
std::shared_ptr<const WasmModule> module, ModuleWireBytes wire_bytes,
int compilation_id, v8::metrics::Recorder::ContextId context_id,
ProfileInformation* pgo_info) {
@ -2019,8 +2019,8 @@ std::shared_ptr<NativeModule> CompileToNativeModule(
wasm::WasmCodeManager::EstimateNativeModuleCodeSize(
module.get(), include_liftoff,
DynamicTiering{v8_flags.wasm_dynamic_tiering.value()});
native_module =
engine->NewNativeModule(isolate, enabled, module, code_size_estimate);
native_module = engine->NewNativeModule(isolate, enabled_features, module,
code_size_estimate);
native_module->SetWireBytes(std::move(wire_bytes_copy));
native_module->compilation_state()->set_compilation_id(compilation_id);
// Sync compilation is user blocking, so we increase the priority.
@ -2090,13 +2090,13 @@ void RecompileNativeModule(NativeModule* native_module,
}
AsyncCompileJob::AsyncCompileJob(
Isolate* isolate, const WasmFeatures& enabled,
Isolate* isolate, WasmFeatures enabled_features,
std::unique_ptr<byte[]> bytes_copy, size_t length, Handle<Context> context,
Handle<Context> incumbent_context, const char* api_method_name,
std::shared_ptr<CompilationResultResolver> resolver, int compilation_id)
: isolate_(isolate),
api_method_name_(api_method_name),
enabled_features_(enabled),
enabled_features_(enabled_features),
dynamic_tiering_(DynamicTiering{v8_flags.wasm_dynamic_tiering.value()}),
start_time_(base::TimeTicks::Now()),
bytes_copy_(std::move(bytes_copy)),
@ -2581,8 +2581,8 @@ class AsyncCompileJob::DecodeModule : public AsyncCompileJob::CompileStep {
"wasm.DecodeModule");
auto enabled_features = job->enabled_features_;
result = DecodeWasmModule(
enabled_features, job->wire_bytes_.start(), job->wire_bytes_.end(),
false, kWasmOrigin, counters_, metrics_recorder_, job->context_id(),
enabled_features, job->wire_bytes_.module_bytes(), false, kWasmOrigin,
counters_, metrics_recorder_, job->context_id(),
DecodingMethod::kAsync, GetWasmEngine()->allocator());
// Validate lazy functions here if requested.

View File

@ -56,7 +56,7 @@ struct WasmModule;
V8_EXPORT_PRIVATE
std::shared_ptr<NativeModule> CompileToNativeModule(
Isolate* isolate, const WasmFeatures& enabled, ErrorThrower* thrower,
Isolate* isolate, WasmFeatures enabled_features, ErrorThrower* thrower,
std::shared_ptr<const WasmModule> module, ModuleWireBytes wire_bytes,
int compilation_id, v8::metrics::Recorder::ContextId context_id,
ProfileInformation* pgo_info);
@ -138,7 +138,7 @@ class WrapperQueue {
// TODO(wasm): factor out common parts of this with the synchronous pipeline.
class AsyncCompileJob {
public:
AsyncCompileJob(Isolate* isolate, const WasmFeatures& enabled_features,
AsyncCompileJob(Isolate* isolate, WasmFeatures enabled_features,
std::unique_ptr<byte[]> bytes_copy, size_t length,
Handle<Context> context, Handle<Context> incumbent_context,
const char* api_method_name,

View File

@ -307,28 +307,16 @@ WasmSectionIterator(Decoder*, T&) -> WasmSectionIterator<T>;
template <class Tracer>
class ModuleDecoderTemplate : public Decoder {
public:
explicit ModuleDecoderTemplate(const WasmFeatures& enabled,
ModuleOrigin origin, Tracer& tracer)
: Decoder(nullptr, nullptr),
enabled_features_(enabled),
ModuleDecoderTemplate(WasmFeatures enabled_features,
base::Vector<const uint8_t> wire_bytes,
ModuleOrigin origin, Tracer& tracer)
: Decoder(wire_bytes),
enabled_features_(enabled_features),
module_start_(wire_bytes.begin()),
module_end_(wire_bytes.end()),
tracer_(tracer),
origin_(origin) {}
ModuleDecoderTemplate(const WasmFeatures& enabled, const byte* module_start,
const byte* module_end, ModuleOrigin origin,
Tracer& tracer)
: Decoder(module_start, module_end),
enabled_features_(enabled),
module_start_(module_start),
module_end_(module_end),
tracer_(tracer),
origin_(origin) {
if (end_ < start_) {
error(start_, "end is less than start");
end_ = start_;
}
}
void onFirstError() override {
pc_ = end_; // On error, terminate section decoding loop.
}
@ -2420,7 +2408,7 @@ class ModuleDecoderTemplate : public Decoder {
// validation error in {this} decoder.
class ValidateFunctionsTask : public JobTask {
public:
ValidateFunctionsTask(ModuleDecoderTemplate* decoder)
explicit ValidateFunctionsTask(ModuleDecoderTemplate* decoder)
: decoder_(decoder),
next_function_(decoder->module_->num_imported_functions),
after_last_function_(next_function_ +

View File

@ -74,38 +74,33 @@ const char* SectionName(SectionCode code) {
// but that doesn't work with the forward declaration in the header file.
class ModuleDecoderImpl : public ModuleDecoderTemplate<NoTracer> {
public:
ModuleDecoderImpl(const WasmFeatures& enabled, ModuleOrigin origin)
: ModuleDecoderTemplate<NoTracer>(enabled, origin, no_tracer_) {}
ModuleDecoderImpl(const WasmFeatures& enabled, const byte* module_start,
const byte* module_end, ModuleOrigin origin)
: ModuleDecoderTemplate<NoTracer>(enabled, module_start, module_end,
origin, no_tracer_) {}
ModuleDecoderImpl(WasmFeatures enabled_features,
base::Vector<const uint8_t> wire_bytes, ModuleOrigin origin)
: ModuleDecoderTemplate<NoTracer>(enabled_features, wire_bytes, origin,
no_tracer_) {}
private:
NoTracer no_tracer_;
};
ModuleResult DecodeWasmModule(
const WasmFeatures& enabled, const byte* module_start,
const byte* module_end, bool validate_functions, ModuleOrigin origin,
Counters* counters, std::shared_ptr<metrics::Recorder> metrics_recorder,
WasmFeatures enabled_features, base::Vector<const uint8_t> wire_bytes,
bool validate_functions, ModuleOrigin origin, Counters* counters,
std::shared_ptr<metrics::Recorder> metrics_recorder,
v8::metrics::Recorder::ContextId context_id, DecodingMethod decoding_method,
AccountingAllocator* allocator) {
size_t size = module_end - module_start;
CHECK_LE(module_start, module_end);
size_t max_size = max_module_size();
if (size > max_size) {
return ModuleResult{
WasmError{0, "size > maximum module size (%zu): %zu", max_size, size}};
if (wire_bytes.size() > max_size) {
return ModuleResult{WasmError{0, "size > maximum module size (%zu): %zu",
max_size, wire_bytes.size()}};
}
// TODO(bradnelson): Improve histogram handling of size_t.
auto size_counter =
SELECT_WASM_COUNTER(counters, origin, wasm, module_size_bytes);
size_counter->AddSample(static_cast<int>(size));
size_counter->AddSample(static_cast<int>(wire_bytes.size()));
// Signatures are stored in zone memory, which have the same lifetime
// as the {module}.
ModuleDecoderImpl decoder(enabled, module_start, module_end, origin);
ModuleDecoderImpl decoder(enabled_features, wire_bytes, origin);
v8::metrics::WasmModuleDecoded metrics_event;
base::ElapsedTimer timer;
timer.Start();
@ -132,23 +127,21 @@ ModuleResult DecodeWasmModule(
} else if (auto&& module = decoder.shared_module()) {
metrics_event.function_count = module->num_declared_functions;
}
metrics_event.module_size_in_bytes = size;
metrics_event.module_size_in_bytes = wire_bytes.size();
metrics_recorder->DelayMainThreadEvent(metrics_event, context_id);
return result;
}
ModuleResult DecodeWasmModuleForDisassembler(const byte* module_start,
const byte* module_end,
AccountingAllocator* allocator) {
ModuleResult DecodeWasmModuleForDisassembler(
base::Vector<const uint8_t> wire_bytes, AccountingAllocator* allocator) {
constexpr bool validate_functions = false;
ModuleDecoderImpl decoder(WasmFeatures::All(), module_start, module_end,
kWasmOrigin);
ModuleDecoderImpl decoder(WasmFeatures::All(), wire_bytes, kWasmOrigin);
return decoder.DecodeModule(nullptr, allocator, validate_functions);
}
ModuleDecoder::ModuleDecoder(const WasmFeatures& enabled)
: enabled_features_(enabled) {}
ModuleDecoder::ModuleDecoder(WasmFeatures enabled_features)
: enabled_features_(enabled_features) {}
ModuleDecoder::~ModuleDecoder() = default;
@ -161,7 +154,8 @@ void ModuleDecoder::StartDecoding(
v8::metrics::Recorder::ContextId context_id, AccountingAllocator* allocator,
ModuleOrigin origin) {
DCHECK_NULL(impl_);
impl_.reset(new ModuleDecoderImpl(enabled_features_, origin));
static constexpr base::Vector<const uint8_t> kNoWireBytes{nullptr, 0};
impl_.reset(new ModuleDecoderImpl(enabled_features_, kNoWireBytes, origin));
impl_->StartDecoding(counters, allocator);
}
@ -206,34 +200,31 @@ size_t ModuleDecoder::IdentifyUnknownSection(ModuleDecoder* decoder,
bool ModuleDecoder::ok() { return impl_->ok(); }
Result<const FunctionSig*> DecodeWasmSignatureForTesting(
const WasmFeatures& enabled, Zone* zone, const byte* start,
const byte* end) {
ModuleDecoderImpl decoder(enabled, start, end, kWasmOrigin);
return decoder.toResult(decoder.DecodeFunctionSignature(zone, start));
WasmFeatures enabled_features, Zone* zone,
base::Vector<const uint8_t> bytes) {
ModuleDecoderImpl decoder(enabled_features, bytes, kWasmOrigin);
return decoder.toResult(decoder.DecodeFunctionSignature(zone, bytes.begin()));
}
ConstantExpression DecodeWasmInitExprForTesting(const WasmFeatures& enabled,
const byte* start,
const byte* end,
ValueType expected) {
ModuleDecoderImpl decoder(enabled, start, end, kWasmOrigin);
ConstantExpression DecodeWasmInitExprForTesting(
WasmFeatures enabled_features, base::Vector<const uint8_t> bytes,
ValueType expected) {
ModuleDecoderImpl decoder(enabled_features, bytes, kWasmOrigin);
AccountingAllocator allocator;
decoder.StartDecoding(nullptr, &allocator);
return decoder.DecodeInitExprForTesting(expected);
}
FunctionResult DecodeWasmFunctionForTesting(
const WasmFeatures& enabled, Zone* zone, ModuleWireBytes wire_bytes,
const WasmModule* module, const byte* function_start,
const byte* function_end, Counters* counters) {
size_t size = function_end - function_start;
CHECK_LE(function_start, function_end);
if (size > kV8MaxWasmFunctionSize) {
return FunctionResult{WasmError{0,
"size > maximum function size (%zu): %zu",
kV8MaxWasmFunctionSize, size}};
WasmFeatures enabled_features, Zone* zone, ModuleWireBytes wire_bytes,
const WasmModule* module, base::Vector<const uint8_t> function_bytes,
Counters* counters) {
if (function_bytes.size() > kV8MaxWasmFunctionSize) {
return FunctionResult{
WasmError{0, "size > maximum function size (%zu): %zu",
kV8MaxWasmFunctionSize, function_bytes.size()}};
}
ModuleDecoderImpl decoder(enabled, function_start, function_end, kWasmOrigin);
ModuleDecoderImpl decoder(enabled_features, function_bytes, kWasmOrigin);
decoder.SetCounters(counters);
return decoder.DecodeSingleFunctionForTesting(zone, wire_bytes, module);
}
@ -294,9 +285,9 @@ AsmJsOffsetsResult DecodeAsmJsOffsets(
return decoder.toResult(AsmJsOffsets{std::move(functions)});
}
std::vector<CustomSectionOffset> DecodeCustomSections(const byte* start,
const byte* end) {
Decoder decoder(start, end);
std::vector<CustomSectionOffset> DecodeCustomSections(
base::Vector<const uint8_t> bytes) {
Decoder decoder(bytes);
decoder.consume_bytes(4, "wasm magic");
decoder.consume_bytes(4, "wasm version");
@ -383,9 +374,9 @@ void DecodeIndirectNameMap(IndirectNameMap& target, Decoder& decoder) {
} // namespace
void DecodeFunctionNames(const byte* module_start, const byte* module_end,
void DecodeFunctionNames(base::Vector<const uint8_t> wire_bytes,
NameMap& names) {
Decoder decoder(module_start, module_end);
Decoder decoder(wire_bytes);
if (FindNameSection(&decoder)) {
while (decoder.ok() && decoder.more()) {
uint8_t name_type = decoder.consume_u8("name type");

View File

@ -84,34 +84,33 @@ enum class DecodingMethod {
kDeserialize
};
// Decodes the bytes of a wasm module between {module_start} and {module_end}.
// Decodes the bytes of a wasm module in {wire_bytes}.
V8_EXPORT_PRIVATE ModuleResult DecodeWasmModule(
const WasmFeatures& enabled, const byte* module_start,
const byte* module_end, bool verify_functions, ModuleOrigin origin,
Counters* counters, std::shared_ptr<metrics::Recorder> metrics_recorder,
WasmFeatures enabled_features, base::Vector<const uint8_t> wire_bytes,
bool validate_functions, ModuleOrigin origin, Counters* counters,
std::shared_ptr<metrics::Recorder> metrics_recorder,
v8::metrics::Recorder::ContextId context_id, DecodingMethod decoding_method,
AccountingAllocator* allocator);
// Stripped down version for disassembler needs.
V8_EXPORT_PRIVATE ModuleResult DecodeWasmModuleForDisassembler(
const byte* module_start, const byte* module_end,
AccountingAllocator* allocator);
base::Vector<const uint8_t> wire_bytes, AccountingAllocator* allocator);
// Exposed for testing. Decodes a single function signature, allocating it
// in the given zone.
V8_EXPORT_PRIVATE Result<const FunctionSig*> DecodeWasmSignatureForTesting(
const WasmFeatures& enabled, Zone* zone, const byte* start,
const byte* end);
WasmFeatures enabled_features, Zone* zone,
base::Vector<const uint8_t> bytes);
// Decodes the bytes of a wasm function between
// {function_start} and {function_end}.
// Decodes the bytes of a wasm function in {function_bytes} (part of
// {wire_bytes}).
V8_EXPORT_PRIVATE FunctionResult DecodeWasmFunctionForTesting(
const WasmFeatures& enabled, Zone* zone, ModuleWireBytes wire_bytes,
const WasmModule* module, const byte* function_start,
const byte* function_end, Counters* counters);
WasmFeatures enabled, Zone* zone, ModuleWireBytes wire_bytes,
const WasmModule* module, base::Vector<const uint8_t> function_bytes,
Counters* counters);
V8_EXPORT_PRIVATE ConstantExpression
DecodeWasmInitExprForTesting(const WasmFeatures& enabled, const byte* start,
const byte* end, ValueType expected);
V8_EXPORT_PRIVATE ConstantExpression DecodeWasmInitExprForTesting(
WasmFeatures enabled_features, base::Vector<const uint8_t> bytes,
ValueType expected);
struct CustomSectionOffset {
WireBytesRef section;
@ -120,7 +119,7 @@ struct CustomSectionOffset {
};
V8_EXPORT_PRIVATE std::vector<CustomSectionOffset> DecodeCustomSections(
const byte* start, const byte* end);
base::Vector<const uint8_t> wire_bytes);
// Extracts the mapping from wasm byte offset to asm.js source position per
// function.
@ -130,14 +129,14 @@ AsmJsOffsetsResult DecodeAsmJsOffsets(
// Decode the function names from the name section. Returns the result as an
// unordered map. Only names with valid utf8 encoding are stored and conflicts
// are resolved by choosing the last name read.
void DecodeFunctionNames(const byte* module_start, const byte* module_end,
void DecodeFunctionNames(base::Vector<const uint8_t> wire_bytes,
NameMap& names);
class ModuleDecoderImpl;
class ModuleDecoder {
public:
explicit ModuleDecoder(const WasmFeatures& enabled);
explicit ModuleDecoder(WasmFeatures enabled);
~ModuleDecoder();
void StartDecoding(Counters* counters,

View File

@ -554,8 +554,9 @@ class OffsetsProvider {
public:
OffsetsProvider() = default;
void CollectOffsets(const WasmModule* module, const byte* start,
const byte* end, AccountingAllocator* allocator) {
void CollectOffsets(const WasmModule* module,
base::Vector<const uint8_t> wire_bytes,
AccountingAllocator* allocator) {
num_imported_tables_ = module->num_imported_tables;
num_imported_globals_ = module->num_imported_globals;
num_imported_tags_ = module->num_imported_tags;
@ -568,7 +569,7 @@ class OffsetsProvider {
data_offsets_.reserve(module->data_segments.size());
using OffsetsCollectingDecoder = ModuleDecoderTemplate<OffsetsProvider>;
OffsetsCollectingDecoder decoder(WasmFeatures::All(), start, end,
OffsetsCollectingDecoder decoder(WasmFeatures::All(), wire_bytes,
kWasmOrigin, *this);
constexpr bool verify_functions = false;
decoder.DecodeModule(nullptr, allocator, verify_functions);
@ -673,8 +674,7 @@ ModuleDisassembler::ModuleDisassembler(MultiLineStringBuilder& out,
offsets_(new OffsetsProvider()),
function_body_offsets_(function_body_offsets) {
if (function_body_offsets != nullptr) {
offsets_->CollectOffsets(module, wire_bytes_.start(), wire_bytes_.end(),
allocator);
offsets_->CollectOffsets(module, wire_bytes_.module_bytes(), allocator);
}
}

View File

@ -475,8 +475,8 @@ bool WasmEngine::SyncValidate(Isolate* isolate, const WasmFeatures& enabled,
return false;
}
auto result = DecodeWasmModule(
enabled, bytes.start(), bytes.end(), true, kWasmOrigin,
isolate->counters(), isolate->metrics_recorder(),
enabled, bytes.module_bytes(), true, kWasmOrigin, isolate->counters(),
isolate->metrics_recorder(),
isolate->GetOrRegisterRecorderContextId(isolate->native_context()),
DecodingMethod::kSync, allocator());
if (result.failed() && error_message) {
@ -499,10 +499,10 @@ MaybeHandle<AsmWasmData> WasmEngine::SyncCompileTranslatedAsmJs(
// the context id in here.
v8::metrics::Recorder::ContextId context_id =
v8::metrics::Recorder::ContextId::Empty();
ModuleResult result = DecodeWasmModule(
WasmFeatures::ForAsmjs(), bytes.start(), bytes.end(), false, origin,
isolate->counters(), isolate->metrics_recorder(), context_id,
DecodingMethod::kSync, allocator());
ModuleResult result =
DecodeWasmModule(WasmFeatures::ForAsmjs(), bytes.module_bytes(), false,
origin, isolate->counters(), isolate->metrics_recorder(),
context_id, DecodingMethod::kSync, allocator());
if (result.failed()) {
// This happens once in a while when we have missed some limit check
// in the asm parser. Output an error message to help diagnose, but crash.
@ -543,10 +543,10 @@ MaybeHandle<WasmModuleObject> WasmEngine::SyncCompile(
isolate->GetOrRegisterRecorderContextId(isolate->native_context());
std::shared_ptr<WasmModule> module;
{
ModuleResult result = DecodeWasmModule(
enabled, bytes.start(), bytes.end(), false, kWasmOrigin,
isolate->counters(), isolate->metrics_recorder(), context_id,
DecodingMethod::kSync, allocator());
ModuleResult result =
DecodeWasmModule(enabled, bytes.module_bytes(), false, kWasmOrigin,
isolate->counters(), isolate->metrics_recorder(),
context_id, DecodingMethod::kSync, allocator());
if (result.failed()) {
thrower->CompileFailed(result.error());
return {};

View File

@ -51,7 +51,7 @@ WireBytesRef LazilyGeneratedNames::LookupFunctionName(
base::MutexGuard lock(&mutex_);
if (!has_functions_) {
has_functions_ = true;
DecodeFunctionNames(wire_bytes.start(), wire_bytes.end(), function_names_);
DecodeFunctionNames(wire_bytes.module_bytes(), function_names_);
}
const WireBytesRef* result = function_names_.Get(function_index);
if (!result) return WireBytesRef();
@ -555,7 +555,7 @@ Handle<JSArray> GetCustomSections(Isolate* isolate,
base::Vector<const uint8_t> wire_bytes =
module_object->native_module()->wire_bytes();
std::vector<CustomSectionOffset> custom_sections =
DecodeCustomSections(wire_bytes.begin(), wire_bytes.end());
DecodeCustomSections(wire_bytes);
std::vector<Handle<Object>> matching_sections;

View File

@ -887,7 +887,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
WasmEngine* wasm_engine = GetWasmEngine();
WasmFeatures enabled_features = WasmFeatures::FromIsolate(isolate);
ModuleResult decode_result = DecodeWasmModule(
enabled_features, owned_wire_bytes.start(), owned_wire_bytes.end(), false,
enabled_features, owned_wire_bytes.as_vector(), false,
i::wasm::kWasmOrigin, isolate->counters(), isolate->metrics_recorder(),
isolate->GetOrRegisterRecorderContextId(isolate->native_context()),
DecodingMethod::kDeserialize, wasm_engine->allocator());

View File

@ -381,13 +381,13 @@ STREAM_TEST(TestAllBytesArriveAOTCompilerFinishesFirst) {
CHECK(tester.IsPromiseFulfilled());
}
size_t GetFunctionOffset(i::Isolate* isolate, const uint8_t* buffer,
size_t size, size_t index) {
size_t GetFunctionOffset(i::Isolate* isolate, base::Vector<const uint8_t> bytes,
size_t index) {
ModuleResult result = DecodeWasmModule(
WasmFeatures::All(), buffer, buffer + size, false,
ModuleOrigin::kWasmOrigin, isolate->counters(),
isolate->metrics_recorder(), v8::metrics::Recorder::ContextId::Empty(),
DecodingMethod::kSyncStream, GetWasmEngine()->allocator());
WasmFeatures::All(), bytes, false, ModuleOrigin::kWasmOrigin,
isolate->counters(), isolate->metrics_recorder(),
v8::metrics::Recorder::ContextId::Empty(), DecodingMethod::kSyncStream,
GetWasmEngine()->allocator());
CHECK(result.ok());
const WasmFunction* func = &result.value()->functions[index];
return func->code.offset();
@ -400,8 +400,7 @@ STREAM_TEST(TestCutAfterOneFunctionStreamFinishesFirst) {
ZoneBuffer buffer = GetValidModuleBytes(tester.zone());
Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
size_t offset =
GetFunctionOffset(i_isolate, buffer.begin(), buffer.size(), 1);
size_t offset = GetFunctionOffset(i_isolate, base::VectorOf(buffer), 1);
tester.OnBytesReceived(buffer.begin(), offset);
tester.RunCompilerTasks();
CHECK(tester.IsPromisePending());
@ -419,8 +418,7 @@ STREAM_TEST(TestCutAfterOneFunctionCompilerFinishesFirst) {
ZoneBuffer buffer = GetValidModuleBytes(tester.zone());
Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
size_t offset =
GetFunctionOffset(i_isolate, buffer.begin(), buffer.size(), 1);
size_t offset = GetFunctionOffset(i_isolate, base::VectorOf(buffer), 1);
tester.OnBytesReceived(buffer.begin(), offset);
tester.RunCompilerTasks();
CHECK(tester.IsPromisePending());

View File

@ -42,8 +42,8 @@ Handle<WasmModuleObject> CompileReferenceModule(Zone* zone, Isolate* isolate,
constexpr bool kNoVerifyFunctions = false;
auto enabled_features = WasmFeatures::FromIsolate(isolate);
ModuleResult module_res = DecodeWasmModule(
enabled_features, wire_bytes.start(), wire_bytes.end(),
kNoVerifyFunctions, ModuleOrigin::kWasmOrigin, isolate->counters(),
enabled_features, wire_bytes.module_bytes(), kNoVerifyFunctions,
ModuleOrigin::kWasmOrigin, isolate->counters(),
isolate->metrics_recorder(), v8::metrics::Recorder::ContextId::Empty(),
DecodingMethod::kSync, GetWasmEngine()->allocator());
CHECK(module_res.ok());
@ -505,7 +505,7 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
constexpr bool kVerifyFunctions = false;
auto enabled_features = WasmFeatures::FromIsolate(isolate);
ModuleResult module_res = DecodeWasmModule(
enabled_features, wire_bytes.start(), wire_bytes.end(), kVerifyFunctions,
enabled_features, wire_bytes.module_bytes(), kVerifyFunctions,
ModuleOrigin::kWasmOrigin, isolate->counters(),
isolate->metrics_recorder(), v8::metrics::Recorder::ContextId::Empty(),
DecodingMethod::kSync, GetWasmEngine()->allocator());

View File

@ -120,12 +120,11 @@ class MemoryProtectionTest : public TestWithNativeContext {
SECTION(Function, ENTRY_COUNT(1), SIG_INDEX(0)),
SECTION(Code, ENTRY_COUNT(1), ADD_COUNT(0 /* locals */, kExprEnd))};
ModuleResult result =
DecodeWasmModule(WasmFeatures::All(), std::begin(module_bytes),
std::end(module_bytes), false, kWasmOrigin,
isolate()->counters(), isolate()->metrics_recorder(),
v8::metrics::Recorder::ContextId::Empty(),
DecodingMethod::kSync, GetWasmEngine()->allocator());
ModuleResult result = DecodeWasmModule(
WasmFeatures::All(), base::ArrayVector(module_bytes), false,
kWasmOrigin, isolate()->counters(), isolate()->metrics_recorder(),
v8::metrics::Recorder::ContextId::Empty(), DecodingMethod::kSync,
GetWasmEngine()->allocator());
CHECK(result.ok());
ErrorThrower thrower(isolate(), "");

View File

@ -32,8 +32,7 @@ class Memory64DecodingTest : public TestWithIsolateAndZone {
static constexpr WasmFeatures kEnabledFeatures{
WasmFeature::kFeature_memory64};
return DecodeWasmModule(
kEnabledFeatures, module_bytes.data(),
module_bytes.data() + module_bytes.size(), false, kWasmOrigin,
kEnabledFeatures, base::VectorOf(module_bytes), false, kWasmOrigin,
isolate()->counters(), isolate()->metrics_recorder(),
v8::metrics::Recorder::ContextId::Empty(), DecodingMethod::kSync,
wasm::GetWasmEngine()->allocator());

View File

@ -116,27 +116,27 @@ namespace module_decoder_unittest {
kWasmArrayTypeCode, type, (mutability ? 1 : 0)
#define WASM_FUNCTION_DEF(...) kWasmFunctionTypeCode, __VA_ARGS__
#define EXPECT_VERIFIES(data) \
do { \
ModuleResult _result = DecodeModule(data, data + sizeof(data)); \
EXPECT_OK(_result); \
#define EXPECT_VERIFIES(data) \
do { \
ModuleResult _result = DecodeModule(base::ArrayVector(data)); \
EXPECT_OK(_result); \
} while (false)
#define EXPECT_FAILURE_LEN(data, length) \
do { \
ModuleResult _result = DecodeModule(data, data + length); \
EXPECT_FALSE(_result.ok()); \
#define EXPECT_FAILURE_LEN(data, length) \
do { \
ModuleResult _result = DecodeModule(base::VectorOf(data, length)); \
EXPECT_FALSE(_result.ok()); \
} while (false)
#define EXPECT_FAILURE(data) EXPECT_FAILURE_LEN(data, sizeof(data))
#define EXPECT_FAILURE_WITH_MSG(data, msg) \
do { \
ModuleResult _result = DecodeModule(data, data + sizeof(data)); \
EXPECT_FALSE(_result.ok()); \
if (!_result.ok()) { \
EXPECT_THAT(_result.error().message(), HasSubstr(msg)); \
} \
#define EXPECT_FAILURE_WITH_MSG(data, msg) \
do { \
ModuleResult _result = DecodeModule(base::ArrayVector(data)); \
EXPECT_FALSE(_result.ok()); \
if (!_result.ok()) { \
EXPECT_THAT(_result.error().message(), HasSubstr(msg)); \
} \
} while (false)
#define EXPECT_OFF_END_FAILURE(data, min) \
@ -200,29 +200,28 @@ class WasmModuleVerifyTest : public TestWithIsolateAndZone {
public:
WasmFeatures enabled_features_ = WasmFeatures::None();
ModuleResult DecodeModule(const byte* module_start, const byte* module_end) {
ModuleResult DecodeModule(base::Vector<const uint8_t> module_bytes) {
// Add the wasm magic and version number automatically.
size_t size = static_cast<size_t>(module_end - module_start);
size_t size = module_bytes.size();
byte header[] = {WASM_MODULE_HEADER};
size_t total = sizeof(header) + size;
auto temp = new byte[total];
memcpy(temp, header, sizeof(header));
if (size > 0) {
memcpy(temp + sizeof(header), module_start, size);
memcpy(temp + sizeof(header), module_bytes.begin(), size);
}
ModuleResult result = DecodeWasmModule(
enabled_features_, temp, temp + total, false, kWasmOrigin,
enabled_features_, base::VectorOf(temp, total), false, kWasmOrigin,
isolate()->counters(), isolate()->metrics_recorder(),
v8::metrics::Recorder::ContextId::Empty(), DecodingMethod::kSync,
GetWasmEngine()->allocator());
delete[] temp;
return result;
}
ModuleResult DecodeModuleNoHeader(const byte* module_start,
const byte* module_end) {
ModuleResult DecodeModuleNoHeader(base::Vector<const uint8_t> bytes) {
return DecodeWasmModule(
enabled_features_, module_start, module_end, false, kWasmOrigin,
isolate()->counters(), isolate()->metrics_recorder(),
enabled_features_, bytes, false, kWasmOrigin, isolate()->counters(),
isolate()->metrics_recorder(),
v8::metrics::Recorder::ContextId::Empty(), DecodingMethod::kSync,
GetWasmEngine()->allocator());
}
@ -231,7 +230,7 @@ class WasmModuleVerifyTest : public TestWithIsolateAndZone {
TEST_F(WasmModuleVerifyTest, WrongMagic) {
for (uint32_t x = 1; x; x <<= 1) {
const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)};
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
ModuleResult result = DecodeModuleNoHeader(base::ArrayVector(data));
EXPECT_FALSE(result.ok());
}
}
@ -239,7 +238,7 @@ TEST_F(WasmModuleVerifyTest, WrongMagic) {
TEST_F(WasmModuleVerifyTest, WrongVersion) {
for (uint32_t x = 1; x; x <<= 1) {
const byte data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion ^ x)};
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
ModuleResult result = DecodeModuleNoHeader(base::ArrayVector(data));
EXPECT_FALSE(result.ok());
}
}
@ -247,12 +246,12 @@ TEST_F(WasmModuleVerifyTest, WrongVersion) {
TEST_F(WasmModuleVerifyTest, WrongSection) {
constexpr byte kInvalidSection = 0x1c;
const byte data[] = {kInvalidSection, 0};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_FALSE(result.ok());
}
TEST_F(WasmModuleVerifyTest, DecodeEmpty) {
ModuleResult result = DecodeModule(nullptr, nullptr);
ModuleResult result = DecodeModule(base::VectorOf<uint8_t>(nullptr, 0));
EXPECT_TRUE(result.ok());
}
@ -267,7 +266,7 @@ TEST_F(WasmModuleVerifyTest, OneGlobal) {
{
// Should decode to exactly one global.
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(1u, result.value()->globals.size());
EXPECT_EQ(0u, result.value()->functions.size());
@ -292,7 +291,7 @@ TEST_F(WasmModuleVerifyTest, S128Global) {
kS128Code, // memory type
0, // immutable
WASM_SIMD_CONSTANT(v.data()), kExprEnd)};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
if (!CheckHardwareSupportsSimd()) {
EXPECT_NOT_OK(result, "Wasm SIMD unsupported");
} else {
@ -332,7 +331,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobal) {
{
// Should decode to two globals.
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(2u, result.value()->globals.size());
EXPECT_EQ(2u, result.value()->functions.size());
@ -375,7 +374,7 @@ TEST_F(WasmModuleVerifyTest, FuncRefGlobal) {
TWO_EMPTY_BODIES};
{
// Should decode to two globals.
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(2u, result.value()->globals.size());
EXPECT_EQ(2u, result.value()->functions.size());
@ -424,7 +423,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobalWithGlobalInit) {
{
// Should decode to exactly one global.
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(2u, result.value()->globals.size());
EXPECT_EQ(0u, result.value()->functions.size());
@ -455,7 +454,7 @@ TEST_F(WasmModuleVerifyTest, NullGlobalWithGlobalInit) {
{
// Should decode to exactly one global.
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
std::cout << result.error().message() << std::endl;
EXPECT_OK(result);
EXPECT_EQ(2u, result.value()->globals.size());
@ -654,7 +653,7 @@ TEST_F(WasmModuleVerifyTest, GlobalInitializer) {
TEST_F(WasmModuleVerifyTest, ZeroGlobals) {
static const byte data[] = {SECTION(Global, ENTRY_COUNT(0))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
}
@ -724,7 +723,7 @@ TEST_F(WasmModuleVerifyTest, NGlobals) {
buffer.insert(buffer.end(), data, data + sizeof(data));
}
ModuleResult result = DecodeModule(&buffer[0], &buffer[0] + buffer.size());
ModuleResult result = DecodeModule(base::VectorOf(buffer));
EXPECT_OK(result);
}
}
@ -741,7 +740,7 @@ TEST_F(WasmModuleVerifyTest, TwoGlobals) {
{
// Should decode to exactly two globals.
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(2u, result.value()->globals.size());
EXPECT_EQ(0u, result.value()->functions.size());
@ -766,7 +765,7 @@ TEST_F(WasmModuleVerifyTest, TwoGlobals) {
TEST_F(WasmModuleVerifyTest, RefNullGlobal) {
static const byte data[] = {SECTION(Global, ENTRY_COUNT(1), kFuncRefCode, 1,
WASM_REF_NULL(kFuncRefCode), kExprEnd)};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
}
@ -774,7 +773,7 @@ TEST_F(WasmModuleVerifyTest, RefNullGlobalInvalid1) {
WASM_FEATURE_SCOPE(typed_funcref);
static const byte data[] = {SECTION(Global, ENTRY_COUNT(1), kRefNullCode, 0,
1, WASM_REF_NULL(0), kExprEnd)};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "Type index 0 is out of bounds");
}
@ -782,7 +781,7 @@ TEST_F(WasmModuleVerifyTest, RefNullGlobalInvalid2) {
WASM_FEATURE_SCOPE(typed_funcref);
static const byte data[] = {SECTION(Global, ENTRY_COUNT(1), kFuncRefCode, 1,
kExprRefNull, U32V_5(1000001), kExprEnd)};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result,
"Type index 1000001 is greater than the maximum number 1000000 "
"of type definitions supported by V8");
@ -1088,7 +1087,7 @@ TEST_F(WasmModuleVerifyTest, SuperTypeDeclarationWith0Supertypes) {
TEST_F(WasmModuleVerifyTest, ZeroExceptions) {
static const byte data[] = {SECTION(Tag, ENTRY_COUNT(0))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(0u, result.value()->tags.size());
}
@ -1098,7 +1097,7 @@ TEST_F(WasmModuleVerifyTest, OneI32Exception) {
SECTION(Type, ENTRY_COUNT(1), SIG_ENTRY_v_x(kI32Code)), // sig#0 (i32)
SECTION(Tag, ENTRY_COUNT(1),
EXCEPTION_ENTRY(SIG_INDEX(0)))}; // except[0] (sig#0)
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(1u, result.value()->tags.size());
@ -1115,7 +1114,7 @@ TEST_F(WasmModuleVerifyTest, TwoExceptions) {
SECTION(Tag, ENTRY_COUNT(2),
EXCEPTION_ENTRY(SIG_INDEX(1)), // except[0] (sig#1)
EXCEPTION_ENTRY(SIG_INDEX(0)))}; // except[1] (sig#0)
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(2u, result.value()->tags.size());
const WasmTag& e0 = result.value()->tags.front();
@ -1133,7 +1132,7 @@ TEST_F(WasmModuleVerifyTest, Exception_invalid_sig_index) {
EXCEPTION_ENTRY(
SIG_INDEX(23)))}; // except[0] (sig#23 [out-of-bounds])
// Should fail decoding exception section.
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "signature index 23 out of bounds");
}
@ -1144,7 +1143,7 @@ TEST_F(WasmModuleVerifyTest, Exception_invalid_sig_return) {
EXCEPTION_ENTRY(
SIG_INDEX(0)))}; // except[0] (sig#0 [invalid-return-type])
// Should fail decoding exception section.
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "tag signature 0 has non-void return");
}
@ -1154,7 +1153,7 @@ TEST_F(WasmModuleVerifyTest, Exception_invalid_attribute) {
SECTION(Tag, ENTRY_COUNT(1), 23,
SIG_INDEX(0))}; // except[0] (sig#0) [invalid-attribute]
// Should fail decoding exception section.
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "exception attribute 23 not supported");
}
@ -1162,14 +1161,14 @@ TEST_F(WasmModuleVerifyTest, TagSectionCorrectPlacement) {
static const byte data[] = {SECTION(Memory, ENTRY_COUNT(0)),
SECTION(Tag, ENTRY_COUNT(0)),
SECTION(Global, ENTRY_COUNT(0))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
}
TEST_F(WasmModuleVerifyTest, TagSectionAfterGlobal) {
static const byte data[] = {SECTION(Global, ENTRY_COUNT(0)),
SECTION(Tag, ENTRY_COUNT(0))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result,
"The Tag section must appear before the Global section");
}
@ -1177,7 +1176,7 @@ TEST_F(WasmModuleVerifyTest, TagSectionAfterGlobal) {
TEST_F(WasmModuleVerifyTest, TagSectionBeforeMemory) {
static const byte data[] = {SECTION(Tag, ENTRY_COUNT(0)),
SECTION(Memory, ENTRY_COUNT(0))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "unexpected section <Memory>");
}
@ -1186,7 +1185,7 @@ TEST_F(WasmModuleVerifyTest, TagSectionAfterTableBeforeMemory) {
static const byte data[] = {SECTION(Table, ENTRY_COUNT(0)),
SECTION(Tag, ENTRY_COUNT(0)),
SECTION(Memory, ENTRY_COUNT(0))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "unexpected section <Memory>");
}
@ -1199,7 +1198,7 @@ TEST_F(WasmModuleVerifyTest, TagImport) {
ADD_COUNT('e', 'x'), // tag name
kExternalTag, // import kind
EXCEPTION_ENTRY(SIG_INDEX(0)))}; // except[0] (sig#0)
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(1u, result.value()->tags.size());
EXPECT_EQ(1u, result.value()->import_table.size());
@ -1214,7 +1213,7 @@ TEST_F(WasmModuleVerifyTest, ExceptionExport) {
NO_NAME, // --
kExternalTag, // --
EXCEPTION_INDEX(0))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(1u, result.value()->tags.size());
EXPECT_EQ(1u, result.value()->export_table.size());
@ -1241,7 +1240,7 @@ TEST_F(WasmModuleVerifyTest, MultipleSignatures) {
SIG_ENTRY_x_xx(kI32Code, kF64Code, kF64Code)), // f64,f64 -> i32
};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(3u, result.value()->types.size());
if (result.value()->types.size() == 3) {
@ -1273,7 +1272,7 @@ TEST_F(WasmModuleVerifyTest, CanonicalTypeIds) {
WASM_ARRAY_DEF(kI32Code, true)) // Array definition
};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
const WasmModule* module = result.value().get();
@ -1308,7 +1307,7 @@ TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableImportedGlobal) {
U32V_1(3), // source size
'a', 'b', 'c') // data bytes
};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
}
@ -1358,7 +1357,7 @@ TEST_F(WasmModuleVerifyTest, OneDataSegment) {
{
EXPECT_VERIFIES(data);
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(0u, result.value()->globals.size());
EXPECT_EQ(0u, result.value()->functions.size());
@ -1392,7 +1391,7 @@ TEST_F(WasmModuleVerifyTest, TwoDataSegments) {
};
{
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(0u, result.value()->globals.size());
EXPECT_EQ(0u, result.value()->functions.size());
@ -1480,7 +1479,7 @@ TEST_F(WasmModuleVerifyTest, OneIndirectFunction) {
// code ----------------------------------------------------------------
ONE_EMPTY_BODY};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
if (result.ok()) {
EXPECT_EQ(1u, result.value()->types.size());
@ -1567,7 +1566,7 @@ TEST_F(WasmModuleVerifyTest, OneIndirectFunction_one_entry) {
// code ----------------------------------------------------------------
ONE_EMPTY_BODY};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(1u, result.value()->types.size());
EXPECT_EQ(1u, result.value()->functions.size());
@ -1595,7 +1594,7 @@ TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) {
FUNC_INDEX(2), FUNC_INDEX(3))),
FOUR_EMPTY_BODIES};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(2u, result.value()->types.size());
EXPECT_EQ(4u, result.value()->functions.size());
@ -1999,7 +1998,7 @@ TEST_F(WasmModuleVerifyTest, MultipleTables) {
11), // table 2: minimum size
};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(2u, result.value()->tables.size());
@ -2021,7 +2020,7 @@ TEST_F(WasmModuleVerifyTest, TypedFunctionTable) {
kRefNullCode, 0, // table 0: type
0, 10)}; // table 0: limits
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(ValueType::RefNull(0), result.value()->tables[0].type);
}
@ -2064,7 +2063,7 @@ TEST_F(WasmModuleVerifyTest, IllegalTableTypes) {
// Add table limits
data.insert(data.end(), {byte{0}, byte{10}});
auto result = DecodeModule(data.data(), data.data() + data.size());
auto result = DecodeModule(base::VectorOf(data));
EXPECT_NOT_OK(result, "Only reference types can be used as table types");
}
}
@ -2082,7 +2081,7 @@ TEST_F(WasmModuleVerifyTest, TableWithInitializer) {
0, 10, // table 0: limits
kExprRefFunc, 0, kExprEnd), // table 0: initial value
SECTION(Code, ENTRY_COUNT(1), NOP_BODY)};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(ValueType::RefNull(0), result.value()->tables[0].type);
}
@ -2100,7 +2099,7 @@ TEST_F(WasmModuleVerifyTest, NonNullableTable) {
0, 10, // table 0: limits
kExprRefFunc, 0, kExprEnd), // table 0: initial value
SECTION(Code, ENTRY_COUNT(1), NOP_BODY)};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(ValueType::Ref(0), result.value()->tables[0].type);
}
@ -2132,7 +2131,7 @@ TEST_F(WasmModuleVerifyTest, TieringCompilationHints) {
SECTION(Code, ENTRY_COUNT(3), NOP_BODY, NOP_BODY, NOP_BODY),
};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(3u, result.value()->compilation_hints.size());
@ -2170,7 +2169,7 @@ TEST_F(WasmModuleVerifyTest, BranchHinting) {
ADD_COUNT(0, /*no locals*/
WASM_BLOCK(WASM_BR_IF(0, WASM_I32V_1(1))), WASM_END))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(2u, result.value()->branch_hints.size());
@ -2184,18 +2183,18 @@ class WasmSignatureDecodeTest : public TestWithZone {
public:
WasmFeatures enabled_features_ = WasmFeatures::None();
const FunctionSig* DecodeSig(const byte* start, const byte* end) {
const FunctionSig* DecodeSig(base::Vector<const uint8_t> bytes) {
Result<const FunctionSig*> res =
DecodeWasmSignatureForTesting(enabled_features_, zone(), start, end);
DecodeWasmSignatureForTesting(enabled_features_, zone(), bytes);
EXPECT_TRUE(res.ok()) << res.error().message() << " at offset "
<< res.error().offset();
return res.ok() ? res.value() : nullptr;
}
V8_NODISCARD testing::AssertionResult DecodeSigError(const byte* start,
const byte* end) {
V8_NODISCARD testing::AssertionResult DecodeSigError(
base::Vector<const uint8_t> bytes) {
Result<const FunctionSig*> res =
DecodeWasmSignatureForTesting(enabled_features_, zone(), start, end);
DecodeWasmSignatureForTesting(enabled_features_, zone(), bytes);
if (res.ok()) {
return testing::AssertionFailure() << "unexpected valid signature";
}
@ -2207,7 +2206,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_v) {
static const byte data[] = {SIG_ENTRY_v_v};
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
const FunctionSig* sig = DecodeSig(base::ArrayVector(data));
ASSERT_TRUE(sig != nullptr);
EXPECT_EQ(0u, sig->parameter_count());
@ -2221,7 +2220,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_v) {
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
ValueTypePair ret_type = kValueTypes[i];
const byte data[] = {SIG_ENTRY_x(ret_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
const FunctionSig* sig = DecodeSig(base::ArrayVector(data));
SCOPED_TRACE("Return type " + ret_type.type.name());
ASSERT_TRUE(sig != nullptr);
@ -2238,7 +2237,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_t) {
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
ValueTypePair param_type = kValueTypes[i];
const byte data[] = {SIG_ENTRY_v_x(param_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
const FunctionSig* sig = DecodeSig(base::ArrayVector(data));
SCOPED_TRACE("Param type " + param_type.type.name());
ASSERT_TRUE(sig != nullptr);
@ -2257,7 +2256,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_t) {
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
ValueTypePair param_type = kValueTypes[j];
const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
const FunctionSig* sig = DecodeSig(base::ArrayVector(data));
SCOPED_TRACE("Param type " + param_type.type.name());
ASSERT_TRUE(sig != nullptr);
@ -2279,7 +2278,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_i_tt) {
ValueTypePair p1_type = kValueTypes[j];
const byte data[] = {
SIG_ENTRY_x_xx(kI32Code, p0_type.code, p1_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
const FunctionSig* sig = DecodeSig(base::ArrayVector(data));
SCOPED_TRACE("Signature i32(" + p0_type.type.name() + ", " +
p1_type.type.name() + ")");
@ -2302,7 +2301,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_tt_tt) {
ValueTypePair p1_type = kValueTypes[j];
const byte data[] = {SIG_ENTRY_xx_xx(p0_type.code, p1_type.code,
p0_type.code, p1_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
const FunctionSig* sig = DecodeSig(base::ArrayVector(data));
SCOPED_TRACE("p0 = " + p0_type.type.name() +
", p1 = " + p1_type.type.name());
@ -2321,10 +2320,10 @@ TEST_F(WasmSignatureDecodeTest, Simd) {
WASM_FEATURE_SCOPE(simd);
const byte data[] = {SIG_ENTRY_x(kS128Code)};
if (!CheckHardwareSupportsSimd()) {
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)))
EXPECT_TRUE(DecodeSigError(base::ArrayVector(data)))
<< "Type S128 should not be allowed on this hardware";
} else {
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
const FunctionSig* sig = DecodeSig(base::ArrayVector(data));
ASSERT_TRUE(sig != nullptr);
EXPECT_EQ(0u, sig->parameter_count());
EXPECT_EQ(1u, sig->return_count());
@ -2336,14 +2335,14 @@ TEST_F(WasmSignatureDecodeTest, TooManyParams) {
static const byte data[] = {kWasmFunctionTypeCode,
WASM_I32V_3(kV8MaxWasmFunctionParams + 1),
kI32Code, 0};
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
EXPECT_TRUE(DecodeSigError(base::ArrayVector(data)));
}
TEST_F(WasmSignatureDecodeTest, TooManyReturns) {
for (int i = 0; i < 2; i++) {
byte data[] = {kWasmFunctionTypeCode, 0,
WASM_I32V_3(kV8MaxWasmFunctionReturns + 1), kI32Code};
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
EXPECT_TRUE(DecodeSigError(base::ArrayVector(data)));
}
}
@ -2355,7 +2354,7 @@ TEST_F(WasmSignatureDecodeTest, Fail_off_end) {
for (int i = 0; i < p + 1; i++) {
// Should fall off the end for all signatures.
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
EXPECT_TRUE(DecodeSigError(base::ArrayVector(data)));
}
}
}
@ -2366,34 +2365,33 @@ TEST_F(WasmSignatureDecodeTest, Fail_invalid_type) {
byte data[] = {SIG_ENTRY_x_xx(kI32Code, kI32Code, kI32Code)};
if (i >= arraysize(data)) break;
data[i] = kInvalidType;
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
EXPECT_TRUE(DecodeSigError(base::ArrayVector(data)));
}
}
TEST_F(WasmSignatureDecodeTest, Fail_invalid_ret_type1) {
static const byte data[] = {SIG_ENTRY_x_x(kVoidCode, kI32Code)};
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
EXPECT_TRUE(DecodeSigError(base::ArrayVector(data)));
}
TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type1) {
static const byte data[] = {SIG_ENTRY_x_x(kI32Code, kVoidCode)};
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
EXPECT_TRUE(DecodeSigError(base::ArrayVector(data)));
}
TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type2) {
static const byte data[] = {SIG_ENTRY_x_xx(kI32Code, kI32Code, kVoidCode)};
EXPECT_TRUE(DecodeSigError(data, data + sizeof(data)));
EXPECT_TRUE(DecodeSigError(base::ArrayVector(data)));
}
class WasmFunctionVerifyTest : public TestWithIsolateAndZone {
public:
FunctionResult DecodeWasmFunction(ModuleWireBytes wire_bytes,
const WasmModule* module,
const byte* function_start,
const byte* function_end) {
FunctionResult DecodeWasmFunction(
ModuleWireBytes wire_bytes, const WasmModule* module,
base::Vector<const uint8_t> function_bytes) {
WasmFeatures enabled_features;
return DecodeWasmFunctionForTesting(enabled_features, zone(), wire_bytes,
module, function_start, function_end,
module, function_bytes,
isolate()->counters());
}
};
@ -2414,8 +2412,8 @@ TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) {
};
WasmModule module;
FunctionResult result = DecodeWasmFunction(ModuleWireBytes({}), &module, data,
data + sizeof(data));
FunctionResult result =
DecodeWasmFunction(ModuleWireBytes({}), &module, base::ArrayVector(data));
EXPECT_OK(result);
if (result.value() && result.ok()) {
@ -2533,7 +2531,7 @@ TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) {
0, // exported
WASM_INIT_EXPR_I32V_1(33)), // init
};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(1u, result.value()->globals.size());
@ -2670,7 +2668,7 @@ TEST_F(WasmModuleVerifyTest, ExportTable_empty1) {
SECTION(Export, ENTRY_COUNT(0)), // --
ONE_EMPTY_BODY};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(1u, result.value()->functions.size());
@ -2698,7 +2696,7 @@ TEST_F(WasmModuleVerifyTest, ExportTableOne) {
kExternalFunction, // --
FUNC_INDEX(0)), // --
ONE_EMPTY_BODY};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(1u, result.value()->functions.size());
@ -2735,7 +2733,7 @@ TEST_F(WasmModuleVerifyTest, ExportTableTwo) {
FUNC_INDEX(0)), // --
ONE_EMPTY_BODY};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(1u, result.value()->functions.size());
@ -2758,7 +2756,7 @@ TEST_F(WasmModuleVerifyTest, ExportTableThree) {
kExternalFunction,
FUNC_INDEX(2)), // --
THREE_EMPTY_BODIES};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
EXPECT_EQ(3u, result.value()->functions.size());
@ -2836,7 +2834,7 @@ TEST_F(WasmModuleVerifyTest, FunctionBodySizeLimit) {
size_t total = sizeof(data) + body_size;
byte* buffer = reinterpret_cast<byte*>(calloc(1, total));
memcpy(buffer, data, sizeof(data));
ModuleResult result = DecodeModule(buffer, buffer + total);
ModuleResult result = DecodeModule(base::VectorOf(buffer, total));
if (body_size <= kV8MaxWasmFunctionSize) {
EXPECT_TRUE(result.ok());
} else {
@ -2952,13 +2950,13 @@ TEST_F(WasmModuleVerifyTest, FunctionSectionWithoutCodeSection) {
TYPE_SECTION(1, SIG_ENTRY_v_v), // Type section.
FUNCTION_SECTION(1, 0), // Function section.
};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "function count is 1, but code section is absent");
}
TEST_F(WasmModuleVerifyTest, CodeSectionWithoutFunctionSection) {
static const byte data[] = {ONE_EMPTY_BODY};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "function body count 1 mismatch (0 expected)");
}
@ -3000,10 +2998,10 @@ TEST_F(WasmModuleVerifyTest, Section_Name_No_UTF8) {
class WasmModuleCustomSectionTest : public TestWithIsolateAndZone {
public:
void CheckSections(const byte* module_start, const byte* module_end,
void CheckSections(base::Vector<const uint8_t> wire_bytes,
const CustomSectionOffset* expected, size_t num_expected) {
std::vector<CustomSectionOffset> custom_sections =
DecodeCustomSections(module_start, module_end);
DecodeCustomSections(wire_bytes);
CHECK_EQ(num_expected, custom_sections.size());
@ -3038,7 +3036,7 @@ TEST_F(WasmModuleCustomSectionTest, ThreeUnknownSections) {
{{27, 8}, {28, 5}, {33, 2}}, // --
};
CheckSections(data, data + sizeof(data), expected, arraysize(expected));
CheckSections(base::ArrayVector(data), expected, arraysize(expected));
}
TEST_F(WasmModuleCustomSectionTest, TwoKnownTwoUnknownSections) {
@ -3057,18 +3055,18 @@ TEST_F(WasmModuleCustomSectionTest, TwoKnownTwoUnknownSections) {
{{29, 8}, {30, 5}, {35, 2}}, // --
};
CheckSections(data, data + sizeof(data), expected, arraysize(expected));
CheckSections(base::ArrayVector(data), expected, arraysize(expected));
}
TEST_F(WasmModuleVerifyTest, SourceMappingURLSection) {
static const byte data[] = {
WASM_MODULE_HEADER,
SECTION_SRC_MAP('s', 'r', 'c', '/', 'x', 'y', 'z', '.', 'c')};
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
ModuleResult result = DecodeModuleNoHeader(base::ArrayVector(data));
EXPECT_TRUE(result.ok());
EXPECT_EQ(WasmDebugSymbols::Type::SourceMap,
result.value()->debug_symbols.type);
ModuleWireBytes wire_bytes(data, data + sizeof(data));
ModuleWireBytes wire_bytes(base::ArrayVector(data));
WasmName external_url =
wire_bytes.GetNameOrNull(result.value()->debug_symbols.external_url);
EXPECT_EQ("src/xyz.c", std::string(external_url.data(), external_url.size()));
@ -3078,7 +3076,7 @@ TEST_F(WasmModuleVerifyTest, BadSourceMappingURLSection) {
static const byte data[] = {
WASM_MODULE_HEADER,
SECTION_SRC_MAP('s', 'r', 'c', '/', 'x', 0xff, 'z', '.', 'c')};
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
ModuleResult result = DecodeModuleNoHeader(base::ArrayVector(data));
EXPECT_TRUE(result.ok());
EXPECT_EQ(WasmDebugSymbols::Type::None, result.value()->debug_symbols.type);
EXPECT_EQ(0u, result.value()->debug_symbols.external_url.length());
@ -3088,11 +3086,11 @@ TEST_F(WasmModuleVerifyTest, MultipleSourceMappingURLSections) {
static const byte data[] = {WASM_MODULE_HEADER,
SECTION_SRC_MAP('a', 'b', 'c'),
SECTION_SRC_MAP('p', 'q', 'r')};
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
ModuleResult result = DecodeModuleNoHeader(base::ArrayVector(data));
EXPECT_TRUE(result.ok());
EXPECT_EQ(WasmDebugSymbols::Type::SourceMap,
result.value()->debug_symbols.type);
ModuleWireBytes wire_bytes(data, data + sizeof(data));
ModuleWireBytes wire_bytes(base::ArrayVector(data));
WasmName external_url =
wire_bytes.GetNameOrNull(result.value()->debug_symbols.external_url);
EXPECT_EQ("abc", std::string(external_url.data(), external_url.size()));
@ -3102,7 +3100,7 @@ TEST_F(WasmModuleVerifyTest, MultipleNameSections) {
static const byte data[] = {
SECTION_NAMES(0, ADD_COUNT(ADD_COUNT('a', 'b', 'c'))),
SECTION_NAMES(0, ADD_COUNT(ADD_COUNT('p', 'q', 'r', 's')))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_TRUE(result.ok());
EXPECT_EQ(3u, result.value()->name.length());
}
@ -3110,7 +3108,7 @@ TEST_F(WasmModuleVerifyTest, MultipleNameSections) {
TEST_F(WasmModuleVerifyTest, BadNameSection) {
static const byte data[] = {SECTION_NAMES(
0, ADD_COUNT(ADD_COUNT('s', 'r', 'c', '/', 'x', 0xff, 'z', '.', 'c')))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_TRUE(result.ok());
EXPECT_EQ(0u, result.value()->name.length());
}
@ -3241,7 +3239,7 @@ TEST_F(WasmModuleVerifyTest, DataCountSectionCorrectPlacement) {
TEST_F(WasmModuleVerifyTest, DataCountSectionAfterCode) {
static const byte data[] = {SECTION(Code, ENTRY_COUNT(0)),
SECTION(DataCount, ENTRY_COUNT(0))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result,
"The DataCount section must appear before the Code section");
}
@ -3249,7 +3247,7 @@ TEST_F(WasmModuleVerifyTest, DataCountSectionAfterCode) {
TEST_F(WasmModuleVerifyTest, DataCountSectionBeforeElement) {
static const byte data[] = {SECTION(DataCount, ENTRY_COUNT(0)),
SECTION(Element, ENTRY_COUNT(0))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "unexpected section <Element>");
}
@ -3265,14 +3263,14 @@ TEST_F(WasmModuleVerifyTest, DataCountSectionAfterStartBeforeElement) {
SECTION(DataCount, ENTRY_COUNT(0)), // DataCount section.
SECTION(Element, ENTRY_COUNT(0)) // Element section.
};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "unexpected section <Element>");
}
TEST_F(WasmModuleVerifyTest, MultipleDataCountSections) {
static const byte data[] = {SECTION(DataCount, ENTRY_COUNT(0)),
SECTION(DataCount, ENTRY_COUNT(0))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "Multiple DataCount sections not allowed");
}
@ -3291,7 +3289,7 @@ TEST_F(WasmModuleVerifyTest, DataCountSegmentCount_greater) {
SECTION(Memory, ENTRY_COUNT(1), 0, 1), // Memory section.
SECTION(DataCount, ENTRY_COUNT(3)), // DataCount section.
SECTION(Data, ENTRY_COUNT(0))}; // Data section.
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "data segments count 0 mismatch (3 expected)");
}
@ -3301,14 +3299,14 @@ TEST_F(WasmModuleVerifyTest, DataCountSegmentCount_less) {
SECTION(DataCount, ENTRY_COUNT(0)), // DataCount section.
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0, // Data section.
WASM_INIT_EXPR_I32V_1(12), ADD_COUNT('a', 'b', 'c'))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "data segments count 1 mismatch (0 expected)");
}
TEST_F(WasmModuleVerifyTest, DataCountSegmentCount_omitted) {
static const byte data[] = {SECTION(Memory, ENTRY_COUNT(1), 0, 1),
SECTION(DataCount, ENTRY_COUNT(1))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "data segments count 0 mismatch (1 expected)");
}
@ -3325,7 +3323,7 @@ TEST_F(WasmModuleVerifyTest, GcStructIdsPass) {
WASM_STRUCT_DEF(FIELD_COUNT(2), STRUCT_FIELD(WASM_OPT_REF(0), true),
STRUCT_FIELD(WASM_OPT_REF(2), true)),
WASM_ARRAY_DEF(WASM_OPT_REF(0), true))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_OK(result);
}
@ -3333,7 +3331,7 @@ TEST_F(WasmModuleVerifyTest, OutOfBoundsTypeInGlobal) {
WASM_FEATURE_SCOPE(typed_funcref);
static const byte data[] = {
SECTION(Global, ENTRY_COUNT(1), kRefCode, 0, WASM_REF_NULL(0), kExprEnd)};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "Type index 0 is out of bounds");
}
@ -3343,7 +3341,7 @@ TEST_F(WasmModuleVerifyTest, OutOfBoundsTypeInType) {
static const byte data[] = {
SECTION(Type, ENTRY_COUNT(1),
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kRefCode, true)))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "Type index 1 is out of bounds");
}
@ -3354,7 +3352,7 @@ TEST_F(WasmModuleVerifyTest, ForwardSupertype) {
SECTION(Type, ENTRY_COUNT(1), kWasmRecursiveTypeGroupCode, ENTRY_COUNT(1),
kWasmSubtypeCode, ENTRY_COUNT(1), 0,
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kRefCode, true)))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "type 0: forward-declared supertype 0");
}
@ -3365,7 +3363,7 @@ TEST_F(WasmModuleVerifyTest, IllegalPackedFields) {
static const byte data[] = {
SECTION(Global, ENTRY_COUNT(1), kI16Code, 0, WASM_INIT_EXPR_I32V_1(13))};
ModuleResult result = DecodeModule(data, data + sizeof(data));
ModuleResult result = DecodeModule(base::ArrayVector(data));
EXPECT_NOT_OK(result, "invalid value type");
}

View File

@ -24,8 +24,8 @@ void CheckDisassemblerOutput(base::Vector<const byte> module_bytes,
std::string expected_output) {
AccountingAllocator allocator;
ModuleResult module_result = DecodeWasmModuleForDisassembler(
module_bytes.begin(), module_bytes.end(), &allocator);
ModuleResult module_result =
DecodeWasmModuleForDisassembler(module_bytes, &allocator);
DCHECK(module_result.ok());
WasmModule* module = module_result.value().get();

View File

@ -36,10 +36,11 @@ void FinalizeModule(void* data) {
g_modules_finalized += static_cast<int>(reinterpret_cast<intptr_t>(data));
}
void RunInStore(Store* store, ZoneBuffer* wire_bytes, int iterations) {
size_t size = wire_bytes->end() - wire_bytes->begin();
void RunInStore(Store* store, base::Vector<const uint8_t> wire_bytes,
int iterations) {
vec<byte_t> binary = vec<byte_t>::make(
size, reinterpret_cast<byte_t*>(const_cast<byte*>(wire_bytes->begin())));
wire_bytes.size(),
reinterpret_cast<byte_t*>(const_cast<byte*>(wire_bytes.begin())));
own<Module> module = Module::make(store, binary);
module->set_host_info(reinterpret_cast<void*>(kModuleMagic), &FinalizeModule);
for (int iteration = 0; iteration < iterations; iteration++) {

View File

@ -69,10 +69,10 @@ TEST_F(WasmCapiTest, Traps) {
i::Isolate* isolate =
reinterpret_cast<::wasm::StoreImpl*>(store())->i_isolate();
ModuleResult result = DecodeWasmModule(
WasmFeatures::All(), wire_bytes()->begin(), wire_bytes()->end(), false,
ModuleOrigin::kWasmOrigin, isolate->counters(),
isolate->metrics_recorder(), v8::metrics::Recorder::ContextId::Empty(),
DecodingMethod::kSync, GetWasmEngine()->allocator());
WasmFeatures::All(), wire_bytes(), false, ModuleOrigin::kWasmOrigin,
isolate->counters(), isolate->metrics_recorder(),
v8::metrics::Recorder::ContextId::Empty(), DecodingMethod::kSync,
GetWasmEngine()->allocator());
ASSERT_TRUE(result.ok());
const WasmFunction* func1 = &result.value()->functions[1];
const WasmFunction* func2 = &result.value()->functions[2];

View File

@ -155,7 +155,9 @@ class WasmCapiTest : public ::testing::Test {
Module* module() { return module_.get(); }
Instance* instance() { return instance_.get(); }
const ownvec<Extern>& exports() { return exports_; }
ZoneBuffer* wire_bytes() { return &wire_bytes_; }
base::Vector<const uint8_t> wire_bytes() {
return base::VectorOf(wire_bytes_);
}
FunctionSig* wasm_i_i_sig() { return &wasm_i_i_sig_; }
FuncType* cpp_i_i_sig() { return cpp_i_i_sig_.get(); }

View File

@ -360,11 +360,10 @@ class ExtendedFunctionDis : public FunctionBodyDisassembler {
class HexDumpModuleDis;
class DumpingModuleDecoder : public ModuleDecoderTemplate<HexDumpModuleDis> {
public:
DumpingModuleDecoder(const ModuleWireBytes wire_bytes,
HexDumpModuleDis* module_dis)
: ModuleDecoderTemplate<HexDumpModuleDis>(
WasmFeatures::All(), wire_bytes.start(), wire_bytes.end(),
kWasmOrigin, *module_dis) {}
DumpingModuleDecoder(ModuleWireBytes wire_bytes, HexDumpModuleDis* module_dis)
: ModuleDecoderTemplate<HexDumpModuleDis>(WasmFeatures::All(),
wire_bytes.module_bytes(),
kWasmOrigin, *module_dis) {}
void onFirstError() override {
// Pretend we've reached the end of the section, but contrary to the
@ -735,7 +734,7 @@ class FormatConverter {
wire_bytes_ = ModuleWireBytes({raw_bytes_.data(), raw_bytes_.size()});
status_ = kIoInitialized;
ModuleResult result =
DecodeWasmModuleForDisassembler(start(), end(), &allocator_);
DecodeWasmModuleForDisassembler(raw_bytes(), &allocator_);
if (result.failed()) {
WasmError error = result.error();
std::cerr << "Decoding error: " << error.message() << " at offset "
@ -769,10 +768,10 @@ class FormatConverter {
void SectionStats() {
DCHECK_EQ(status_, kModuleReady);
Decoder decoder(start(), end());
Decoder decoder(raw_bytes());
decoder.consume_bytes(kModuleHeaderSize, "module header");
uint32_t module_size = static_cast<uint32_t>(end() - start());
uint32_t module_size = static_cast<uint32_t>(raw_bytes().size());
int digits = GetNumDigits(module_size);
size_t kMinNameLength = 8;
// 18 = kMinNameLength + strlen(" section: ").
@ -798,7 +797,7 @@ class FormatConverter {
void Strip() {
DCHECK_EQ(status_, kModuleReady);
Decoder decoder(start(), end());
Decoder decoder(raw_bytes());
out_.write(reinterpret_cast<const char*>(decoder.pc()), kModuleHeaderSize);
decoder.consume_bytes(kModuleHeaderSize);
NoTracer no_tracer;
@ -1043,8 +1042,9 @@ class FormatConverter {
}
}
byte* start() { return raw_bytes_.data(); }
byte* end() { return start() + raw_bytes_.size(); }
base::Vector<const uint8_t> raw_bytes() const {
return base::VectorOf(raw_bytes_);
}
const WasmModule* module() { return module_.get(); }
NamesProvider* names() { return names_provider_.get(); }
@ -1052,7 +1052,7 @@ class FormatConverter {
Output output_;
std::ostream& out_;
Status status_{kNotReady};
std::vector<byte> raw_bytes_;
std::vector<uint8_t> raw_bytes_;
ModuleWireBytes wire_bytes_{{}};
std::shared_ptr<WasmModule> module_;
std::unique_ptr<NamesProvider> names_provider_;