@@ -54,12 +54,14 @@ static JSObject* objectForEventTargetListeners(VM& vm, JSGlobalObject* exec, Eve
5454 auto * scriptExecutionContext = eventTarget->scriptExecutionContext ();
5555 if (!scriptExecutionContext)
5656 return nullptr ;
57+ auto scope = DECLARE_THROW_SCOPE (vm);
5758
5859 JSObject* listeners = nullptr ;
5960
6061 for (auto & eventType : eventTarget->eventTypes ()) {
6162 unsigned listenersForEventIndex = 0 ;
6263 auto * listenersForEvent = constructEmptyArray (exec, nullptr );
64+ RETURN_IF_EXCEPTION (scope, {});
6365
6466 for (auto & eventListener : eventTarget->eventListeners (eventType)) {
6567 if (!is<JSEventListener>(eventListener->callback ()))
@@ -74,6 +76,7 @@ static JSObject* objectForEventTargetListeners(VM& vm, JSGlobalObject* exec, Eve
7476 continue ;
7577
7678 auto * propertiesForListener = constructEmptyObject (exec);
79+ RETURN_IF_EXCEPTION (scope, {});
7780 propertiesForListener->putDirect (vm, Identifier::fromString (vm, " callback" _s), jsFunction);
7881 propertiesForListener->putDirect (vm, Identifier::fromString (vm, " capture" _s), jsBoolean (eventListener->useCapture ()));
7982 propertiesForListener->putDirect (vm, Identifier::fromString (vm, " passive" _s), jsBoolean (eventListener->isPassive ()));
@@ -82,8 +85,10 @@ static JSObject* objectForEventTargetListeners(VM& vm, JSGlobalObject* exec, Eve
8285 }
8386
8487 if (listenersForEventIndex) {
85- if (!listeners)
88+ if (!listeners) {
8689 listeners = constructEmptyObject (exec);
90+ RETURN_IF_EXCEPTION (scope, {});
91+ }
8792 listeners->putDirect (vm, Identifier::fromString (vm, eventType), listenersForEvent);
8893 }
8994 }
@@ -121,6 +126,7 @@ JSValue BunInjectedScriptHost::getInternalProperties(VM& vm, JSGlobalObject* exe
121126 if (auto * worker = JSWorker::toWrapped (vm, value)) {
122127 unsigned index = 0 ;
123128 auto * array = constructEmptyArray (exec, nullptr );
129+ RETURN_IF_EXCEPTION (scope, {});
124130
125131 String name = worker->name ();
126132 if (!name.isEmpty ())
@@ -142,13 +148,15 @@ JSValue BunInjectedScriptHost::getInternalProperties(VM& vm, JSGlobalObject* exe
142148 if (type == JSDOMWrapperType) {
143149 if (auto * headers = jsDynamicCast<JSFetchHeaders*>(value)) {
144150 auto * array = constructEmptyArray (exec, nullptr );
151+ RETURN_IF_EXCEPTION (scope, {});
145152 constructDataProperties (vm, exec, array, WebCore::getInternalProperties (vm, exec, headers));
146153 RETURN_IF_EXCEPTION (scope, {});
147154 return array;
148155 }
149156
150157 if (auto * formData = jsDynamicCast<JSDOMFormData*>(value)) {
151158 auto * array = constructEmptyArray (exec, nullptr );
159+ RETURN_IF_EXCEPTION (scope, {});
152160 constructDataProperties (vm, exec, array, WebCore::getInternalProperties (vm, exec, formData));
153161 RETURN_IF_EXCEPTION (scope, {});
154162 return array;
@@ -157,20 +165,23 @@ JSValue BunInjectedScriptHost::getInternalProperties(VM& vm, JSGlobalObject* exe
157165 } else if (type == JSAsJSONType) {
158166 if (auto * params = jsDynamicCast<JSURLSearchParams*>(value)) {
159167 auto * array = constructEmptyArray (exec, nullptr );
168+ RETURN_IF_EXCEPTION (scope, {});
160169 constructDataProperties (vm, exec, array, WebCore::getInternalProperties (vm, exec, params));
161170 RETURN_IF_EXCEPTION (scope, {});
162171 return array;
163172 }
164173
165174 if (auto * cookie = jsDynamicCast<JSCookie*>(value)) {
166175 auto * array = constructEmptyArray (exec, nullptr );
176+ RETURN_IF_EXCEPTION (scope, {});
167177 constructDataProperties (vm, exec, array, WebCore::getInternalProperties (vm, exec, cookie));
168178 RETURN_IF_EXCEPTION (scope, {});
169179 return array;
170180 }
171181
172182 if (auto * cookieMap = jsDynamicCast<JSCookieMap*>(value)) {
173183 auto * array = constructEmptyArray (exec, nullptr );
184+ RETURN_IF_EXCEPTION (scope, {});
174185 constructDataProperties (vm, exec, array, WebCore::getInternalProperties (vm, exec, cookieMap));
175186 RETURN_IF_EXCEPTION (scope, {});
176187 return array;
@@ -181,11 +192,13 @@ JSValue BunInjectedScriptHost::getInternalProperties(VM& vm, JSGlobalObject* exe
181192 if (auto * eventTarget = JSEventTarget::toWrapped (vm, value)) {
182193 unsigned index = 0 ;
183194 auto * array = constructEmptyArray (exec, nullptr );
195+ RETURN_IF_EXCEPTION (scope, {});
184196
185- if (auto * listeners = objectForEventTargetListeners (vm, exec, eventTarget))
197+ if (auto * listeners = objectForEventTargetListeners (vm, exec, eventTarget)) {
186198 array->putDirectIndex (exec, index++, constructInternalProperty (vm, exec, " listeners" _s, listeners));
199+ RETURN_IF_EXCEPTION (scope, {});
200+ }
187201
188- RETURN_IF_EXCEPTION (scope, {});
189202 return array;
190203 }
191204
0 commit comments