@@ -322,20 +322,20 @@ string_view V8::getCustomSection(string_view name) {
322
322
const byte_t *end = source_.get () + source_.size ();
323
323
while (pos < end) {
324
324
if (pos + 1 > end) {
325
- fail (" Failed to parse corrupted Wasm module" );
325
+ fail (FailState::UnableToInitializeCode, " Failed to parse corrupted Wasm module" );
326
326
return " " ;
327
327
}
328
328
const auto section_type = *pos++;
329
329
const auto section_len = parseVarint (pos, end);
330
330
if (section_len == static_cast <uint32_t >(-1 ) || pos + section_len > end) {
331
- fail (" Failed to parse corrupted Wasm module" );
331
+ fail (FailState::UnableToInitializeCode, " Failed to parse corrupted Wasm module" );
332
332
return " " ;
333
333
}
334
334
if (section_type == 0 /* custom section */ ) {
335
335
const auto section_data_start = pos;
336
336
const auto section_name_len = parseVarint (pos, end);
337
337
if (section_name_len == static_cast <uint32_t >(-1 ) || pos + section_name_len > end) {
338
- fail (" Failed to parse corrupted Wasm module" );
338
+ fail (FailState::UnableToInitializeCode, " Failed to parse corrupted Wasm module" );
339
339
return " " ;
340
340
}
341
341
if (section_name_len == name.size () && ::memcmp (pos, name.data (), section_name_len) == 0 ) {
@@ -382,28 +382,31 @@ bool V8::link(string_view debug_name) {
382
382
case wasm::EXTERN_FUNC: {
383
383
auto it = host_functions_.find (std::string (module ) + " ." + std::string (name));
384
384
if (it == host_functions_.end ()) {
385
- fail (std::string (" Failed to load Wasm module due to a missing import: " ) +
386
- std::string (module ) + " ." + std::string (name));
385
+ fail (FailState::UnableToInitializeCode,
386
+ std::string (" Failed to load Wasm module due to a missing import: " ) +
387
+ std::string (module ) + " ." + std::string (name));
387
388
break ;
388
389
}
389
390
auto func = it->second .get ()->callback_ .get ();
390
391
if (!equalValTypes (import_type->func ()->params (), func->type ()->params ()) ||
391
392
!equalValTypes (import_type->func ()->results (), func->type ()->results ())) {
392
- fail (std::string (" Failed to load Wasm module due to an import type mismatch: " ) +
393
- std::string (module ) + " ." + std::string (name) +
394
- " , want: " + printValTypes (import_type->func ()->params ()) + " -> " +
395
- printValTypes (import_type->func ()->results ()) +
396
- " , but host exports: " + printValTypes (func->type ()->params ()) + " -> " +
397
- printValTypes (func->type ()->results ()));
393
+ fail (FailState::UnableToInitializeCode,
394
+ std::string (" Failed to load Wasm module due to an import type mismatch: " ) +
395
+ std::string (module ) + " ." + std::string (name) +
396
+ " , want: " + printValTypes (import_type->func ()->params ()) + " -> " +
397
+ printValTypes (import_type->func ()->results ()) +
398
+ " , but host exports: " + printValTypes (func->type ()->params ()) + " -> " +
399
+ printValTypes (func->type ()->results ()));
398
400
break ;
399
401
}
400
402
imports.push_back (func);
401
403
} break ;
402
404
403
405
case wasm::EXTERN_GLOBAL: {
404
406
// TODO(PiotrSikora): add support when/if needed.
405
- fail (" Failed to load Wasm module due to a missing import: " + std::string (module ) + " ." +
406
- std::string (name));
407
+ fail (FailState::UnableToInitializeCode,
408
+ " Failed to load Wasm module due to a missing import: " + std::string (module ) + " ." +
409
+ std::string (name));
407
410
} break ;
408
411
409
412
case wasm::EXTERN_MEMORY: {
@@ -565,7 +568,8 @@ void V8::getModuleFunctionImpl(string_view function_name,
565
568
const wasm::Func *func = it->second .get ();
566
569
if (!equalValTypes (func->type ()->params (), convertArgsTupleToValTypes<std::tuple<Args...>>()) ||
567
570
!equalValTypes (func->type ()->results (), convertArgsTupleToValTypes<std::tuple<>>())) {
568
- fail (std::string (" Bad function signature for: " ) + std::string (function_name));
571
+ fail (FailState::UnableToInitializeCode,
572
+ std::string (" Bad function signature for: " ) + std::string (function_name));
569
573
*function = nullptr ;
570
574
return ;
571
575
}
@@ -574,8 +578,8 @@ void V8::getModuleFunctionImpl(string_view function_name,
574
578
SaveRestoreContext saved_context (context);
575
579
auto trap = func->call (params, nullptr );
576
580
if (trap) {
577
- fail (" Function: " + std::string (function_name) +
578
- " failed: " + std::string (trap->message ().get (), trap->message ().size ()));
581
+ fail (FailState::RuntimeError, " Function: " + std::string (function_name) + " failed: " +
582
+ std::string (trap->message ().get (), trap->message ().size ()));
579
583
}
580
584
};
581
585
}
@@ -591,7 +595,8 @@ void V8::getModuleFunctionImpl(string_view function_name,
591
595
const wasm::Func *func = it->second .get ();
592
596
if (!equalValTypes (func->type ()->params (), convertArgsTupleToValTypes<std::tuple<Args...>>()) ||
593
597
!equalValTypes (func->type ()->results (), convertArgsTupleToValTypes<std::tuple<R>>())) {
594
- fail (" Bad function signature for: " + std::string (function_name));
598
+ fail (FailState::UnableToInitializeCode,
599
+ " Bad function signature for: " + std::string (function_name));
595
600
*function = nullptr ;
596
601
return ;
597
602
}
@@ -601,8 +606,8 @@ void V8::getModuleFunctionImpl(string_view function_name,
601
606
SaveRestoreContext saved_context (context);
602
607
auto trap = func->call (params, results);
603
608
if (trap) {
604
- fail (" Function: " + std::string (function_name) +
605
- " failed: " + std::string (trap->message ().get (), trap->message ().size ()));
609
+ fail (FailState::RuntimeError, " Function: " + std::string (function_name) + " failed: " +
610
+ std::string (trap->message ().get (), trap->message ().size ()));
606
611
return R{};
607
612
}
608
613
R rvalue = results[0 ].get <typename ConvertWordTypeToUint32<R>::type>();
0 commit comments