View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript;
16  
17  import java.io.Serializable;
18  
19  import org.htmlunit.corejs.javascript.Delegator;
20  import org.htmlunit.corejs.javascript.Scriptable;
21  
22  /**
23   * Proxy for a {@link HtmlUnitScriptable}.
24   *
25   * @param <T> the type of scriptable object being wrapped
26   * @author Marc Guillemot
27   * @author Daniel Gredler
28   * @author Ronald Brill
29   */
30  public abstract class HtmlUnitScriptableProxy<T extends HtmlUnitScriptable> extends Delegator
31          implements Serializable {
32  
33      /**
34       * {@inheritDoc}
35       */
36      @Override
37      public Object get(final int index, Scriptable start) {
38          if (start instanceof HtmlUnitScriptableProxy<?>) {
39              start = ((HtmlUnitScriptableProxy<?>) start).getDelegee();
40          }
41          return getDelegee().get(index, start);
42      }
43  
44      /**
45       * {@inheritDoc}
46       */
47      @Override
48      public Object get(final String name, Scriptable start) {
49          if (start instanceof HtmlUnitScriptableProxy<?>) {
50              start = ((HtmlUnitScriptableProxy<?>) start).getDelegee();
51          }
52          return getDelegee().get(name, start);
53      }
54  
55      /**
56       * {@inheritDoc}
57       */
58      @Override
59      public boolean has(final int index, Scriptable start) {
60          if (start instanceof HtmlUnitScriptableProxy<?>) {
61              start = ((HtmlUnitScriptableProxy<?>) start).getDelegee();
62          }
63          return getDelegee().has(index, start);
64      }
65  
66      /**
67       * {@inheritDoc}
68       */
69      @Override
70      public boolean has(final String name, Scriptable start) {
71          if (start instanceof HtmlUnitScriptableProxy<?>) {
72              start = ((HtmlUnitScriptableProxy<?>) start).getDelegee();
73          }
74          return getDelegee().has(name, start);
75      }
76  
77      /**
78       * {@inheritDoc}
79       */
80      @Override
81      public boolean hasInstance(Scriptable instance) {
82          if (instance instanceof HtmlUnitScriptableProxy<?>) {
83              instance = ((HtmlUnitScriptableProxy<?>) instance).getDelegee();
84          }
85          return getDelegee().hasInstance(instance);
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      public void put(final int index, Scriptable start, final Object value) {
93          if (start instanceof HtmlUnitScriptableProxy<?>) {
94              start = ((HtmlUnitScriptableProxy<?>) start).getDelegee();
95          }
96          getDelegee().put(index, start, value);
97      }
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public void put(final String name, Scriptable start, final Object value) {
104         if (start instanceof HtmlUnitScriptableProxy<?>) {
105             start = ((HtmlUnitScriptableProxy<?>) start).getDelegee();
106         }
107         getDelegee().put(name, start, value);
108     }
109 
110     /**
111      * Delegates call to delegee.
112      * @param hint the type hint
113      * @return the default value
114      *
115      * @see org.htmlunit.corejs.javascript.Scriptable#getDefaultValue
116      */
117     @Override
118     public Object getDefaultValue(final Class<?> hint) {
119         return getDelegee().getDefaultValue(hint);
120     }
121 }