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