satyr 0.43
Loading...
Searching...
No Matches
platform.h
Go to the documentation of this file.
1/*
2 js_platform.h
3
4 Copyright (C) 2016 ABRT Team
5 Copyright (C) 2016 Red Hat, Inc.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20*/
21#ifndef SATYR_JS_PLATFORM_H
22#define SATYR_JS_PLATFORM_H
23
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <inttypes.h>
34#include <json.h>
35
36struct sr_location;
37
38enum sr_js_engine
39{
40 /* Skipped 0 to enable use of ! in conditions */
41
42 SR_JS_ENGINE_V8 = 0x1,
43
44 /* SR_JS_ENGINE_SPIDERMONKEY = 0x2, */
45 /* SR_JS_ENGINE_JAVASCRIPTCORE = 0x3, */
46
47 /* Keep this the last entry.
48 * Must be lower than 0xF.
49 */
50 _SR_JS_ENGINE_UPPER_BOUND,
51
52 /* Uninitialized value.
53 */
54 _SR_JS_ENGINE_UNINIT = 0xF,
55};
56
57#define SR_JS_ENGINE_VALIDITY_CHECK(engine) (engine > 0 && engine < _SR_JS_ENGINE_UPPER_BOUND)
58
59enum sr_js_runtime
60{
61 /* Skipped 0 to enable use of ! in conditions */
62
63 SR_JS_RUNTIME_NODEJS = 0x1,
64
65 /* SR_JS_RUNTIME_MONGODB = 0x2, */
66 /* SR_JS_RUNTIME_PHANTOMEJS = 0x3, */
67 /* SR_JS_RUNTIME_CHROME = 0x4, */
68 /* SR_JS_RUNTIME_FIREFOX = 0x5, */
69 /* SR_JS_RUNTIME_GJS = 0x6, */
70
71
72 /* Keep this the last entry.
73 * Must be lower than 0xFFF.
74 */
75 _SR_JS_RUNTIME_UPPER_BOUND,
76
77 /* Uninitialized.
78 */
79 _SR_JS_RUNTIME_UNINIT=0xFFF,
80};
81
82#define SR_JS_RUNTIME_VALIDITY_CHECK(runtime) (runtime > 0 && runtime < _SR_JS_RUNTIME_UPPER_BOUND)
83
84/* bits 31-9 = rutime
85 * bits 8-0 = engine
86 */
87typedef uint32_t sr_js_platform_t;
88
89#define SR_JS_PLATFORM_NULL 0
90
91#define _sr_js_platform_assemble(runtime, engine) ((uint32_t)(runtime << 4) | engine)
92
93/* Initialize to 0xFFFF to mimic a pointer logic with !. */
94#define sr_js_platform_new() (_sr_js_platform_assemble(_SR_JS_RUNTIME_UNINIT, _SR_JS_ENGINE_UNINIT))
95
96#define sr_js_platform_init(platform, runtime, engine) \
97 do { platform = _sr_js_platform_assemble(runtime, engine); } while (0)
98
99#define sr_js_platform_free(platform) ((void)platform)
100
101#define sr_js_platform_dup(platform) (platform)
102
103#define sr_js_platform_engine(platform) (platform & 0xF)
104
105#define sr_js_platform_runtime(platform) (platform >> 4)
106
107const char *
108sr_js_engine_to_string(enum sr_js_engine engine);
109
110enum sr_js_engine
111sr_js_engine_from_string(const char * engine);
112
113const char *
114sr_js_runtime_to_string(enum sr_js_runtime runtime);
115
116enum sr_js_runtime
117sr_js_runtime_from_string(const char * runtime);
118
119/* Creates new JavaScript platform entity from passed information.
120 *
121 * The runtime_name argument is mandatory.
122 *
123 * The runtime_version argument can be NULL which means "the most common
124 * version". The argument is used to determine JavaScript engine because the
125 * engine is sometimes subject to change in JavaScript platforms (i.e. MongoDB
126 * : V8 -> * SpiderMonkey) .
127 */
128sr_js_platform_t
129sr_js_platform_from_string(const char *runtime_name,
130 const char *runtime_version,
131 char **error_message);
132
133char *
134sr_js_platform_to_json(sr_js_platform_t platform);
135
136sr_js_platform_t
137sr_js_platform_from_json(json_object *root, char **error_message);
138
139struct sr_js_stacktrace *
140sr_js_platform_parse_stacktrace(sr_js_platform_t platform, const char **input,
141 struct sr_location *location);
142
143struct sr_js_frame *
144sr_js_platform_parse_frame(sr_js_platform_t platform, const char **input,
145 struct sr_location *location);
146
147#ifdef __cplusplus
148}
149#endif
150
151#endif /* SATYR_JS_PLATFORM_H */
A location of a parser in the input stream.
Definition location.h:43