aboutsummaryrefslogtreecommitdiff
path: root/src/zjs_error.h
blob: 4b36d413482b9c1fb4e1d492053d85f4563d5316 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2017, Intel Corporation.

#ifndef __zjs_error_h__
#define __zjs_error_h__

#include "jerry-api.h"

typedef enum zjs_error_type {
    AssertionError,
    NetworkError,
    NotSupportedError,
    RangeError,
    SecurityError,
    SyntaxError,
    SystemError,
    TimeoutError,
    TypeError,
    Error
} zjs_error_type_t;

/** Initialize the error module, or reinitialize after cleanup. */
void zjs_error_init();

/** Release resources held by the error module. */
void zjs_error_cleanup();

/**
 * Create an error object to return from an API.
 *
 * @param name A custom name for the error.
 * @param message String for additional detail about the error.
 *
 * @return A new Error object with the given name and message set.
 */
jerry_value_t zjs_custom_error(const char *name, const char *message);

/**
 * Create an error object to return from an API.
 *
 * @param type An error type from zjs_error_type enum.
 * @param message String for additional detail about the error.
 *
 * @return A new Error or subclass object.
 */
jerry_value_t zjs_standard_error(zjs_error_type_t type, const char *message);

#define zjs_error(msg)          (zjs_standard_error(Error, (msg)))

#define ASSERTION_ERROR(msg)    (zjs_standard_error(AssertionError, (msg)))
#define SECURITY_ERROR(msg)     (zjs_standard_error(SecurityError, (msg)))
#define NOTSUPPORTED_ERROR(msg) (zjs_standard_error(NotSupportedError, (msg)))
#define SYNTAX_ERROR(msg)       (zjs_standard_error(SyntaxError, (msg)))
#define TYPE_ERROR(msg)         (zjs_standard_error(TypeError, (msg)))
#define RANGE_ERROR(msg)        (zjs_standard_error(RangeError, (msg)))
#define TIMEOUT_ERROR(msg)      (zjs_standard_error(TimeoutError, (msg)))
#define NETWORK_ERROR(msg)      (zjs_standard_error(NetworkError, (msg)))
#define SYSTEM_ERROR(msg)       (zjs_standard_error(SystemError, (msg)))

#endif  // __zjs_error_h__