Skip to content

Commit c277b96

Browse files
committed
Move event section before global section
We decided move the event section before the global section in WebAssembly/exception-handling#98.
1 parent 7898e57 commit c277b96

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/binary-writer.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,19 @@ Result BinaryWriter::WriteModule() {
10111011
EndSection();
10121012
}
10131013

1014+
assert(module_->events.size() >= module_->num_event_imports);
1015+
Index num_events = module_->events.size() - module_->num_event_imports;
1016+
if (num_events) {
1017+
BeginKnownSection(BinarySection::Event);
1018+
WriteU32Leb128(stream_, num_events, "event count");
1019+
for (size_t i = 0; i < num_events; ++i) {
1020+
WriteHeader("event", i);
1021+
const Event* event = module_->events[i + module_->num_event_imports];
1022+
WriteEventType(event);
1023+
}
1024+
EndSection();
1025+
}
1026+
10141027
assert(module_->globals.size() >= module_->num_global_imports);
10151028
Index num_globals = module_->globals.size() - module_->num_global_imports;
10161029
if (num_globals) {
@@ -1025,19 +1038,6 @@ Result BinaryWriter::WriteModule() {
10251038
EndSection();
10261039
}
10271040

1028-
assert(module_->events.size() >= module_->num_event_imports);
1029-
Index num_events = module_->events.size() - module_->num_event_imports;
1030-
if (num_events) {
1031-
BeginKnownSection(BinarySection::Event);
1032-
WriteU32Leb128(stream_, num_events, "event count");
1033-
for (size_t i = 0; i < num_events; ++i) {
1034-
WriteHeader("event", i);
1035-
const Event* event = module_->events[i + module_->num_event_imports];
1036-
WriteEventType(event);
1037-
}
1038-
EndSection();
1039-
}
1040-
10411041
if (module_->exports.size()) {
10421042
BeginKnownSection(BinarySection::Export);
10431043
WriteU32Leb128(stream_, module_->exports.size(), "num exports");

src/binary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
V(Function, function, 3) \
3737
V(Table, table, 4) \
3838
V(Memory, memory, 5) \
39-
V(Global, global, 6) \
4039
V(Event, event, 13) \
40+
V(Global, global, 6) \
4141
V(Export, export, 7) \
4242
V(Start, start, 8) \
4343
V(Elem, elem, 9) \

test/binary/bad-event-after-export.txt renamed to test/binary/bad-event-after-global.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;;; ARGS2: --enable-exceptions
44
magic
55
version
6-
section(EXPORT) { count[0] }
6+
section(GLOBAL) { count[0] }
77
section(EVENT) { count[0] }
88
(;; STDERR ;;;
99
000000d: error: section Event out of order

test/binary/bad-event-before-global.txt renamed to test/binary/bad-event-before-memory.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
magic
55
version
66
section(EVENT) { count[0] }
7-
section(GLOBAL) { count[0] }
7+
section(MEMORY) { count[0] }
88
(;; STDERR ;;;
9-
000000d: error: section Global out of order
10-
000000d: error: section Global out of order
9+
000000d: error: section Memory out of order
10+
000000d: error: section Memory out of order
1111
;;; STDERR ;;)

0 commit comments

Comments
 (0)