1 /* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdlib.h>
17
18 #include "jerryscript.h"
19
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)20 int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
21 {
22 srand (0);
23 jerry_init (JERRY_INIT_EMPTY);
24
25 if (jerry_is_valid_utf8_string ((jerry_char_t *) data, (jerry_size_t) size))
26 {
27 jerry_value_t parse_value = jerry_parse (NULL, 0, (jerry_char_t *) data, size, JERRY_PARSE_NO_OPTS);
28
29 if (!jerry_value_is_error (parse_value))
30 {
31 jerry_value_t run_value = jerry_run (parse_value);
32 jerry_release_value (run_value);
33
34 jerry_value_t run_queue_value = jerry_run_all_enqueued_jobs ();
35 jerry_release_value (run_queue_value);
36 }
37
38 jerry_release_value (parse_value);
39 }
40
41 jerry_cleanup ();
42
43 return 0;
44 } /* LLVMFuzzerTestOneInput */
45