• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "jerryscript.h"
17 #include "test-common.h"
18 
main(void)19 int main (void)
20 {
21   if (!jerry_is_feature_enabled (JERRY_FEATURE_MEM_STATS))
22   {
23     return 0;
24   }
25   const jerry_char_t test_source[] = TEST_STRING_LITERAL (
26     "var a = 'hello';"
27     "var b = 'world';"
28     "var c = a + ' ' + b;"
29   );
30 
31   jerry_init (JERRY_INIT_EMPTY);
32   jerry_value_t parsed_code_val = jerry_parse (NULL,
33                                                0,
34                                                test_source,
35                                                sizeof (test_source) - 1,
36                                                JERRY_PARSE_NO_OPTS);
37   TEST_ASSERT (!jerry_value_is_error (parsed_code_val));
38 
39   jerry_value_t res = jerry_run (parsed_code_val);
40   TEST_ASSERT (!jerry_value_is_error (res));
41 
42   jerry_heap_stats_t stats;
43   memset (&stats, 0, sizeof (stats));
44   bool get_stats_ret = jerry_get_memory_stats (&stats);
45   TEST_ASSERT (get_stats_ret);
46   TEST_ASSERT (stats.version == 1);
47   TEST_ASSERT (stats.size == 524280);
48 
49   TEST_ASSERT (!jerry_get_memory_stats (NULL));
50 
51   jerry_release_value (res);
52   jerry_release_value (parsed_code_val);
53 
54   jerry_cleanup ();
55 
56   return 0;
57 } /* main */
58