|
75 | 75 | import org.htmlunit.javascript.host.ConsoleCustom; |
76 | 76 | import org.htmlunit.javascript.host.URLSearchParams; |
77 | 77 | import org.htmlunit.javascript.host.Window; |
| 78 | +import org.htmlunit.javascript.host.WindowOrWorkerGlobalScope; |
78 | 79 | import org.htmlunit.javascript.host.dom.DOMException; |
79 | 80 | import org.htmlunit.javascript.host.html.HTMLElement; |
80 | 81 | import org.htmlunit.javascript.host.html.HTMLImageElement; |
81 | 82 | import org.htmlunit.javascript.host.html.HTMLOptionElement; |
82 | 83 | import org.htmlunit.javascript.host.intl.Intl; |
| 84 | +import org.htmlunit.javascript.host.worker.WorkerGlobalScope; |
83 | 85 | import org.htmlunit.javascript.host.xml.FormData; |
84 | 86 | import org.htmlunit.javascript.polyfill.Polyfill; |
85 | 87 | import org.htmlunit.util.StringUtils; |
@@ -1286,7 +1288,14 @@ public static EcmaError constructError(final String error, final String message) |
1286 | 1288 | public static RhinoException asJavaScriptException(final HtmlUnitScriptable scriptable, final String message, final int type) { |
1287 | 1289 | final DOMException domException = new DOMException(message, type); |
1288 | 1290 | domException.setParentScope(scriptable.getParentScope()); |
1289 | | - domException.setPrototype(scriptable.getWindow().getPrototype(DOMException.class)); |
| 1291 | + |
| 1292 | + final WindowOrWorkerGlobalScope wow = HtmlUnitScriptable.getWindowOrWorkerGlobalScope(scriptable); |
| 1293 | + if (wow instanceof Window window) { |
| 1294 | + domException.setPrototype(window.getPrototype(DOMException.class)); |
| 1295 | + } |
| 1296 | + else if (wow instanceof WorkerGlobalScope w) { |
| 1297 | + domException.setPrototype(w.getPrototype(DOMException.class)); |
| 1298 | + } |
1290 | 1299 |
|
1291 | 1300 | final EcmaError helper = ScriptRuntime.syntaxError("helper"); |
1292 | 1301 | String fileName = helper.sourceName(); |
|
0 commit comments