@@ -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}
@@ -236,19 +236,26 @@ Result SharedValidator::OnGlobalImport(const Location& loc,
236236 result |= PrintError (loc, " mutable globals cannot be imported" );
237237 }
238238 globals_.push_back (GlobalType{type, mutable_});
239- ++num_imported_globals_ ;
239+ ++last_initialized_global_ ;
240240 return result;
241241}
242242
243- Result SharedValidator::OnGlobal (const Location& loc,
244- Type type,
245- bool mutable_) {
243+ Result SharedValidator::BeginGlobal (const Location& loc,
244+ Type type,
245+ bool mutable_) {
246246 CHECK_RESULT (
247247 CheckReferenceType (loc, type, type_fields_.NumTypes (), " globals" ));
248248 globals_.push_back (GlobalType{type, mutable_});
249249 return Result::Ok;
250250}
251251
252+ Result SharedValidator::EndGlobal (const Location&) {
253+ if (options_.features .gc_enabled ()) {
254+ last_initialized_global_++;
255+ }
256+ return Result::Ok;
257+ }
258+
252259Result SharedValidator::CheckType (const Location& loc,
253260 Type actual,
254261 Type expected,
@@ -277,8 +284,6 @@ Result SharedValidator::CheckReferenceType(const Location& loc,
277284
278285Result SharedValidator::CheckSupertypes (const Location& loc,
279286 SupertypesInfo* supertypes) {
280- assert (options_.features .function_references_enabled ());
281-
282287 TypeEntry& entry = type_fields_.type_entries .back ();
283288 Index current_index = type_fields_.NumTypes () - 1 ;
284289 Index end_index;
@@ -786,8 +791,7 @@ Index SharedValidator::GetCanonicalTypeIndex(Index type_index) {
786791 return kInvalidIndex ;
787792 }
788793
789- if (options_.features .function_references_enabled () &&
790- Succeeded (type_validation_result_)) {
794+ if (Succeeded (type_validation_result_)) {
791795 return type_fields_.type_entries [type_index].canonical_index ;
792796 }
793797
@@ -1210,7 +1214,7 @@ Result SharedValidator::OnCallIndirect(const Location& loc,
12101214 TableType table_type;
12111215 result |= CheckFuncTypeIndex (sig_var, &func_type);
12121216 result |= CheckTableIndex (table_var, &table_type);
1213- if (table_type.element != Type::FuncRef) {
1217+ if (Failed (typechecker_. CheckType ( table_type.element , Type::FuncRef)) ) {
12141218 result |= PrintError (
12151219 loc,
12161220 " type mismatch: call_indirect must reference table of funcref type" );
@@ -1319,7 +1323,7 @@ Result SharedValidator::OnGlobalGet(const Location& loc, Var global_var) {
13191323 result |= CheckGlobalIndex (global_var, &global_type);
13201324 result |= typechecker_.OnGlobalGet (global_type.type );
13211325 if (Succeeded (result) && in_init_expr_) {
1322- if (global_var.index () >= num_imported_globals_ ) {
1326+ if (global_var.index () >= last_initialized_global_ ) {
13231327 result |= PrintError (
13241328 global_var.loc ,
13251329 " initializer expression can only reference an imported global" );
0 commit comments