├── .clang-format ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── appveyor.yml ├── build.config ├── cmake ├── JSONParser.cmake ├── config │ ├── arm-linux.cmake │ ├── arm-nuttx.cmake │ ├── arm-tizen.cmake │ ├── arm-tizenrt.cmake │ ├── i686-linux.cmake │ ├── i686-windows.cmake │ ├── mips-openwrt.cmake │ ├── noarch-linux.cmake │ ├── noarch-tizen.cmake │ ├── x86_64-darwin.cmake │ ├── x86_64-linux.cmake │ ├── x86_64-mock.cmake │ └── x86_64-windows.cmake ├── http-parser.cmake ├── iotjs.cmake ├── jerry.cmake ├── libtuv.cmake └── mbedtls.cmake ├── config ├── mbedtls │ └── config-for-iotjs.h ├── nuttx │ ├── stm32f4dis │ │ ├── app │ │ │ ├── Kconfig │ │ │ ├── Make.defs │ │ │ ├── Makefile │ │ │ ├── iotjs_main.c │ │ │ ├── jerry_port.c │ │ │ ├── setjmp.S │ │ │ └── setjmp.h │ │ ├── config.alloptions │ │ ├── config.default │ │ ├── config.travis │ │ └── patch │ └── stm32f7nucleo │ │ ├── config.default │ │ └── nuttx.profile ├── tizen │ ├── .gbs.conf │ ├── filter.txt │ ├── gbsbuild.sh │ ├── iotjs_tizen.patch │ ├── packaging │ │ ├── iotjs.manifest │ │ ├── iotjs.pc.in │ │ └── iotjs.spec │ ├── patch4tizenorg.sh │ ├── release.sh │ ├── sample.gbs.conf │ └── template │ │ └── IoTjsApp │ │ ├── description.xml │ │ ├── ic_l_service.png │ │ ├── ic_m_service_n.png │ │ ├── ic_m_service_s.png │ │ ├── ic_s_service.png │ │ ├── project │ │ ├── inc │ │ │ └── main.h │ │ ├── project_def.prop │ │ ├── res │ │ │ └── index.js │ │ ├── src │ │ │ └── main.c │ │ └── tizen-manifest.xml │ │ └── sample.xml └── tizenrt │ ├── Kconfig.runtime │ ├── Makefile │ └── artik05x │ └── configs │ ├── debug │ └── defconfig │ └── release │ └── defconfig ├── docs ├── Developer's-Guide.md ├── Getting-Started.md ├── License.md ├── README.md ├── api │ ├── IoT.js-API-ADC.md │ ├── IoT.js-API-Assert.md │ ├── IoT.js-API-BLE.md │ ├── IoT.js-API-Buffer.md │ ├── IoT.js-API-Crypto.md │ ├── IoT.js-API-DGRAM.md │ ├── IoT.js-API-DNS.md │ ├── IoT.js-API-Events.md │ ├── IoT.js-API-File-System.md │ ├── IoT.js-API-GPIO.md │ ├── IoT.js-API-HTTP-Signature.md │ ├── IoT.js-API-HTTP.md │ ├── IoT.js-API-HTTPS.md │ ├── IoT.js-API-I2C.md │ ├── IoT.js-API-MQTT.md │ ├── IoT.js-API-Module.md │ ├── IoT.js-API-N-API.md │ ├── IoT.js-API-Net.md │ ├── IoT.js-API-PWM.md │ ├── IoT.js-API-Process.md │ ├── IoT.js-API-SPI.md │ ├── IoT.js-API-Stream.md │ ├── IoT.js-API-TLS.md │ ├── IoT.js-API-Timers.md │ ├── IoT.js-API-UART.md │ ├── IoT.js-API-WebSocket.md │ └── IoT.js-API-reference.md ├── build │ ├── Build-Script.md │ ├── Build-for-ARTIK053-TizenRT.md │ ├── Build-for-OpenWrt.md │ ├── Build-for-RPi2-Linux.md │ ├── Build-for-RPi3-Tizen.md │ ├── Build-for-STM32F4-NuttX.md │ ├── Build-for-Windows.md │ └── Build-for-x86-Linux.md ├── contributing │ ├── Assigned-People.md │ ├── Community-Guidelines.md │ ├── Governance.md │ └── Patch-Submission-Process.md ├── devs │ ├── API-Document-Guidelines.md │ ├── Advanced-Development.md │ ├── Coding-Style-Guidelines.md │ ├── Developer-Tutorial.md │ ├── Development-Process.md │ ├── Experimental-Features.md │ ├── Extended-API-Guidelines.md │ ├── Inside-IoT.js.md │ ├── IoT.js-Developer's-Certificate-of-Origin-1.0.md │ ├── IoT.js-Module-Generator.md │ ├── IoT.js-Package-(outdated).md │ ├── Logging-IoT.js-execution.md │ ├── Memory-savings-with-libtuv.md │ ├── Native-Module-vs-JS-Module.md │ ├── Optimization-Tips.md │ ├── Test-Guidelines.md │ ├── Use-JerryScript-Debugger.md │ └── Writing-New-Module.md └── targets │ ├── nuttx │ └── stm32f4dis │ │ └── IoT.js-API-Stm32f4dis.md │ ├── tizen │ └── SystemIO-Pin-Information-Tizen.md │ └── tizenrt │ └── artik05x │ └── IoT.js-API-artik053.md ├── include ├── iotjs.h ├── node_api.h └── node_api_types.h ├── package.json ├── profiles ├── default.profile └── minimal.profile ├── sonar-project.properties ├── src ├── internal │ ├── node_api_internal.h │ └── node_api_internal_types.h ├── iotjs.c ├── iotjs_binding.c ├── iotjs_binding.h ├── iotjs_binding_helper.c ├── iotjs_binding_helper.h ├── iotjs_compatibility.h ├── iotjs_debuglog.c ├── iotjs_debuglog.h ├── iotjs_def.h ├── iotjs_env.c ├── iotjs_env.h ├── iotjs_magic_strings.h ├── iotjs_module.c ├── iotjs_module.h ├── iotjs_string.c ├── iotjs_string.h ├── iotjs_string_ext.c ├── iotjs_string_ext.h ├── iotjs_util.c ├── iotjs_util.h ├── iotjs_uv_handle.c ├── iotjs_uv_handle.h ├── iotjs_uv_request.c ├── iotjs_uv_request.h ├── js │ ├── adc.js │ ├── assert.js │ ├── ble.js │ ├── ble_characteristic.js │ ├── ble_descriptor.js │ ├── ble_hci_socket.js │ ├── ble_hci_socket_acl_stream.js │ ├── ble_hci_socket_bindings.js │ ├── ble_hci_socket_crypto.js │ ├── ble_hci_socket_gap.js │ ├── ble_hci_socket_gatt.js │ ├── ble_hci_socket_hci.js │ ├── ble_hci_socket_hci_status.js │ ├── ble_hci_socket_mgmt.js │ ├── ble_hci_socket_smp.js │ ├── ble_primary_service.js │ ├── ble_uuid_util.js │ ├── bridge.js │ ├── buffer.js │ ├── console.js │ ├── crypto.js │ ├── dgram.js │ ├── dns.js │ ├── events.js │ ├── fs.js │ ├── gpio.js │ ├── http.js │ ├── http_client.js │ ├── http_common.js │ ├── http_incoming.js │ ├── http_outgoing.js │ ├── http_server.js │ ├── http_signature.js │ ├── https.js │ ├── i2c.js │ ├── iotjs.js │ ├── module.js │ ├── mqtt.js │ ├── net.js │ ├── pwm.js │ ├── spi.js │ ├── stream.js │ ├── stream_duplex.js │ ├── stream_internal.js │ ├── stream_readable.js │ ├── stream_writable.js │ ├── timers.js │ ├── tizen.js │ ├── tls.js │ ├── uart.js │ ├── util.js │ └── websocket.js ├── modules.json ├── modules │ ├── iotjs_module_adc.c │ ├── iotjs_module_adc.h │ ├── iotjs_module_blehcisocket.c │ ├── iotjs_module_blehcisocket.h │ ├── iotjs_module_bridge.c │ ├── iotjs_module_bridge.h │ ├── iotjs_module_buffer.c │ ├── iotjs_module_buffer.h │ ├── iotjs_module_console.c │ ├── iotjs_module_constants.c │ ├── iotjs_module_crypto.c │ ├── iotjs_module_crypto.h │ ├── iotjs_module_dns.c │ ├── iotjs_module_dynamicloader.c │ ├── iotjs_module_fs.c │ ├── iotjs_module_gpio.c │ ├── iotjs_module_gpio.h │ ├── iotjs_module_http_parser.c │ ├── iotjs_module_i2c.c │ ├── iotjs_module_i2c.h │ ├── iotjs_module_mqtt.c │ ├── iotjs_module_mqtt.h │ ├── iotjs_module_periph_common.c │ ├── iotjs_module_periph_common.h │ ├── iotjs_module_process.c │ ├── iotjs_module_pwm.c │ ├── iotjs_module_pwm.h │ ├── iotjs_module_spi.c │ ├── iotjs_module_spi.h │ ├── iotjs_module_stm32f4dis.c │ ├── iotjs_module_stm32f4dis.h │ ├── iotjs_module_stm32f7nucleo.c │ ├── iotjs_module_stm32f7nucleo.h │ ├── iotjs_module_tcp.c │ ├── iotjs_module_tcp.h │ ├── iotjs_module_timer.c │ ├── iotjs_module_tizen.c │ ├── iotjs_module_tls.c │ ├── iotjs_module_tls.h │ ├── iotjs_module_uart.c │ ├── iotjs_module_uart.h │ ├── iotjs_module_udp.c │ ├── iotjs_module_websocket.c │ ├── iotjs_module_websocket.h │ ├── linux │ │ ├── iotjs_module_adc-linux.c │ │ ├── iotjs_module_blehcisocket-linux.c │ │ ├── iotjs_module_gpio-linux.c │ │ ├── iotjs_module_i2c-linux.c │ │ ├── iotjs_module_pwm-linux.c │ │ ├── iotjs_module_spi-linux.c │ │ └── iotjs_module_uart-linux.c │ ├── mock │ │ ├── iotjs_module_gpio-mock.c │ │ ├── iotjs_module_i2c-mock.c │ │ └── iotjs_module_pwm-mock.c │ ├── nuttx │ │ ├── iotjs_module_adc-nuttx.c │ │ ├── iotjs_module_blehcisocket-nuttx.c │ │ ├── iotjs_module_gpio-nuttx.c │ │ ├── iotjs_module_i2c-nuttx.c │ │ ├── iotjs_module_pwm-nuttx.c │ │ ├── iotjs_module_spi-nuttx.c │ │ ├── iotjs_module_stm32f4dis-nuttx.c │ │ ├── iotjs_module_stm32f7nucleo-nuttx.c │ │ └── iotjs_module_uart-nuttx.c │ ├── tizen │ │ ├── iotjs_module_gpio-tizen.c │ │ ├── iotjs_module_i2c-tizen.c │ │ ├── iotjs_module_pwm-tizen.c │ │ ├── iotjs_module_spi-tizen.c │ │ ├── iotjs_module_tizen-tizen.c │ │ └── iotjs_module_uart-tizen.c │ └── tizenrt │ │ ├── iotjs_module_adc-tizenrt.c │ │ ├── iotjs_module_gpio-tizenrt.c │ │ ├── iotjs_module_i2c-tizenrt.c │ │ ├── iotjs_module_pwm-tizenrt.c │ │ ├── iotjs_module_spi-tizenrt.c │ │ └── iotjs_module_uart-tizenrt.c ├── napi │ ├── node_api.c │ ├── node_api_async.c │ ├── node_api_env.c │ ├── node_api_function.c │ ├── node_api_lifetime.c │ ├── node_api_module.c │ ├── node_api_object_wrap.c │ ├── node_api_property.c │ ├── node_api_value.c │ └── node_symbols.txt └── platform │ ├── linux │ ├── iotjs_linux.c │ ├── iotjs_systemio-linux.c │ └── iotjs_systemio-linux.h │ ├── nuttx │ ├── iotjs_systemio-nuttx.c │ └── iotjs_systemio-nuttx.h │ ├── tizen │ ├── iotjs_tizen_service_app.c │ └── iotjs_tizen_service_app.h │ └── tizenrt │ └── iotjs_main_tizenrt.c ├── test ├── external_modules │ ├── mymodule1 │ │ ├── js │ │ │ └── helloworld.js │ │ └── modules.json │ ├── mymodule2 │ │ ├── modules.json │ │ └── my_module.c │ ├── test-external-module1.js │ └── test-external-module2.js ├── hello.js ├── module_generator │ ├── test.py │ ├── test_c │ │ ├── test.c │ │ ├── test.h │ │ └── test.js │ └── test_cpp │ │ ├── test.cpp │ │ ├── test.h │ │ └── test.js ├── napi │ ├── .gitignore │ ├── binding.gyp │ ├── common.h │ ├── common.js │ ├── test_napi_arguments.c │ ├── test_napi_arguments_return.js │ ├── test_napi_arguments_return_this.js │ ├── test_napi_arguments_throw.js │ ├── test_napi_array.c │ ├── test_napi_array.js │ ├── test_napi_async.c │ ├── test_napi_async.js │ ├── test_napi_buffer.c │ ├── test_napi_buffer.js │ ├── test_napi_construct.c │ ├── test_napi_construct.js │ ├── test_napi_conversions.c │ ├── test_napi_conversions.js │ ├── test_napi_create_error.js │ ├── test_napi_dataview.c │ ├── test_napi_dataview.js │ ├── test_napi_env.js │ ├── test_napi_env_compare.c │ ├── test_napi_env_store.c │ ├── test_napi_error_handling.c │ ├── test_napi_exception.js │ ├── test_napi_general.c │ ├── test_napi_general.js │ ├── test_napi_general_es2015.js │ ├── test_napi_handle_scope.c │ ├── test_napi_handle_scope.js │ ├── test_napi_is_error.js │ ├── test_napi_make_callback.c │ ├── test_napi_make_callback.js │ ├── test_napi_make_callback_error.js │ ├── test_napi_object_wrap.c │ ├── test_napi_object_wrap.js │ ├── test_napi_promise.c │ ├── test_napi_promise.js │ ├── test_napi_properties.c │ ├── test_napi_properties.js │ ├── test_napi_reference.c │ ├── test_napi_reference.js │ ├── test_napi_strictequal_and_instanceof.c │ ├── test_napi_strictequal_and_instanceof.js │ ├── test_napi_string.c │ ├── test_napi_string.js │ ├── test_napi_symbol.c │ ├── test_napi_symbol.js │ ├── test_napi_throw.js │ ├── test_napi_throw_error.js │ ├── test_napi_typedarray.c │ └── test_napi_typedarray.js ├── node │ ├── common.js │ └── parallel │ │ ├── test-assert.js │ │ ├── test-http-catch-uncaughtexception.js │ │ ├── test-http-status-message.js │ │ ├── test-http-write-head.js │ │ ├── test-module-circular-b.js │ │ ├── test-module-circular.js │ │ ├── test-net-after-close.js │ │ ├── test-net-bind-twice.js │ │ ├── test-net-end-without-connect.js │ │ ├── test-net-keepalive.js │ │ └── test-timers-clear-null-does-not-throw-error.js ├── profiles │ ├── host-darwin.profile │ ├── host-linux.profile │ ├── mock-linux.profile │ ├── nuttx.profile │ ├── rpi2-linux.profile │ ├── tizen-jerry.profile │ ├── tizen.profile │ └── tizenrt.profile ├── resources │ ├── crypto_public.pem │ ├── greeting.txt │ ├── http_signature_key.key │ ├── my_ca.crt │ ├── my_ca.key │ ├── my_ca.srl │ ├── my_crt.crt │ ├── my_csr.csr │ ├── my_key.key │ ├── process │ │ └── package.json │ ├── promise_chain_calls │ │ ├── 1.txt │ │ ├── 2.txt │ │ ├── 3.txt │ │ └── 4.txt │ ├── readdir │ │ ├── DO_NOT_MODIFY_THIS_FOLDER │ │ ├── This_is_a_directory │ │ │ └── .gitkeep │ │ ├── This_is_another_directory │ │ │ └── .gitkeep │ │ └── regular.txt │ ├── rename.txt │ ├── test.json │ ├── test1.txt │ ├── test2.txt │ ├── test_console_stdout.txt │ └── tobeornottobe.txt ├── run_fail │ ├── test-issue-1349.js │ ├── test-issue-1360.js │ ├── test-issue-1570.js │ ├── test-issue-1915.js │ ├── test-issue-1917.js │ ├── test_assert_equal.js │ ├── test_assert_fail.js │ ├── test_assert_notequal.js │ ├── test_events_emit_error.js │ ├── test_fs_callbacks_called.js │ ├── test_iotjs_runtime_error.js │ ├── test_iotjs_syntax_error.js │ ├── test_module_require_invalid_file.js │ ├── test_module_require_path_below_root.js │ ├── test_process_exitcode_arg.js │ ├── test_process_exitcode_var.js │ ├── test_process_explicit_exit.js │ ├── test_process_implicit_exit.js │ └── test_timers_issue_1353.js ├── run_pass │ ├── issue │ │ ├── issue-1046.js │ │ ├── issue-1077.js │ │ ├── issue-1101.js │ │ ├── issue-1165.js │ │ ├── issue-133.js │ │ ├── issue-1348.js │ │ ├── issue-1350.js │ │ ├── issue-137.js │ │ ├── issue-1463.js │ │ ├── issue-1485.js │ │ ├── issue-1507.js │ │ ├── issue-1557.js │ │ ├── issue-1897.js │ │ ├── issue-1904.js │ │ ├── issue-198.js │ │ ├── issue-223.js │ │ ├── issue-266.js │ │ ├── issue-323.js │ │ └── issue-816.js │ ├── require1 │ │ ├── module_cache.js │ │ ├── require_add.js │ │ ├── test_index │ │ │ ├── add2.js │ │ │ ├── index.js │ │ │ ├── lib │ │ │ │ └── multi.js │ │ │ └── package.json │ │ ├── test_index2 │ │ │ ├── add2.js │ │ │ ├── index_test.js │ │ │ ├── lib │ │ │ │ └── multi.js │ │ │ └── package.json │ │ └── test_pkg │ │ │ ├── add2.js │ │ │ ├── lib │ │ │ └── multi.js │ │ │ ├── main.js │ │ │ └── package.json │ ├── test_adc.js │ ├── test_assert.js │ ├── test_ble_advertisement.js │ ├── test_ble_setservices.js │ ├── test_ble_setservices_central.js │ ├── test_buffer.js │ ├── test_buffer_from.js │ ├── test_buffer_from_arraybuffer.js │ ├── test_buffer_inmutability_creation.js │ ├── test_buffer_str_conv.js │ ├── test_console.js │ ├── test_crypto.js │ ├── test_crypto_tls.js │ ├── test_dgram_1_server_1_client.js │ ├── test_dgram_1_server_n_clients.js │ ├── test_dgram_address.js │ ├── test_dgram_broadcast.js │ ├── test_dgram_multicast_membership.js │ ├── test_dgram_multicast_set_multicast_loop.js │ ├── test_dgram_setttl_client.js │ ├── test_dgram_setttl_server.js │ ├── test_dns.js │ ├── test_dns_lookup.js │ ├── test_events.js │ ├── test_events_assert_emit_error.js │ ├── test_events_uncaught_error.js │ ├── test_fs_event.js │ ├── test_fs_exists.js │ ├── test_fs_exists_sync.js │ ├── test_fs_fstat.js │ ├── test_fs_fstat_sync.js │ ├── test_fs_mkdir_rmdir.js │ ├── test_fs_open_close.js │ ├── test_fs_open_read.js │ ├── test_fs_open_read_sync_1.js │ ├── test_fs_open_read_sync_2.js │ ├── test_fs_open_read_sync_3.js │ ├── test_fs_read_stream.js │ ├── test_fs_readdir.js │ ├── test_fs_readfile.js │ ├── test_fs_readfile_sync.js │ ├── test_fs_rename.js │ ├── test_fs_rename_sync.js │ ├── test_fs_stat.js │ ├── test_fs_stream_pipe.js │ ├── test_fs_write.js │ ├── test_fs_write_stream.js │ ├── test_fs_writefile.js │ ├── test_fs_writefile_sync.js │ ├── test_fs_writefile_unlink.js │ ├── test_fs_writefile_unlink_sync.js │ ├── test_gpio_api.js │ ├── test_gpio_direction.js │ ├── test_gpio_event.js │ ├── test_gpio_input.js │ ├── test_gpio_output.js │ ├── test_http_signature.js │ ├── test_i2c_api.js │ ├── test_i2c_gy30.js │ ├── test_iotjs_promise.js │ ├── test_iotjs_promise_chain_calls.js │ ├── test_module_cache.js │ ├── test_module_json.js │ ├── test_module_require.js │ ├── test_mqtt.js │ ├── test_mqtt_frags.js │ ├── test_net_1.js │ ├── test_net_10.js │ ├── test_net_2.js │ ├── test_net_3.js │ ├── test_net_4.js │ ├── test_net_5.js │ ├── test_net_6.js │ ├── test_net_7.js │ ├── test_net_8.js │ ├── test_net_9.js │ ├── test_net_connect.js │ ├── test_net_headers.js │ ├── test_net_http_get.js │ ├── test_net_http_methods.js │ ├── test_net_http_modified_req_resp.js │ ├── test_net_http_modified_request.js │ ├── test_net_http_modified_response.js │ ├── test_net_http_outgoing_buffer.js │ ├── test_net_http_request_http_version.js │ ├── test_net_http_request_response.js │ ├── test_net_http_response_twice.js │ ├── test_net_http_server.js │ ├── test_net_http_server_timeout.js │ ├── test_net_http_status_codes.js │ ├── test_net_httpclient_error.js │ ├── test_net_httpclient_parse_error.js │ ├── test_net_httpclient_timeout_1.js │ ├── test_net_httpclient_timeout_2.js │ ├── test_net_https_get.js │ ├── test_net_https_modified_req_resp.js │ ├── test_net_https_post_status_codes.js │ ├── test_net_https_request_response.js │ ├── test_net_https_server.js │ ├── test_net_https_timeout.js │ ├── test_process.js │ ├── test_process_chdir.js │ ├── test_process_cwd.js │ ├── test_process_exit.js │ ├── test_process_experimental_off.js │ ├── test_process_experimental_on.js │ ├── test_process_next_tick.js │ ├── test_process_uncaught_order.js │ ├── test_process_uncaught_simple.js │ ├── test_pwm_api.js │ ├── test_pwm_async.js │ ├── test_pwm_sync.js │ ├── test_spi.js │ ├── test_spi_buffer_async.js │ ├── test_spi_buffer_sync.js │ ├── test_spi_mcp3008.js │ ├── test_stream.js │ ├── test_stream_duplex.js │ ├── test_stream_pipe.js │ ├── test_timers_arguments.js │ ├── test_timers_error.js │ ├── test_timers_simple.js │ ├── test_tizen_app_control.js │ ├── test_tls_1.js │ ├── test_tls_2.js │ ├── test_tls_3.js │ ├── test_tls_4.js │ ├── test_tls_ca.js │ ├── test_tls_stream_duplex.js │ ├── test_uart.js │ ├── test_uart_api.js │ ├── test_util.js │ ├── test_websocket.js │ ├── test_websocket_headercheck.js │ ├── test_websocket_server.js │ └── test_websocket_server_secure.js ├── testsets.json ├── tmp │ └── README └── tools │ ├── iotjs_build_info.js │ └── systemio_common.js └── tools ├── __init__.py ├── apt-get-install-arm.sh ├── apt-get-install-deps.sh ├── apt-get-install-nuttx.sh ├── apt-get-install-tizen.sh ├── apt-get-install-tizenrt.sh ├── apt-get-install-travis-i686.sh ├── brew-install-deps.sh ├── build.py ├── check_license.py ├── check_signed_off.sh ├── check_sonarqube.sh ├── check_tidy.py ├── common_py ├── __init__.py ├── path.py └── system │ ├── __init__.py │ ├── executor.py │ ├── filesystem.py │ └── sys_platform.py ├── iotjs-create-module.py ├── iotjs-generate-module.py ├── js2c.py ├── measure_coverage.sh ├── measure_js_heap.py ├── mem_stats.sh ├── module_generator ├── __init__.py ├── c_source_templates.py ├── clang_translation_unit_visitor.py ├── cpp_source_templates.py └── source_generator.py ├── module_templates ├── basic_module_template │ ├── js │ │ └── module.js │ ├── module.cmake │ ├── modules.json │ └── src │ │ └── module.c └── shared_module_template │ ├── CMakeLists.txt │ ├── README.md │ ├── js │ └── test.js │ └── src │ └── module_entry.c ├── repl.js ├── testrunner.py └── travis_script.py /.eslintignore: -------------------------------------------------------------------------------- 1 | /build/** 2 | /deps/** 3 | /src/js/ble* 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Produced files 2 | 3 | /build 4 | /build/* 5 | /src/iotjs_js.h 6 | /src/iotjs_js.c 7 | /src/iotjs_string_ext.inl.h 8 | /src/iotjs_module_inl.h 9 | /test/tmp/* 10 | /test/dynamicmodule/build/* 11 | /tools/module_generator/output 12 | /test/module_generator/test_c/*.a 13 | /test/module_generator/test_c/*.o 14 | /test/module_generator/test_cpp/*.a 15 | /test/module_generator/test_cpp/*.o 16 | eslint.log 17 | 18 | # IDE related files 19 | nbproject 20 | **.sublime-project 21 | **.sublime-workspace 22 | .idea 23 | 24 | # Random Trash 25 | *.swp 26 | *.swo 27 | *~ 28 | core 29 | vgcore.* 30 | **.orig 31 | **.directory 32 | **.patch 33 | .tags* 34 | cscope.* 35 | *.pyc 36 | 37 | # Dependency directories 38 | node_modules/ 39 | iotjs_modules/ 40 | 41 | # Coverage directory used by tools like istanbul 42 | coverage 43 | 44 | # ctags and ID database 45 | tags 46 | ID 47 | TAGS 48 | 49 | # config files 50 | *.config 51 | !build.config 52 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/jerry"] 2 | path = deps/jerry 3 | url = https://github.com/jerryscript-project/jerryscript.git 4 | ignore = untracked 5 | [submodule "deps/http-parser"] 6 | path = deps/http-parser 7 | url = https://github.com/Samsung/http-parser.git 8 | ignore = untracked 9 | [submodule "deps/libtuv"] 10 | path = deps/libtuv 11 | url = https://github.com/Samsung/libtuv.git 12 | ignore = untracked 13 | [submodule "deps/mbedtls"] 14 | path = deps/mbedtls 15 | url = https://github.com/ARMmbed/mbedtls.git 16 | ignore = untracked 17 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: "{build}" 2 | branches: 3 | except: 4 | - coverity_scan 5 | - gh_pages 6 | skip_tags: true 7 | image: 8 | - Visual Studio 2017 9 | configuration: 10 | - Debug 11 | - Release 12 | platform: 13 | - Win32 14 | - x64 15 | init: 16 | - cmd: | 17 | if "%PLATFORM%"=="Win32" set SYS_ARCH=i686 18 | if "%PLATFORM%"=="x64" set SYS_ARCH=x86_64 19 | cmake -version 20 | 21 | install: 22 | - ps: | 23 | Install-Product node 10.15.3 24 | 25 | artifacts: 26 | - path: build\%SYS_ARCH%-windows\$(configuration)\bin\$(configuration)\ 27 | name: IoTjsbinary 28 | 29 | before_build: 30 | - cmd: | 31 | tools\build.py --experimental --buildtype=%CONFIGURATION% --target-arch=%SYS_ARCH% --jerry-profile=es2015-subset --n-api 32 | 33 | build: 34 | project: build\%SYS_ARCH%-windows\%CONFIGURATION%\IOTJS.sln 35 | parallel: true 36 | verbosity: minimal 37 | 38 | before_test: 39 | - cmd: npm install 40 | 41 | test_script: 42 | - cmd: | 43 | tools\testrunner.py build\%SYS_ARCH%-windows\%CONFIGURATION%\bin\%CONFIGURATION%\iotjs.exe 44 | -------------------------------------------------------------------------------- /build.config: -------------------------------------------------------------------------------- 1 | { 2 | "builddir": "", 3 | "buildlib": false, 4 | "buildtype": "debug", 5 | "clean": false, 6 | "config": "", 7 | "cmake-param": [], 8 | "compile-flag": [], 9 | "external-include-dir": [], 10 | "external-lib": [], 11 | "jerry-cmake-param": [], 12 | "jerry-compile-flag": [], 13 | "jerry-heaplimit": 256, 14 | "jerry-link-flag": [], 15 | "jerry-lto": false, 16 | "jerry-memstat": false, 17 | "link-flag": [], 18 | "no-check-tidy": false, 19 | "no-init-submodule": false, 20 | "no-parallel-build": false, 21 | "no-snapshot": false, 22 | "run-test": false, 23 | "sysroot": "", 24 | "target-arch": "", 25 | "target-os": "", 26 | "target-board": "" 27 | } 28 | -------------------------------------------------------------------------------- /cmake/config/arm-linux.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME Linux) 16 | set(CMAKE_SYSTEM_PROCESSOR armv7l) 17 | 18 | set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) 19 | set(CMAKE_C_COMPILER_WORKS TRUE) 20 | -------------------------------------------------------------------------------- /cmake/config/arm-nuttx.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME Nuttx) 16 | set(CMAKE_SYSTEM_PROCESSOR armv7l) 17 | 18 | set(CMAKE_C_COMPILER arm-none-eabi-gcc) 19 | set(CMAKE_C_COMPILER_WORKS TRUE) 20 | -------------------------------------------------------------------------------- /cmake/config/arm-tizen.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME Linux) 16 | set(CMAKE_SYSTEM_PROCESSOR armv7l) 17 | 18 | # Only set the compiler if not provided already 19 | if(NOT "${CMAKE_C_COMPILER}" STREQUAL "") 20 | find_program(COMPILER_PATH ${CMAKE_C_COMPILER}) 21 | if(COMPILER_PATH STREQUAL "") 22 | message(WARNING "Command ${CMAKE_C_COMPILER} not found") 23 | unset(CMAKE_C_COMPILER) 24 | endif() 25 | unset(COMPILER_PATH) 26 | endif() 27 | 28 | if("${CMAKE_C_COMPILER}" STREQUAL "") 29 | set(CMAKE_C_COMPILER arm-linux-gnueabi-gcc) 30 | endif() 31 | -------------------------------------------------------------------------------- /cmake/config/arm-tizenrt.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME Tizenrt) 16 | set(CMAKE_SYSTEM_PROCESSOR armv7l) 17 | 18 | set(CMAKE_C_COMPILER arm-none-eabi-gcc) 19 | set(CMAKE_C_COMPILER_WORKS TRUE) 20 | -------------------------------------------------------------------------------- /cmake/config/i686-linux.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME Linux) 16 | set(CMAKE_SYSTEM_PROCESSOR i686) 17 | -------------------------------------------------------------------------------- /cmake/config/i686-windows.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME Windows) 16 | set(CMAKE_SYSTEM_PROCESSOR i686) 17 | 18 | set(CMAKE_C_COMPILER CL.exe) 19 | set(CMAKE_C_COMPILER_WORKS TRUE) 20 | -------------------------------------------------------------------------------- /cmake/config/mips-openwrt.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME Openwrt) 16 | set(CMAKE_SYSTEM_PROCESSOR mips) 17 | 18 | set(CMAKE_C_COMPILER mips-openwrt-linux-gcc) 19 | set(CMAKE_C_COMPILER_WORKS TRUE) 20 | 21 | -------------------------------------------------------------------------------- /cmake/config/noarch-linux.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME Linux) 16 | -------------------------------------------------------------------------------- /cmake/config/noarch-tizen.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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(CMakeForceCompiler) 16 | 17 | set(CMAKE_SYSTEM_NAME Tizen) 18 | -------------------------------------------------------------------------------- /cmake/config/x86_64-darwin.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME Darwin) 16 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 17 | -------------------------------------------------------------------------------- /cmake/config/x86_64-linux.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME Linux) 16 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 17 | -------------------------------------------------------------------------------- /cmake/config/x86_64-mock.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME MockLinux) 16 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 17 | -------------------------------------------------------------------------------- /cmake/config/x86_64-windows.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | set(CMAKE_SYSTEM_NAME Windows) 16 | set(CMAKE_SYSTEM_PROCESSOR x64) 17 | 18 | set(CMAKE_C_COMPILER CL.exe) 19 | set(CMAKE_C_COMPILER_WORKS TRUE) 20 | -------------------------------------------------------------------------------- /config/nuttx/stm32f4dis/app/Kconfig: -------------------------------------------------------------------------------- 1 | # 2 | # For a description of the syntax of this configuration file, 3 | # see the file kconfig-language.txt in the NuttX tools repository. 4 | # 5 | 6 | config IOTJS 7 | bool "IoT.js" 8 | default n 9 | ---help--- 10 | Enable IoT.js platform 11 | 12 | if IOTJS 13 | 14 | config IOTJS_PRIORITY 15 | int "IoT.js task priority" 16 | default 100 17 | 18 | config IOTJS_STACKSIZE 19 | int "IoT.js stack size" 20 | default 16384 21 | 22 | endif 23 | -------------------------------------------------------------------------------- /config/nuttx/stm32f4dis/app/Make.defs: -------------------------------------------------------------------------------- 1 | # Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 2 | # Copyright 2016 University of Szeged 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | ifeq ($(CONFIG_IOTJS),y) 17 | CONFIGURED_APPS += system/iotjs 18 | endif 19 | -------------------------------------------------------------------------------- /config/nuttx/stm32f4dis/patch: -------------------------------------------------------------------------------- 1 | --- a/configs/stm32f4discovery/include/board.h 2 | +++ b/configs/stm32f4discovery/include/board.h 3 | @@ -253,6 +253,13 @@ 4 | # define GPIO_CAN2_TX GPIO_CAN2_TX_1 5 | #endif 6 | 7 | # Patch code to enable UART1: 8 | # It maps pin PB6 and pin PB7 to USART1_TX and USART2_RX respectively. 9 | # 10 | + 11 | +#define GPIO_USART1_RX GPIO_USART1_RX_2 12 | +#define GPIO_USART1_TX GPIO_USART1_TX_2 13 | + 14 | # Patch code to enable UART4: 15 | # It maps pin PA0 and pin PA1 to UART4_TX and UART4_RX respectively. 16 | # Because it makes conflict with pins of USART2, 17 | # you have to disable USART2 to use this port. 18 | # 19 | +#define GPIO_UART4_RX GPIO_UART4_RX_1 20 | +#define GPIO_UART4_TX GPIO_UART4_TX_1 21 | + 22 | /* UART2: 23 | * 24 | * The STM32F4 Discovery has no on-board serial devices, but the console is 25 | -------------------------------------------------------------------------------- /config/nuttx/stm32f7nucleo/nuttx.profile: -------------------------------------------------------------------------------- 1 | ENABLE_MODULE_IOTJS_BASIC_MODULES 2 | ENABLE_MODULE_IOTJS_CORE_MODULES 3 | ENABLE_MODULE_ADC 4 | ENABLE_MODULE_GPIO 5 | ENABLE_MODULE_PWM 6 | ENABLE_MODULE_STM32F7NUCLEO 7 | -------------------------------------------------------------------------------- /config/tizen/.gbs.conf: -------------------------------------------------------------------------------- 1 | [general] 2 | upstream_branch = ${upstreamversion} 3 | upstream_tag = ${upstreamversion} 4 | packaging_dir = config/tizen/packaging 5 | -------------------------------------------------------------------------------- /config/tizen/filter.txt: -------------------------------------------------------------------------------- 1 | P /.git 2 | - .git 3 | -------------------------------------------------------------------------------- /config/tizen/packaging/iotjs.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /config/tizen/packaging/iotjs.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: iotjs 7 | Description: Platform for Internet of Things with JavaScript 8 | Version: 1.0.0 9 | Libs: -L${libdir} -liotjs -lcapi-system-peripheral-io -lpthread -lcurl -ldlog -lappcore-agent 10 | Cflags: -I${includedir}/iotjs 11 | -------------------------------------------------------------------------------- /config/tizen/template/IoTjsApp/description.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | IoTjs App 4 | 1.0 5 | 6 | 7 | iot-headless 8 | 4.0 9 | 10 | 11 | org.tizen.nativecore.buildArtefactType.app 12 | False 13 | 14 | Template 15 | 16 | 17 | ic_s_service.png 18 | ic_m_service_n.png 19 | ic_m_service_s.png 20 | ic_l_service.png 21 | 22 | 23 | This is the empty template for developing IoT.js application. 24 | 25 | 26 | -------------------------------------------------------------------------------- /config/tizen/template/IoTjsApp/ic_l_service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jerryscript-project/iotjs/02599f35810cfa6ea5495bbc42194ed576b969de/config/tizen/template/IoTjsApp/ic_l_service.png -------------------------------------------------------------------------------- /config/tizen/template/IoTjsApp/ic_m_service_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jerryscript-project/iotjs/02599f35810cfa6ea5495bbc42194ed576b969de/config/tizen/template/IoTjsApp/ic_m_service_n.png -------------------------------------------------------------------------------- /config/tizen/template/IoTjsApp/ic_m_service_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jerryscript-project/iotjs/02599f35810cfa6ea5495bbc42194ed576b969de/config/tizen/template/IoTjsApp/ic_m_service_s.png -------------------------------------------------------------------------------- /config/tizen/template/IoTjsApp/ic_s_service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jerryscript-project/iotjs/02599f35810cfa6ea5495bbc42194ed576b969de/config/tizen/template/IoTjsApp/ic_s_service.png -------------------------------------------------------------------------------- /config/tizen/template/IoTjsApp/project/inc/main.h: -------------------------------------------------------------------------------- 1 | #ifndef __$(appName)_H__ 2 | #define __$(appName)_H__ 3 | 4 | #include 5 | 6 | #ifdef LOG_TAG 7 | #undef LOG_TAG 8 | #endif 9 | #define LOG_TAG "$(appName)" 10 | 11 | 12 | #endif /* __$(appName)_H__ */ 13 | -------------------------------------------------------------------------------- /config/tizen/template/IoTjsApp/project/project_def.prop: -------------------------------------------------------------------------------- 1 | APPNAME = $(appName) 2 | 3 | type = app 4 | profile = $(platform) 5 | 6 | USER_SRCS = src/$(appName).c 7 | USER_DEFS = 8 | USER_INC_DIRS = inc 9 | USER_OBJS = 10 | USER_LIBS = 11 | USER_EDCS = 12 | -------------------------------------------------------------------------------- /config/tizen/template/IoTjsApp/project/res/index.js: -------------------------------------------------------------------------------- 1 | console.log('Hello IoT.js'); 2 | 3 | -------------------------------------------------------------------------------- /config/tizen/template/IoTjsApp/project/tizen-manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | $(appName).png 6 | 7 | 8 | 9 | 10 | http://tizen.org/privilege/network.get 11 | http://tizen.org/privilege/network.set 12 | http://tizen.org/privilege/internet 13 | http://tizen.org/privilege/alarm.set 14 | http://tizen.org/privilege/network.profile 15 | http://tizen.org/privilege/peripheralio 16 | 17 | 18 | -------------------------------------------------------------------------------- /config/tizenrt/Kconfig.runtime: -------------------------------------------------------------------------------- 1 | # 2 | # For a description of the syntax of this configuration file, 3 | # see kconfig-language at https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt 4 | # 5 | 6 | config ENABLE_IOTJS 7 | bool "IoT.js" 8 | default n 9 | select SPI_EXCHANGE 10 | select IOTBUS 11 | select IOTBUS_GPIO 12 | select IOTBUS_I2C 13 | select IOTBUS_PWM 14 | select IOTBUS_SPI 15 | select IOTBUS_UART 16 | ---help--- 17 | Enable IoT.js framework 18 | 19 | if ENABLE_IOTJS 20 | 21 | config IOTJS_PRIORITY 22 | int "IoT.js task priority" 23 | default 100 24 | 25 | config IOTJS_STACKSIZE 26 | int "IoT.js stack size" 27 | default 32768 28 | 29 | config IOTJS_JERRY_HEAP 30 | int "Jerryscript Heaplimit" 31 | default 128 32 | 33 | endif #ENABLE_IOTJS 34 | 35 | -------------------------------------------------------------------------------- /docs/Developer's-Guide.md: -------------------------------------------------------------------------------- 1 | To contribute to the IoT.js Project (such as reporting bugs and submitting patches): 2 | * Follow the [Development Process](devs/Development-Process.md) and [GitHub contributor guidelines](https://guides.github.com/activities/contributing-to-open-source/). 3 | * Add the [IoT.js DCO](devs/IoT.js-Developer's-Certificate-of-Origin-1.0.md) signoff to each commit message during development. 4 | * Add the [License](License.md) if you introduce any new source code or script files 5 | -------------------------------------------------------------------------------- /docs/License.md: -------------------------------------------------------------------------------- 1 | ### Introduce License Policy 2 | 3 | IoT.js is open source software under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0). Complete license and copyright information can be found within the code. 4 | 5 | > Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 6 | 7 | > 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. 8 | 9 | ※ [IoT.js Developer's Certificate of Origin 1.0](IoT.js-Developer's-Certificate-of-Origin-1.0) applies from _15th June in 2015_ 10 | 11 | ### Open Source Software 12 | 13 | The following Open Source software supports IoT.js: 14 | * **_[libuv](https://github.com/libuv/libuv)_** licensed under [MIT License](http://opensource.org/licenses/MIT) 15 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | Welcome to the IoT.js! 2 | 3 | > IoT.js is a framework for "Internet of Things" built on 4 | > lightweight JavaScript interpreter ['JerryScript'](https://github.com/jerryscript-project/jerryscript) 5 | > and libtuv for event driven(non-blocking I/O model) similar to node.js. 6 | 7 | ### IoT.js Wiki 8 | 9 | **About** 10 | - [License](License.md) 11 | - [Governance](contributing/Governance.md) 12 | 13 | **[Getting Started](Getting-Started.md)** 14 | - [x86 / Linux](build/Build-for-x86-Linux.md) 15 | - [Raspberry Pi 2 / Linux](build/Build-for-RPi2-Linux.md) 16 | - [Raspberry Pi 3 / Tizen](build/Build-for-RPi3-Tizen.md) 17 | - [Stm32f4 / NuttX](build/Build-for-STM32F4-NuttX.md) 18 | - [ARTIK053 / TizenRT](build/Build-for-ARTIK053-TizenRT.md) 19 | 20 | **[Developer Guide](Developer's-Guide.md)** 21 | - [Development Process](devs/Development-Process.md) 22 | - [Certificate of Origin](devs/IoT.js-Developer's-Certificate-of-Origin-1.0.md) 23 | - [Test Guidelines](devs/Test-Guidelines.md) 24 | - [Coding Style Guidelines](devs/Coding-Style-Guidelines.md) 25 | - [API Document Guidelines](devs/API-Document-Guidelines.md) 26 | - [Developer Tutorial](devs/Developer-Tutorial.md) 27 | - [Advanced Development](devs/Advanced-Development.md) 28 | - [IoT.js API Reference](api/IoT.js-API-reference.md) 29 | 30 | **Contributing** 31 | - [Patch Submission Process](contributing/Patch-Submission-Process.md) 32 | - [Community Guideline](contributing/Community-Guidelines.md) 33 | - [Assigned People](contributing/Assigned-People.md) 34 | -------------------------------------------------------------------------------- /docs/api/IoT.js-API-reference.md: -------------------------------------------------------------------------------- 1 | # IoT.js modules 2 | ## Basic API 3 | * [Assert](IoT.js-API-Assert.md) 4 | * [Buffer](IoT.js-API-Buffer.md) 5 | * [DNS](IoT.js-API-DNS.md) 6 | * [Events](IoT.js-API-Events.md) 7 | * [File System](IoT.js-API-File-System.md) 8 | * [HTTP](IoT.js-API-HTTP.md) 9 | * [Module](IoT.js-API-Module.md) 10 | * [Net](IoT.js-API-Net.md) 11 | * [Process](IoT.js-API-Process.md) 12 | * [Timers](IoT.js-API-Timers.md) 13 | 14 | ## Extended API 15 | * [(ADC)](IoT.js-API-ADC.md) 16 | * [(BLE)](IoT.js-API-BLE.md) 17 | * [(GPIO)](IoT.js-API-GPIO.md) 18 | * [HTTPS](IoT.js-API-HTTPS.md) 19 | * [(I2C)](IoT.js-API-I2C.md) 20 | * [(PWM)](IoT.js-API-PWM.md) 21 | * [(SPI)](IoT.js-API-SPI.md) 22 | * [TLS](IoT.js-API-TLS.md) 23 | * [(UART)](IoT.js-API-UART.md) 24 | * [UDP/Datagram](IoT.js-API-DGRAM.md) 25 | 26 | ## Abstract interfaces 27 | * [Stream](IoT.js-API-Stream.md) 28 | 29 | *() not supported by node.js 30 | -------------------------------------------------------------------------------- /docs/contributing/Assigned-People.md: -------------------------------------------------------------------------------- 1 | #### Maintainers 2 | * akosthekiss (integration) 3 | * LaszloLango (integration) 4 | * zherczeg (Steering Committee) 5 | * yichoi (Steering Committee, Project main contact) 6 | 7 | #### Committers 8 | * chokobole 9 | * glistening 10 | * hs0225 11 | * daeyeon 12 | * bzsolt 13 | * galpeter -------------------------------------------------------------------------------- /docs/devs/Advanced-Development.md: -------------------------------------------------------------------------------- 1 | - [Inside IoT.js](Inside-IoT.js.md) 2 | - [Experimental Features](Experimental-Features.md) 3 | - [Logging Execution](Logging-IoT.js-execution.md) 4 | - [Memory saving with libtuv](Memory-savings-with-libtuv.md) 5 | - [Optimization Tips](Optimization-Tips.md) 6 | - [JerryScript Debugger](Use-JerryScript-Debugger.md) 7 | - [Writing New Builtin Module](Writing-New-Builtin-Module.md) 8 | - [Extended API Guidelines](Extended-API-Guidelines.md) 9 | -------------------------------------------------------------------------------- /docs/devs/Logging-IoT.js-execution.md: -------------------------------------------------------------------------------- 1 | ### Logging Support 2 | 3 | IoT.js supports logging on Debug version. It can output message strings to the stderr console by default or any file you give. 4 | 5 | To add a message line, use one of three macros in the source, defined in iotjs_module_debug.h 6 | ``` 7 | DLOG() 8 | DDLOG() 9 | DDDLOG() 10 | ``` 11 | DLOG is level 1 which means it's an error so that should be displayed. DDLOG is for warning messages and is level 2. DDDLOG is information you need while IoT.js is running, which is level 3. Default is 1. 12 | 13 | ### Setting logging level 14 | 15 | In linux, use `IOTJS_DEBUG_LEVEL` environment variable to change the level, for example, if you want to see error and warning messages; 16 | ``` 17 | export IOTJS_DEBUG_LEVEL=2 18 | ``` 19 | Numbers can be 0, 1, 2 or 3. If you give 0, it will be silence, no message. 20 | 21 | ### Logging to a file 22 | 23 | To save to a file, use also the environment variable, for example; 24 | ``` 25 | export IOTJS_DEBUG_LOGFILE="/home/iotjsdev/iotjslog.txt" 26 | ``` 27 | You must have file creation rights to that directory. File will be overwritten on every start, so don't run the program before looking inside or backing it up. 28 | 29 | To disable logging to a file, 30 | ``` 31 | unset IOTJS_DEBUG_LOGFILE 32 | ``` 33 | will do. 34 | -------------------------------------------------------------------------------- /docs/targets/tizenrt/artik05x/IoT.js-API-artik053.md: -------------------------------------------------------------------------------- 1 | ## Artik053 module 2 | 3 | ## `Pin` 4 | To use system IO, such as PWM, you must know pin name. 5 | 6 | 7 | ### `PWM Pin Number` 8 | 9 | For example, 10 | ``` javascript 11 | var pwm = new require('pwm')(); 12 | var config = { 13 | pin: 0, 14 | period: 0.001, 15 | dutyCycle: 0.5 16 | } 17 | var pwm0 = pwm.open(config, function() { 18 | if (err) { 19 | throw err; 20 | } 21 | }); 22 | ``` 23 | The following is a list of PWM pin numbers. 24 | 25 | | PWM Pin number | GPIO Name | 26 | | :---: | :---: | 27 | | 0 | XPWMTOUT_0 | 28 | | 1 | XPWMTOUT_1 | 29 | | 2 | XPWMTOUT_2 | 30 | | 3 | XPWMTOUT_3 | 31 | | 4 | XPWMTOUT_4 | 32 | | 5 | XPWMTOUT_5 | 33 | | 6 | XPWMTOUT_6 | 34 | -------------------------------------------------------------------------------- /include/iotjs.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | #ifndef IOTJS_IOTJS_H 17 | #define IOTJS_IOTJS_H 18 | 19 | 20 | #ifdef __cplusplus 21 | #define IOTJS_EXTERN_C extern "C" 22 | #else /* !__cplusplus */ 23 | #define IOTJS_EXTERN_C extern 24 | #endif /* !__cplusplus */ 25 | 26 | 27 | IOTJS_EXTERN_C int iotjs_entry(int argc, char** argv); 28 | 29 | IOTJS_EXTERN_C void iotjs_conf_console_out(int (*fp)(int level, const char* fmt, 30 | ...)); 31 | 32 | #endif /* IOTJS_IOTJS_H */ 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "IoT.js", 3 | "description": "Platform for Internet of Things with JavaScript", 4 | "scripts": { 5 | "lint": "eslint src -f codeframe || true", 6 | "lint-autofix": "eslint src -f codeframe --fix || true" 7 | }, 8 | "author": "Samsung Electronics Co., Ltd.", 9 | "license": "Apache-2.0", 10 | "devDependencies": { 11 | "eslint": "^4.7.2" 12 | }, 13 | "dependencies": { 14 | "node-gyp": "^3.8.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /profiles/default.profile: -------------------------------------------------------------------------------- 1 | ENABLE_MODULE_IOTJS_BASIC_MODULES 2 | ENABLE_MODULE_IOTJS_CORE_MODULES 3 | -------------------------------------------------------------------------------- /profiles/minimal.profile: -------------------------------------------------------------------------------- 1 | ENABLE_MODULE_IOTJS_CORE_MODULES 2 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=pando-project_iotjs 2 | sonar.projectName=IoT.js 3 | sonar.sources=src 4 | sonar.cfamily.build-wrapper-output=bw-output 5 | -------------------------------------------------------------------------------- /src/iotjs_binding_helper.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | #ifndef IOTJS_BINDING_HELPER_H 17 | #define IOTJS_BINDING_HELPER_H 18 | 19 | 20 | #include "iotjs_binding.h" 21 | 22 | 23 | void iotjs_uncaught_exception(jerry_value_t jexception); 24 | 25 | void iotjs_process_emit_exit(int code); 26 | 27 | bool iotjs_process_next_tick(void); 28 | 29 | void iotjs_invoke_callback(jerry_value_t jfunc, jerry_value_t jthis, 30 | const jerry_value_t* jargv, size_t jargc); 31 | jerry_value_t iotjs_invoke_callback_with_result(jerry_value_t jfunc, 32 | jerry_value_t jthis, 33 | const jerry_value_t* jargv, 34 | size_t jargc); 35 | 36 | int iotjs_process_exitcode(void); 37 | void iotjs_set_process_exitcode(int code); 38 | 39 | #endif /* IOTJS_BINDING_HELPER_H */ 40 | -------------------------------------------------------------------------------- /src/iotjs_compatibility.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | #ifndef IOTJS_COMPATIBILITY_H 16 | #define IOTJS_COMPATIBILITY_H 17 | 18 | /* Windows compatiblity defines */ 19 | #ifdef WIN32 20 | #include 21 | #include 22 | /* Map windows _O_* to O_* defines as on Linux systems. */ 23 | #define O_APPEND _O_APPEND 24 | #define O_CREAT _O_CREAT 25 | #define O_EXCL _O_EXCL 26 | #define O_RDONLY _O_RDONLY 27 | #define O_RDWR _O_RDWR 28 | #define O_TRUNC _O_TRUNC 29 | #define O_WRONLY _O_WRONLY 30 | /* On windows there is no O_SYNC directly, disable it for now. */ 31 | #define O_SYNC 0x0 32 | 33 | #ifndef PATH_MAX 34 | #define PATH_MAX MAX_PATH 35 | #endif 36 | 37 | #endif 38 | 39 | #ifndef S_ISREG 40 | #define S_ISREG(mode) (((mode) & (S_IFMT)) == S_IFREG) 41 | #endif 42 | 43 | #endif /* IOTJS_COMPATIBILITY_H */ 44 | -------------------------------------------------------------------------------- /src/iotjs_module.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | #ifndef IOTJS_MODULE_H 17 | #define IOTJS_MODULE_H 18 | 19 | #include "iotjs_binding.h" 20 | 21 | typedef jerry_value_t (*register_func)(void); 22 | 23 | typedef struct { 24 | const char* name; 25 | register_func fn_register; 26 | } iotjs_module_ro_data_t; 27 | 28 | extern const unsigned iotjs_module_count; 29 | extern const iotjs_module_ro_data_t iotjs_module_ro_data[]; 30 | 31 | void iotjs_module_list_cleanup(void); 32 | 33 | jerry_value_t iotjs_module_get(const char* name); 34 | 35 | #endif /* IOTJS_MODULE_H */ 36 | -------------------------------------------------------------------------------- /src/iotjs_string_ext.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | #ifndef IOTJS_STRING_EXT_H 17 | #define IOTJS_STRING_EXT_H 18 | 19 | 20 | void iotjs_register_jerry_magic_string(void); 21 | 22 | 23 | #endif /* IOTJS_STRING_EXT_H */ 24 | -------------------------------------------------------------------------------- /src/js/adc.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | var adc = { 17 | open: function(config, callback) { 18 | var adcPin = new native(config, function(err) { 19 | callback(err, adcPin); 20 | }); 21 | return adcPin; 22 | }, 23 | openSync: function(config) { 24 | return new native(config); 25 | }, 26 | }; 27 | 28 | module.exports = adc; 29 | -------------------------------------------------------------------------------- /src/js/bridge.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | function Bridge(moduleName) { 17 | this.moduleName = moduleName; 18 | } 19 | 20 | Bridge.prototype.send = function(command, message, callback) { 21 | native.send(this.moduleName, command, message, function(err, results) { 22 | callback(err, results); 23 | }); 24 | }; 25 | 26 | Bridge.prototype.sendSync = function(command, message) { 27 | return native.send(this.moduleName, command, message); 28 | }; 29 | 30 | module.exports = Bridge; 31 | -------------------------------------------------------------------------------- /src/js/console.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var util = require('util'); 18 | 19 | 20 | function Console() { 21 | } 22 | 23 | 24 | Console.prototype.log = 25 | Console.prototype.info = function() { 26 | native.stdout(util.format.apply(this, arguments) + '\n'); 27 | }; 28 | 29 | 30 | Console.prototype.warn = 31 | Console.prototype.error = function() { 32 | native.stderr(util.format.apply(this, arguments) + '\n'); 33 | }; 34 | 35 | 36 | module.exports = new Console(); 37 | module.exports.Console = Console; 38 | -------------------------------------------------------------------------------- /src/js/gpio.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var gpio = { 18 | open: function(config, callback) { 19 | var gpioPin = new native(config, function(err) { 20 | callback(err, gpioPin); 21 | }); 22 | return gpioPin; 23 | }, 24 | openSync: function(config) { 25 | return new native(config); 26 | }, 27 | DIRECTION: native.DIRECTION, 28 | EDGE: native.EDGE, 29 | MODE: native.MODE, 30 | }; 31 | 32 | module.exports = gpio; 33 | -------------------------------------------------------------------------------- /src/js/i2c.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | var i2c = { 17 | open: function(config, callback) { 18 | var i2cBus = new native(config, function(err) { 19 | callback(err, i2cBus); 20 | }); 21 | return i2cBus; 22 | }, 23 | openSync: function(config) { 24 | return new native(config); 25 | }, 26 | }; 27 | 28 | module.exports = i2c; 29 | -------------------------------------------------------------------------------- /src/js/pwm.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | var pwm = { 17 | open: function(config, callback) { 18 | var pwmPin = new native(config, function(err) { 19 | callback(err, pwmPin); 20 | }); 21 | return pwmPin; 22 | }, 23 | openSync: function(config) { 24 | return new native(config); 25 | }, 26 | }; 27 | 28 | module.exports = pwm; 29 | -------------------------------------------------------------------------------- /src/js/spi.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | var spi = { 17 | open: function(config, callback) { 18 | var spiBus = new native(config, function(err) { 19 | callback(err, spiBus); 20 | }); 21 | return spiBus; 22 | }, 23 | openSync: function(config) { 24 | return new native(config); 25 | }, 26 | MODE: native.MODE, 27 | CHIPSELECT: native.CHIPSELECT, 28 | BITORDER: native.BITORDER, 29 | }; 30 | 31 | module.exports = spi; 32 | -------------------------------------------------------------------------------- /src/js/stream.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var StreamInternal = require('stream_internal'); 18 | var util = require('util'); 19 | 20 | 21 | function Stream() { 22 | StreamInternal.call(this); 23 | } 24 | 25 | util.inherits(Stream, StreamInternal); 26 | 27 | exports.Stream = Stream; 28 | 29 | exports.Readable = require('stream_readable'); 30 | exports.Writable = require('stream_writable'); 31 | exports.Duplex = require('stream_duplex'); 32 | -------------------------------------------------------------------------------- /src/js/stream_internal.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var eventEmitter = require('events').EventEmitter; 18 | var util = require('util'); 19 | 20 | 21 | function Stream() { 22 | eventEmitter.call(this); 23 | } 24 | 25 | util.inherits(Stream, eventEmitter); 26 | 27 | module.exports = Stream; 28 | -------------------------------------------------------------------------------- /src/js/uart.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | var EventEmitter = require('events').EventEmitter; 17 | var util = require('util'); 18 | 19 | util.mixin(native.prototype, EventEmitter.prototype); 20 | 21 | var uart = { 22 | open: function(config, callback) { 23 | var uartPort = new native(config, function(err) { 24 | callback(err); 25 | }); 26 | return uartPort; 27 | }, 28 | openSync: function(config) { 29 | return new native(config); 30 | }, 31 | }; 32 | 33 | module.exports = uart; 34 | -------------------------------------------------------------------------------- /src/modules/iotjs_module_bridge.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | #ifndef IOTJS_BRIDGE_H 17 | #define IOTJS_BRIDGE_H 18 | 19 | #define MAX_RETURN_MESSAGE 512 * 2 20 | 21 | /* 22 | */ 23 | typedef void (*iotjs_bridge_func)(const char* command, const char* message, 24 | void* return_handle); 25 | 26 | int iotjs_bridge_register(char* module_name, iotjs_bridge_func callback); 27 | 28 | void iotjs_bridge_set_err(void* return_handle, char* err); 29 | void iotjs_bridge_set_msg(void* return_handle, char* msg); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/modules/iotjs_module_crypto.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | #ifndef IOTJS_MODULE_CRYPTO_H 16 | #define IOTJS_MODULE_CRYPTO_H 17 | 18 | size_t iotjs_sha1_encode(unsigned char **out_buff, const unsigned char *in_buff, 19 | size_t buff_len); 20 | size_t iotjs_sha256_encode(unsigned char **out_buff, 21 | const unsigned char *in_buff, size_t buff_len); 22 | #endif /* IOTJS_MODULE_CRYPTO_H */ 23 | -------------------------------------------------------------------------------- /src/modules/iotjs_module_stm32f4dis.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 "iotjs_def.h" 17 | #include "iotjs_module_stm32f4dis.h" 18 | 19 | 20 | jerry_value_t iotjs_init_stm32f4dis() { 21 | jerry_value_t stm32f4dis = jerry_create_object(); 22 | 23 | #if defined(__NUTTX__) 24 | 25 | iotjs_stm32f4dis_pin_initialize(stm32f4dis); 26 | 27 | #endif 28 | 29 | return stm32f4dis; 30 | } 31 | -------------------------------------------------------------------------------- /src/modules/iotjs_module_stm32f4dis.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | #ifndef IOTJS_MODULE_STM32F4DIS_H 17 | #define IOTJS_MODULE_STM32F4DIS_H 18 | 19 | 20 | void iotjs_stm32f4dis_pin_initialize(jerry_value_t jobj); 21 | 22 | 23 | #endif /* IOTJS_MODULE_STM32F4DIS_H */ 24 | -------------------------------------------------------------------------------- /src/modules/iotjs_module_stm32f7nucleo.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors 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 "iotjs_def.h" 17 | #include "iotjs_module_stm32f7nucleo.h" 18 | 19 | 20 | jerry_value_t iotjs_init_stm32f7nucleo() { 21 | jerry_value_t stm32f7nucleo = jerry_create_object(); 22 | /* Hardware support in progress, do initialization here */ 23 | 24 | #if defined(__NUTTX__) 25 | 26 | iotjs_stm32f7nucleo_pin_initialize(stm32f7nucleo); 27 | 28 | #endif 29 | return stm32f7nucleo; 30 | } 31 | -------------------------------------------------------------------------------- /src/modules/iotjs_module_stm32f7nucleo.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors 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 | #ifndef IOTJS_MODULE_STM32F4DIS_H 17 | #define IOTJS_MODULE_STM32F4DIS_H 18 | 19 | 20 | void iotjs_stm32f7nucleo_pin_initialize(jerry_value_t jobj); 21 | 22 | 23 | #endif /* IOTJS_MODULE_STM32F4DIS_H */ 24 | -------------------------------------------------------------------------------- /src/modules/iotjs_module_tcp.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | #ifndef IOTJS_MODULE_TCP_H 18 | #define IOTJS_MODULE_TCP_H 19 | 20 | 21 | #include "iotjs_binding.h" 22 | 23 | 24 | typedef struct sockaddr sockaddr; 25 | typedef struct sockaddr_in sockaddr_in; 26 | typedef struct sockaddr_in6 sockaddr_in6; 27 | typedef struct sockaddr_storage sockaddr_storage; 28 | 29 | 30 | void address_to_js(jerry_value_t obj, const sockaddr* addr); 31 | 32 | 33 | #endif /* IOTJS_MODULE_TCP_H */ 34 | -------------------------------------------------------------------------------- /src/modules/iotjs_module_tizen.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 "iotjs_def.h" 17 | #include "iotjs_module_bridge.h" 18 | 19 | extern void iotjs_tizen_func(const char* command, const char* message, 20 | void* handle); 21 | 22 | /** 23 | * Init method called by IoT.js 24 | */ 25 | jerry_value_t iotjs_init_tizen() { 26 | char* module_name = IOTJS_MAGIC_STRING_TIZEN; 27 | jerry_value_t mymodule = jerry_create_object(); 28 | iotjs_jval_set_property_string_raw(mymodule, IOTJS_MAGIC_STRING_MODULE_NAME, 29 | module_name); 30 | 31 | iotjs_bridge_register(module_name, iotjs_tizen_func); 32 | return mymodule; 33 | } 34 | -------------------------------------------------------------------------------- /src/platform/linux/iotjs_linux.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 "iotjs.h" 17 | 18 | int main(int argc, char** argv) { 19 | return iotjs_entry(argc, argv); 20 | } 21 | -------------------------------------------------------------------------------- /test/external_modules/mymodule1/js/helloworld.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | module.exports = { 17 | foo: function() { return "Hello"; }, 18 | message: " world!" 19 | } 20 | -------------------------------------------------------------------------------- /test/external_modules/mymodule1/modules.json: -------------------------------------------------------------------------------- 1 | { 2 | "modules": { 3 | "mymodule1": { 4 | "js_file": "js/helloworld.js", 5 | "require": ["buffer", "console"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/external_modules/mymodule2/modules.json: -------------------------------------------------------------------------------- 1 | { 2 | "modules": { 3 | "mymodule2": { 4 | "native_files": ["my_module.c"], 5 | "init": "InitMyNativeModule" 6 | } 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /test/external_modules/mymodule2/my_module.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 "iotjs_def.h" 17 | 18 | jerry_value_t InitMyNativeModule() { 19 | jerry_value_t mymodule = jerry_create_object(); 20 | iotjs_jval_set_property_string_raw(mymodule, "message", "Hello world!"); 21 | return mymodule; 22 | } 23 | -------------------------------------------------------------------------------- /test/external_modules/test-external-module1.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | var mymodule = require('mymodule1'); 18 | 19 | assert.equal(mymodule.foo() + mymodule.message, "Hello world!"); 20 | -------------------------------------------------------------------------------- /test/external_modules/test-external-module2.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | var mymodule = require('mymodule2'); 18 | 19 | assert.equal(mymodule.message, "Hello world!"); 20 | -------------------------------------------------------------------------------- /test/hello.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors 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 | console.log("Hello IoT.js!"); 17 | -------------------------------------------------------------------------------- /test/napi/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.node 3 | -------------------------------------------------------------------------------- /test/napi/test_napi_arguments.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "common.h" 3 | 4 | static napi_value Throw(napi_env env, napi_callback_info info) { 5 | size_t argc = 1; 6 | napi_value argv[1]; 7 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); 8 | 9 | NAPI_CALL(env, napi_throw(env, argv[0])); 10 | 11 | return NULL; 12 | } 13 | 14 | static napi_value Return(napi_env env, napi_callback_info info) { 15 | size_t argc = 1; 16 | napi_value argv[1]; 17 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); 18 | 19 | return argv[0]; 20 | } 21 | 22 | static napi_value ReturnThis(napi_env env, napi_callback_info info) { 23 | napi_value this; 24 | NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &this, NULL)); 25 | 26 | return this; 27 | } 28 | 29 | static napi_value Init(napi_env env, napi_value exports) { 30 | SET_NAMED_METHOD(env, exports, "Throw", Throw); 31 | SET_NAMED_METHOD(env, exports, "Return", Return); 32 | SET_NAMED_METHOD(env, exports, "ReturnThis", ReturnThis); 33 | 34 | return exports; 35 | } 36 | 37 | NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) 38 | -------------------------------------------------------------------------------- /test/napi/test_napi_arguments_return.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var assert = require('assert'); 3 | var common = require('common.js'); 4 | var test = require('./build/' + common.buildTypePath + 5 | '/test_napi_arguments.node'); 6 | 7 | 8 | var obj = {}; 9 | assert.strictEqual(test.Return(obj), obj); 10 | -------------------------------------------------------------------------------- /test/napi/test_napi_arguments_return_this.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var assert = require('assert'); 3 | var common = require('common.js'); 4 | var test = require('./build/' + common.buildTypePath + 5 | '/test_napi_arguments.node'); 6 | 7 | 8 | var obj = {}; 9 | assert.strictEqual(test.ReturnThis.call(obj), obj); 10 | -------------------------------------------------------------------------------- /test/napi/test_napi_arguments_throw.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var assert = require('assert'); 3 | var common = require('common.js'); 4 | var test = require('./build/' + common.buildTypePath + 5 | '/test_napi_arguments.node'); 6 | 7 | try { 8 | test.Throw(new Error('foo')); 9 | assert.fail('fail path'); 10 | } catch (err) { 11 | assert(err != null); 12 | assert.strictEqual(err.message, 'foo'); 13 | } 14 | -------------------------------------------------------------------------------- /test/napi/test_napi_async.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var common = require('common.js'); 4 | var assert = require('assert'); 5 | var test_async = require('./build/' + common.buildTypePath + 6 | '/test_napi_async.node'); 7 | 8 | // Successful async execution and completion callback. 9 | test_async.Test(5, {}, common.mustCall(function(err, val) { 10 | console.log(err, val); 11 | assert.strictEqual(err, null); 12 | assert.strictEqual(val, 10); 13 | process.nextTick(common.mustCall()); 14 | })); 15 | 16 | // Async work item cancellation with callback. 17 | test_async.TestCancel(common.mustCall()); 18 | -------------------------------------------------------------------------------- /test/napi/test_napi_buffer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var global = process; 4 | var common = require('common.js'); 5 | var binding = require('./build/' + common.buildTypePath + 6 | '/test_napi_buffer.node'); 7 | var assert = require('assert'); 8 | 9 | assert.strictEqual(binding.newBuffer().toString(), binding.theText); 10 | assert.strictEqual(binding.newExternalBuffer().toString(), binding.theText); 11 | console.log('gc1'); 12 | global.gc(); 13 | assert.strictEqual(binding.getDeleterCallCount(), 1); 14 | assert.strictEqual(binding.copyBuffer().toString(), binding.theText); 15 | 16 | var buffer = binding.staticBuffer(); 17 | assert.strictEqual(binding.bufferHasInstance(buffer), true); 18 | assert.strictEqual(binding.bufferInfo(buffer), true); 19 | buffer = null; 20 | global.gc(); 21 | console.log('gc2'); 22 | assert.strictEqual(binding.getDeleterCallCount(), 2); 23 | -------------------------------------------------------------------------------- /test/napi/test_napi_construct.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "common.h" 3 | 4 | static napi_ref ConstructRef; 5 | 6 | static void cleanup(void* data) { 7 | napi_env env = (napi_env)data; 8 | napi_delete_reference(env, ConstructRef); 9 | } 10 | 11 | napi_value Construct(napi_env env, napi_callback_info info) { 12 | size_t argc = 1; 13 | napi_value argv[1]; 14 | napi_value this; 15 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &this, NULL)); 16 | 17 | NAPI_CALL(env, napi_set_named_property(env, this, "value", argv[0])); 18 | 19 | return NULL; 20 | } 21 | 22 | napi_value Constructor(napi_env env, napi_callback_info info) { 23 | napi_value construct; 24 | NAPI_CALL(env, napi_get_reference_value(env, ConstructRef, &construct)); 25 | 26 | size_t argc = 1; 27 | napi_value argv[1]; 28 | napi_value result; 29 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); 30 | 31 | NAPI_CALL(env, napi_new_instance(env, construct, argc, argv, &result)); 32 | return result; 33 | } 34 | 35 | NAPI_MODULE_INIT() { 36 | napi_value construct; 37 | NAPI_CALL(env, napi_create_function(env, "Constructor", NAPI_AUTO_LENGTH, 38 | Construct, NULL, &construct)); 39 | NAPI_CALL(env, napi_create_reference(env, construct, 1, &ConstructRef)); 40 | NAPI_CALL(env, napi_add_env_cleanup_hook(env, cleanup, env)); 41 | 42 | SET_NAMED_METHOD(env, exports, "Constructor", Constructor); 43 | return exports; 44 | } 45 | -------------------------------------------------------------------------------- /test/napi/test_napi_construct.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var assert = require('assert'); 3 | var common = require('common.js'); 4 | var test = require('./build/' + common.buildTypePath + 5 | '/test_napi_construct.node'); 6 | 7 | var val = test.Constructor(123); 8 | assert.strictEqual(val.value, 123); 9 | -------------------------------------------------------------------------------- /test/napi/test_napi_create_error.js: -------------------------------------------------------------------------------- 1 | var common = require('common.js'); 2 | var addon = require('./build/' + common.buildTypePath + 3 | '/test_napi_error_handling'); 4 | var assert = require('assert'); 5 | 6 | var ERROR_CODE = "ErrorCode"; 7 | var ERROR_MSG = "ErrorMSG" 8 | 9 | var error = addon.CreateError(ERROR_CODE, ERROR_MSG); 10 | 11 | assert(error.code == ERROR_CODE); 12 | assert(error.message == ERROR_MSG); 13 | 14 | assert(error instanceof Error); 15 | 16 | var typeError = addon.CreateTypeError(ERROR_CODE, ERROR_MSG); 17 | assert(typeError.code == ERROR_CODE); 18 | assert(typeError.message == ERROR_MSG); 19 | 20 | assert(typeError instanceof TypeError); 21 | 22 | var rangeError = addon.CreateRangeError(ERROR_CODE, ERROR_MSG); 23 | assert(rangeError.code == ERROR_CODE); 24 | assert(rangeError.message == ERROR_MSG); 25 | 26 | assert(rangeError instanceof RangeError); 27 | -------------------------------------------------------------------------------- /test/napi/test_napi_dataview.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var assert = require('assert'); 3 | var common = require('common.js'); 4 | 5 | // Testing api calls for arrays 6 | var test_dataview = require('./build/' + common.buildTypePath + 7 | '/test_napi_dataview.node'); 8 | 9 | // Test for creating dataview 10 | { 11 | var buffer = new ArrayBuffer(128); 12 | var template = new DataView(buffer); 13 | 14 | var theDataview = test_dataview.CreateDataViewFromJSDataView(template); 15 | assert(theDataview instanceof DataView, 16 | 'Expect ' + theDataview + ' to be a DataView'); 17 | } 18 | 19 | // Test for creating dataview with invalid range 20 | { 21 | var buffer = new ArrayBuffer(128); 22 | assert.throws(function() { 23 | test_dataview.CreateDataView(buffer, 10, 200); 24 | }, RangeError); 25 | } 26 | -------------------------------------------------------------------------------- /test/napi/test_napi_env.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var common = require('common.js'); 4 | var storeEnv = require('./build/' + common.buildTypePath + 5 | '/test_napi_env_store.node'); 6 | var compareEnv = require('./build/' + common.buildTypePath + 7 | '/test_napi_env_compare.node'); 8 | var assert = require('assert'); 9 | 10 | // N-API environment pointers in two different modules must be different 11 | assert.strictEqual(compareEnv(storeEnv), true); 12 | -------------------------------------------------------------------------------- /test/napi/test_napi_env_compare.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "common.h" 3 | 4 | static napi_value compare(napi_env env, napi_callback_info info) { 5 | napi_value external; 6 | size_t argc = 1; 7 | void* data; 8 | napi_value return_value; 9 | 10 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &external, NULL, NULL)); 11 | NAPI_CALL(env, napi_get_value_external(env, external, &data)); 12 | NAPI_CALL(env, napi_get_boolean(env, ((napi_env)data) == env, &return_value)); 13 | 14 | return return_value; 15 | } 16 | 17 | static napi_value Init(napi_env env, napi_value exports) { 18 | NAPI_CALL(env, napi_create_function(env, "exports", NAPI_AUTO_LENGTH, compare, 19 | NULL, &exports)); 20 | return exports; 21 | } 22 | 23 | NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) 24 | -------------------------------------------------------------------------------- /test/napi/test_napi_env_store.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "common.h" 3 | 4 | static napi_value Init(napi_env env, napi_value exports) { 5 | napi_value external; 6 | NAPI_CALL(env, napi_create_external(env, env, NULL, NULL, &external)); 7 | return external; 8 | } 9 | 10 | NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) 11 | -------------------------------------------------------------------------------- /test/napi/test_napi_exception.js: -------------------------------------------------------------------------------- 1 | var common = require('common.js'); 2 | var addon = require('./build/' + common.buildTypePath + 3 | '/test_napi_error_handling'); 4 | var assert = require('assert'); 5 | 6 | var ERROR_MSG = "ErrorMSG"; 7 | 8 | process.on("uncaughtException", function (e) { 9 | assert(e.message === ERROR_MSG); 10 | }); 11 | 12 | assert(addon.GetandClearLastException() === undefined); 13 | 14 | var err = new Error(ERROR_MSG); 15 | 16 | addon.FatalException(err); 17 | -------------------------------------------------------------------------------- /test/napi/test_napi_general.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors 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 | 'use strict'; 17 | var assert = require('assert'); 18 | var common = require('common.js'); 19 | 20 | var test_general = require('./build/' + common.buildTypePath + 21 | '/test_napi_general.node'); 22 | 23 | assert.strictEqual(test_general.GetUndefined(), undefined); 24 | assert.strictEqual(test_general.GetNull(), null); 25 | 26 | [ 27 | 123, 28 | 'test string', 29 | function() {}, 30 | new Object(), 31 | true, 32 | undefined 33 | ].forEach(function(val) { 34 | assert.strictEqual(test_general.TypeOf(val), typeof val); 35 | }); 36 | -------------------------------------------------------------------------------- /test/napi/test_napi_handle_scope.js: -------------------------------------------------------------------------------- 1 | var common = require('common.js'); 2 | var assert = require('assert'); 3 | var testHandleScope = require('./build/' + common.buildTypePath + 4 | '/test_napi_handle_scope.node'); 5 | 6 | testHandleScope.NewScope(); 7 | 8 | assert(testHandleScope.NewScopeEscape() instanceof Object); 9 | 10 | testHandleScope.NewScopeEscapeTwice(); 11 | 12 | assert.throws( 13 | function() { 14 | testHandleScope.NewScopeWithException(function() { 15 | throw new RangeError(); 16 | }); 17 | }, 18 | RangeError 19 | ); 20 | -------------------------------------------------------------------------------- /test/napi/test_napi_is_error.js: -------------------------------------------------------------------------------- 1 | var common = require('common.js'); 2 | var addon = require('./build/' + common.buildTypePath + 3 | '/test_napi_error_handling'); 4 | var assert = require('assert'); 5 | 6 | var err = new Error("ErrorMSG"); 7 | try { 8 | var c = true; 9 | throw c 10 | } catch (e) { 11 | assert(addon.IsError(e) === false); 12 | } 13 | assert(addon.IsError(err)); 14 | -------------------------------------------------------------------------------- /test/napi/test_napi_make_callback.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var common = require('common.js'); 4 | var assert = require('assert'); 5 | var binding = require('./build/' + common.buildTypePath + 6 | '/test_napi_make_callback.node'); 7 | var makeCallback = binding.makeCallback; 8 | 9 | function myMultiArgFunc(arg1, arg2, arg3) { 10 | assert.strictEqual(arg1, 1); 11 | assert.strictEqual(arg2, 2); 12 | assert.strictEqual(arg3, 3); 13 | return 42; 14 | } 15 | 16 | assert.strictEqual(42, makeCallback(process, common.mustCall(function() { 17 | assert.strictEqual(0, arguments.length); 18 | assert.strictEqual(this, process); 19 | return 42; 20 | }))); 21 | 22 | assert.strictEqual(42, makeCallback(process, common.mustCall(function(x) { 23 | assert.strictEqual(1, arguments.length); 24 | assert.strictEqual(this, process); 25 | assert.strictEqual(x, 1337); 26 | return 42; 27 | }), 1337)); 28 | 29 | assert.strictEqual(42, 30 | makeCallback(this, 31 | common.mustCall(myMultiArgFunc), 1, 2, 3)); 32 | -------------------------------------------------------------------------------- /test/napi/test_napi_make_callback_error.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var common = require('common.js'); 4 | var assert = require('assert'); 5 | var binding = require('./build/' + common.buildTypePath + 6 | '/test_napi_make_callback.node'); 7 | var makeCallback = binding.makeCallback; 8 | 9 | var first = true; 10 | process.on('uncaughtException', function(err) { 11 | if (first) { 12 | assert.strictEqual(err.message, 'foobar'); 13 | first = false; 14 | return; 15 | } 16 | assert.strictEqual(err.message, 'tick'); 17 | }); 18 | 19 | process.nextTick(common.mustCall(function() { 20 | throw new Error('tick'); 21 | })); 22 | makeCallback(process, common.mustCall(function() { 23 | throw new Error('foobar'); 24 | })); 25 | -------------------------------------------------------------------------------- /test/napi/test_napi_object_wrap.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | var assert = require('assert'); 4 | var common = require('common.js'); 5 | var test = require('./build/' + common.buildTypePath + 6 | '/test_napi_object_wrap.node'); 7 | 8 | function context() { 9 | var obj = {}; 10 | assert.strictEqual(test.Wrap(obj), obj); 11 | } 12 | 13 | assert.strictEqual(test.GetNativeCounter(), 0); 14 | context(); 15 | process.gc(); 16 | assert.strictEqual(test.GetNativeCounter(), 1); 17 | -------------------------------------------------------------------------------- /test/napi/test_napi_strictequal_and_instanceof.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var assert = require('assert'); 3 | var common = require('common.js'); 4 | var napi_test = 5 | require('./build/' + common.buildTypePath + 6 | '/test_napi_strictequal_and_instanceof.node'); 7 | 8 | assert(napi_test !== null); 9 | assert.strictEqual(typeof napi_test, 'object'); 10 | assert.strictEqual(napi_test.id, 321); 11 | 12 | assert.strictEqual(typeof napi_test.sayHello, 'function'); 13 | assert.strictEqual(napi_test.sayHello(), 'Hello'); 14 | 15 | assert.strictEqual(typeof napi_test.sayError, 'function'); 16 | 17 | var error; 18 | try { 19 | napi_test.sayError(); 20 | } catch (err) { 21 | error = err; 22 | } 23 | assert(error instanceof Error); 24 | assert.strictEqual(error.code, 'foo'); 25 | assert.strictEqual(error.message, 'bar'); 26 | 27 | var lhs = {}; 28 | assert.strictEqual(napi_test.strictEquals(lhs, lhs), true); 29 | assert.strictEqual(napi_test.instanceof(lhs, Object), lhs instanceof Object); 30 | -------------------------------------------------------------------------------- /test/napi/test_napi_string.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var assert = require('assert'); 3 | var common = require('common.js'); 4 | var test = require('./build/' + common.buildTypePath + 5 | '/test_napi_string.node'); 6 | 7 | var empty = ''; 8 | assert.strictEqual(test.TestUtf8(empty), empty); 9 | assert.strictEqual(test.Utf8Length(empty), 0); 10 | 11 | var str1 = 'hello world'; 12 | assert.strictEqual(test.TestUtf8(str1), str1); 13 | assert.strictEqual(test.Utf8Length(str1), 11); 14 | 15 | var str2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 16 | assert.strictEqual(test.TestUtf8(str2), str2); 17 | assert.strictEqual(test.Utf8Length(str2), 62); 18 | 19 | var str3 = '?!@#$%^&*()_+-=[]{}/.,<>\'"\\'; 20 | assert.strictEqual(test.TestUtf8(str3), str3); 21 | assert.strictEqual(test.Utf8Length(str3), 27); 22 | 23 | var str4 = '¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿'; 24 | assert.strictEqual(test.TestUtf8(str4), str4); 25 | assert.strictEqual(test.Utf8Length(str4), 62); 26 | 27 | var str5 ='ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞ' 28 | + 'ßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ'; 29 | assert.strictEqual(test.TestUtf8(str5), str5); 30 | assert.strictEqual(test.Utf8Length(str5), 126); 31 | 32 | // TODO: jerry-script doesn't support copy string value to insufficient buf 33 | -------------------------------------------------------------------------------- /test/napi/test_napi_symbol.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "node_api.h" 3 | 4 | static napi_value create_symbol(napi_env env, napi_callback_info info) { 5 | size_t argc = 1; 6 | napi_value args[1]; 7 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); 8 | 9 | napi_value description = NULL; 10 | if (argc >= 1) { 11 | napi_valuetype valuetype; 12 | NAPI_CALL(env, napi_typeof(env, args[0], &valuetype)); 13 | 14 | NAPI_ASSERT(env, valuetype == napi_string, 15 | "Wrong type of arguments. Expects a string."); 16 | 17 | description = args[0]; 18 | } 19 | 20 | napi_value symbol; 21 | NAPI_CALL(env, napi_create_symbol(env, description, &symbol)); 22 | 23 | return symbol; 24 | } 25 | 26 | static napi_value Init(napi_env env, napi_value exports) { 27 | napi_property_descriptor properties[] = { 28 | DECLARE_NAPI_PROPERTY("CreateSymbol", create_symbol), 29 | }; 30 | 31 | NAPI_CALL(env, napi_define_properties(env, exports, sizeof(properties) / 32 | sizeof(*properties), 33 | properties)); 34 | 35 | return exports; 36 | } 37 | 38 | NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) 39 | -------------------------------------------------------------------------------- /test/napi/test_napi_throw.js: -------------------------------------------------------------------------------- 1 | var common = require('common.js'); 2 | var addon = require('./build/' + common.buildTypePath + 3 | '/test_napi_error_handling'); 4 | var assert = require('assert'); 5 | 6 | var ERROR_MSG = "ErrorMSG"; 7 | var error = new Error(ERROR_MSG); 8 | var catched; 9 | 10 | try { 11 | addon.Throw(error) 12 | } catch (e) { 13 | catched = e; 14 | } 15 | 16 | assert(catched instanceof Error) 17 | assert(catched.message === ERROR_MSG) 18 | 19 | try { 20 | addon.Throw(ERROR_MSG) 21 | } catch (e) { 22 | catched = e; 23 | } 24 | 25 | assert(typeof catched === 'string') 26 | assert(catched === ERROR_MSG) 27 | -------------------------------------------------------------------------------- /test/napi/test_napi_throw_error.js: -------------------------------------------------------------------------------- 1 | var common = require('common.js'); 2 | var addon = require('./build/' + common.buildTypePath + 3 | '/test_napi_error_handling'); 4 | var assert = require('assert'); 5 | 6 | var error; 7 | var ERROR_CODE = "ErrorCODE"; 8 | var ERROR_MSG = "ErrorMSG"; 9 | 10 | // Error 11 | try { 12 | addon.ThrowError(); 13 | } catch (e) { 14 | error = e; 15 | } 16 | 17 | assert(error instanceof Error); 18 | assert(error.code === "ErrorCODE"); 19 | assert(error.message === "ErrorMSG"); 20 | 21 | //TypeError 22 | try { 23 | addon.ThrowTypeError(); 24 | } catch (e) { 25 | error = e; 26 | } 27 | 28 | assert(error instanceof TypeError); 29 | assert(error.code === "ErrorCODE"); 30 | assert(error.message === "ErrorMSG"); 31 | 32 | //RangeError 33 | try { 34 | addon.ThrowRangeError(); 35 | } catch (e) { 36 | error = e; 37 | } 38 | assert(error instanceof RangeError); 39 | assert(error.code === "ErrorCODE"); 40 | assert(error.message === "ErrorMSG"); 41 | -------------------------------------------------------------------------------- /test/profiles/host-darwin.profile: -------------------------------------------------------------------------------- 1 | ENABLE_MODULE_IOTJS_BASIC_MODULES 2 | ENABLE_MODULE_IOTJS_CORE_MODULES 3 | ENABLE_MODULE_HTTPS 4 | -------------------------------------------------------------------------------- /test/profiles/host-linux.profile: -------------------------------------------------------------------------------- 1 | ENABLE_MODULE_IOTJS_BASIC_MODULES 2 | ENABLE_MODULE_IOTJS_CORE_MODULES 3 | ENABLE_MODULE_ADC 4 | ENABLE_MODULE_BLE 5 | ENABLE_MODULE_CRYPTO 6 | ENABLE_MODULE_DGRAM 7 | ENABLE_MODULE_GPIO 8 | ENABLE_MODULE_HTTP_SIGNATURE 9 | ENABLE_MODULE_HTTPS 10 | ENABLE_MODULE_I2C 11 | ENABLE_MODULE_MQTT 12 | ENABLE_MODULE_PWM 13 | ENABLE_MODULE_SPI 14 | ENABLE_MODULE_UART 15 | ENABLE_MODULE_WEBSOCKET 16 | -------------------------------------------------------------------------------- /test/profiles/mock-linux.profile: -------------------------------------------------------------------------------- 1 | ENABLE_MODULE_IOTJS_BASIC_MODULES 2 | ENABLE_MODULE_IOTJS_CORE_MODULES 3 | ENABLE_MODULE_GPIO 4 | ENABLE_MODULE_I2C 5 | ENABLE_MODULE_PWM 6 | -------------------------------------------------------------------------------- /test/profiles/nuttx.profile: -------------------------------------------------------------------------------- 1 | ENABLE_MODULE_IOTJS_BASIC_MODULES 2 | ENABLE_MODULE_IOTJS_CORE_MODULES 3 | ENABLE_MODULE_ADC 4 | ENABLE_MODULE_CRYPTO 5 | ENABLE_MODULE_DGRAM 6 | ENABLE_MODULE_GPIO 7 | ENABLE_MODULE_I2C 8 | ENABLE_MODULE_PWM 9 | ENABLE_MODULE_SPI 10 | ENABLE_MODULE_STM32F4DIS 11 | ENABLE_MODULE_UART 12 | -------------------------------------------------------------------------------- /test/profiles/rpi2-linux.profile: -------------------------------------------------------------------------------- 1 | ENABLE_MODULE_IOTJS_BASIC_MODULES 2 | ENABLE_MODULE_IOTJS_CORE_MODULES 3 | ENABLE_MODULE_BLE 4 | ENABLE_MODULE_CRYPTO 5 | ENABLE_MODULE_DGRAM 6 | ENABLE_MODULE_GPIO 7 | ENABLE_MODULE_HTTP_SIGNATURE 8 | ENABLE_MODULE_HTTPS 9 | ENABLE_MODULE_MQTT 10 | ENABLE_MODULE_I2C 11 | ENABLE_MODULE_PWM 12 | ENABLE_MODULE_SPI 13 | ENABLE_MODULE_UART 14 | ENABLE_MODULE_WEBSOCKET 15 | -------------------------------------------------------------------------------- /test/profiles/tizen-jerry.profile: -------------------------------------------------------------------------------- 1 | JERRY_ES2015=0 2 | -------------------------------------------------------------------------------- /test/profiles/tizen.profile: -------------------------------------------------------------------------------- 1 | ENABLE_MODULE_IOTJS_BASIC_MODULES 2 | ENABLE_MODULE_IOTJS_CORE_MODULES 3 | ENABLE_MODULE_BRIDGE 4 | ENABLE_MODULE_CRYPTO 5 | ENABLE_MODULE_DGRAM 6 | ENABLE_MODULE_GPIO 7 | ENABLE_MODULE_HTTP_SIGNATURE 8 | ENABLE_MODULE_HTTPS 9 | ENABLE_MODULE_MQTT 10 | ENABLE_MODULE_I2C 11 | ENABLE_MODULE_PWM 12 | ENABLE_MODULE_SPI 13 | ENABLE_MODULE_TIZEN 14 | ENABLE_MODULE_UART 15 | ENABLE_MODULE_WEBSOCKET 16 | -------------------------------------------------------------------------------- /test/profiles/tizenrt.profile: -------------------------------------------------------------------------------- 1 | ENABLE_MODULE_IOTJS_BASIC_MODULES 2 | ENABLE_MODULE_IOTJS_CORE_MODULES 3 | ENABLE_MODULE_ADC 4 | ENABLE_MODULE_CRYPTO 5 | ENABLE_MODULE_DGRAM 6 | ENABLE_MODULE_GPIO 7 | ENABLE_MODULE_HTTP_SIGNATURE 8 | ENABLE_MODULE_HTTPS 9 | ENABLE_MODULE_MQTT 10 | ENABLE_MODULE_I2C 11 | ENABLE_MODULE_PWM 12 | ENABLE_MODULE_SPI 13 | ENABLE_MODULE_UART 14 | ENABLE_MODULE_WEBSOCKET 15 | -------------------------------------------------------------------------------- /test/resources/crypto_public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsHbJBfgc4tPdH0bkuVoL 3 | AAhN6rxk7RaD73thMVP1KtlyomXdydWT9CEBR/MBepyQaokHHYt430tqbOYeeYss 4 | +SJUp2mU0C+XCcuD27T5lcwbUOFhN8pkerUKvuqM8u+ndYwgEbn8XHXSM+x62qWd 5 | wM6CO/kJx5CtzQaJ+2jPfdPnUYB3BpZvRL4ymzvGa3lUpwmtns3jfyZjJMz7Bd3A 6 | kH9gJTREhTLM3A4LNocgvIFLJNadlTbB5OgMMHxH3EEmXn1Wq+LeC57E4f2PuhmX 7 | vSRLbT85NpGC1U1AmuG2IVitwFkw1Hx23lZG8Zld/ZeV3kLBwJ2o002U3rs+H1aP 8 | 8QIDAQAB 9 | -----END PUBLIC KEY----- 10 | -------------------------------------------------------------------------------- /test/resources/greeting.txt: -------------------------------------------------------------------------------- 1 | Hello IoT.js!! -------------------------------------------------------------------------------- /test/resources/http_signature_key.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv5B5QBJx+XGoK8xbY2Q9L5pJyv0Ddlzx 3 | pwWSz6q049b/+7YzVsFLt7S+O7soW7upfwTxFkCcpWWTKIoRac6vCYY14lTmWK/M1cntho8BiFoL 4 | cvDAx7dXgH2OfIsr6VgJMFl4DZebcN2fvhsZBo2lTyhJt8lSw8esTDHFZ8App6ilvVXJ4p6uKWJp 5 | 1bzJQxvwHuNa4itN6GKyMR5kqklDwTa359JXXZf5LO7kFwO7ULCrtliaCUEUvG4xTgZfctD4gKMb 6 | WScMzx2U4ksSFhlmGyxcED2FH+fUn98Qo5KFflu01RaHScodXUZo6VMV5oY466Yq7y7z2R4KdpL4 7 | vC4v4wIDAQAB 8 | -----END PUBLIC KEY----- 9 | -------------------------------------------------------------------------------- /test/resources/my_ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDuzCCAqOgAwIBAgIJAMeGQlu8r9jlMA0GCSqGSIb3DQEBCwUAMHQxCzAJBgNV 3 | BAYTAkhVMRMwEQYDVQQIDApTb21lLVN0YXRlMQ8wDQYDVQQHDAZTemVnZWQxDjAM 4 | BgNVBAoMBU15IENBMREwDwYDVQQDDAhteWNhLm9yZzEcMBoGCSqGSIb3DQEJARYN 5 | bXljYUBteWNhLm9yZzAeFw0xODA2MjgxMDQzMThaFw0yODA2MjUxMDQzMThaMHQx 6 | CzAJBgNVBAYTAkhVMRMwEQYDVQQIDApTb21lLVN0YXRlMQ8wDQYDVQQHDAZTemVn 7 | ZWQxDjAMBgNVBAoMBU15IENBMREwDwYDVQQDDAhteWNhLm9yZzEcMBoGCSqGSIb3 8 | DQEJARYNbXljYUBteWNhLm9yZzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC 9 | ggEBALCPKzrZoSVHjswF0W/5pn0ElmAjO3GmYH1rHbTdSfQ9fXWiXWHREcGXeGXJ 10 | Vs/OIr6hxrghuPehYxERW2RhZESosOZgtifLC5hpg5guHzls0p8ix1gZ/olNBhzV 11 | /1qO5J7MSxx87DldDvoVTNyUzp/FEL5U45N4B8ECrY5+41BN1SPgAs5xc+LJLiag 12 | JjrsUxrpzngqsfpf15zcFsXcknB3VZKLQStkbmZB2RNWJm2dulSwr1tdXeZhBs1M 13 | seKh7MZ86ay/8/LJPedBUNUnIm/ZlinFYC5dxRpfA4RFL7Q91PZbAIRMphpXfE2x 14 | SSeOnkB2InXXwaPi+PlQnDzzSIMCAwEAAaNQME4wHQYDVR0OBBYEFNm9NQ9P2i35 15 | oCIFHQmft53GXlCNMB8GA1UdIwQYMBaAFNm9NQ9P2i35oCIFHQmft53GXlCNMAwG 16 | A1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAIurYWyw/AkMlNeW7PIu7zsh 17 | 6mknQ0RCI8h05CgJ6SlSlVQSB6Tu9BiLT0DNc0PTIQxHoqgVofATndLLn7a6G0Lc 18 | iy8mcYDbfAEcXiXFlo58gyWCa+/azJ/hslOVKvCs66BieHOiDhaBVzqWwUYaVMYA 19 | EocmusQmx44qrSsMfNPqq4b15b9sn0WximHtc76Czibnj35Nkhr/x2Cd07vnoU/2 20 | 5fpiu8PfrSAjOw6oaAINwP6pXskl1+wtJ9NpqvEJVl4aEUWpSJoGtIJGOtM0zbNF 21 | /IPITiGuLri8FzYqfvYBxRR2Wuq94Vcmwh8r2mysuPC1dHtjg5l1hm8vqiBW3p4= 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /test/resources/my_ca.srl: -------------------------------------------------------------------------------- 1 | 94825A52EA8A27F1 2 | -------------------------------------------------------------------------------- /test/resources/process/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.9.1", 3 | "name": "npm", 4 | "description": "a package manager for JavaScript", 5 | "config": { 6 | "publishtest": false 7 | }, 8 | "homepage": "https://docs.npmjs.com/", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/npm/npm" 12 | }, 13 | "bugs": { 14 | "url": "http://github.com/npm/npm/issues" 15 | }, 16 | "directories": { 17 | "doc": "./doc", 18 | "man": "./man", 19 | "lib": "./lib", 20 | "bin": "./bin" 21 | }, 22 | "main": "./lib/npm.js", 23 | "bin": "./bin/npm-cli.js", 24 | "scripts": { 25 | "test-legacy": "node ./test/run.js", 26 | "test": "tap --timeout 240 test/tap/*.js", 27 | "tap": "tap --timeout 240 test/tap/*.js" 28 | }, 29 | "license": "Artistic-2.0" 30 | } 31 | -------------------------------------------------------------------------------- /test/resources/promise_chain_calls/1.txt: -------------------------------------------------------------------------------- 1 | Content of 1.txt 2 | -------------------------------------------------------------------------------- /test/resources/promise_chain_calls/2.txt: -------------------------------------------------------------------------------- 1 | Content of 2.txt 2 | -------------------------------------------------------------------------------- /test/resources/promise_chain_calls/3.txt: -------------------------------------------------------------------------------- 1 | Content of 3.txt 2 | -------------------------------------------------------------------------------- /test/resources/promise_chain_calls/4.txt: -------------------------------------------------------------------------------- 1 | Content of 4.txt 2 | -------------------------------------------------------------------------------- /test/resources/readdir/DO_NOT_MODIFY_THIS_FOLDER: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jerryscript-project/iotjs/02599f35810cfa6ea5495bbc42194ed576b969de/test/resources/readdir/DO_NOT_MODIFY_THIS_FOLDER -------------------------------------------------------------------------------- /test/resources/readdir/This_is_a_directory/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jerryscript-project/iotjs/02599f35810cfa6ea5495bbc42194ed576b969de/test/resources/readdir/This_is_a_directory/.gitkeep -------------------------------------------------------------------------------- /test/resources/readdir/This_is_another_directory/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jerryscript-project/iotjs/02599f35810cfa6ea5495bbc42194ed576b969de/test/resources/readdir/This_is_another_directory/.gitkeep -------------------------------------------------------------------------------- /test/resources/readdir/regular.txt: -------------------------------------------------------------------------------- 1 | Hello IoT.js!! -------------------------------------------------------------------------------- /test/resources/rename.txt: -------------------------------------------------------------------------------- 1 | Hello IoT.js!! -------------------------------------------------------------------------------- /test/resources/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "IoT.js", 3 | "description": "Platform for Internet of Things with JavaScript", 4 | "author": "Samsung Electronics Co., Ltd.", 5 | "license": "Apache-2.0", 6 | "number": 123, 7 | "array": [1,2,3,4] 8 | } 9 | -------------------------------------------------------------------------------- /test/resources/test1.txt: -------------------------------------------------------------------------------- 1 | TEST File Read & Write 2 | -------------------------------------------------------------------------------- /test/resources/test2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jerryscript-project/iotjs/02599f35810cfa6ea5495bbc42194ed576b969de/test/resources/test2.txt -------------------------------------------------------------------------------- /test/resources/test_console_stdout.txt: -------------------------------------------------------------------------------- 1 | Hello IoT.js!! 2 | 1 3 | 2 4 | 3 5 | 13 6 | 1,2,3 7 | 1 2 3 8 | a 1 b 2 c 3 9 | -------------------------------------------------------------------------------- /test/run_fail/test-issue-1349.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var dns = require( 'dns' ); 17 | var assert = require( 'assert' ); 18 | assert.throws(function ( ) { dns.lookup ('localhost', require) } ); 19 | -------------------------------------------------------------------------------- /test/run_fail/test-issue-1360.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | process.on('exit', function() {}); 17 | setTimeout(function() { Array.prototype.slice += 'B' }, 500); 18 | -------------------------------------------------------------------------------- /test/run_fail/test-issue-1570.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | Object.freeze(process); 17 | throw new Error("Some error"); 18 | -------------------------------------------------------------------------------- /test/run_fail/test-issue-1915.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors 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 | var uart = require('uart'); 17 | uart.open(this); 18 | -------------------------------------------------------------------------------- /test/run_fail/test-issue-1917.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors 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 | var fs = require('fs') 17 | setInterval(fs.fstatSync(1).isFile, 1); 18 | -------------------------------------------------------------------------------- /test/run_fail/test_assert_equal.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | 19 | assert.equal(1, 2); 20 | -------------------------------------------------------------------------------- /test/run_fail/test_assert_fail.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | 19 | assert.fail(); 20 | -------------------------------------------------------------------------------- /test/run_fail/test_assert_notequal.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | 19 | assert.notEqual(1, 1); 20 | -------------------------------------------------------------------------------- /test/run_fail/test_events_emit_error.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var EventEmitter = require('events').EventEmitter; 18 | 19 | var ee = new EventEmitter(); 20 | 21 | ee.emit('error'); 22 | -------------------------------------------------------------------------------- /test/run_fail/test_fs_callbacks_called.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert') 18 | var invocation_count = 0; 19 | var callback_count = 13; 20 | 21 | var callback = function () { 22 | if (++invocation_count == callback_count) { 23 | assert.fail("pass") // All the callbacks were called 24 | } 25 | } 26 | 27 | var fs = require('fs'); 28 | fs.open("", "r", callback); 29 | fs.close(0, callback); 30 | fs.read(0, Buffer(1), 0, 0, 0, callback); 31 | fs.write(0, Buffer(1), 0, 0, 0, callback); 32 | fs.readFile("", callback); 33 | fs.writeFile("", Buffer(1), callback); 34 | fs.rename("", "", callback); 35 | fs.stat("", callback); 36 | fs.exists("", callback); 37 | fs.unlink("", callback); 38 | fs.mkdir("", callback); 39 | fs.rmdir("", callback); 40 | fs.readdir("", callback); 41 | -------------------------------------------------------------------------------- /test/run_fail/test_iotjs_runtime_error.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var a = null; 18 | 19 | a.no_exist_function(); 20 | -------------------------------------------------------------------------------- /test/run_fail/test_iotjs_syntax_error.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | for syntax error 17 | -------------------------------------------------------------------------------- /test/run_fail/test_module_require_invalid_file.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | require('no exist file path'); 18 | -------------------------------------------------------------------------------- /test/run_fail/test_process_exitcode_arg.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | 19 | process.on('exit', function(code) { 20 | assert.equal(1, code); 21 | assert.fail(); 22 | }); 23 | 24 | process.exit(1); 25 | -------------------------------------------------------------------------------- /test/run_fail/test_process_exitcode_var.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | 19 | process.on('exit', function(code) { 20 | assert.equal(2, code); 21 | assert.fail(); 22 | }); 23 | 24 | process.exitCode = 2; 25 | process.exit(); 26 | -------------------------------------------------------------------------------- /test/run_fail/test_process_explicit_exit.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | 19 | process.on('exit', function() { 20 | assert.fail(); 21 | }); 22 | 23 | process.exit(); 24 | -------------------------------------------------------------------------------- /test/run_fail/test_process_implicit_exit.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | 19 | process.on('exit', function() { 20 | assert.fail(); 21 | }); 22 | -------------------------------------------------------------------------------- /test/run_fail/test_timers_issue_1353.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | setTimeout(function() { throw "error" }, 100); 17 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1046.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var Buffer = require('buffer'); 17 | var assert = require('assert'); 18 | 19 | assert.equal(Buffer("").readUInt16LE(10, true), 0); 20 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1077.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | 18 | try { 19 | var m = require('issue-1077'); 20 | } catch (e) { 21 | assert(e.name === 'Error'); 22 | assert(e.message == 'Module not found: issue-1077'); 23 | } 24 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1101.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var uart = require('uart'); 17 | var res = uart.open({ 18 | device: '/dev/ttyS1', 19 | baudRate: 115200, 20 | dataBits: 8 21 | }, function(err) { 22 | if (err) { 23 | console.error(err); 24 | } else { 25 | console.log('opened'); 26 | res.close(function(err) { 27 | if (err) { 28 | console.error(err); 29 | } else { 30 | console.log('closed'); 31 | } 32 | }); 33 | var c = 0; 34 | var p = function() { 35 | c++; 36 | console.log('this should still run'); 37 | if (c < 10) { 38 | setTimeout(p, 250); 39 | } 40 | }; 41 | p(); 42 | } 43 | }); 44 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1165.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 16 | var s1 = Buffer('737263', 'hex').toString(); 17 | var s2 = new Buffer('737263', 'hex').toString() 18 | assert(s1 === s2); 19 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-133.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | // FIX: issue #133. 18 | console.log(""); 19 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1348.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | process.on('uncaughtException', function(err) { } ); 17 | process.exit('callback'); 18 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1350.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | process.on('exit', function() { process.exit("callback"); } ); 17 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-137.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | // FIX: issue #137. 18 | console.log('hello world'); 19 | console.log(1); 20 | console.log(9 + 10); 21 | console.log(null); 22 | console.log(true); 23 | console.log(false); 24 | console.log(undefined); 25 | console.log(0.09); 26 | console.log(NaN); 27 | console.log(function () {}); 28 | console.log(function f() { return 0; }); 29 | console.log({}); 30 | console.log({a:1, b:2}); 31 | console.log([]); 32 | console.log([1,2,3]); 33 | console.log("%s=%d", "1+10", 1 + 10); 34 | console.log("%s+%s=%d", 2, 10, 2 + 10); 35 | console.log("%d+%d=%d", 3, 10, 3 + 10); 36 | console.log("%s+%s=%s", 4, 10, 4 + 10); 37 | console.log("%d+%d=%d", "5", "10", 5 + 10); 38 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1463.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | 18 | function readfile(fileName) { 19 | return new Promise(function(resolve, reject) { 20 | throw function() {}(), Buffer; 21 | }); 22 | }; 23 | 24 | try { 25 | readfile(readfile).then(function(value) { 26 | loadfi([], 0); 27 | }).prototype(function(e) {}); 28 | assert(false); 29 | } catch (ex) { 30 | assert(ex instanceof TypeError); 31 | } 32 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1485.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | process.emitExit = 1; 17 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1507.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | var x = require("console"); 17 | process.exitCode = x.id_0; 18 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1557.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | var fz_globalObject = Function("return this")( ) 17 | var prop_names = Object.getOwnPropertyNames(fz_globalObject) 18 | console.log(prop_names) 19 | for (var i = 0; i < 10; i++) { 20 | var prop_name = prop_names[i] 21 | console.log(prop_name) 22 | } 23 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1897.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors 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 | var websocket = require('websocket'); 17 | var client = new websocket.Websocket(); 18 | var client2 = new websocket.Websocket(); 19 | var wss = new websocket.Server({port: 8081}, function () {}); 20 | 21 | client.connect('ws://localhost', 8081, '/', function() { 22 | client2.connect('ws://localhost', 8081, '/'); 23 | client2.on('open', function() { 24 | wss.broadcast('a'); 25 | // prevent blocking 26 | wss.close(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-1904.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors 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 | var module = require('module'); 17 | var dgram = require('dgram'); 18 | var assert = require('assert'); 19 | 20 | try { 21 | dgram.createSocket('udp4')._handle.send(this, 0, '', new module()); 22 | assert(false); 23 | } catch (e) { 24 | assert(e instanceof TypeError); 25 | } 26 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-198.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | 19 | assert.throws( 20 | function() { 21 | process.binding("builtin not exist"); 22 | } 23 | , Error 24 | ); 25 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-223.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | var net = require("net"); 19 | 20 | 21 | assert.throws( 22 | function() { 23 | net.Server.prototype._createTCP(375); 24 | }, 25 | Error 26 | ); 27 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-266.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var net = require('net'); 18 | var assert = require('assert'); 19 | 20 | 21 | var server = net.createServer(); 22 | var port = 30266; 23 | 24 | server.listen(port); 25 | 26 | server.on('connection', function(socket) { 27 | socket.on('data', function(data) { 28 | server.close() 29 | }); 30 | socket.on('finish', function() { 31 | socket.destroy(); 32 | socket.destroy(); 33 | socket.destroy(); 34 | }); 35 | }); 36 | 37 | var socket = new net.Socket(); 38 | socket.connect(port, "127.0.0.1"); 39 | socket.end('test'); 40 | 41 | process.on('exit', function() { 42 | assert.equal(server._socketCount, 0); 43 | }); 44 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-323.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | var fs = require('fs'); 17 | var assert = require('assert'); 18 | 19 | var fileName = ""; 20 | 21 | assert.throws( 22 | function() { 23 | var stats1 = fs.statSync(fileName); 24 | }, 25 | Error 26 | ); 27 | 28 | assert.throws( 29 | function() { 30 | var open1 = fs.openSync(fileName, 'r'); 31 | }, 32 | Error 33 | ); 34 | -------------------------------------------------------------------------------- /test/run_pass/issue/issue-816.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var Buffer = require('buffer'); 17 | var assert = require('assert'); 18 | 19 | assert.throws(function () { 20 | var buf = new Buffer("ABCDEF"); 21 | var o = { 22 | _builtin: { 23 | compare: function () { 24 | buf._builtin.compare.call(this, arguments); 25 | } 26 | }, 27 | compare: buf.compare 28 | }; 29 | 30 | o.compare(buf); 31 | }, Error); 32 | -------------------------------------------------------------------------------- /test/run_pass/require1/module_cache.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | /** 17 | @NOTEST 18 | */ 19 | 20 | exports.i = -100; 21 | -------------------------------------------------------------------------------- /test/run_pass/require1/require_add.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | /* 17 | @NOTEST 18 | */ 19 | 20 | exports.add = function(a, b) { 21 | return a + b; 22 | }; 23 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_index/add2.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | /* 17 | @NOTEST 18 | */ 19 | 20 | exports.add2 = function(a, b) { 21 | return a + b; 22 | } 23 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_index/index.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | /* 17 | @NOTEST 18 | */ 19 | 20 | exports.add = function(a, b) { 21 | return a + b; 22 | }; 23 | 24 | var x = require("lib/multi.js"); 25 | exports.multi = x.multi; 26 | exports.add2 = x.add2; 27 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_index/lib/multi.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | /* 17 | @NOTEST 18 | */ 19 | 20 | exports.multi = function(a, b) { 21 | return a * b; 22 | }; 23 | 24 | exports.add2 = require('../add2').add2; 25 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_index/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "index_test" 3 | } 4 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_index2/add2.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | exports.add2 = function(a, b) { 17 | return a + b; 18 | } 19 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_index2/index_test.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | exports.add = function(a, b) { 17 | return a + b; 18 | }; 19 | 20 | var x = require("lib/multi.js"); 21 | exports.multi = x.multi; 22 | exports.add2 = x.add2; 23 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_index2/lib/multi.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | exports.multi = function(a, b) { 17 | return a * b; 18 | }; 19 | 20 | exports.add2 = require('../add2').add2; 21 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_index2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "index_test" 3 | } 4 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_pkg/add2.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | /* 17 | @NOTEST 18 | */ 19 | 20 | exports.add2 = function(a, b) { 21 | return a + b; 22 | } 23 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_pkg/lib/multi.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | /* 17 | @NOTEST 18 | */ 19 | 20 | exports.multi = function(a, b) { 21 | return a * b; 22 | }; 23 | 24 | exports.add2 = require('../add2').add2; 25 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_pkg/main.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | /* 17 | @NOTEST 18 | */ 19 | 20 | exports.add = function(a, b) { 21 | return a + b; 22 | }; 23 | 24 | var x = require("lib/multi.js"); 25 | exports.multi = x.multi; 26 | exports.add2 = x.add2; 27 | -------------------------------------------------------------------------------- /test/run_pass/require1/test_pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "main.js" 3 | } 4 | -------------------------------------------------------------------------------- /test/run_pass/test_ble_advertisement.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | var ble = require('ble'); 17 | 18 | ble.on('stateChange', function(state){ 19 | console.log('onStateChange: ' + state); 20 | 21 | if (state == 'poweredOn') { 22 | ble.startAdvertising('iotjs', ['180F'], function(err) { 23 | if (err) console.log(err); 24 | else { 25 | 26 | setTimeout(function() { 27 | ble.stopAdvertising(function(err) { 28 | if (err) console.log(err); 29 | else console.log('stop advertising.'); 30 | }); 31 | }, 5000); 32 | } 33 | }); 34 | } else { 35 | ble.stopAdvertising(function(err) { 36 | if (err) console.log(err); 37 | else console.log('stop advertising.'); 38 | }); 39 | } 40 | }); 41 | -------------------------------------------------------------------------------- /test/run_pass/test_buffer_inmutability_creation.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | /* Related issue: https://github.com/Samsung/iotjs/issues/1379 */ 17 | 18 | var assert = require('assert'); 19 | 20 | /* The global Buffer by default is a function */ 21 | assert.strictEqual(typeof(Buffer), "function"); 22 | 23 | var backup_buffer = Buffer; 24 | 25 | /* Modify the global Buffer */ 26 | Buffer++; 27 | 28 | /** 29 | * The ++ operation will change the value of the "Buffer" variable. 30 | * Thus the type shouldn't be a function now. 31 | */ 32 | assert.notStrictEqual(typeof(Buffer), "function"); 33 | 34 | /** 35 | * Still the creation of buffer should work. 36 | * Using an already saved buffer reference 37 | */ 38 | var new_buffer = backup_buffer("OK"); 39 | 40 | assert.equal(new_buffer.length, 2); 41 | assert.equal(new_buffer.toString(), "OK"); 42 | -------------------------------------------------------------------------------- /test/run_pass/test_console.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | var console = require('console'); 17 | 18 | console.log("Hello IoT.js!!"); 19 | console.log(1); 20 | console.log(2); 21 | console.log(3); 22 | console.log(3+5*2); 23 | console.log([1, 2, 3]); 24 | console.log(1, 2, 3); 25 | console.log('a', 1, 'b', 2, 'c', 3); 26 | console.log("test", null, undefined); 27 | console.log({ a: '123', b: 123, c: [1, 2, 3]}); 28 | 29 | console.error("Hello IoT.js!!"); 30 | console.error(1); 31 | console.error(2); 32 | console.error(3); 33 | console.error(3+5*2); 34 | console.error([1, 2, 3]); 35 | console.error(1, 2, 3); 36 | console.error('a', 1, 'b', 2, 'c', 3); 37 | -------------------------------------------------------------------------------- /test/run_pass/test_crypto.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | var crypto = require('crypto'); 17 | var assert = require('assert'); 18 | 19 | var hash = crypto.createHash('sha1'); 20 | 21 | assert.throws(function() { var err_hash = crypto.createHash('sadf'); }); 22 | 23 | hash.update('Hello IoT.js'); 24 | 25 | assert.equal(hash.digest('hex'), '4f5cf1945efb60f400c23172edb4e36b47f5a25e'); 26 | assert.throws(function() { hash.digest('hex'); }); 27 | 28 | var hash2 = crypto.createHash('sha1'); 29 | hash2.update('Hello IoT.js'); 30 | hash2.update(' v2'); 31 | 32 | assert.equal(hash2.digest('base64'), 'DBnLTkxZ70AgUzCjZ7FTv91AWZw='); 33 | -------------------------------------------------------------------------------- /test/run_pass/test_dgram_multicast_set_multicast_loop.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | var dgram = require('dgram'); 18 | 19 | var port = 41240; 20 | var multicast_address = '230.255.255.250'; 21 | 22 | var msg = 'Hello IoT.js'; 23 | var server = dgram.createSocket('udp4'); 24 | 25 | server.on('error', function(err) { 26 | assert.fail(); 27 | }); 28 | 29 | server.on('message', function(data, rinfo) { 30 | assert.fail(); 31 | }); 32 | 33 | server.bind(port, function() { 34 | server.setMulticastLoopback(false); 35 | server.addMembership(multicast_address); 36 | server.send(msg, port, multicast_address); 37 | }); 38 | 39 | setTimeout(function() { 40 | server.close(); 41 | }, 1000); 42 | 43 | process.on('exit', function(code) { 44 | assert.equal(code, 0); 45 | }); 46 | -------------------------------------------------------------------------------- /test/run_pass/test_events_assert_emit_error.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | var EventEmitter = require('events').EventEmitter; 19 | 20 | 21 | var ee = new EventEmitter(); 22 | 23 | assert.throws( 24 | function() { 25 | ee.emit('error'); 26 | }, Error); 27 | -------------------------------------------------------------------------------- /test/run_pass/test_events_uncaught_error.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | var EventEmitter = require('events').EventEmitter; 19 | 20 | 21 | var uncaught_error = false; 22 | 23 | process.on('uncaughtException', function(err) { 24 | assert.equal(err.message, "Uncaught 'error' event", 25 | 'Error type does not match'); 26 | uncaught_error = true; 27 | }); 28 | 29 | process.on('exit', function(code) { 30 | process.removeAllListeners('uncaughtException'); 31 | assert.equal(code, 0, 'Non-zero exit status code:' + code); 32 | assert(uncaught_error, 'Expected uncaughtException was not executed'); 33 | }); 34 | 35 | var ee = new EventEmitter(); 36 | ee.emit('error'); 37 | -------------------------------------------------------------------------------- /test/run_pass/test_fs_exists_sync.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | var fs = require('fs'); 17 | var assert = require('assert'); 18 | 19 | { 20 | var filePath = process.cwd() + "/resources/tobeornottobe.txt"; 21 | 22 | var result = fs.existsSync(filePath); 23 | assert.equal(result, true, 'File should exist: ' + filePath); 24 | } 25 | 26 | { 27 | var filePath = process.cwd() + "/resources/empty.txt"; 28 | 29 | var result = fs.existsSync(filePath); 30 | assert.equal(result, false, 'File should not exist: ' + filePath); 31 | } 32 | 33 | { 34 | var filePath = ""; 35 | 36 | var result = fs.existsSync(filePath); 37 | assert.equal(result, false, 'File with empty should not exist'); 38 | } 39 | 40 | { 41 | var filePath = " "; 42 | 43 | var result = fs.existsSync(filePath); 44 | assert.equal(result, false, 'File name with single whitespace check'); 45 | } 46 | -------------------------------------------------------------------------------- /test/run_pass/test_fs_fstat_sync.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var fs = require('fs'); 17 | var assert = require('assert'); 18 | 19 | var testfile = process.cwd() + "/run_pass/test_fs_fstat_sync.js"; 20 | var testdir = process.cwd() + "/resources"; 21 | var flags = "r"; 22 | 23 | 24 | // fstatSync - file 25 | try { 26 | var fd = fs.openSync(testfile, flags); 27 | var stat = fs.fstatSync(fd); 28 | 29 | assert.equal(stat.isFile(), true); 30 | assert.equal(stat.isDirectory(), false); 31 | fs.closeSync(fd); 32 | } catch (err) { 33 | throw err; 34 | } 35 | 36 | 37 | // fstatSync - directory 38 | try { 39 | var fd = fs.openSync(testdir, flags); 40 | var stat = fs.fstatSync(fd); 41 | 42 | assert.equal(stat.isFile(), false); 43 | assert.equal(stat.isDirectory(), true); 44 | fs.closeSync(fd); 45 | } catch (err) { 46 | throw err; 47 | } 48 | -------------------------------------------------------------------------------- /test/run_pass/test_fs_open_read_sync_2.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var fs = require('fs'); 17 | var assert = require('assert'); 18 | 19 | var fileName = process.cwd() + "/resources/greeting.txt"; 20 | var expectedContents = "Hello IoT.js!!"; 21 | var flags = "r"; 22 | var mode = 438; 23 | 24 | 25 | // test sync open & read 26 | try { 27 | var fd = fs.openSync(fileName, flags, mode); 28 | var buffer = new Buffer(64); 29 | fs.readSync(fd, buffer, 0, buffer.length, 0); 30 | assert.equal(buffer.toString(), expectedContents); 31 | } catch (err) { 32 | throw err; 33 | } 34 | -------------------------------------------------------------------------------- /test/run_pass/test_fs_open_read_sync_3.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var fs = require('fs'); 17 | var assert = require('assert'); 18 | 19 | var fileName = process.cwd() + "/resources/greeting.txt"; 20 | var expectedContents = "Hello IoT.js!!"; 21 | var flags = "r"; 22 | 23 | 24 | // test the position argument of fs.readSync() 25 | try { 26 | var buffer = new Buffer(64); 27 | var fd = fs.openSync(fileName, flags); 28 | var bytes1 = fs.readSync(fd, buffer, 0, 7, null); 29 | var bytes2 = fs.readSync(fd, buffer, 7, 7, null); 30 | 31 | assert.equal(buffer.toString(), expectedContents); 32 | fs.closeSync(fd); 33 | } catch (err) { 34 | throw err; 35 | } 36 | -------------------------------------------------------------------------------- /test/run_pass/test_fs_readdir.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | var fs = require('fs'); 17 | var assert = require('assert'); 18 | 19 | var path = process.cwd() + '/resources/readdir' 20 | var ans = 'DO_NOT_MODIFY_THIS_FOLDER\n'+ 21 | 'This_is_a_directory\n'+ 22 | 'This_is_another_directory\n'+ 23 | 'regular.txt\n'; 24 | 25 | var res; 26 | var items, i; 27 | 28 | res = ""; 29 | items = fs.readdirSync(path); 30 | items.sort(); 31 | for (i = 0; i < items.length; i++) 32 | res += items[i] + '\n'; 33 | assert.equal(res, ans); 34 | 35 | res = ""; 36 | fs.readdir(path, function(err, items) { 37 | assert.equal(err, null); 38 | items.sort(); 39 | for (i = 0; i < items.length; i++) 40 | res += items[i] + '\n'; 41 | assert.equal(res, ans); 42 | }); 43 | -------------------------------------------------------------------------------- /test/run_pass/test_fs_writefile_sync.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | /* 17 | @STDOUT=Pass 18 | */ 19 | 20 | var fs = require('fs'); 21 | var assert = require('assert'); 22 | 23 | var file = process.cwd() + '/resources/test'; 24 | var buff1 = new Buffer('test string1'); 25 | var buff2 = null; 26 | var str = 'test string2'; 27 | var num = 1; 28 | 29 | if (process.platform === 'tizenrt') { 30 | file = '/mnt/test'; 31 | } 32 | 33 | fs.writeFileSync(file, buff1); 34 | buff2 = fs.readFileSync(file); 35 | assert.equal(buff2.equals(buff1), true); 36 | 37 | fs.writeFileSync(file, str); 38 | buff2 = fs.readFileSync(file); 39 | assert.equal(str.valueOf(), buff2.toString('utf8')); 40 | 41 | 42 | fs.writeFileSync(file, num); 43 | buff2 = fs.readFileSync(file); 44 | assert.equal(num, parseInt(buff2.toString('utf8'), 10)); 45 | 46 | console.log('Pass'); 47 | 48 | fs.unlinkSync(file); 49 | -------------------------------------------------------------------------------- /test/run_pass/test_fs_writefile_unlink_sync.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | var fs = require('fs'); 17 | var assert = require('assert'); 18 | 19 | var file1 = process.cwd() + '/resources/tobeornottobe.txt'; 20 | var file2 = process.cwd() + '/resources/tobeornottobe_sync.txt'; 21 | 22 | if (process.platform === 'tizenrt') { 23 | file2 = '/mnt/tobeornottobe_sync.txt'; 24 | } 25 | 26 | /* make a new file2 from file1 */ 27 | var buf1 = fs.readFileSync(file1); 28 | fs.writeFileSync(file2, buf1); 29 | 30 | /* Does file2 exists ? */ 31 | var result = fs.existsSync(file2); 32 | assert.equal(result, true); 33 | 34 | /* Is file2 equal to file1 */ 35 | var buf2 = fs.readFileSync(file2); 36 | assert(buf1.toString(), buf2.toString()); 37 | 38 | /* Remove file2 */ 39 | fs.unlinkSync(file2); 40 | 41 | /* Is file2 removed? */ 42 | result = fs.existsSync(file2); 43 | assert.equal(result, false); 44 | -------------------------------------------------------------------------------- /test/run_pass/test_gpio_direction.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | var gpio = require('gpio'); 17 | var pin = require('tools/systemio_common').pin; 18 | 19 | var gpioPin = gpio.openSync({ 20 | pin: pin.led, 21 | direction: gpio.DIRECTION.OUT, 22 | }); 23 | 24 | console.log('GPIO input test. Press the button.'); 25 | gpioPin.setDirectionSync(gpio.DIRECTION.IN); 26 | var loop = setInterval(function() { 27 | var value = gpioPin.readSync(); 28 | console.log('GpioPin value:', value); 29 | }, 500); 30 | 31 | setTimeout(function() { 32 | clearInterval(loop); 33 | 34 | console.log('GPIO output test. Led is on for 5000ms.'); 35 | gpioPin.setDirectionSync(gpio.DIRECTION.OUT); 36 | gpioPin.writeSync(1); 37 | setTimeout(function() { 38 | gpioPin.writeSync(0); 39 | }, 5000); 40 | }, 5000); 41 | 42 | -------------------------------------------------------------------------------- /test/run_pass/test_gpio_event.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var gpio = require('gpio'); 17 | 18 | var testGpioInfo = [ 19 | { 20 | pin: 13, 21 | edge: gpio.EDGE.RISING 22 | }, 23 | { 24 | pin: 19, 25 | edge: gpio.EDGE.FALLING 26 | }, 27 | { 28 | pin: 26, 29 | edge: gpio.EDGE.BOTH 30 | } 31 | ]; 32 | 33 | testGpioInfo.forEach(function(info) { 34 | var switchGpio = gpio.open({ 35 | pin: info.pin, 36 | edge: info.edge, 37 | direction: gpio.DIRECTION.IN 38 | }, function() { 39 | switchGpio.on('change', function() { 40 | console.log('pin:', info.pin, ', current value:', switchGpio.readSync()); 41 | }); 42 | }); 43 | }); 44 | 45 | setTimeout(function(){ 46 | console.log('finish test'); 47 | }, 10000); 48 | -------------------------------------------------------------------------------- /test/run_pass/test_iotjs_promise.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 16 | var fulfill_ret; 17 | var p = new Promise(function(resolve, reject) { 18 | // mimic asynchronous operation via setTimeout 19 | setTimeout(function() { resolve("Resolved") }, 100); 20 | }); 21 | 22 | p.then(function (msg) { 23 | // Promise does not like throwing error in fulfill handler 24 | // So just set the message in global variable. 25 | fulfill_ret = msg; 26 | }); 27 | 28 | // If Promise's fulfill worked well, assertion must be valid. 29 | setTimeout(function() { assert.equal(fulfill_ret, "Resolved"); }, 1000); 30 | -------------------------------------------------------------------------------- /test/run_pass/test_module_cache.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | 18 | var dir = process.cwd() + '/run_pass/require1/'; 19 | var dirDoubleDot = dir + '../require1/'; 20 | var dirDot = dir + './'; 21 | 22 | var moduleCache = require(dir + 'module_cache.js'); 23 | moduleCache.i = 100; 24 | 25 | moduleCache = require(dir + 'module_cache.js'); 26 | assert.equal(moduleCache.i, 100); 27 | 28 | moduleCache = require(dirDoubleDot + 'module_cache.js'); 29 | assert.equal(moduleCache.i, 100); 30 | 31 | moduleCache = require(dirDot + 'module_cache.js'); 32 | assert.equal(moduleCache.i, 100); 33 | -------------------------------------------------------------------------------- /test/run_pass/test_module_json.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | var json = require(process.cwd() + '/resources/test.json'); 18 | 19 | assert.equal(json.name, 'IoT.js'); 20 | assert.equal(json.author, 'Samsung Electronics Co., Ltd.'); 21 | assert.equal(json.license, 'Apache-2.0'); 22 | assert.equal(json.number, 123); 23 | assert.equal(Array.isArray(json.array), true); 24 | assert.equal(json.array.toString(), [1,2,3,4].toString()); 25 | -------------------------------------------------------------------------------- /test/run_pass/test_net_1.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | var net = require('net'); 17 | var assert = require('assert'); 18 | 19 | 20 | var server = net.createServer(); 21 | var port = 22701; 22 | 23 | server.listen(port, 5); 24 | 25 | server.on('connection', function(socket) { 26 | socket.on('data', function(data) { 27 | socket.end('Hello IoT.js'); 28 | }); 29 | socket.on('close', function() { 30 | server.close(); 31 | }); 32 | }); 33 | 34 | 35 | var socket = new net.Socket(); 36 | var msg = ""; 37 | 38 | socket.connect(port, "127.0.0.1"); 39 | socket.write("Hello IoT.js"); 40 | 41 | socket.on('data', function(data) { 42 | msg += data; 43 | }); 44 | 45 | socket.on('end', function() { 46 | socket.end(); 47 | }); 48 | 49 | process.on('exit', function(code) { 50 | assert.equal(msg, "Hello IoT.js"); 51 | }); 52 | -------------------------------------------------------------------------------- /test/run_pass/test_net_2.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var net = require('net'); 18 | var assert = require('assert'); 19 | 20 | var port = 22702; 21 | 22 | var server = net.createServer({ 23 | allowHalfOpen: true 24 | }); 25 | 26 | server.listen(port, 5); 27 | 28 | server.on('connection', function(socket) { 29 | var msg = ''; 30 | socket.on('data', function(data) { 31 | msg += data; 32 | }); 33 | socket.on('end', function() { 34 | socket.end(msg); 35 | server.close(); 36 | }); 37 | }); 38 | 39 | 40 | var socket = new net.Socket(); 41 | var echo_msg = ''; 42 | 43 | socket.connect(port, '127.0.0.1', function() { 44 | socket.end('Hello IoT.js'); 45 | }); 46 | 47 | socket.on('data', function(data) { 48 | echo_msg += data; 49 | }); 50 | 51 | socket.on('end', function() { 52 | assert.equal(echo_msg, "Hello IoT.js"); 53 | }); 54 | -------------------------------------------------------------------------------- /test/run_pass/test_net_connect.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | var net = require('net'); 18 | var host = '127.0.0.1'; 19 | var port = 5696; 20 | var msg = 'Hello IoT.js'; 21 | 22 | var server = net.createServer({ 23 | allowHalfOpen: true 24 | } 25 | ).listen(port); 26 | 27 | server.on('connection', function(socket) { 28 | var data = ''; 29 | socket.on('data', function(chuck) { 30 | data += chuck; 31 | }); 32 | socket.on('end', function() { 33 | socket.end(data); 34 | }); 35 | }); 36 | 37 | var socket = net.connect(port, host, function() { 38 | var data = ''; 39 | socket.on('data', function(chuck) { 40 | data += chuck; 41 | }); 42 | 43 | socket.on('end', function() { 44 | assert.equal(data, msg); 45 | server.close(); 46 | }); 47 | 48 | socket.end(msg); 49 | }); 50 | -------------------------------------------------------------------------------- /test/run_pass/test_net_http_methods.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | var http = require('http'); 18 | 19 | assert(http.METHODS instanceof Array, 'http.METHODS should be an array'); 20 | 21 | for (var idx in http.METHODS) { 22 | assert(typeof(http.METHODS[idx]) === 'string', 23 | 'Elements of the http.METHODS should be strings. ' + 24 | 'Found an invalid element, index: ' + idx); 25 | } 26 | 27 | /* Test if at least the basic HTTP methods should be supported */ 28 | var main_methods = ['GET', 'POST', 'PUT', 'DELETE', 'HEAD']; 29 | for (var idx in main_methods) { 30 | var method_name = main_methods[idx]; 31 | assert.notEqual(http.METHODS.indexOf(method_name), -1, 32 | 'http.METHODS is missing the value: ' + method_name); 33 | } 34 | -------------------------------------------------------------------------------- /test/run_pass/test_net_http_request_http_version.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | var http = require('http'); 18 | 19 | var server = http.createServer(function(request, response) { 20 | // the http version in IoT.js is hardcoded to 1.1 21 | assert.equal(request.httpVersion, "1.1", 22 | "incorrect http version returned via the http request object"); 23 | 24 | response.writeHead(200); 25 | response.end(); 26 | }); 27 | server.listen(3008, 5); 28 | 29 | var request = http.request({ 30 | method: 'HEAD', 31 | port: 3008, 32 | path: '/' 33 | }, function(response) { 34 | assert.equal(response.statusCode, 200); 35 | 36 | response.on('end', function() { 37 | server.close(); 38 | }); 39 | }) 40 | request.end(); 41 | -------------------------------------------------------------------------------- /test/run_pass/test_net_http_server_timeout.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | 18 | var assert = require('assert'); 19 | var http = require('http'); 20 | 21 | var timeouted = false; 22 | 23 | var server = http.createServer(function(req, res) { 24 | // do nothing 25 | }); 26 | 27 | server.listen(3003); 28 | 29 | server.setTimeout(100, function(socket) { 30 | timeouted = true; 31 | socket.destroy(); 32 | server.close(); 33 | }); 34 | 35 | 36 | // client will connect to server, and do nothing. 37 | var options = { 38 | method : 'GET', 39 | port : 3003 40 | }; 41 | 42 | 43 | var getReq = http.request(options); 44 | getReq.on('error', function() {}); 45 | 46 | process.on('exit', function(code) { 47 | assert.equal(timeouted, true); 48 | assert.equal(code, 0); 49 | }); 50 | 51 | getReq.end(); 52 | -------------------------------------------------------------------------------- /test/run_pass/test_net_httpclient_parse_error.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 16 | var http = require('http'); 17 | var net = require('net'); 18 | 19 | var errors = 0; 20 | 21 | // Create a TCP server 22 | var server = net.createServer(function(socket) { 23 | socket.end('Bad http\r\n\r\n'); // This should trigger the Parse Error. 24 | server.close(); 25 | }); 26 | 27 | server.listen(3085, '127.0.0.1'); 28 | 29 | // Create a simple get request. 30 | var request = http.request({ 31 | host: '127.0.0.1', 32 | port: 3085, 33 | method: 'GET', 34 | path: '/' 35 | }); 36 | request.on('error', function(err) { 37 | errors++; 38 | }); 39 | request.end(); 40 | 41 | process.on('exit', function() { 42 | // The error is a Parse Error. 43 | assert.equal(errors, 1); 44 | }); 45 | -------------------------------------------------------------------------------- /test/run_pass/test_net_https_timeout.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | 18 | var assert = require('assert'); 19 | var https = require('https'); 20 | 21 | options = { 22 | method: 'GET', 23 | host: 'httpbin.org', 24 | rejectUnauthorized: false, 25 | path: '/delay/10' 26 | }; 27 | 28 | var getReq = https.get(options); 29 | 30 | getReq.on('error', function(){}); 31 | 32 | var timeouted = false; 33 | getReq.setTimeout(5000, function() { 34 | timeouted = true; 35 | getReq.abort(); 36 | }); 37 | 38 | process.on('exit', function(code) { 39 | assert.equal(timeouted, true); 40 | }); 41 | -------------------------------------------------------------------------------- /test/run_pass/test_process.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | 18 | var sequence = ''; 19 | 20 | process.nextTick(function() { 21 | sequence += '2' 22 | }); 23 | 24 | sequence = '1'; 25 | 26 | process.on('exit', function() { 27 | assert.equal(sequence, '12'); 28 | }); 29 | -------------------------------------------------------------------------------- /test/run_pass/test_process_chdir.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 16 | 17 | var currentPath = process.cwd(); 18 | 19 | try { 20 | process.chdir('/'); 21 | } catch (err) { 22 | console.log('invalid path'); 23 | } 24 | 25 | var newPath = process.cwd(); 26 | if (process.platform === "windows") { 27 | /* check if the path is in format: :\ */ 28 | assert.equal(newPath.substr(1), ':\\'); 29 | } else { 30 | assert.equal(newPath, '/'); 31 | } 32 | 33 | process.chdir(currentPath); 34 | -------------------------------------------------------------------------------- /test/run_pass/test_process_cwd.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | console.log(process.cwd()); 18 | -------------------------------------------------------------------------------- /test/run_pass/test_process_exit.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | process.exit(0); 18 | -------------------------------------------------------------------------------- /test/run_pass/test_process_experimental_off.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | 18 | assert.notEqual(process.env.IOTJS_ENV, 'experimental'); 19 | -------------------------------------------------------------------------------- /test/run_pass/test_process_experimental_on.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | 18 | assert.equal(process.env.IOTJS_ENV, 'experimental'); 19 | -------------------------------------------------------------------------------- /test/run_pass/test_process_next_tick.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | 18 | 19 | var tickTrace = ""; 20 | 21 | process.nextTick(function() { 22 | tickTrace += "1"; 23 | process.nextTick(function() { 24 | tickTrace += "2"; 25 | process.nextTick(function() { 26 | tickTrace += "3"; 27 | process.nextTick(function() { 28 | tickTrace += "4"; 29 | process.nextTick(function() { 30 | tickTrace += "5"; 31 | }); 32 | }); 33 | }); 34 | }); 35 | }); 36 | 37 | 38 | process.on('exit', function(code) { 39 | assert.equal(code, 0); 40 | assert.equal(tickTrace, "12345"); 41 | }); 42 | -------------------------------------------------------------------------------- /test/run_pass/test_process_uncaught_order.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | 18 | var assert = require('assert'); 19 | 20 | var trace = ''; 21 | 22 | process.on('uncaughtException', function (err) { 23 | trace += 'A'; 24 | }); 25 | 26 | process.on('uncaughtException', function (err) { 27 | trace += 'B'; 28 | }); 29 | 30 | process.on('exit', function() { 31 | trace += 'C'; 32 | process.removeAllListeners('uncaughtException'); 33 | assert.equal(trace, 'ABABC'); 34 | }); 35 | 36 | 37 | process.nextTick(function() { 38 | assert.fail(); 39 | }); 40 | 41 | assert.fail(); 42 | -------------------------------------------------------------------------------- /test/run_pass/test_process_uncaught_simple.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | 18 | var assert = require('assert'); 19 | 20 | var trace = ''; 21 | 22 | process.on('uncaughtException', function (err) { 23 | trace += 'A'; 24 | }); 25 | 26 | process.on('exit', function() { 27 | process.removeAllListeners('uncaughtException'); 28 | assert.equal(trace, 'AB'); 29 | }); 30 | 31 | setTimeout(function() { 32 | trace += 'B' 33 | }, 500); 34 | 35 | nonexistentFunc(); 36 | 37 | trace += 'C'; 38 | -------------------------------------------------------------------------------- /test/run_pass/test_spi_buffer_sync.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | var spi = require('spi'); 18 | var pin = require('tools/systemio_common').pin; 19 | 20 | var configuration = { 21 | device: pin.spi1, // for Linux 22 | bus: pin.spi1, // for Tizen, TizenRT and Nuttx 23 | }; 24 | 25 | // Buffer test 26 | var spi1 = spi.openSync(configuration); 27 | var data = 'Hello IoTjs'; 28 | var tx = new Buffer(data); 29 | 30 | var rx = spi1.transferSync(tx); 31 | var len = data.length; 32 | assert.equal(rx.length, len); 33 | var value = ''; 34 | for (var i = 0; i < len; i++) { 35 | value += String.fromCharCode(rx[i]); 36 | } 37 | console.log(value); 38 | assert.equal(value, data); 39 | 40 | spi1.closeSync(); 41 | -------------------------------------------------------------------------------- /test/run_pass/test_stream_duplex.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | var Duplex = require('stream').Duplex; 18 | 19 | var duplex = Duplex({ highWaterMark: 0 }); 20 | 21 | assert(duplex instanceof Duplex); 22 | assert(duplex.write); 23 | assert(duplex.read); 24 | 25 | var msg1 = 'message 1'; 26 | var msg2 = 'message 2'; 27 | 28 | duplex._write = function(chunk, callback) { 29 | assert.equal(chunk == msg1, true); 30 | duplex.push(msg2); 31 | duplex.end(); 32 | } 33 | duplex._readyToWrite(); 34 | duplex.write(msg1); 35 | 36 | process.on('exit', function() { 37 | assert.equal(duplex.read() == msg2, true); 38 | }); 39 | -------------------------------------------------------------------------------- /test/run_pass/test_timers_simple.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors 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 | 17 | var assert = require('assert'); 18 | 19 | 20 | var timerACnt = 0; 21 | var timerBCnt = 0; 22 | var timerCCnt = 0; 23 | var timerSequence = ''; 24 | 25 | var timerA = setTimeout(function() { 26 | timerSequence += 'A'; 27 | timerACnt++; 28 | }, 1000); 29 | 30 | var timerB = setInterval(function() { 31 | timerSequence += 'B'; 32 | timerBCnt++; 33 | if (timerBCnt > 5) { 34 | clearInterval(timerB); 35 | } 36 | }, 300); 37 | 38 | var timerC = setInterval(function() { 39 | timerSequence += 'C'; 40 | timerCCnt++; 41 | if (timerCCnt > 10) { 42 | clearInterval(timerC); 43 | } 44 | }, 0); 45 | 46 | process.on('exit', function(code) { 47 | assert.equal(code, 0); 48 | assert.equal(timerACnt, 1); 49 | assert.equal(timerBCnt, 6); 50 | assert.equal(timerCCnt, 11); 51 | assert.equal(timerSequence.length, 18); 52 | }); 53 | -------------------------------------------------------------------------------- /test/run_pass/test_tizen_app_control.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | var tizen = require('tizen'); 17 | 18 | // Need to set target APP_ID e.g) app.control.receiver 19 | var app_id = ''; 20 | var data = { 21 | str: 'iotjs' 22 | }; 23 | 24 | // test: tizen.on 25 | tizen.on('appControl', function(msg) { 26 | console.log('appControl', msg); 27 | 28 | var extra_data = msg.extra_data; 29 | if(extra_data && extra_data.key === 'iotjs' ) { 30 | 31 | //test: tizen.launchAppControl 32 | try { 33 | var res = tizen.launchAppControl({ 34 | app_id: app_id, 35 | extra_data: data, 36 | }); 37 | console.log('Result', res); 38 | } catch(e) { 39 | console.log(e); 40 | } 41 | } 42 | }); 43 | -------------------------------------------------------------------------------- /test/run_pass/test_uart_api.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 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 | var assert = require('assert'); 17 | var uart = require('uart'); 18 | 19 | // ------ Test API existence 20 | assert.equal(typeof uart.open, 'function', 21 | 'uart does not provide \'open\' function'); 22 | assert.equal(typeof uart.openSync, 'function', 23 | 'uart does not provide \'openSync\' function'); 24 | -------------------------------------------------------------------------------- /test/tmp/README: -------------------------------------------------------------------------------- 1 | This directory is for temporary files will be generated during build test. 2 | -------------------------------------------------------------------------------- /tools/__init__.py: -------------------------------------------------------------------------------- 1 | # Required for Python to search this directory for module files 2 | -------------------------------------------------------------------------------- /tools/apt-get-install-arm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | sudo apt-get update -q 18 | sudo apt-get install -q -y \ 19 | gcc-arm-linux-gnueabihf libc6-dev-armhf-cross 20 | -------------------------------------------------------------------------------- /tools/apt-get-install-deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | sudo apt-get update -q 18 | sudo apt-get install -q -y \ 19 | cmake gcc valgrind clang-format-3.9 20 | -------------------------------------------------------------------------------- /tools/apt-get-install-nuttx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | sudo apt-get update -q 18 | sudo apt-get install -q -y \ 19 | autoconf libtool gperf flex bison autoconf2.13 \ 20 | cmake libncurses-dev libusb-1.0-0-dev genromfs \ 21 | libsgutils2-dev gcc-arm-none-eabi 22 | -------------------------------------------------------------------------------- /tools/apt-get-install-tizen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | wget https://releases.linaro.org/components/\ 18 | toolchain/binaries/4.9-2017.01/arm-linux-gnueabi/\ 19 | gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi.tar.xz 20 | tar Jxf gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi.tar.xz 21 | mv gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi arm-linux-gnueabi 22 | export PATH=$(pwd)/arm-linux-gnueabi/bin:$PATH 23 | arm-linux-gnueabi-gcc --version 24 | -------------------------------------------------------------------------------- /tools/apt-get-install-tizenrt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | sudo apt-get update 19 | sudo apt-get install gcc-arm-none-eabi 20 | arm-none-eabi-gcc --version 21 | -------------------------------------------------------------------------------- /tools/apt-get-install-travis-i686.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | sudo dpkg --add-architecture i386 18 | sudo apt-get update -q 19 | sudo apt-get install -q -y \ 20 | linux-libc-dev:i386 21 | -------------------------------------------------------------------------------- /tools/brew-install-deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | brew update 18 | 19 | PKGS=" 20 | cmake 21 | " 22 | 23 | for pkg in $PKGS 24 | do 25 | if ! ( brew list -1 | grep -q "^${pkg}\$" ) 26 | then 27 | brew install $pkg 28 | fi 29 | done 30 | -------------------------------------------------------------------------------- /tools/check_sonarqube.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | if [[ "${TRAVIS_REPO_SLUG}" == "jerryscript-project/iotjs" 18 | && ${TRAVIS_BRANCH} == "master" 19 | && ${TRAVIS_EVENT_TYPE} == "push" ]] 20 | then 21 | git fetch --unshallow 22 | build-wrapper-linux-x86-64 --out-dir bw-output ./tools/build.py 23 | sonar-scanner -Dsonar.projectVersion="${TRAVIS_COMMIT}" 24 | else 25 | echo "Skip: The pull request from ${TRAVIS_PULL_REQUEST_SLUG} is an \ 26 | external one. It's not supported yet in Travis-CI" 27 | fi 28 | -------------------------------------------------------------------------------- /tools/common_py/__init__.py: -------------------------------------------------------------------------------- 1 | # Required for Python to search this directory for module files 2 | -------------------------------------------------------------------------------- /tools/common_py/system/__init__.py: -------------------------------------------------------------------------------- 1 | # Required for Python to search this directory for module files 2 | -------------------------------------------------------------------------------- /tools/common_py/system/sys_platform.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors 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 | import os 16 | import platform 17 | import sys 18 | 19 | class Platform(object): 20 | def __init__(self): 21 | if sys.platform == "win32": 22 | _os = "windows" 23 | if platform.architecture()[0] == "64bit": 24 | _arch = "x86_64" 25 | else: 26 | _arch = "i686" 27 | else: 28 | _os, _, _, _, _arch = os.uname() 29 | self._os = _os 30 | self._arch = _arch 31 | 32 | def os(self): 33 | """ Retrieve host OS name. """ 34 | return self._os.lower() 35 | 36 | def arch(self): 37 | """ Retrieve host arch name. """ 38 | arch = self._arch.lower() 39 | if arch in ["armv7l"]: 40 | arch = "arm" 41 | return arch 42 | -------------------------------------------------------------------------------- /tools/module_generator/__init__.py: -------------------------------------------------------------------------------- 1 | # Required for Python to search this directory for module files 2 | -------------------------------------------------------------------------------- /tools/module_templates/basic_module_template/js/module.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | /** 17 | * To export an object/value use the 'module.exports' object. 18 | */ 19 | var demo_value = "Hello"; 20 | 21 | /* Export an object with two properties. */ 22 | module.exports = { 23 | /* the 'native' means the object returned by the C init method. */ 24 | demo2: function() { return native.message; }, 25 | add: native.add 26 | } 27 | 28 | /* Export a local variable. */ 29 | module.exports.demo_value = demo_value; 30 | -------------------------------------------------------------------------------- /tools/module_templates/basic_module_template/modules.json: -------------------------------------------------------------------------------- 1 | { 2 | "modules": { 3 | "$MODULE_NAME$": { 4 | "js_file": "js/module.js", 5 | "native_files": ["src/module.c"], 6 | "init": "Init$MODULE_NAME$", 7 | "cmakefile": "module.cmake" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tools/module_templates/shared_module_template/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | # This is a standalone shared libray which 17 | # only requires the iotjs and jerry header file(s). 18 | # 19 | cmake_minimum_required(VERSION 2.8) 20 | set(NAME $MODULE_NAME$) 21 | 22 | set(IOTJS_INCLUDE_DIR "$IOTJS_PATH$/include") 23 | 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") 25 | 26 | add_library(${NAME} SHARED 27 | src/module_entry.c) 28 | target_include_directories(${NAME} 29 | PRIVATE ${IOTJS_INCLUDE_DIR} ${JERRY_INCLUDE_DIR}) 30 | set_target_properties(${NAME} PROPERTIES 31 | LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" 32 | PREFIX "" 33 | SUFFIX ".node") 34 | -------------------------------------------------------------------------------- /tools/module_templates/shared_module_template/README.md: -------------------------------------------------------------------------------- 1 | # IoT.js module: $MODULE_NAME$ 2 | 3 | ## How to build? 4 | 5 | In the source directory of the module: 6 | 7 | ```sh 8 | $ cmake -Bbuild -H. 9 | $ make -C build 10 | ``` 11 | 12 | ## How to test? 13 | 14 | In the source directory of the module: 15 | 16 | ```sh 17 | $ iotjs js/test.js 18 | ``` 19 | -------------------------------------------------------------------------------- /tools/module_templates/shared_module_template/js/test.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 | var console = require("console"); 17 | var demo_module = require("build/lib/$MODULE_NAME$"); 18 | 19 | console.log(demo_module.hello()); 20 | 21 | -------------------------------------------------------------------------------- /tools/module_templates/shared_module_template/src/module_entry.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors 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 17 | #include 18 | 19 | static napi_value hello_world(napi_env env, napi_callback_info info) { 20 | napi_value world; 21 | const char* str = "Hello world!"; 22 | size_t str_len = strlen(str); 23 | 24 | if (napi_create_string_utf8(env, str, str_len, &world) != napi_ok) 25 | return NULL; 26 | 27 | return world; 28 | } 29 | 30 | napi_value init_$MODULE_NAME$(napi_env env, napi_value exports) { 31 | napi_property_descriptor desc = { "hello", 0, hello_world, 0, 32 | 0, 0, napi_default, 0 }; 33 | 34 | if (napi_define_properties(env, exports, 1, &desc) != napi_ok) 35 | return NULL; 36 | 37 | return exports; 38 | } 39 | 40 | NAPI_MODULE($MODULE_NAME$, init_$MODULE_NAME$) 41 | --------------------------------------------------------------------------------