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.host.event;
16  
17  import org.htmlunit.corejs.javascript.Scriptable;
18  import org.htmlunit.corejs.javascript.ScriptableObject;
19  import org.htmlunit.javascript.JavaScriptEngine;
20  import org.htmlunit.javascript.configuration.JsxClass;
21  import org.htmlunit.javascript.configuration.JsxConstructor;
22  import org.htmlunit.javascript.configuration.JsxGetter;
23  
24  /**
25   * A JavaScript object for {@code PopStateEvent}.
26   *
27   * @author Ahmed Ashour
28   * @author Adam Afeltowicz
29   * @author Ronald Brill
30   */
31  @JsxClass
32  public class PopStateEvent extends Event {
33  
34      private Object state_;
35  
36      /**
37       * Default constructor.
38       */
39      public PopStateEvent() {
40          super("");
41      }
42  
43      /**
44       * {@inheritDoc}
45       */
46      @Override
47      @JsxConstructor
48      public void jsConstructor(final String type, final ScriptableObject details) {
49          super.jsConstructor(type, details);
50  
51          if (details != null && !JavaScriptEngine.isUndefined(details)) {
52              state_ = details.get("state");
53          }
54      }
55  
56      /**
57       * Creates a new event instance.
58       *
59       * @param target the event target
60       * @param type the event type
61       * @param state the state object
62       */
63      public PopStateEvent(final EventTarget target, final String type, final Object state) {
64          super(target, type);
65          state_ = state;
66      }
67  
68      /**
69       * Return the state object.
70       * @return the state object
71       */
72      @JsxGetter
73      public Object getState() {
74          return state_;
75      }
76  
77      /**
78       * {@inheritDoc}
79       */
80      @Override
81      public void put(final String name, final Scriptable start, final Object value) {
82          if (!"state".equals(name)) {
83              super.put(name, start, value);
84          }
85      }
86  }