Skip to content

Commit e6747a2

Browse files
authored
fix: raise an error during wizening for async functions given to addEventListener (#689)
1 parent 367c934 commit e6747a2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

runtime/js-compute-runtime/js-compute-runtime.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "js/Initialization.h"
1818
#include "js/SourceText.h"
1919
#include "jsapi.h"
20+
#include "jsfriendapi.h"
2021

2122
#pragma clang diagnostic pop
2223

@@ -361,6 +362,23 @@ static bool addEventListener(JSContext *cx, unsigned argc, Value *vp) {
361362
exit(1);
362363
}
363364

365+
JS::RootedObject obj(cx, &val.toObject());
366+
JS::RootedObject result(cx);
367+
if (!JS_GetPrototype(cx, obj, &result)) {
368+
return false;
369+
}
370+
JS::RootedObject asyncproto(cx);
371+
if (!JS_GetClassPrototype(cx, JSProtoKey::JSProto_AsyncFunction, &asyncproto)) {
372+
return false;
373+
}
374+
375+
if (result == asyncproto) {
376+
fprintf(stderr,
377+
"Error: addEventListener: Argument 2 should not be async function. Please rewrite this "
378+
"to be a synchronous function which returns a Response or a Promise of a Response.\n");
379+
exit(1);
380+
}
381+
364382
return FETCH_HANDLERS->append(&val.toObject());
365383
}
366384

0 commit comments

Comments
 (0)