diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/assert-js.h b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/assert-js.h deleted file mode 100644 index 25e9ed309..000000000 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/assert-js.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef _JERRYSCRIPT_MBED_DRIVERS_ASSERT_H -#define _JERRYSCRIPT_MBED_DRIVERS_ASSERT_H - -#include "jerryscript-mbed-library-registry/wrap_tools.h" -#include "jerryscript-mbed-util/logging.h" - -DECLARE_GLOBAL_FUNCTION(assert); - -#endif // _JERRYSCRIPT_MBED_DRIVERS_ASSERT_H diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/gc-js.h b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/gc-js.h deleted file mode 100644 index 0d94c0bd0..000000000 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/gc-js.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef _JERRYSCRIPT_MBED_DRIVERS_GC_H -#define _JERRYSCRIPT_MBED_DRIVERS_GC_H - -#include "jerryscript-mbed-library-registry/wrap_tools.h" -#include "jerryscript-mbed-util/logging.h" - -DECLARE_GLOBAL_FUNCTION(gc); - -#endif // _JERRYSCRIPT_MBED_DRIVERS_GC_H diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/lib_drivers.h b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/lib_drivers.h index e95e12224..7ec44d0ca 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/lib_drivers.h +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/lib_drivers.h @@ -15,25 +15,23 @@ #ifndef _JERRYSCRIPT_MBED_DRIVERS_LIB_DRIVERS_H #define _JERRYSCRIPT_MBED_DRIVERS_LIB_DRIVERS_H +#include "jerryscript-ext/handler.h" #include "jerryscript-mbed-drivers/InterruptIn-js.h" #include "jerryscript-mbed-drivers/DigitalOut-js.h" #include "jerryscript-mbed-drivers/setInterval-js.h" #include "jerryscript-mbed-drivers/setTimeout-js.h" -#include "jerryscript-mbed-drivers/print-js.h" -#include "jerryscript-mbed-drivers/assert-js.h" #include "jerryscript-mbed-drivers/I2C-js.h" -#include "jerryscript-mbed-drivers/gc-js.h" #include "jerryscript-mbed-drivers/AnalogIn-js.h" #include "jerryscript-mbed-drivers/PwmOut-js.h" DECLARE_JS_WRAPPER_REGISTRATION (base) { - REGISTER_GLOBAL_FUNCTION(assert); - REGISTER_GLOBAL_FUNCTION(gc); + REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(assert, jerryx_handler_assert); + REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(gc, jerryx_handler_gc); + REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(print, jerryx_handler_print); REGISTER_GLOBAL_FUNCTION(setInterval); REGISTER_GLOBAL_FUNCTION(setTimeout); REGISTER_GLOBAL_FUNCTION(clearInterval); REGISTER_GLOBAL_FUNCTION(clearTimeout); - REGISTER_GLOBAL_FUNCTION(print); REGISTER_CLASS_CONSTRUCTOR(DigitalOut); REGISTER_CLASS_CONSTRUCTOR(I2C); REGISTER_CLASS_CONSTRUCTOR(InterruptIn); diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/print-js.h b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/print-js.h deleted file mode 100644 index 43aba07f2..000000000 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/print-js.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef _JERRYSCRIPT_MBED_DRIVERS_PRINT_H -#define _JERRYSCRIPT_MBED_DRIVERS_PRINT_H - -#include "jerryscript-mbed-library-registry/wrap_tools.h" - -DECLARE_GLOBAL_FUNCTION(print); - -#endif // _JERRYSCRIPT_MBED_DRIVERS_PRINT_H diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/assert-js.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/assert-js.cpp deleted file mode 100644 index 089bfc63c..000000000 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/assert-js.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "jerryscript-mbed-drivers/assert-js.h" - -/** - * assert (native JavaScript function) - * - * @param condition The condition to assert to be true - * @returns undefined if the assertion passes, returns an error if the assertion - * fails. - */ -DECLARE_GLOBAL_FUNCTION(assert) { - CHECK_ARGUMENT_COUNT(global, assert, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(global, assert, 0, boolean); - - if (!jerry_get_boolean_value(args[0])) { - const char* error_msg = "Assertion failed"; - return jerry_create_error(JERRY_ERROR_TYPE, reinterpret_cast(error_msg)); - } - - return jerry_create_undefined(); -} diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/gc-js.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/gc-js.cpp deleted file mode 100644 index f548a01d1..000000000 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/gc-js.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "jerryscript-mbed-drivers/gc-js.h" - -/** - * gc (native JavaScript function) - * - * Manually cause JerryScript to run garbage collection. - */ -DECLARE_GLOBAL_FUNCTION(gc) { - jerry_gc(); - return jerry_create_undefined(); -} diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/print-js.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/print-js.cpp deleted file mode 100644 index a11af8a2c..000000000 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/print-js.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "mbed.h" -#include "jerryscript-mbed-drivers/print-js.h" - -/** - * print (native JavaScript function) - * - * Print a string over serial (baud rate 115,200) - * - * @param string String to print - */ -DECLARE_GLOBAL_FUNCTION(print) { - CHECK_ARGUMENT_COUNT(global, print, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(global, print, 0, string); - - jerry_size_t szArg0 = jerry_get_string_size(args[0]); - jerry_char_t *sArg0 = (jerry_char_t*) calloc(szArg0 + 1, sizeof(jerry_char_t)); - jerry_string_to_char_buffer(args[0], sArg0, szArg0); - - printf("%s\n", (const char*)sArg0); - - return jerry_create_undefined(); -} diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-util/wrappers.h b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-util/wrappers.h index f0463237b..19c751b9a 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-util/wrappers.h +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-util/wrappers.h @@ -37,6 +37,9 @@ NAME_FOR_GLOBAL_FUNCTION(NAME) (const jerry_value_t function_obj_p, \ #define REGISTER_GLOBAL_FUNCTION(NAME) \ jsmbed_wrap_register_global_function ( # NAME, NAME_FOR_GLOBAL_FUNCTION(NAME) ) +#define REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(NAME, HANDLER) \ + jsmbed_wrap_register_global_function ( # NAME, HANDLER ) + // Class constructors #define DECLARE_CLASS_CONSTRUCTOR(CLASS) \ jerry_value_t \