Akos Kiss f29e6f9020
Fix undefined overflow behavior when converting double to integer (#3629)
Overflows in conversions from floating-point to integer are
undefined behavior in the C99 standard. (Clause 6.3.1.4: "If the
value of the integral part cannot be represented by the integer
type, the behavior is undefined.")

When UBSAN is enabled, this gets reported at `srand()` calls. (The
random seed is usually initialized using the date port API, which
represents dates as `double`s. But `srand` takes an `unsigned int`.
A simple cast from `double` to `unsigned` becomes undefined
behavior if the value is too large. And "now" is too large
nowadays. So, effectively, all executions start with an undefined
behavior.)

This patch fixes this by casting the floating-point value of the
date to an integer through a union.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
2020-03-27 11:03:28 +01:00
..
2019-07-15 20:21:00 +02:00

JerryScript with mbed OS 5

TL;DR? jump straight to quickstart

Introduction

This directory contains the necessary code to build JerryScript for devices capable of running mbed OS 5. It has been tested with the following boards so far:

Features

Peripheral Drivers

Peripheral Drivers are intended as a 1-to-1 mapping to mbed C++ APIs, with a few differences (due to differences between JavaScript and C++ like lack of operator overloading).

Dependencies

mbed CLI

mbed CLI is used as the build tool for mbed OS 5. You can find out how to install it in the official documentation.

arm-none-eabi-gcc

arm-none-eabi-gcc is the only currently tested compiler for jerryscript on mbed, and instructions for building can be found as part of the mbed-cli installation instructions above.

make

make is used to automate the process of fetching dependencies, and making sure that mbed-cli is called with the correct arguments.

nodejs

npm is used to install the dependencies in the local node_modules folder.

gulp

gulp is used to automate tasks, like cloning repositories or generate source files. If you create an own project, for more info see mbed-js-gulp.

(optional) jshint

jshint is used to statically check your JavaScript code, as part of the build process. This ensures that pins you are using in your code are available on your chosen target platform.

Quick Start

Once you have all of your dependencies installed, you can build the example project as follows:

git clone https://github.com/ARMmbed/mbed-js-example
cd mbed-js-example
npm install
gulp --target=YOUR_TARGET_NAME

The produced file (in build/out/YOUR_TARGET_NAME) can then be uploaded to your board, and will run when you press reset.