适用于 CloudFront Functions 的 JavaScript 运行时系统 2.0 特征 - Amazon CloudFront
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

适用于 CloudFront Functions 的 JavaScript 运行时系统 2.0 特征

CloudFront Functions JavaScript 运行时系统环境符合 ECMAScript (ES) 5.1 的要求,也支持 ES 版本 6 至 9 的某些特征。它还提供了一些不属于 ES 规范的非标准方法。以下主题列出了此运行时系统中支持的所有特征。

核心功能

支持 ES 的以下核心功能。

类型

支持所有 ES 5.1 类型。其中包括布尔值、数字、字符串、对象、数组、函数和正则表达式。

运算符

支持所有 ES 5.1 运算符。

支持 ES 7 幂运算符 (**)。

语句

支持以下 ES 5.1 语句:

  • break

  • catch

  • continue

  • do-while

  • else

  • finally

  • for

  • for-in

  • if

  • label

  • return

  • switch

  • throw

  • try

  • var

  • while

支持以下 ES 6 语句:

  • async

  • await

  • const

  • let

    注意

    asyncawaitconstlet 是 JavaScript 运行时系统 2.0 中的新语句。

文本

支持 ES 6 模板文本:多行字符串、表达式插值和嵌套模板。

函数

支持所有的 ES 5.1 函数功能。

支持 ES 6 箭头函数,并支持 ES 6 rest 参数语法。

Unicode

源文本和字符串文本可以包含 Unicode 编码的字符。还支持由六个字符组成的 Unicode 代码点转义序列(例如,\uXXXX)。

严格模式

默认情况下,函数在严格模式下运行,因此您无需在函数代码中添加 use strict 语句。无法对其进行更改。

原语对象

支持 ES 的以下原语对象。

对象

支持对对象使用以下 ES 5.1 方法:

  • Object.create()(没有属性列表)

  • Object.defineProperties()

  • Object.defineProperty()

  • Object.freeze()

  • Object.getOwnPropertyDescriptor()

  • Object.getOwnPropertyDescriptors()

  • Object.getOwnPropertyNames()

  • Object.getPrototypeOf()

  • Object.isExtensible()

  • Object.isFrozen()

  • Object.isSealed()

  • Object.keys()

  • Object.preventExtensions()

  • Object.seal()

支持对对象使用以下 ES 6 方法:

  • Object.assign()

支持对对象使用以下 ES 8 方法:

  • Object.entries()

  • Object.values()

支持对对象使用以下 ES 5.1 原型方法:

  • Object.prototype.hasOwnProperty()

  • Object.prototype.isPrototypeOf()

  • Object.prototype.propertyIsEnumerable()

  • Object.prototype.toString()

  • Object.prototype.valueOf()

支持对对象使用以下 ES 6 原型方法:

  • Object.prototype.is()

  • Object.prototype.setPrototypeOf()

String

支持对字符串使用以下 ES 5.1 方法:

  • String.fromCharCode()

支持对字符串使用以下 ES 6 方法:

  • String.fromCodePoint()

支持对字符串使用以下 ES 5.1 原型方法:

  • String.prototype.charAt()

  • String.prototype.concat()

  • String.prototype.indexOf()

  • String.prototype.lastIndexOf()

  • String.prototype.match()

  • String.prototype.replace()

  • String.prototype.search()

  • String.prototype.slice()

  • String.prototype.split()

  • String.prototype.substr()

  • String.prototype.substring()

  • String.prototype.toLowerCase()

  • String.prototype.trim()

  • String.prototype.toUpperCase()

支持对字符串使用以下 ES 6 原型方法:

  • String.prototype.codePointAt()

  • String.prototype.endsWith()

  • String.prototype.includes()

  • String.prototype.repeat()

  • String.prototype.startsWith()

支持对字符串使用以下 ES 8 原型方法:

  • String.prototype.padStart()

  • String.prototype.padEnd()

