1/*
2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef HandlerInfo_h
27#define HandlerInfo_h
28
29#include "CodeLocation.h"
30
31namespace JSC {
32
33enum class HandlerType {
34 Illegal = 0,
35 Catch = 1,
36 Finally = 2,
37 SynthesizedFinally = 3
38};
39
40struct HandlerInfoBase {
41 HandlerType type() const { return static_cast<HandlerType>(typeBits); }
42 void setType(HandlerType type) { typeBits = static_cast<uint32_t>(type); }
43
44 const char* typeName()
45 {
46 switch (type()) {
47 case HandlerType::Catch:
48 return "catch";
49 case HandlerType::Finally:
50 return "finally";
51 case HandlerType::SynthesizedFinally:
52 return "synthesized finally";
53 default:
54 ASSERT_NOT_REACHED();
55 }
56 return nullptr;
57 }
58
59 bool isCatchHandler() const { return type() == HandlerType::Catch; }
60
61 uint32_t start;
62 uint32_t end;
63 uint32_t target;
64 uint32_t typeBits : 2; // HandlerType
65};
66
67struct UnlinkedHandlerInfo : public HandlerInfoBase {
68 UnlinkedHandlerInfo(uint32_t start, uint32_t end, uint32_t target, HandlerType handlerType)
69 {
70 this->start = start;
71 this->end = end;
72 this->target = target;
73 setType(handlerType);
74 ASSERT(type() == handlerType);
75 }
76};
77
78struct HandlerInfo : public HandlerInfoBase {
79 void initialize(const UnlinkedHandlerInfo& unlinkedInfo)
80 {
81 start = unlinkedInfo.start;
82 end = unlinkedInfo.end;
83 target = unlinkedInfo.target;
84 typeBits = unlinkedInfo.typeBits;
85 }
86
87#if ENABLE(JIT)
88 void initialize(const UnlinkedHandlerInfo& unlinkedInfo, CodeLocationLabel label)
89 {
90 initialize(unlinkedInfo);
91 nativeCode = label;
92 }
93
94 CodeLocationLabel nativeCode;
95#endif
96};
97
98} // namespace JSC
99
100#endif // HandlerInfo_h
101
102