summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/bytecode/HandlerInfo.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/bytecode/HandlerInfo.h')
-rw-r--r--Source/JavaScriptCore/bytecode/HandlerInfo.h91
1 files changed, 83 insertions, 8 deletions
diff --git a/Source/JavaScriptCore/bytecode/HandlerInfo.h b/Source/JavaScriptCore/bytecode/HandlerInfo.h
index 8396c9607..752defe8a 100644
--- a/Source/JavaScriptCore/bytecode/HandlerInfo.h
+++ b/Source/JavaScriptCore/bytecode/HandlerInfo.h
@@ -23,25 +23,100 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef HandlerInfo_h
-#define HandlerInfo_h
+#pragma once
#include "CodeLocation.h"
-#include <wtf/Platform.h>
+#include <wtf/Vector.h>
namespace JSC {
-struct HandlerInfo {
+enum class HandlerType {
+ Catch = 0,
+ Finally = 1,
+ SynthesizedCatch = 2,
+ SynthesizedFinally = 3
+};
+
+enum class RequiredHandler {
+ CatchHandler,
+ AnyHandler
+};
+
+struct HandlerInfoBase {
+ HandlerType type() const { return static_cast<HandlerType>(typeBits); }
+ void setType(HandlerType type) { typeBits = static_cast<uint32_t>(type); }
+
+ const char* typeName()
+ {
+ switch (type()) {
+ case HandlerType::Catch:
+ return "catch";
+ case HandlerType::Finally:
+ return "finally";
+ case HandlerType::SynthesizedCatch:
+ return "synthesized catch";
+ case HandlerType::SynthesizedFinally:
+ return "synthesized finally";
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ return nullptr;
+ }
+
+ bool isCatchHandler() const { return type() == HandlerType::Catch; }
+
+ template<typename Handler>
+ static Handler* handlerForIndex(Vector<Handler>& exeptionHandlers, unsigned index, RequiredHandler requiredHandler)
+ {
+ for (Handler& handler : exeptionHandlers) {
+ if ((requiredHandler == RequiredHandler::CatchHandler) && !handler.isCatchHandler())
+ continue;
+
+ // Handlers are ordered innermost first, so the first handler we encounter
+ // that contains the source address is the correct handler to use.
+ // This index used is either the BytecodeOffset or a CallSiteIndex.
+ if (handler.start <= index && handler.end > index)
+ return &handler;
+ }
+
+ return nullptr;
+ }
+
uint32_t start;
uint32_t end;
uint32_t target;
- uint32_t scopeDepth;
+ uint32_t typeBits : 2; // HandlerType
+};
+
+struct UnlinkedHandlerInfo : public HandlerInfoBase {
+ UnlinkedHandlerInfo(uint32_t start, uint32_t end, uint32_t target, HandlerType handlerType)
+ {
+ this->start = start;
+ this->end = end;
+ this->target = target;
+ setType(handlerType);
+ ASSERT(type() == handlerType);
+ }
+};
+
+struct HandlerInfo : public HandlerInfoBase {
+ void initialize(const UnlinkedHandlerInfo& unlinkedInfo)
+ {
+ start = unlinkedInfo.start;
+ end = unlinkedInfo.end;
+ target = unlinkedInfo.target;
+ typeBits = unlinkedInfo.typeBits;
+ }
+
#if ENABLE(JIT)
+ void initialize(const UnlinkedHandlerInfo& unlinkedInfo, CodeLocationLabel label)
+ {
+ initialize(unlinkedInfo);
+ nativeCode = label;
+ }
+
CodeLocationLabel nativeCode;
#endif
};
} // namespace JSC
-
-#endif // HandlerInfo_h
-