@@ -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}
@@ -232,19 +232,26 @@ Result SharedValidator::OnGlobalImport(const Location& loc,
232232 result |= PrintError (loc, " mutable globals cannot be imported" );
233233 }
234234 globals_.push_back (GlobalType{type, mutable_});
235- ++num_imported_globals_ ;
235+ ++last_initialized_global_ ;
236236 return result;
237237}
238238
239- Result SharedValidator::OnGlobal (const Location& loc,
240- Type type,
241- bool mutable_) {
239+ Result SharedValidator::BeginGlobal (const Location& loc,
240+ Type type,
241+ bool mutable_) {
242242 CHECK_RESULT (
243243 CheckReferenceType (loc, type, type_fields_.NumTypes (), " globals" ));
244244 globals_.push_back (GlobalType{type, mutable_});
245245 return Result::Ok;
246246}
247247
248+ Result SharedValidator::EndGlobal (const Location&) {
249+ if (options_.features .gc_enabled ()) {
250+ last_initialized_global_++;
251+ }
252+ return Result::Ok;
253+ }
254+
248255Result SharedValidator::CheckType (const Location& loc,
249256 Type actual,
250257 Type expected,
@@ -273,8 +280,6 @@ Result SharedValidator::CheckReferenceType(const Location& loc,
273280
274281Result SharedValidator::CheckSupertypes (const Location& loc,
275282 SupertypesInfo* supertypes) {
276- assert (options_.features .function_references_enabled ());
277-
278283 TypeEntry& entry = type_fields_.type_entries .back ();
279284 Index current_index = type_fields_.NumTypes () - 1 ;
280285 Index end_index;
@@ -782,8 +787,7 @@ Index SharedValidator::GetCanonicalTypeIndex(Index type_index) {
782787 return kInvalidIndex ;
783788 }
784789
785- if (options_.features .function_references_enabled () &&
786- Succeeded (type_validation_result_)) {
790+ if (Succeeded (type_validation_result_)) {
787791 return type_fields_.type_entries [type_index].canonical_index ;
788792 }
789793
@@ -1206,7 +1210,7 @@ Result SharedValidator::OnCallIndirect(const Location& loc,
12061210 TableType table_type;
12071211 result |= CheckFuncTypeIndex (sig_var, &func_type);
12081212 result |= CheckTableIndex (table_var, &table_type);
1209- if (table_type.element != Type::FuncRef) {
1213+ if (Failed (typechecker_. CheckType ( table_type.element , Type::FuncRef)) ) {
12101214 result |= PrintError (
12111215 loc,
12121216 " type mismatch: call_indirect must reference table of funcref type" );
@@ -1315,7 +1319,7 @@ Result SharedValidator::OnGlobalGet(const Location& loc, Var global_var) {
13151319 result |= CheckGlobalIndex (global_var, &global_type);
13161320 result |= typechecker_.OnGlobalGet (global_type.type );
13171321 if (Succeeded (result) && in_init_expr_) {
1318- if (global_var.index () >= num_imported_globals_ ) {
1322+ if (global_var.index () >= last_initialized_global_ ) {
13191323 result |= PrintError (
13201324 global_var.loc ,
13211325 " initializer expression can only reference an imported global" );
0 commit comments