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.ScriptableObject;
18 import org.htmlunit.javascript.JavaScriptEngine;
19 import org.htmlunit.javascript.configuration.JsxClass;
20 import org.htmlunit.javascript.configuration.JsxConstructor;
21 import org.htmlunit.javascript.configuration.JsxGetter;
22
23 /**
24 * A JavaScript object for {@code CloseEvent}.
25 *
26 * @author Ahmed Ashour
27 * @author Ronald Brill
28 */
29 @JsxClass
30 public class CloseEvent extends Event {
31
32 private String reason_;
33 private int code_;
34 private boolean wasClean_;
35
36 /**
37 * Creates a new event instance.
38 */
39 public CloseEvent() {
40 super();
41 setType(TYPE_CLOSE);
42 reason_ = "";
43 }
44
45 /**
46 * {@inheritDoc}
47 */
48 @Override
49 public void eventCreated() {
50 super.eventCreated();
51 setType("");
52 }
53
54 /**
55 * JavaScript constructor.
56 *
57 * @param type the event type
58 * @param details the event details (optional)
59 */
60 @Override
61 @JsxConstructor
62 public void jsConstructor(final String type, final ScriptableObject details) {
63 super.jsConstructor(type, details);
64
65 if (details != null && !JavaScriptEngine.isUndefined(details)) {
66 code_ = JavaScriptEngine.toInt32(details.get("code"));
67 reason_ = JavaScriptEngine.toString(details.get("reason"));
68 wasClean_ = JavaScriptEngine.toBoolean(details.get("wasClean"));
69 }
70 }
71
72 /**
73 * @return the code
74 */
75 @JsxGetter
76 public int getCode() {
77 return code_;
78 }
79
80 /**
81 * @param code the code
82 */
83 public void setCode(final int code) {
84 code_ = code;
85 }
86
87 /**
88 * @return the reason
89 */
90 @JsxGetter
91 public String getReason() {
92 return reason_;
93 }
94
95 /**
96 * @param reason the reason
97 */
98 public void setReason(final String reason) {
99 reason_ = reason;
100 }
101
102 /**
103 * @return the wasClean
104 */
105 @JsxGetter
106 public boolean isWasClean() {
107 return wasClean_;
108 }
109
110 /**
111 * @param wasClean the wasClean
112 */
113 public void setWasClean(final boolean wasClean) {
114 wasClean_ = wasClean;
115 }
116 }