支持对字符串使用以下 ES 9 原型方法:

  • String.prototype.trimStart()

  • String.prototype.trimEnd()

支持对字符串使用以下 ES 12 原型方法:

  • String.prototype.replaceAll()

    注意

    String.prototype.replaceAll() 是 JavaScript 运行时系统 2.0 中的新功能。

数字

支持所有 ES 5 数字。

支持对数字使用以下 ES 6 属性:

  • Number.EPSILON

  • Number.MAX_SAFE_INTEGER

  • Number.MIN_SAFE_INTEGER

  • Number.MAX_VALUE

  • Number.MIN_VALUE

  • Number.NaN

  • Number.NEGATIVE_INFINITY

  • Number.POSITIVE_INFINITY

支持对数字使用以下 ES 6 方法:

  • Number.isFinite()

  • Number.isInteger()

  • Number.isNaN()

  • Number.isSafeInteger()

  • Number.parseInt()

  • Number.parseFloat()

支持对数字使用以下 ES 5.1 原型方法:

  • Number.prototype.toExponential()

  • Number.prototype.toFixed()

  • Number.prototype.toPrecision()

支持 ES 12 数字分隔符。

注意

ES 12 数字分隔符是 JavaScript 运行时系统 2.0 中的新功能。

内置对象

支持 ES 的以下内置对象。

数学

支持所有 ES 5.1 数学方法。

注意

在 CloudFront Functions 运行时环境中,Math.random() 实现使用植入有函数运行时间戳的 OpenBSD arc4random

支持以下 ES 6 数学属性:

  • Math.E

  • Math.LN10

  • Math.LN2

  • Math.LOG10E

  • Math.LOG2E

  • Math.PI

  • Math.SQRT1_2

  • Math.SQRT2

支持以下 ES 6 数学方法:

  • Math.abs()

  • Math.acos()

  • Math.acosh()

  • Math.asin()

  • Math.asinh()

  • Math.atan()

  • Math.atan2()

  • Math.atanh()

  • Math.cbrt()

  • Math.ceil()

  • Math.clz32()

  • Math.cos()

  • Math.cosh()

  • Math.exp()

  • Math.expm1()

  • Math.floor()

  • Math.fround()

  • Math.hypot()

  • Math.imul()

  • Math.log()

  • Math.log1p()

  • Math.log2()

  • Math.log10()

  • Math.max()

  • Math.min()

  • Math.pow()

  • Math.random()

  • Math.round()

  • Math.sign()

  • Math.sinh()

  • Math.sin()

  • Math.sqrt()

  • Math.tan()

  • Math.tanh()

  • Math.trunc()

日期

支持所有 ES 5.1 Date 功能。

注意

出于安全原因,在单个函数运行的生命周期内,Date 始终返回相同的值(函数的开始时间)。有关更多信息,请参阅 受限功能

函数

支持以下 ES 5.1 原型方法:

  • Function.prototype.apply()

  • Function.prototype.bind()

  • Function.prototype.call()

不支持函数构造函数。

正则表达式

支持所有 ES 5.1 正则表达式功能。正则表达式语言与 Perl 兼容。

支持以下 ES 5.1 原型存取器属性:

  • RegExp.prototype.global

  • RegExp.prototype.ignoreCase

  • RegExp.protoype.multiline

  • RegExp.protoype.source

  • RegExp.prototype.sticky

  • RegExp.prototype.flags

    注意

    RegExp.prototype.stickyRegExp.prototype.flags 是 JavaScript 运行时系统 2.0 中的新功能。

支持以下 ES 5.1 原型方法:

  • RegExp.prototype.exec()

  • RegExp.prototype.test()

  • RegExp.prototype.toString()

  • RegExp.prototype[@@replace]()

  • RegExp.prototype[@@split]()

    注意

    RegExp.prototype[@@split]() 是 JavaScript 运行时系统 2.0 中的新功能。

支持以下 ES 5.1 实例属性:

  • lastIndex

