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 #include <stdlib.h> 16 #include <stdio.h> 17 18 #include "jerryscript-mbed-launcher/setup.h" 19 #include "jerryscript-mbed-util/logging.h" 20 21 extern uint32_t jsmbed_js_magic_string_count; 22 extern uint32_t jsmbed_js_magic_string_values[]; 23 24 extern const jerry_char_t *jsmbed_js_magic_strings[]; 25 extern const jerry_length_t jsmbed_js_magic_string_lengths[]; 26 jsmbed_js_load_magic_strings()27void jsmbed_js_load_magic_strings() { 28 if (jsmbed_js_magic_string_count == 0) { 29 return; 30 } 31 32 jerry_register_magic_strings(jsmbed_js_magic_strings, 33 jsmbed_js_magic_string_count, 34 jsmbed_js_magic_string_lengths); 35 36 jerry_value_t global = jerry_get_global_object(); 37 38 for (unsigned int idx = 0; idx < jsmbed_js_magic_string_count; idx++) { 39 jerry_value_t constant_value = jerry_create_number(jsmbed_js_magic_string_values[idx]); 40 jerry_value_t magic_string = jerry_create_string(jsmbed_js_magic_strings[idx]); 41 42 jerry_release_value(jerry_set_property(global, magic_string, constant_value)); 43 44 jerry_release_value(constant_value); 45 jerry_release_value(magic_string); 46 } 47 48 jerry_release_value(global); 49 } 50