History

js: fix event registration (keys, script-message, more)

Commit 63205981 removed some events but left all other event IDs at their original values, which created "holes" at the events IDs array. The JS backend for mp.register_event maps a name to an ID by scanning all IDs and stopping when the name was found or a NULL name was returned. Lua does the same except that it doesn't stop on NULL name. Previously it was not possible to have a NULL name before the end of the array, but now it is possible due to the enumeration holes. Fix by skipping missing names, like lua does.

Avi Halachmi (:avih) committed 4 years ago

Commit 5c5e35c1 parent d92cf771 file · +3 −3Browse files

Showing the changes to player/javascript.c (1 of 1 file). Show all

Unified · Split

player/javascript.c+3−3
@@ -610,9 +610,9 @@ static void script__request_event(js_State *J) · 609 unmodified lines
610610 const char *event = js_tostring(J, 1);
611611 bool enable = js_toboolean(J, 2);
612612
613− const char *name;
614− for (int n = 0; n < 256 && (name = mpv_event_name(n)); n++) {
615− if (strcmp(name, event) == 0) {
613+ for (int n = 0; n < 256; n++) {
614+ const char *name = mpv_event_name(n);
615+ if (name && strcmp(name, event) == 0) {
616616 push_status(J, mpv_request_event(jclient(J), n, enable));
617617 return;
618618 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t