@@ -85,8 +85,8 @@ Result SharedValidator::OnFuncType(const Location& loc,
8585 }
8686
8787 type_validation_result_ |= result;
88- result |= CheckGCTypeExtension (loc, gc_ext);
8988 }
89+ result |= CheckGCTypeExtension (loc, gc_ext);
9090
9191 return result;
9292}
@@ -229,19 +229,26 @@ Result SharedValidator::OnGlobalImport(const Location& loc,
229229 result |= PrintError (loc, " mutable globals cannot be imported" );
230230 }
231231 globals_.push_back (GlobalType{type, mutable_});
232- ++num_imported_globals_ ;
232+ ++last_initialized_global_ ;
233233 return result;
234234}
235235
236- Result SharedValidator::OnGlobal (const Location& loc,
237- Type type,
238- bool mutable_) {
236+ Result SharedValidator::BeginGlobal (const Location& loc,
237+ Type type,
238+ bool mutable_) {
239239 CHECK_RESULT (
240240 CheckReferenceType (loc, type, type_fields_.NumTypes (), " globals" ));
241241 globals_.push_back (GlobalType{type, mutable_});
242242 return Result::Ok;
243243}
244244
245+ Result SharedValidator::EndGlobal (const Location&) {
246+ if (options_.features .gc_enabled ()) {
247+ last_initialized_global_++;
248+ }
249+ return Result::Ok;
250+ }
251+
245252Result SharedValidator::CheckType (const Location& loc,
246253 Type actual,
247254 Type expected,
@@ -268,8 +275,6 @@ Result SharedValidator::CheckReferenceType(const Location& loc,
268275
269276Result SharedValidator::CheckGCTypeExtension (const Location& loc,
270277 GCTypeExtension* gc_ext) {
271- assert (options_.features .function_references_enabled ());
272-
273278 TypeEntry& entry = type_fields_.type_entries .back ();
274279 Index current_index = type_fields_.NumTypes () - 1 ;
275280 Index end_index;
@@ -778,8 +783,7 @@ Index SharedValidator::GetCanonicalTypeIndex(Index type_index) {
778783 return kInvalidIndex ;
779784 }
780785
781- if (options_.features .function_references_enabled () &&
782- Succeeded (type_validation_result_)) {
786+ if (Succeeded (type_validation_result_)) {
783787 return type_fields_.type_entries [type_index].canonical_index ;
784788 }
785789
@@ -1190,7 +1194,7 @@ Result SharedValidator::OnCallIndirect(const Location& loc,
11901194 TableType table_type;
11911195 result |= CheckFuncTypeIndex (sig_var, &func_type);
11921196 result |= CheckTableIndex (table_var, &table_type);
1193- if (table_type.element != Type::FuncRef) {
1197+ if (Failed (typechecker_. CheckType ( table_type.element , Type::FuncRef)) ) {
11941198 result |= PrintError (
11951199 loc,
11961200 " type mismatch: call_indirect must reference table of funcref type" );
@@ -1299,7 +1303,7 @@ Result SharedValidator::OnGlobalGet(const Location& loc, Var global_var) {
12991303 result |= CheckGlobalIndex (global_var, &global_type);
13001304 result |= typechecker_.OnGlobalGet (global_type.type );
13011305 if (Succeeded (result) && in_init_expr_) {
1302- if (global_var.index () >= num_imported_globals_ ) {
1306+ if (global_var.index () >= last_initialized_global_ ) {
13031307 result |= PrintError (
13041308 global_var.loc ,
13051309 " initializer expression can only reference an imported global" );
0 commit comments