JavaScript runtime 1.0 features for CloudFront Functions
The CloudFront Functions JavaScript runtime environment is compliant with ECMAScript (ES) version 5.1
The following topics list all the supported language features.
Topics
Core features
The following core features of ES are supported.
- Types
-
All ES 5.1 types are supported. This includes Boolean values, numbers, strings, objects, arrays, functions, function constructors, and regular expressions.
- Operators
-
All ES 5.1 operators are supported.
The ES 7 exponentiation operator (
**) is supported. - Statements
-
Note
The
constandletstatements are not supported.The following ES 5.1 statements are supported:
-
break -
catch -
continue -
do-while -
else -
finally -
for -
for-in -
if -
return -
switch -
throw -
try -
var -
while -
Labeled statements
-
- Literals
-
ES 6 template literals are supported: multiline strings, expression interpolation, and nesting templates.
- Functions
-
All ES 5.1 function features are supported.
ES 6 arrow functions are supported, and ES 6 rest parameter syntax is supported.
- Unicode
-
Source text and string literals can contain Unicode-encoded characters. Unicode code point escape sequences of six characters (for example,
\uXXXX) are also supported. - Strict mode
-
Functions operate in strict mode by default, so you don’t need to add a
use strictstatement in your function code. This cannot be changed.
Primitive objects
The following primitive objects of ES are supported.
- Object
-
The following ES 5.1 methods on objects are supported:
-
create(without properties list) -
defineProperties -
defineProperty -
freeze -
getOwnPropertyDescriptor -
getOwnPropertyNames -
getPrototypeOf -
hasOwnProperty -
isExtensible -
isFrozen -
prototype.isPrototypeOf -
isSealed -
keys -
preventExtensions -
prototype.propertyIsEnumerable -
seal -
prototype.toString -
prototype.valueOf
The following ES 6 methods on objects are supported:
-
assign -
is -
prototype.setPrototypeOf
The following ES 8 methods on objects are supported:
-
entries -
values
-
- String
-
The following ES 5.1 methods on strings are supported:
-
fromCharCode -
prototype.charAt -
prototype.concat -
prototype.indexOf -
prototype.lastIndexOf -
prototype.match -
prototype.replace -
prototype.search -
prototype.slice -
prototype.split -
prototype.substr -
prototype.substring -
prototype.toLowerCase -
prototype.trim -
prototype.toUpperCase
The following ES 6 methods on strings are supported:
-
fromCodePoint -
prototype.codePointAt -
prototype.endsWith -
prototype.includes -
prototype.repeat -
prototype.startsWith
The following ES 8 methods on strings are supported:
-
prototype.padStart -
prototype.padEnd
The following ES 9 methods on strings are supported:
-
prototype.trimStart -
prototype.trimEnd
The following nonstandard methods on strings are supported:
-
prototype.bytesFrom(array | string, encoding)Creates a byte string from an array of octets or an encoded string. The string encoding options are
hex,base64, andbase64url. -
prototype.fromBytes(start[, end])Creates a Unicode string from a byte string where each byte is replaced with the corresponding Unicode code point.
-
prototype.fromUTF8(start[, end])Creates a Unicode string from a UTF-8 encoded byte string. If the encoding is incorrect, it returns
null. -
prototype.toBytes(start[, end])Creates a byte string from a Unicode string. All characters must be in the [0,255] range. If not, it returns
null. -
prototype.toUTF8(start[, end])Creates a UTF-8 encoded byte string from a Unicode string.
-
- Number
-
All ES 5.1 methods on numbers are supported.
The following ES 6 methods on numbers are supported:
-
isFinite -
isInteger -
isNaN -
isSafeInteger -
parseFloat -
parseInt -
prototype.toExponential -
prototype.toFixed -
prototype.toPrecision -
EPSILON -
MAX_SAFE_INTEGER -
MAX_VALUE -
MIN_SAFE_INTEGER -
MIN_VALUE -
NEGATIVE_INFINITY -
NaN -
POSITIVE_INFINITY
-
Built-in objects
The following built-in objects of ES are supported.
- Math
-
All ES 5.1 math methods are supported.
Note
In the CloudFront Functions runtime environment, the
Math.random()implementation uses OpenBSDarc4randomseeded with the timestamp of when the function runs.The following ES 6 math methods are supported:
-
acosh -
asinh -
atanh -
cbrt -
clz32 -
cosh -
expm1 -
fround -
hypot -
imul -
log10 -
log1p -
log2 -
sign -
sinh -
tanh -
trunc -
E -
LN10 -
LN2 -
LOG10E -
LOG2E -
PI -
SQRT1_2 -
SQRT2
-
- Date
-
All ES 5.1
Datefeatures are supported.Note
For security reasons,
Datealways returns the same value—the function’s start time—during the lifetime of a single function run. For more information, see Restricted features. - Function
-
The
apply,bind, andcallmethods are supported.Function constructors are not supported.
- Regular expressions
-
All ES 5.1 regular expression features are supported. The regular expression language is Perl compatible. ES 9 named capture groups are supported.
- JSON
-
All ES 5.1 JSON features are supported, including
parseandstringify. - Array
-
The following ES 5.1 methods on arrays are supported:
-
isArray -
prototype.concat -
prototype.every -
prototype.filter -
prototype.forEach -
prototype.indexOf -
prototype.join -
prototype.lastIndexOf -
prototype.map -
prototype.pop -
prototype.push -
prototype.reduce -
prototype.reduceRight -
prototype.reverse -
prototype.shift -
prototype.slice -
prototype.some -
prototype.sort -
prototype.splice -
prototype.unshift
The following ES 6 methods on arrays are supported:
-
of -
prototype.copyWithin -
prototype.fill -
prototype.find -
prototype.findIndex
The following ES 7 methods on arrays are supported:
-
prototype.includes
-
- Typed arrays
-
The following ES 6 typed arrays are supported:
-
Int8Array -
Uint8Array -
Uint8ClampedArray -
Int16Array -
Uint16Array -
Int32Array -
Uint32Array -
Float32Array -
Float64Array -
prototype.copyWithin -
prototype.fill -
prototype.join -
prototype.set -
prototype.slice -
prototype.subarray -
prototype.toString
-
- ArrayBuffer
-
The following methods on
ArrayBufferare supported:-
prototype.isView -
prototype.slice
-
- Promise
-
The following methods on promises are supported:
-
reject -
resolve -
prototype.catch -
prototype.finally -
prototype.then
-
- Crypto
-
The cryptographic module provides standard hashing and hash-based message authentication code (HMAC) helpers. You can load the module using
require('crypto'). The module exposes the following methods that behave exactly as their Node.js counterparts:-
createHash(algorithm) -
hash.update(data) -
hash.digest([encoding]) -
createHmac(algorithm, secret key) -
hmac.update(data) -
hmac.digest([encoding])
For more information, see Crypto (hash and HMAC) in the built-in modules section.
-
- Console
-
This is a helper object for debugging. It only supports the
log()method, to record log messages.Note
CloudFront Functions doesn't support comma syntax, such as
console.log('a', 'b'). Instead, use theconsole.log('a' + ' ' + 'b')format.
Error types
The following error objects are supported:
-
Error -
EvalError -
InternalError -
MemoryError -
RangeError -
ReferenceError -
SyntaxError -
TypeError -
URIError
Globals
The globalThis object is supported.
The following ES 5.1 global functions are supported:
-
decodeURI -
decodeURIComponent -
encodeURI -
encodeURIComponent -
isFinite -
isNaN -
parseFloat -
parseInt
The following global constants are supported:
-
NaN -
Infinity