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.Context;
20  import org.htmlunit.corejs.javascript.Function;
21  import org.htmlunit.corejs.javascript.Scriptable;
22  
23  /**
24   * Wrapper for a {@link Function} delegating all calls to the wrapped instance.
25   *
26   * @author Marc Guillemot
27   * @author Ahmed Ashour
28   * @author Ronald Brill
29   */
30  public class FunctionWrapper implements Function, Serializable {
31      private final Function wrapped_;
32  
33      /**
34       * Constructs a new instance.
35       * @param wrapped the wrapped function
36       */
37      public FunctionWrapper(final Function wrapped) {
38          wrapped_ = wrapped;
39      }
40  
41      /**
42       * {@inheritDoc}
43       */
44      @Override
45      public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) {
46          return wrapped_.call(cx, scope, thisObj, args);
47      }
48  
49      /**
50       * {@inheritDoc}
51       */
52      @Override
53      public String getClassName() {
54          return wrapped_.getClassName();
55      }
56  
57      /**
58       * {@inheritDoc}
59       */
60      @Override
61      public Scriptable construct(final Context cx, final Scriptable scope, final Object[] args) {
62          return wrapped_.construct(cx, scope, args);
63      }
64  
65      /**
66       * {@inheritDoc}
67       */
68      @Override
69      public Object get(final String name, final Scriptable start) {
70          return wrapped_.get(name, start);
71      }
72  
73      /**
74       * {@inheritDoc}
75       */
76      @Override
77      public Object get(final int index, final Scriptable start) {
78          return wrapped_.get(index, start);
79      }
80  
81      /**
82       * {@inheritDoc}
83       */
84      @Override
85      public boolean has(final String name, final Scriptable start) {
86          return wrapped_.has(name, start);
87      }
88  
89      /**
90       * {@inheritDoc}
91       */
92      @Override
93      public boolean has(final int index, final Scriptable start) {
94          return wrapped_.has(index, start);
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     public void put(final String name, final Scriptable start, final Object value) {
102         wrapped_.put(name, wrapped_, value);
103     }
104 
105     /**
106      * {@inheritDoc}
107      */
108     @Override
109     public void put(final int index, final Scriptable start, final Object value) {
110         wrapped_.put(index, wrapped_, value);
111     }
112 
113     /**
114      * {@inheritDoc}
115      */
116     @Override
117     public void delete(final String name) {
118         wrapped_.delete(name);
119     }
120 
121     /**
122      * {@inheritDoc}
123      */
124     @Override
125     public void delete(final int index) {
126         wrapped_.delete(index);
127     }
128 
129     /**
130      * {@inheritDoc}
131      */
132     @Override
133     public Scriptable getPrototype() {
134         return wrapped_.getPrototype();
135     }
136 
137     /**
138      * {@inheritDoc}
139      */
140     @Override
141     public void setPrototype(final Scriptable prototype) {
142         wrapped_.setPrototype(prototype);
143     }
144 
145     /**
146      * {@inheritDoc}
147      */
148     @Override
149     public Scriptable getParentScope() {
150         return wrapped_.getParentScope();
151     }
152 
153     /**
154      * {@inheritDoc}
155      */
156     @Override
157     public void setParentScope(final Scriptable parent) {
158         wrapped_.setParentScope(parent);
159     }
160 
161     /**
162      * {@inheritDoc}
163      */
164     @Override
165     public Object[] getIds() {
166         return wrapped_.getIds();
167     }
168 
169     /**
170      * {@inheritDoc}
171      */
172     @Override
173     public Object getDefaultValue(final Class<?> hint) {
174         return wrapped_.getDefaultValue(hint);
175     }
176 
177     /**
178      * {@inheritDoc}
179      */
180     @Override
181     public boolean hasInstance(final Scriptable instance) {
182         return wrapped_.hasInstance(instance);
183     }
184 }