From d510aa2122da8e7abfd37df8572e97424f79488c Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Sun, 19 Nov 2023 16:49:48 +0100 Subject: [PATCH] fix last commit --- .../htmlunit/javascript/MethodWrapper.java | 113 ------------------ .../javascript/host/css/CSSFontFaceRule.java | 2 +- .../javascript/host/dom/DOMException.java | 5 +- .../htmlunit/javascript/host/event/Event.java | 4 +- 4 files changed, 6 insertions(+), 118 deletions(-) delete mode 100644 src/main/java/org/htmlunit/javascript/MethodWrapper.java diff --git a/src/main/java/org/htmlunit/javascript/MethodWrapper.java b/src/main/java/org/htmlunit/javascript/MethodWrapper.java deleted file mode 100644 index cc14535a749..00000000000 --- a/src/main/java/org/htmlunit/javascript/MethodWrapper.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2002-2023 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; - -import java.lang.reflect.Method; - -import org.apache.commons.lang3.ArrayUtils; -import org.htmlunit.corejs.javascript.Context; -import org.htmlunit.corejs.javascript.Function; -import org.htmlunit.corejs.javascript.FunctionObject; -import org.htmlunit.corejs.javascript.Scriptable; -import org.htmlunit.corejs.javascript.ScriptableObject; - -/** - * Wraps a Java method to make it available as a JavaScript function - * (more flexible than Rhino's {@link FunctionObject}). - * - * @author Marc Guillemot - */ -public class MethodWrapper extends ScriptableObject implements Function { - - private final Class clazz_; - private final Method method_; - private final int[] jsTypeTags_; - - /** - * Facility constructor to wrap a method without arguments. - * @param methodName the name of the method to wrap - * @param clazz the class declaring the method - * @throws NoSuchMethodException if the method is no found - */ - MethodWrapper(final String methodName, final Class clazz) throws NoSuchMethodException { - this(methodName, clazz, ArrayUtils.EMPTY_CLASS_ARRAY); - } - - /** - * Wraps a method as a JavaScript function. - * @param methodName the name of the method to wrap - * @param clazz the class declaring the method - * @param parameterTypes the types of the method's parameter - * @throws NoSuchMethodException if the method is no found - */ - MethodWrapper(final String methodName, final Class clazz, final Class[] parameterTypes) - throws NoSuchMethodException { - - clazz_ = clazz; - method_ = clazz.getMethod(methodName, parameterTypes); - jsTypeTags_ = new int[parameterTypes.length]; - int i = 0; - for (final Class klass : parameterTypes) { - jsTypeTags_[i++] = FunctionObject.getTypeTag(klass); - } - } - - /** - * @see org.htmlunit.corejs.javascript.ScriptableObject#getClassName() - * @return a name based on the method name - */ - @Override - public String getClassName() { - return "function " + method_.getName(); - } - - /** - * {@inheritDoc} - */ - @Override - public Object call(final Context context, final Scriptable scope, final Scriptable thisObj, final Object[] args) { - return Context.reportRuntimeError("Function " + method_.getName() - + " called on incompatible object: " + thisObj); - } - - /** - * Converts JavaScript arguments to Java arguments. - * @param context the current context - * @param scope the current scope - * @param jsArgs the JavaScript arguments - * @return the java arguments - */ - Object[] convertJSArgsToJavaArgs(final Context context, final Scriptable scope, final Object[] jsArgs) { - if (jsArgs.length != jsTypeTags_.length) { - throw Context.reportRuntimeError("Bad number of parameters for function " + method_.getName() - + ": expected " + jsTypeTags_.length + " got " + jsArgs.length); - } - final Object[] javaArgs = new Object[jsArgs.length]; - int i = 0; - for (final Object object : jsArgs) { - javaArgs[i] = FunctionObject.convertArg(context, scope, object, jsTypeTags_[i++]); - } - return javaArgs; - } - - /** - * {@inheritDoc} - */ - @Override - public Scriptable construct(final Context context, final Scriptable scope, final Object[] args) { - throw Context.reportRuntimeError("Function " + method_.getName() + " can't be used as a constructor"); - } - -} diff --git a/src/main/java/org/htmlunit/javascript/host/css/CSSFontFaceRule.java b/src/main/java/org/htmlunit/javascript/host/css/CSSFontFaceRule.java index 45eaf0b85b3..b2abab673d6 100644 --- a/src/main/java/org/htmlunit/javascript/host/css/CSSFontFaceRule.java +++ b/src/main/java/org/htmlunit/javascript/host/css/CSSFontFaceRule.java @@ -65,7 +65,7 @@ protected CSSFontFaceRule(final CSSStyleSheet stylesheet, final CSSFontFaceRuleI * {@inheritDoc} */ @Override - public short getType() { + public int getType() { return FONT_FACE_RULE; } diff --git a/src/main/java/org/htmlunit/javascript/host/dom/DOMException.java b/src/main/java/org/htmlunit/javascript/host/dom/DOMException.java index 6817a858a12..d78c3487945 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/DOMException.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/DOMException.java @@ -35,6 +35,7 @@ * @author Marc Guillemot * @author Frank Danek * @author Ahmed Ashour + * @author Ronald Brill */ @JsxClass public class DOMException extends HtmlUnitScriptable { @@ -120,7 +121,7 @@ public class DOMException extends HtmlUnitScriptable { @JsxConstant(IE) public static final int SERIALIZE_ERR = 82; - private final short code_; + private final int code_; private final String message_; private int lineNumber_; private String fileName_; @@ -139,7 +140,7 @@ public DOMException() { * @param message the exception message * @param errorCode the error code */ - public DOMException(final String message, final short errorCode) { + public DOMException(final String message, final int errorCode) { code_ = errorCode; message_ = message; } diff --git a/src/main/java/org/htmlunit/javascript/host/event/Event.java b/src/main/java/org/htmlunit/javascript/host/event/Event.java index 91b18c44a08..c619975e168 100644 --- a/src/main/java/org/htmlunit/javascript/host/event/Event.java +++ b/src/main/java/org/htmlunit/javascript/host/event/Event.java @@ -577,7 +577,7 @@ public class Event extends HtmlUnitScriptable { * The current event phase. This is a W3C standard attribute. One of {@link #NONE}, * {@link #CAPTURING_PHASE}, {@link #AT_TARGET} or {@link #BUBBLING_PHASE}. */ - private short eventPhase_; + private int eventPhase_; /** * Whether or not the event bubbles. The value of this attribute depends on the event type. To @@ -886,7 +886,7 @@ public int getEventPhase() { * * @param phase the phase the event is in */ - public void setEventPhase(final short phase) { + public void setEventPhase(final int phase) { if (phase != CAPTURING_PHASE && phase != AT_TARGET && phase != BUBBLING_PHASE) { throw new IllegalArgumentException("Illegal phase specified: " + phase); }