| 34 | #ifdef ENABLE_SCRIPTING |
| 35 | |
| 36 | TEST_F(ScriptingTests, MultipleSubscribersToSameEventShouldNotCrash) |
| 37 | { |
| 38 | auto& scriptEngine = static_cast<ScriptEngine&>(_context->GetScriptEngine()); |
| 39 | |
| 40 | // Register a plugin that subscribes twice to the same event |
| 41 | const char* pluginCode = R"( |
| 42 | registerPlugin({ |
| 43 | name: 'test-plugin-multiple-subscribers', |
| 44 | version: '1.0.0', |
| 45 | authors: ['openrct2-test'], |
| 46 | type: 'remote', |
| 47 | licence: 'MIT', |
| 48 | minApiVersion: 110, // deliberately the version before quickjs |
| 49 | targetApiVersion: 110, |
| 50 | main: function () { |
| 51 | context.subscribe('interval.tick', function (e) { |
| 52 | // first subscriber |
| 53 | }); |
| 54 | context.subscribe('interval.tick', function (e) { |
| 55 | // second subscriber |
| 56 | }); |
| 57 | } |
| 58 | }); |
| 59 | )"; |
| 60 | |
| 61 | scriptEngine.AddNetworkPlugin(pluginCode); |
| 62 | scriptEngine.LoadTransientPlugins(); |
| 63 | scriptEngine.Tick(); |
| 64 | |
| 65 | auto& hookEngine = scriptEngine.GetHookEngine(); |
| 66 | |
| 67 | // We need a JSValue to pass to Call. |
| 68 | JSContext* ctx = scriptEngine.GetContext(); |
| 69 | JSValue arg = JS_NewObject(ctx); |
| 70 | JS_SetPropertyStr(ctx, arg, "test", JS_NewInt32(ctx, 1)); |
| 71 | |
| 72 | // This should NOT crash. |
| 73 | hookEngine.Call(HookType::intervalTick, arg, false); |
| 74 | } |
| 75 | |
| 76 | #endif |
nothing calls this directly
no test coverage detected