支持 ES 9 命名的捕获组。

JSON

支持以下 ES 5.1 方法:

  • JSON.parse()

  • JSON.stringify()

数组

支持对数组使用以下 ES 5.1 方法:

  • Array.isArray()

支持对数组使用以下 ES 6 方法:

  • Array.of()

支持以下 ES 5.1 原型方法:

  • Array.prototype.concat()

  • Array.prototype.every()

  • Array.prototype.filter()

  • Array.prototype.forEach()

  • Array.prototype.indexOf()

  • Array.prototype.join()

  • Array.prototype.lastIndexOf()

  • Array.prototype.map()

  • Array.prototype.pop()

  • Array.prototype.push()

  • Array.prototype.reduce()

  • Array.prototype.reduceRight()

  • Array.prototype.reverse()

  • Array.prototype.shift()

  • Array.prototype.slice()

  • Array.prototype.some()

  • Array.prototype.sort()

  • Array.prototype.splice()

  • Array.prototype.unshift()

支持以下 ES 6 原型方法

  • Array.prototype.copyWithin()

  • Array.prototype.fill()

  • Array.prototype.find()

  • Array.prototype.findIndex()

支持以下 ES 7 原型方法:

  • Array.prototype.includes()

类型化数组

支持以下 ES 6 类型化数组构造函数:

  • Float32Array

  • Float64Array

  • Int8Array

  • Int16Array

  • Int32Array

  • Uint8Array

  • Uint8ClampedArray

  • Uint16Array

  • Uint32Array

支持以下 ES 6 方法:

  • TypedArray.from()

  • TypedArray.of()

    注意

    TypedArray.from()TypedArray.of() 是 JavaScript 运行时系统 2.0 中的新功能。

支持以下 ES 6 原型方法:

  • TypedArray.prototype.copyWithin()

  • TypedArray.prototype.every()

  • TypedArray.prototype.fill()

  • TypedArray.prototype.filter()

  • TypedArray.prototype.find()

  • TypedArray.prototype.findIndex()

  • TypedArray.prototype.forEach()

  • TypedArray.prototype.includes()

  • TypedArray.prototype.indexOf()

  • TypedArray.prototype.join()

  • TypedArray.prototype.lastIndexOf()

  • TypedArray.prototype.map()

  • TypedArray.prototype.reduce()

  • TypedArray.prototype.reduceRight()

  • TypedArray.prototype.reverse()

  • TypedArray.prototype.some()

  • TypedArray.prototype.set()

  • TypedArray.prototype.slice()

  • TypedArray.prototype.sort()

  • TypedArray.prototype.subarray()

  • TypedArray.prototype.toString()

    注意

    TypedArray.prototype.every()TypedArray.prototype.fill()TypedArray.prototype.filter()TypedArray.prototype.find()TypedArray.prototype.findIndex()TypedArray.prototype.forEach()TypedArray.prototype.includes()TypedArray.prototype.indexOf()TypedArray.prototype.join()TypedArray.prototype.lastIndexOf()TypedArray.prototype.map()TypedArray.prototype.reduce()TypedArray.prototype.reduceRight()TypedArray.prototype.reverse()TypedArray.prototype.some() 是 JavaScript 运行时系统 2.0 中的新功能。

ArrayBuffer

支持对 ArrayBuffer 使用以下 ES 6 方法:

  • isView()

支持对 ArrayBuffer 使用以下 ES 6 原型方法:

  • ArrayBuffer.prototype.slice()

Promise

支持对 Promise 使用 ES 6 方法:

  • Promise.all()

  • Promise.allSettled()

  • Promise.any()

  • Promise.reject()

  • Promise.resolve()

  • Promise.race()

    注意

    Promise.all()Promise.allSettled()Promise.any()Promise.race() 是 JavaScript 运行时系统 2.0 中的新功能。

