@@ -85,8 +85,8 @@ Result SharedValidator::OnFuncType(const Location& loc,
8585 }
8686
8787 type_validation_result_ |= result;
88- result |= CheckSupertypes (loc, supertypes);
8988 }
89+ result |= CheckSupertypes (loc, supertypes);
9090
9191 return result;
9292}
@@ -233,19 +233,26 @@ Result SharedValidator::OnGlobalImport(const Location& loc,
233233 result |= PrintError (loc, " mutable globals cannot be imported" );
234234 }
235235 globals_.push_back (GlobalType{type, mutable_});
236- ++num_imported_globals_ ;
236+ ++last_initialized_global_ ;
237237 return result;
238238}
239239
240- Result SharedValidator::OnGlobal (const Location& loc,
241- Type type,
242- bool mutable_) {
240+ Result SharedValidator::BeginGlobal (const Location& loc,
241+ Type type,
242+ bool mutable_) {
243243 CHECK_RESULT (
244244 CheckReferenceType (loc, type, type_fields_.NumTypes (), " globals" ));
245245 globals_.push_back (GlobalType{type, mutable_});
246246 return Result::Ok;
247247}
248248
249+ Result SharedValidator::EndGlobal (const Location&) {
250+ if (options_.features .gc_enabled ()) {
251+ last_initialized_global_++;
252+ }
253+ return Result::Ok;
254+ }
255+
249256Result SharedValidator::CheckType (const Location& loc,
250257 Type actual,
251258 Type expected,
@@ -274,8 +281,6 @@ Result SharedValidator::CheckReferenceType(const Location& loc,
274281
275282Result SharedValidator::CheckSupertypes (const Location& loc,
276283 SupertypesInfo* supertypes) {
277- assert (options_.features .function_references_enabled ());
278-
279284 TypeEntry& entry = type_fields_.type_entries .back ();
280285 Index current_index = type_fields_.NumTypes () - 1 ;
281286 Index end_index;
@@ -783,8 +788,7 @@ Index SharedValidator::GetCanonicalTypeIndex(Index type_index) {
783788 return kInvalidIndex ;
784789 }
785790
786- if (options_.features .function_references_enabled () &&
787- Succeeded (type_validation_result_)) {
791+ if (Succeeded (type_validation_result_)) {
788792 return type_fields_.type_entries [type_index].canonical_index ;
789793 }
790794
@@ -1207,7 +1211,7 @@ Result SharedValidator::OnCallIndirect(const Location& loc,
12071211 TableType table_type;
12081212 result |= CheckFuncTypeIndex (sig_var, &func_type);
12091213 result |= CheckTableIndex (table_var, &table_type);
1210- if (table_type.element != Type::FuncRef) {
1214+ if (Failed (typechecker_. CheckType ( table_type.element , Type::FuncRef)) ) {
12111215 result |= PrintError (
12121216 loc,
12131217 " type mismatch: call_indirect must reference table of funcref type" );
@@ -1316,7 +1320,7 @@ Result SharedValidator::OnGlobalGet(const Location& loc, Var global_var) {
13161320 result |= CheckGlobalIndex (global_var, &global_type);
13171321 result |= typechecker_.OnGlobalGet (global_type.type );
13181322 if (Succeeded (result) && in_init_expr_) {
1319- if (global_var.index () >= num_imported_globals_ ) {
1323+ if (global_var.index () >= last_initialized_global_ ) {
13201324 result |= PrintError (
13211325 global_var.loc ,
13221326 " initializer expression can only reference an imported global" );
0 commit comments