Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
* vim: set ts=8 sts=2 et sw=2 tw=80:
3
* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef frontend_BinAST_macros_h
8
#define frontend_BinAST_macros_h
9
10
#include "vm/JSContext.h"
11
12
// Evaluate an expression EXPR, checking that the result is not falsy.
13
//
14
// Throw `cx->alreadyReportedError()` if it returns 0/nullptr.
15
#define BINJS_TRY(EXPR) \
16
do { \
17
if (!EXPR) return cx_->alreadyReportedError(); \
18
} while (false)
19
20
// Evaluate an expression EXPR, checking that the result is not falsy.
21
// In case of success, assign the result to VAR.
22
//
23
// Throw `cx->alreadyReportedError()` if it returns 0/nullptr.
24
#define BINJS_TRY_VAR(VAR, EXPR) \
25
do { \
26
VAR = EXPR; \
27
if (!VAR) return cx_->alreadyReportedError(); \
28
} while (false)
29
30
// Evaluate an expression EXPR, checking that the result is not falsy.
31
// In case of success, assign the result to a new variable VAR.
32
//
33
// Throw `cx->alreadyReportedError()` if it returns 0/nullptr.
34
#define BINJS_TRY_DECL(VAR, EXPR) \
35
auto VAR = EXPR; \
36
if (!VAR) return cx_->alreadyReportedError();
37
38
#define BINJS_TRY_EMPL(VAR, EXPR) \
39
do { \
40
auto _tryEmplResult = EXPR; \
41
if (!_tryEmplResult) return cx_->alreadyReportedError(); \
42
VAR.emplace(_tryEmplResult.unwrap()); \
43
} while (false)
44
45
#define BINJS_MOZ_TRY_EMPLACE(VAR, EXPR) \
46
do { \
47
auto _tryEmplResult = EXPR; \
48
if (_tryEmplResult.isErr()) \
49
return ::mozilla::Err(_tryEmplResult.unwrapErr()); \
50
VAR.emplace(_tryEmplResult.unwrap()); \
51
} while (false)
52
53
// Evaluate an expression EXPR, checking that the result is a success.
54
// In case of success, unwrap and assign the result to a new variable VAR.
55
//
56
// In case of error, propagate the error.
57
#define BINJS_MOZ_TRY_DECL(VAR, EXPR) \
58
auto _##VAR = EXPR; \
59
if (_##VAR.isErr()) return ::mozilla::Err(_##VAR.unwrapErr()); \
60
auto VAR = _##VAR.unwrap();
61
62
#endif // frontend_BinAST_macros_h