支持对 Promise 使用 ES 6 原型方法:

  • Promise.prototype.catch()

  • Promise.prototype.finally()

  • Promise.prototype.then()

DataView

支持以下 ES 6 原型方法:

  • DataView.prototype.getFloat32()

  • DataView.prototype.getFloat64()

  • DataView.prototype.getInt16()

  • DataView.prototype.getInt32()

  • DataView.prototype.getInt8()

  • DataView.prototype.getUint16()

  • DataView.prototype.getUint32()

  • DataView.prototype.getUint8()

  • DataView.prototype.setFloat32()

  • DataView.prototype.setFloat64()

  • DataView.prototype.setInt16()

  • DataView.prototype.setInt32()

  • DataView.prototype.setInt8()

  • DataView.prototype.setUint16()

  • DataView.prototype.setUint32()

  • DataView.prototype.setUint8()

    注意

    所有 Dataview ES 6 原型方法都是 JavaScript 运行时系统 2.0 中的新功能。

符号

支持以下 ES 6 方法:

  • Symbol.for()

  • Symbol.keyfor()

    注意

    所有符号 ES 6 方法都是 JavaScript 运行时系统 2.0 中的新功能。

文本解码器

支持以下原型方法:

  • TextDecoder.prototype.decode()

支持以下原型存取器属性:

  • TextDecoder.prototype.encoding

  • TextDecoder.prototype.fatal

  • TextDecoder.prototype.ignoreBOM

文本编码器

支持以下原型方法:

  • TextEncoder.prototype.encode()

  • TextEncoder.prototype.encodeInto()

错误类型

支持以下错误对象:

  • Error

  • EvalError

  • InternalError

  • RangeError

  • ReferenceError

  • SyntaxError

  • TypeError

  • URIError

全局变量

支持 globalThis 对象。

支持以下 ES 5.1 全局函数:

  • decodeURI()

  • decodeURIComponent()

  • encodeURI()

  • encodeURIComponent()

  • isFinite()

  • isNaN()

  • parseFloat()

  • parseInt()

支持以下 ES 6 全局函数:

  • atob()

  • btoa()

    注意

    atob()btoa() 是 JavaScript 运行时系统 2.0 中的新功能。

支持以下全局常数:

  • NaN

  • Infinity

  • undefined

  • arguments

内置模块

支持以下内置模块。

Buffer

该模块提供了以下方法:

  • Buffer.alloc(size[, fill[, encoding]])

    分配 Buffer

    • size:缓冲区大小。输入一个整数。

    • fill:可选。输入字符串、Buffer、Uint8Array 或整数。默认值为 0

    • encoding:可选。如果 fill 是字符串,请输入以下值之一:utf8hexbase64base64url。默认值为 utf8

  • Buffer.allocUnsafe(size)

    分配一个未初始化的 Buffer

    • size:输入一个整数。

  • Buffer.byteLength(value[, encoding])

    返回值的长度,以字节为单位。

    • value:字符串、Buffer、TypedArray、Dataview 或 Arraybuffer。

    • encoding:可选。如果 value 是字符串,请输入以下值之一:utf8hexbase64base64url。默认值为 utf8

  • Buffer.compare(buffer1, buffer2)

    比较两个 Buffer 以帮助对数组进行排序。如果它们相同,则返回 0,如果 buffer1 排在第一位,则返回 -1,如果 buffer2 排在第一位,则返回 1

    • buffer1:输入一个 Buffer

    • buffer2:输入不同的 Buffer

  • Buffer.concat(list[, totalLength])

    连接多个 Buffer。如果为无,则返回 0。最多可返回 totalLength

    • list:输入 Buffer 的列表。请注意,这将被截断为 totalLength

    • totalLength:可选。输入一个无符号整数。如果为空,则使用列表中的 Buffer 实例总和。

  • Buffer.from(array)

    从数组中创建 Buffer

    • array:输入从 0255 的字节数组。

  • Buffer.from(arrayBuffer, byteOffset[, length]))

    arrayBuffer 中创建视图,从偏移量 byteOffset 开始,长度为 length

    • arrayBuffer:输入 Buffer 数组。

    • byteOffset:输入一个整数。

    • length:可选。输入一个整数。

  • Buffer.from(buffer)

    创建 Buffer 的副本。

    • buffer:输入一个 Buffer

  • Buffer.from(object[, offsetOrEncoding[, length]])

    从对象创建 Buffer。如果 valueOf() 不等于对象,则返回 Buffer.from(object.valueOf(), offsetOrEncoding, length)

    • object:输入一个对象。

    • offsetOrEncoding:可选。输入整数或编码字符串。

    • length:可选。输入一个整数。

  • Buffer.from(string[, encoding])

    从字符串创建 Buffer

    • string:输入一个字符串。

    • encoding:可选。输入以下值之一:utf8hexbase64base64url。默认值为 utf8

  • Buffer.isBuffer(object)

    检查 object 是否为缓冲区。返回 truefalse

    • object:输入一个对象。

  • Buffer.isEncoding(encoding)

    检查 encoding 是否受支持。返回 truefalse

    • encoding:可选。输入以下值之一:utf8hexbase64base64url。默认值为 utf8

