Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Difference between Safe and Unsafe Mode

Micha Reiser edited this page May 19, 2017 · 1 revision

The Speedy.js exists in two variations: a safe that often behaves identically to the JavaScript specification and an unsafe implementation that follows c like semantics. This page describes the differences between the two modes. By default. the unsafe runtime is used to achieve the highest possible throughput. However, it might be useful to use the safe mode during development or when encountering unexpected behavior.

Array

Range Checks: The safe mode adds in range checks to prevent illegal memory access. For example, accessing an index out of range results in a runtime exception. The unsafe mode omits all these checks.

Memory initialization: The safe mode guarantees that all array elements are initialized with the default value of the element type. The unsafe mode does not default initialize elements as it is an expensive operation. Therefore, accessing elements for which no value has been assigned may return arbitrary values.

Objects

Memory initialization: The safe mode guarantees that object fields are either initialized with a user defined value or the default value of its type. On the contrary, fields are not default initialized in the unsafe mode. Therefore, a field contains an arbitrary value until a value has explicitly been assigned.

Casts

toInt32: The safe mode implements the toInt32 operation ---used to cast a number to an int--- as defined by the standard. The unsafe mode simply casts the value to an int, which may truncate the value.

Clone this wiki locally