@@ -85,8 +85,8 @@ Result SharedValidator::OnFuncType(const Location& loc,
85
85
}
86
86
87
87
type_validation_result_ |= result;
88
- result |= CheckGCTypeExtension (loc, gc_ext);
89
88
}
89
+ result |= CheckGCTypeExtension (loc, gc_ext);
90
90
91
91
return result;
92
92
}
@@ -229,19 +229,26 @@ Result SharedValidator::OnGlobalImport(const Location& loc,
229
229
result |= PrintError (loc, " mutable globals cannot be imported" );
230
230
}
231
231
globals_.push_back (GlobalType{type, mutable_});
232
- ++num_imported_globals_ ;
232
+ ++last_initialized_global_ ;
233
233
return result;
234
234
}
235
235
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_) {
239
239
CHECK_RESULT (
240
240
CheckReferenceType (loc, type, type_fields_.NumTypes (), " globals" ));
241
241
globals_.push_back (GlobalType{type, mutable_});
242
242
return Result::Ok;
243
243
}
244
244
245
+ Result SharedValidator::EndGlobal (const Location&) {
246
+ if (options_.features .gc_enabled ()) {
247
+ last_initialized_global_++;
248
+ }
249
+ return Result::Ok;
250
+ }
251
+
245
252
Result SharedValidator::CheckType (const Location& loc,
246
253
Type actual,
247
254
Type expected,
@@ -268,8 +275,6 @@ Result SharedValidator::CheckReferenceType(const Location& loc,
268
275
269
276
Result SharedValidator::CheckGCTypeExtension (const Location& loc,
270
277
GCTypeExtension* gc_ext) {
271
- assert (options_.features .function_references_enabled ());
272
-
273
278
TypeEntry& entry = type_fields_.type_entries .back ();
274
279
Index current_index = type_fields_.NumTypes () - 1 ;
275
280
Index end_index;
@@ -778,8 +783,7 @@ Index SharedValidator::GetCanonicalTypeIndex(Index type_index) {
778
783
return kInvalidIndex ;
779
784
}
780
785
781
- if (options_.features .function_references_enabled () &&
782
- Succeeded (type_validation_result_)) {
786
+ if (Succeeded (type_validation_result_)) {
783
787
return type_fields_.type_entries [type_index].canonical_index ;
784
788
}
785
789
@@ -1190,7 +1194,7 @@ Result SharedValidator::OnCallIndirect(const Location& loc,
1190
1194
TableType table_type;
1191
1195
result |= CheckFuncTypeIndex (sig_var, &func_type);
1192
1196
result |= CheckTableIndex (table_var, &table_type);
1193
- if (table_type.element != Type::FuncRef) {
1197
+ if (Failed (typechecker_. CheckType ( table_type.element , Type::FuncRef)) ) {
1194
1198
result |= PrintError (
1195
1199
loc,
1196
1200
" type mismatch: call_indirect must reference table of funcref type" );
@@ -1299,7 +1303,7 @@ Result SharedValidator::OnGlobalGet(const Location& loc, Var global_var) {
1299
1303
result |= CheckGlobalIndex (global_var, &global_type);
1300
1304
result |= typechecker_.OnGlobalGet (global_type.type );
1301
1305
if (Succeeded (result) && in_init_expr_) {
1302
- if (global_var.index () >= num_imported_globals_ ) {
1306
+ if (global_var.index () >= last_initialized_global_ ) {
1303
1307
result |= PrintError (
1304
1308
global_var.loc ,
1305
1309
" initializer expression can only reference an imported global" );
0 commit comments