该模块提供以下缓冲区原型方法:

  • Buffer.prototype.compare(target[, targetStart[, targetEnd[, sourceStart[, sourceEnd]]]])

    Buffer 与目标进行比较。如果它们相同,则返回 0,如果 buffer 排在第一位,则返回 1,如果 target 排在第一位,则返回 -1

    • target:输入一个 Buffer

    • targetStart:可选。输入一个整数。默认值为 0。

    • targetEnd:可选。输入一个整数。默认为 target 长度。

    • sourceStart:可选。输入一个整数。默认值为 0。

    • sourceEnd:可选。输入一个整数。默认为 Buffer 长度。

  • Buffer.prototype.copy(target[, targetStart[, sourceStart[, sourceEnd]]])

    将缓冲区复制到 target

    • target:输入 BufferUint8Array

    • targetStart:可选。输入一个整数。默认值为 0。

    • sourceStart:可选。输入一个整数。默认值为 0。

    • sourceEnd:可选。输入一个整数。默认为 Buffer 长度。

  • Buffer.prototype.equals(otherBuffer)

    BufferotherBuffer 进行比较。返回 truefalse

    • otherBuffer:输入一个字符串。

  • Buffer.prototype.fill(value[, offset[, end][, encoding])

    使用 value 填充 Buffer

    • value:输入字符串、Buffer 或整数。

    • offset:可选。输入一个整数。

    • end:可选。输入一个整数。

    • encoding:可选。输入以下值之一:utf8hexbase64base64url。默认值为 utf8

  • Buffer.prototype.includes(value[, byteOffset][, encoding])

    Buffer 中搜索 value。返回 truefalse

    • value:输入字符串、BufferUint8Array 或整数。

    • byteOffset:可选。输入一个整数。

    • encoding:可选。输入以下值之一:utf8hexbase64base64url。默认值为 utf8

  • Buffer.prototype.indexOf(value[, byteOffset][, encoding])

    Buffer 中搜索第一个 value。如果找到,则返回 index;如果找不到,则返回 -1

    • value:输入一个字符串、Buffer、Unit8Array 或 0 到 255 之间的整数。

    • byteOffset:可选。输入一个整数。

    • encoding:可选。如果 value 是字符串,则输入以下值之一:utf8hexbase64base64url。默认值为 utf8

  • Buffer.prototype.lastIndexOf(value[, byteOffset][, encoding])

    Buffer 中搜索最后一个 value。如果找到,则返回 index;如果找不到,则返回 -1

    • value:输入一个字符串、Buffer、Unit8Array 或 0 到 255 之间的整数。

    • byteOffset:可选。输入一个整数。

    • encoding:可选。如果 value 是字符串,则输入以下值之一:utf8hexbase64base64url。默认值为 utf8

  • Buffer.prototype.readInt8(offset)

    Buffer 中按 offset 偏移量读取 Int8

    • offset:输入一个整数。

  • Buffer.prototype.readIntBE(offset, byteLength)

    Buffer 中按 offset 偏移量以大端序形式读取 Int

    • offset:输入一个整数。

    • byteLength:可选。输入一个从 16 的整数。

  • Buffer.prototype.readInt16BE(offset)

    Buffer 中按 offset 偏移量以大端序形式读取 Int16

    • offset:输入一个整数。

  • Buffer.prototype.readInt32BE(offset)

    Buffer 中按 offset 偏移量以大端序形式读取 Int32

    • offset:输入一个整数。

  • Buffer.prototype.readIntLE(offset, byteLength)

    Buffer 中按 offset 偏移量以小端序形式读取 Int

    • offset:输入一个整数。

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.readInt16LE(offset)

    Buffer 中按 offset 偏移量以小端序形式读取 Int16

    • offset:输入一个整数。

  • Buffer.prototype.readInt32LE(offset)

    Buffer 中按 offset 偏移量以小端序形式读取 Int32

    • offset:输入一个整数。

  • Buffer.prototype.readUInt8(offset)

    Buffer 中按 offset 偏移量读取 UInt8

    • offset:输入一个整数。

  • Buffer.prototype.readUIntBE(offset, byteLength)

    Buffer 中按 offset 偏移量以大端序形式读取 UInt

    • offset:输入一个整数。

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.readUInt16BE(offset)

    Buffer 中按 offset 偏移量以大端序形式读取 UInt16

    • offset:输入一个整数。

  • Buffer.prototype.readUInt32BE(offset)

    Buffer 中按 offset 偏移量以大端序形式读取 UInt32

    • offset:输入一个整数。

  • Buffer.prototype.readUIntLE(offset, byteLength)

    Buffer 中按 offset 偏移量以小端序形式读取 UInt

    • offset:输入一个整数。

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.readUInt16LE(offset)

    Buffer 中按 offset 偏移量以小端序形式读取 UInt16

    • offset:输入一个整数。

  • Buffer.prototype.readUInt32LE(offset)

    Buffer 中按 offset 偏移量以小端序形式读取 UInt32

    • offset:输入一个整数。

  • Buffer.prototype.readDoubleBE([offset])

    Buffer 中按 offset 偏移量以大端序形式读取 64 位双精度浮点数。

    • offset:可选。输入一个整数。

  • Buffer.prototype.readDoubleLE([offset])

    Buffer 中按 offset 偏移量以小端序形式读取 64 位双精度浮点数。

    • offset:可选。输入一个整数。

  • Buffer.prototype.readFloatBE([offset])

    Buffer 中按 offset 偏移量以大端序形式读取 32 位浮点数。

    • offset:可选。输入一个整数。

  • Buffer.prototype.readFloatLE([offset])

    Buffer 中按 offset 偏移量以小端序形式读取 32 位浮点数。

    • offset:可选。输入一个整数。

  • Buffer.prototype.subarray([start[, end]])

    返回 Buffer 的一个副本,该副本经过偏移并用新的 startend 进行裁剪。

    • start:可选。输入一个整数。默认值为 0。

    • end:可选。输入一个整数。默认为缓冲区长度。

  • Buffer.prototype.swap16()

    交换 Buffer 数组字节顺序,将其视为一个 16 位数字的数组。Buffer 长度必须可以被 2 整除,否则您将收到错误。

  • Buffer.prototype.swap32()

    交换 Buffer 数组字节顺序,将其视为一个 32 位数字的数组。Buffer 长度必须可以被 4 整除,否则您将收到错误。

  • Buffer.prototype.swap64()

    交换 Buffer 数组字节顺序,将其视为一个 64 位数字的数组。Buffer 长度必须可以被 8 整除,否则您将收到错误。

  • Buffer.prototype.toJSON()

    以 JSON 格式返回 Buffer

  • Buffer.prototype.toString([encoding[, start[, end]]])

    Bufferstartend 转换为编码字符串。

    • encoding:可选。输入以下值之一:utf8hexbase64base64url。默认值为 utf8

    • start:可选。输入一个整数。默认值为 0。

    • end:可选。输入一个整数。默认为缓冲区长度。

  • Buffer.prototype.write(string[, offset[, length]][, encoding])

    如果有空格,则将编码的 string 写入 Buffer,如果空间不足,则写入截断的 string

    • string:输入一个字符串。

    • offset:可选。输入一个整数。默认值为 0。

    • length:可选。输入一个整数。默认为字符串的长度。

    • encoding:可选。(可选)输入以下值之一:utf8hexbase64base64url。默认值为 utf8

  • Buffer.prototype.writeInt8(value, offset, byteLength)

    offset 偏移量将 byteLengthInt8 value 写入 Buffer

    • value:输入一个整数。

    • offset:输入一个整数

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeIntBE(value, offset, byteLength)

    使用大端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:输入一个整数

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeInt16BE(value, offset, byteLength)

    使用大端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:输入一个整数

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeInt32BE(value, offset, byteLength)

    使用大端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:输入一个整数

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeIntLE(offset, byteLength)

    使用小端序按 offset 偏移量将 value 写入 Buffer

    • offset:输入一个整数。

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeInt16LE(offset, byteLength)

    使用小端序按 offset 偏移量将 value 写入 Buffer

    • offset:输入一个整数。

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeInt32LE(offset, byteLength)

    使用小端序按 offset 偏移量将 value 写入 Buffer

    • offset:输入一个整数。

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeUInt8(value, offset, byteLength)

    offset 偏移量将 byteLengthUInt8 value 写入 Buffer

    • value:输入一个整数。

    • offset:输入一个整数

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeUIntBE(value, offset, byteLength)

    使用大端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:输入一个整数

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeUInt16BE(value, offset, byteLength)

    使用大端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:输入一个整数

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeUInt32BE(value, offset, byteLength)

    使用大端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:输入一个整数

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeUIntLE(value, offset, byteLength)

    使用小端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:输入一个整数

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeUInt16LE(value, offset, byteLength)

    使用小端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:输入一个整数

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeUInt32LE(value, offset, byteLength)

    使用小端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:输入一个整数

    • byteLength:输入一个从 16 的整数。

  • Buffer.prototype.writeDoubleBE(value, [offset])

    使用大端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:可选。输入一个整数。默认值为 0。

  • Buffer.prototype.writeDoubleLE(value, [offset])

    使用小端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:可选。输入一个整数。默认值为 0。

  • Buffer.prototype.writeFloatBE(value, [offset])

    使用大端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:可选。输入一个整数。默认值为 0。

  • Buffer.prototype.writeFloatLE(value, [offset])

    使用小端序按 offset 偏移量将 value 写入 Buffer

    • value:输入一个整数。

    • offset:可选。输入一个整数。默认值为 0。

支持以下实例方法:

  • buffer[index]

    Buffer 中的 index 处获取和设置八位字节(字节)。

    • 获取一个从 0255 的数字。或者设置一个从 0255 的数字。

支持以下实例属性:

  • buffer

    获取缓冲区的 ArrayBuffer 对象。

  • byteOffset

    获取缓冲区的 Arraybuffer 对象的 byteOffset

  • length

    获取缓冲区字节计数。

注意

所有缓冲区模块方法都是 JavaScript 运行时系统 2.0 中的新功能。

查询字符串

注意

CloudFront Functions 事件对象自动为您解析 URL 查询字符串。这意味着,在大多数情况下您不需要使用此模块。

查询字符串模块 (querystring) 提供了解析和格式化 URL 查询字符串的方法。您可以使用 require('querystring') 加载模块。该模块提供了以下方法。

querystring.escape(string)

URL - 对给定的 string 进行编码,从而返回转义的查询字符串。该方法由 querystring.stringify() 使用,不应直接使用。

querystring.parse(string[, separator[, equal[, options]]])

解析查询字符串 (string) 并返回对象。

separator 参数是用于在查询字符串中分隔键和值对的子字符串。默认为 &

equal 参数是用于在查询字符串中分隔键和值的子字符串。默认为 =

options 参数是具有以下键的对象:

decodeURIComponent function

用于解码查询字符串中百分比编码字符的函数。默认为 querystring.unescape()

maxKeys number

要解析的最大密钥数。默认为 1000。使用 0 的值取消键的计数限制。

默认情况下,假定查询字符串中的百分比编码字符使用 UTF-8 编码。无效的 UTF-8 序列将被替换为 U+FFFD 替换字符。

例如,对于以下查询字符串:

'name=value&abc=xyz&abc=123'

querystring.parse() 的返回值为:

{ name: 'value', abc: ['xyz', '123'] }

querystring.decode()querystring.parse() 的别名。

querystring.stringify(object[, separator[, equal[, options]]])

序列化 object 并返回查询字符串。

separator 参数是用于在查询字符串中分隔键和值对的子字符串。默认为 &

equal 参数是用于在查询字符串中分隔键和值的子字符串。默认为 =

options 参数是具有以下键的对象:

encodeURIComponent function

用于将 URL 不安全字符转换为查询字符串中的百分比编码的函数。默认为 querystring.escape()

默认情况下,查询字符串中需要百分比编码的字符将编码为 UTF-8。要使用其他编码,请指定 encodeURIComponent 选项。

例如,在下面的代码中:

querystring.stringify({ name: 'value', abc: ['xyz', '123'], anotherName: '' });

返回值为:

'name=value&abc=xyz&abc=123&anotherName='

querystring.encode()querystring.stringify() 的别名。

querystring.unescape(string)

对给定的 string 中的 URL 百分比编码字符进行解码,以返回未转义的查询字符串。此方法由 querystring.parse() 使用,不应直接使用。

加密

加密模块 (crypto) 提供标准哈希和基于哈希的消息身份验证码 (HMAC) 帮助程序。您可以使用 require('crypto') 加载模块。

哈希方法

crypto.createHash(algorithm)

创建并返回哈希对象,您可以使用给定的算法:md5sha1sha256 通过它生成哈希摘要。

hash.update(data)

用给定的 data 更新哈希内容。

hash.digest([encoding])

计算使用 hash.update() 传递的所有数据的摘要。编码可以是 hexbase64base64url

HMAC 方法

crypto.createHmac(algorithm, secret key)

创建并返回使用给定的 algorithmsecret key 的 HMAC 对象。算法可以是 md5sha1sha256

hmac.update(data)

用给定的 data 更新 HMAC 内容。

hmac.digest([encoding])

计算使用 hmac.update() 传递的所有数据的摘要。编码可以是 hexbase64base64url

受限功能

由于安全考虑,以下 JavaScript 语言功能或不受支持,或收到限制。

动态代码评估

不支持动态代码评估。如果尝试,eval()Function 构造函数都会引发错误。例如,const sum = new Function('a', 'b', 'return a + b') 引发错误。

计时器

不支持 setTimeout()setImmediate()clearTimeout() 函数。在函数运行中没有可以推迟或生成的预置。您的函数必须同步运行才能完成。

日期和时间戳

出于安全原因,无法访问高分辨率计时器。在单个函数运行的生命周期内,查询当前时间的所有 Date 方法始终返回相同的值。返回的时间戳是函数开始运行的时间。因此,您无法度量函数中的经过时间。

文件系统访问

没有文件系统访问权限。

网络访问

不支持网络调用。例如,不支持 XHR、HTTP (S) 和套接字。