Skip to content

Commit

Permalink
'Illegal constructor' is a type error
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Feb 7, 2025
1 parent 6a9c14c commit 1b5598f
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public GeolocationCoordinates() {
*/
@JsxConstructor
public void jsConstructor() {
throw JavaScriptEngine.reportRuntimeError("Illegal constructor.");
throw JavaScriptEngine.typeError("Illegal constructor.");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public GeolocationPosition() {
*/
@JsxConstructor
public void jsConstructor() {
throw JavaScriptEngine.reportRuntimeError("Illegal constructor.");
throw JavaScriptEngine.typeError("Illegal constructor.");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public class GeolocationPositionError extends HtmlUnitScriptable {
*/
@JsxConstructor
public void jsConstructor() {
throw JavaScriptEngine.reportRuntimeError("Illegal constructor.");
throw JavaScriptEngine.typeError("Illegal constructor.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2002-2025 Gargoyle Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.htmlunit.javascript.host.geo;

import org.htmlunit.WebDriverTestCase;
import org.htmlunit.junit.BrowserRunner;
import org.htmlunit.junit.annotation.Alerts;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Tests for {@link GeolocationCoordinates}.
*
* @author Ronald Brill
*/
@RunWith(BrowserRunner.class)
public class GeolocationCoordinatesTest extends WebDriverTestCase {

/**
* @throws Exception if the test fails
*/
@Test
@Alerts("TypeError")
public void ctor() throws Exception {
final String html =
"<html><head><script>\n"
+ LOG_TITLE_FUNCTION
+ " function test() {\n"
+ " try {\n"
+ " new GeolocationCoordinates();\n"
+ " } catch(e) { logEx(e) }\n"
+ " }\n"
+ "</script></head><body onload='test()'>\n"
+ "</body></html>";

loadPageVerifyTitle2(html);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2002-2025 Gargoyle Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.htmlunit.javascript.host.geo;

import org.htmlunit.WebDriverTestCase;
import org.htmlunit.junit.BrowserRunner;
import org.htmlunit.junit.annotation.Alerts;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Tests for {@link GeolocationPositionError}.
*
* @author Ronald Brill
*/
@RunWith(BrowserRunner.class)
public class GeolocationPositionErrorTest extends WebDriverTestCase {

/**
* @throws Exception if the test fails
*/
@Test
@Alerts("TypeError")
public void ctor() throws Exception {
final String html =
"<html><head><script>\n"
+ LOG_TITLE_FUNCTION
+ " function test() {\n"
+ " try {\n"
+ " new GeolocationPositionError();\n"
+ " } catch(e) { logEx(e) }\n"
+ " }\n"
+ "</script></head><body onload='test()'>\n"
+ "</body></html>";

loadPageVerifyTitle2(html);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2002-2025 Gargoyle Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.htmlunit.javascript.host.geo;

import org.htmlunit.WebDriverTestCase;
import org.htmlunit.junit.BrowserRunner;
import org.htmlunit.junit.annotation.Alerts;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Tests for {@link GeolocationPosition}.
*
* @author Ronald Brill
*/
@RunWith(BrowserRunner.class)
public class GeolocationPositionTest extends WebDriverTestCase {

/**
* @throws Exception if the test fails
*/
@Test
@Alerts("TypeError")
public void ctor() throws Exception {
final String html =
"<html><head><script>\n"
+ LOG_TITLE_FUNCTION
+ " function test() {\n"
+ " try {\n"
+ " new GeolocationPosition();\n"
+ " } catch(e) { logEx(e) }\n"
+ " }\n"
+ "</script></head><body onload='test()'>\n"
+ "</body></html>";

loadPageVerifyTitle2(html);
}
}

0 comments on commit 1b5598f

Please sign in to comment.