@@ -79,6 +79,28 @@ static void test_function_snapshot (void)
79
79
jerry_cleanup ();
80
80
} /* test_function_snapshot */
81
81
82
+ static void test_exec_snapshot (uint32_t * snapshot_p , size_t snapshot_size , bool copy_bytecode )
83
+ {
84
+ char string_data [32 ];
85
+
86
+ jerry_init (JERRY_INIT_EMPTY );
87
+
88
+ jerry_value_t res = jerry_exec_snapshot (snapshot_p ,
89
+ snapshot_size ,
90
+ copy_bytecode );
91
+
92
+ TEST_ASSERT (!jerry_value_has_error_flag (res ));
93
+ TEST_ASSERT (jerry_value_is_string (res ));
94
+ jerry_size_t sz = jerry_get_string_size (res );
95
+ TEST_ASSERT (sz == 20 );
96
+ sz = jerry_string_to_char_buffer (res , (jerry_char_t * ) string_data , sz );
97
+ TEST_ASSERT (sz == 20 );
98
+ jerry_release_value (res );
99
+ TEST_ASSERT (!strncmp (string_data , "string from snapshot" , (size_t ) sz ));
100
+
101
+ jerry_cleanup ();
102
+ } /* test_exec_snapshot */
103
+
82
104
int
83
105
main (void )
84
106
{
@@ -90,7 +112,6 @@ main (void)
90
112
{
91
113
static uint32_t global_mode_snapshot_buffer [SNAPSHOT_BUFFER_SIZE ];
92
114
static uint32_t eval_mode_snapshot_buffer [SNAPSHOT_BUFFER_SIZE ];
93
- char string_data [32 ];
94
115
95
116
const char * code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();" ;
96
117
@@ -114,35 +135,21 @@ main (void)
114
135
TEST_ASSERT (eval_mode_snapshot_size != 0 );
115
136
jerry_cleanup ();
116
137
117
- jerry_init (JERRY_INIT_EMPTY );
118
-
119
- jerry_value_t res = jerry_exec_snapshot (global_mode_snapshot_buffer ,
120
- global_mode_snapshot_size ,
121
- false);
122
-
123
- TEST_ASSERT (!jerry_value_has_error_flag (res ));
124
- TEST_ASSERT (jerry_value_is_string (res ));
125
- jerry_size_t sz = jerry_get_string_size (res );
126
- TEST_ASSERT (sz == 20 );
127
- sz = jerry_string_to_char_buffer (res , (jerry_char_t * ) string_data , sz );
128
- TEST_ASSERT (sz == 20 );
129
- jerry_release_value (res );
130
- TEST_ASSERT (!strncmp (string_data , "string from snapshot" , (size_t ) sz ));
138
+ test_exec_snapshot (global_mode_snapshot_buffer ,
139
+ global_mode_snapshot_size ,
140
+ false);
131
141
132
- res = jerry_exec_snapshot ( eval_mode_snapshot_buffer ,
133
- eval_mode_snapshot_size ,
134
- false );
142
+ test_exec_snapshot ( global_mode_snapshot_buffer ,
143
+ global_mode_snapshot_size ,
144
+ true );
135
145
136
- TEST_ASSERT (!jerry_value_has_error_flag (res ));
137
- TEST_ASSERT (jerry_value_is_string (res ));
138
- sz = jerry_get_string_size (res );
139
- TEST_ASSERT (sz == 20 );
140
- sz = jerry_string_to_char_buffer (res , (jerry_char_t * ) string_data , sz );
141
- TEST_ASSERT (sz == 20 );
142
- jerry_release_value (res );
143
- TEST_ASSERT (!strncmp (string_data , "string from snapshot" , (size_t ) sz ));
146
+ test_exec_snapshot (eval_mode_snapshot_buffer ,
147
+ eval_mode_snapshot_size ,
148
+ false);
144
149
145
- jerry_cleanup ();
150
+ test_exec_snapshot (eval_mode_snapshot_buffer ,
151
+ eval_mode_snapshot_size ,
152
+ true);
146
153
}
147
154
148
155
/* Merge snapshot */
0 commit comments