2525import org .htmlunit .javascript .configuration .JsxClass ;
2626import org .htmlunit .javascript .configuration .JsxConstructor ;
2727import org .htmlunit .javascript .configuration .JsxGetter ;
28+ import org .htmlunit .javascript .host .dom .DOMException ;
2829import org .htmlunit .platform .canvas .rendering .RenderingBackend ;
2930
3031/**
@@ -61,7 +62,7 @@ public ImageData() {
6162 public static ImageData jsConstructor (final Context cx , final Scriptable scope ,
6263 final Object [] args , final Function ctorObj , final boolean inNewExpr ) {
6364 if (args .length < 2 ) {
64- throw JavaScriptEngine .reportRuntimeError ("ImageData ctor - too less arguments" );
65+ throw JavaScriptEngine .typeError ("ImageData ctor - too less arguments" );
6566 }
6667
6768 NativeUint8ClampedArray data = null ;
@@ -70,23 +71,35 @@ public static ImageData jsConstructor(final Context cx, final Scriptable scope,
7071 if (args [0 ] instanceof NativeUint8ClampedArray ) {
7172 data = (NativeUint8ClampedArray ) args [0 ];
7273 if (data .getArrayLength () % 4 != 0 ) {
73- throw JavaScriptEngine .reportRuntimeError ("ImageData ctor - data length mod 4 not zero" );
74+ throw JavaScriptEngine .asJavaScriptException (
75+ (HtmlUnitScriptable ) JavaScriptEngine .getTopCallScope (),
76+ new DOMException (
77+ "ImageData ctor - data length mod 4 not zero" ,
78+ DOMException .INVALID_STATE_ERR ));
7479 }
7580
7681 width = (int ) JavaScriptEngine .toInteger (args [1 ]);
7782 if (args .length < 3 ) {
7883 height = data .getArrayLength () / 4 / width ;
7984
8085 if (data .getArrayLength () != 4 * width * height ) {
81- throw JavaScriptEngine .reportRuntimeError ("ImageData ctor - width not correct" );
86+ throw JavaScriptEngine .asJavaScriptException (
87+ (HtmlUnitScriptable ) JavaScriptEngine .getTopCallScope (),
88+ new DOMException (
89+ "ImageData ctor - width not correct" ,
90+ DOMException .INDEX_SIZE_ERR ));
8291 }
8392 }
8493 else {
8594 height = (int ) JavaScriptEngine .toInteger (args [2 ]);
8695 }
8796
8897 if (data .getArrayLength () != 4 * width * height ) {
89- throw JavaScriptEngine .reportRuntimeError ("ImageData ctor - width/height not correct" );
98+ throw JavaScriptEngine .asJavaScriptException (
99+ (HtmlUnitScriptable ) JavaScriptEngine .getTopCallScope (),
100+ new DOMException (
101+ "ImageData ctor - width/height not correct" ,
102+ DOMException .INDEX_SIZE_ERR ));
90103 }
91104 }
92105 else {
@@ -95,10 +108,18 @@ public static ImageData jsConstructor(final Context cx, final Scriptable scope,
95108 }
96109
97110 if (width < 0 ) {
98- throw JavaScriptEngine .reportRuntimeError ("ImageData ctor - width negative" );
111+ throw JavaScriptEngine .asJavaScriptException (
112+ (HtmlUnitScriptable ) JavaScriptEngine .getTopCallScope (),
113+ new DOMException (
114+ "ImageData ctor - width negative" ,
115+ DOMException .INDEX_SIZE_ERR ));
99116 }
100117 if (height < 0 ) {
101- throw JavaScriptEngine .reportRuntimeError ("ImageData ctor - height negative" );
118+ throw JavaScriptEngine .asJavaScriptException (
119+ (HtmlUnitScriptable ) JavaScriptEngine .getTopCallScope (),
120+ new DOMException (
121+ "ImageData ctor - height negative" ,
122+ DOMException .INDEX_SIZE_ERR ));
102123 }
103124
104125 final ImageData result = new ImageData (null , 0 , 0 , width , height );
0 commit comments