@@ -88,8 +88,8 @@ Result SharedValidator::OnFuncType(const Location& loc,
8888 }
8989
9090 type_validation_result_ |= result;
91- result |= CheckSupertypes (loc, supertypes);
9291 }
92+ result |= CheckSupertypes (loc, supertypes);
9393
9494 return result;
9595}
@@ -237,19 +237,26 @@ Result SharedValidator::OnGlobalImport(const Location& loc,
237237 result |= PrintError (loc, " mutable globals cannot be imported" );
238238 }
239239 globals_.push_back (GlobalType{type, mutable_});
240- ++num_imported_globals_ ;
240+ ++last_initialized_global_ ;
241241 return result;
242242}
243243
244- Result SharedValidator::OnGlobal (const Location& loc,
245- Type type,
246- bool mutable_) {
244+ Result SharedValidator::BeginGlobal (const Location& loc,
245+ Type type,
246+ bool mutable_) {
247247 CHECK_RESULT (
248248 CheckReferenceType (loc, type, type_fields_.NumTypes (), " globals" ));
249249 globals_.push_back (GlobalType{type, mutable_});
250250 return Result::Ok;
251251}
252252
253+ Result SharedValidator::EndGlobal (const Location&) {
254+ if (options_.features .gc_enabled ()) {
255+ last_initialized_global_++;
256+ }
257+ return Result::Ok;
258+ }
259+
253260Result SharedValidator::CheckType (const Location& loc,
254261 Type actual,
255262 Type expected,
@@ -278,8 +285,6 @@ Result SharedValidator::CheckReferenceType(const Location& loc,
278285
279286Result SharedValidator::CheckSupertypes (const Location& loc,
280287 SupertypesInfo* supertypes) {
281- assert (options_.features .function_references_enabled ());
282-
283288 TypeEntry& entry = type_fields_.type_entries .back ();
284289 Index current_index = type_fields_.NumTypes () - 1 ;
285290 Index end_index;
@@ -787,8 +792,7 @@ Index SharedValidator::GetCanonicalTypeIndex(Index type_index) {
787792 return kInvalidIndex ;
788793 }
789794
790- if (options_.features .function_references_enabled () &&
791- Succeeded (type_validation_result_)) {
795+ if (Succeeded (type_validation_result_)) {
792796 return type_fields_.type_entries [type_index].canonical_index ;
793797 }
794798
@@ -1321,7 +1325,7 @@ Result SharedValidator::OnGlobalGet(const Location& loc, Var global_var) {
13211325 result |= CheckGlobalIndex (global_var, &global_type);
13221326 result |= typechecker_.OnGlobalGet (global_type.type );
13231327 if (Succeeded (result) && in_init_expr_) {
1324- if (global_var.index () >= num_imported_globals_ ) {
1328+ if (global_var.index () >= last_initialized_global_ ) {
13251329 result |= PrintError (
13261330 global_var.loc ,
13271331 " initializer expression can only reference an imported global" );
0 commit comments