Return
Rethinking Exception Handling in a Lightweight JavaScript Interpreter
DOI:10.1109/access.2026.3726724.png)
Abstract
En 中文
Dynamic language interpreters must handle exceptions as part of normal execution, since many semantic checks are performed at runtime. In interpreter-based JavaScript engines, particularly in lightweight or resource-constrained environments, exception propagation is often implemented using return-based mechanisms, where potentially failing operations return tagged results that must be explicitly checked and propagated by the interpreter. While this approach provides explicit control over exceptional states, it introduces repetitive checks in the interpreter hotpath and increases implementation complexity. In this paper, we revisit this design choice by exploring Native Exception-based Handling (NEH), which leverages the host language’s zero-cost exception mechanism to propagate JavaScript exceptions via native stack unwinding. We present a detailed design and implementation of NEH in a lightweight JavaScript interpreter and compare it with a conventional return-based approach within the same system. The proposed design preserves JavaScript semantics while ensuring robust failure containment through a sandboxed execution boundary. We evaluate both approaches across multiple architectures and compiler toolchains, focusing on code complexity, binary size, and runtime performance using representative JavaScript workloads. Our results show that NEH significantly reduces exception-related boilerplate and simplifies the interpreter hotpath without increasing binary footprint, while introducing no systematic runtime penalty despite relying on native C++ exceptions. Overall, this case study suggests that native exception mechanisms can serve as a practical design alternative for lightweight interpreter-based JavaScript engines with similar architectural characteristics.
Keywords:
Dynamic language runtimes
exception handling
interpreter design
JavaScript engine
native exception propagation
runtime system optimization
zero-cost exceptions
Journal
IF:
3.6
Papers:
9.8W
Citations:
29.4W

