适用于 CloudFront Functions 的 JavaScript 运行时系统 2.0 特征
CloudFront Functions JavaScript 运行时系统环境符合 ECMAScript (ES) 5.1
核心功能
支持 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 语句:
-
const -
let
支持以下 ES 8 语句:
async-
await
注意
JavaScript 运行时 2.0 支持
async、await、const和let。await只能在async函数内部使用。不支持async参数和闭包。 -
- 文本
-
支持 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()
-
- 字符串
-
支持对字符串使用以下 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()实现使用植入有函数运行时间戳的 OpenBSDarc4random。支持以下 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.sticky和RegExp.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是字符串,请输入以下值之一:utf8、hex、base64、base64url。默认值为utf8。
-
-
Buffer.allocUnsafe(size)分配一个未初始化的
Buffer。-
size:输入一个整数。
-
-
Buffer.byteLength(value[, encoding])返回值的长度,以字节为单位。
-
value:字符串、Buffer、TypedArray、Dataview 或 Arraybuffer。 -
encoding:可选。如果value是字符串,请输入以下值之一:utf8、hex、base64、base64url。默认值为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:输入从0到255的字节数组。
-
-
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:可选。输入以下值之一:utf8、hex、base64、base64url。默认值为utf8。
-
-
Buffer.isBuffer(object)检查
object是否为缓冲区。返回true或false。-
object:输入一个对象。
-
-
Buffer.isEncoding(encoding)检查
encoding是否受支持。返回true或false。-
encoding:可选。输入以下值之一:utf8、hex、base64、base64url。默认值为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:输入Buffer或Uint8Array。 -
targetStart:可选。输入一个整数。默认值为 0。 -
sourceStart:可选。输入一个整数。默认值为 0。 -
sourceEnd:可选。输入一个整数。默认为Buffer长度。
-
-
Buffer.prototype.equals(otherBuffer)将
Buffer与otherBuffer进行比较。返回true或false。-
otherBuffer:输入一个字符串。
-
-
Buffer.prototype.fill(value[, offset[, end][, encoding])使用
value填充Buffer。-
value:输入字符串、Buffer或整数。 -
offset:可选。输入一个整数。 -
end:可选。输入一个整数。 -
encoding:可选。输入以下值之一:utf8、hex、base64、base64url。默认值为utf8。
-
-
Buffer.prototype.includes(value[, byteOffset][, encoding])在
Buffer中搜索value。返回true或false。-
value:输入字符串、Buffer、Uint8Array或整数。 -
byteOffset:可选。输入一个整数。 -
encoding:可选。输入以下值之一:utf8、hex、base64、base64url。默认值为utf8。
-
-
Buffer.prototype.indexOf(value[, byteOffset][, encoding])在
Buffer中搜索第一个value。如果找到,则返回index;如果找不到,则返回-1。-
value:输入一个字符串、Buffer、Unit8Array 或 0 到 255 之间的整数。 -
byteOffset:可选。输入一个整数。 -
encoding:可选。如果value是字符串,则输入以下值之一:utf8、hex、base64、base64url。默认值为utf8。
-
-
Buffer.prototype.lastIndexOf(value[, byteOffset][, encoding])在
Buffer中搜索最后一个value。如果找到,则返回index;如果找不到,则返回-1。-
value:输入一个字符串、Buffer、Unit8Array 或 0 到 255 之间的整数。 -
byteOffset:可选。输入一个整数。 -
encoding:可选。如果value是字符串,则输入以下值之一:utf8、hex、base64、base64url。默认值为utf8。
-
-
Buffer.prototype.readInt8(offset)从
Buffer中按offset偏移量读取Int8。-
offset:输入一个整数。
-
-
Buffer.prototype.readIntBE(offset, byteLength)从
Buffer中按offset偏移量以大端序形式读取Int。-
offset:输入一个整数。 -
byteLength:可选。输入一个从1到6的整数。
-
-
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:输入一个从1到6的整数。
-
-
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:输入一个从1到6的整数。
-
-
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:输入一个从1到6的整数。
-
-
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的一个副本,该副本经过偏移并用新的start和end进行裁剪。-
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]]])将
Buffer从start到end转换为编码字符串。-
encoding:可选。输入以下值之一:utf8、hex、base64或base64url。默认值为utf8。 -
start:可选。输入一个整数。默认值为 0。 -
end:可选。输入一个整数。默认为缓冲区长度。
-
-
Buffer.prototype.write(string[, offset[, length]][, encoding])如果有空格,则将编码的
string写入Buffer,如果空间不足,则写入截断的string。-
string:输入一个字符串。 -
offset:可选。输入一个整数。默认值为 0。 -
length:可选。输入一个整数。默认为字符串的长度。 -
encoding:可选。(可选)输入以下值之一:utf8、hex、base64或base64url。默认值为utf8。
-
-
Buffer.prototype.writeInt8(value, offset, byteLength)按
offset偏移量将byteLength的Int8value写入Buffer。-
value:输入一个整数。 -
offset:输入一个整数 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeIntBE(value, offset, byteLength)使用大端序按
offset偏移量将value写入Buffer。-
value:输入一个整数。 -
offset:输入一个整数 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeInt16BE(value, offset, byteLength)使用大端序按
offset偏移量将value写入Buffer。-
value:输入一个整数。 -
offset:输入一个整数 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeInt32BE(value, offset, byteLength)使用大端序按
offset偏移量将value写入Buffer。-
value:输入一个整数。 -
offset:输入一个整数 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeIntLE(offset, byteLength)使用小端序按
offset偏移量将value写入Buffer。-
offset:输入一个整数。 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeInt16LE(offset, byteLength)使用小端序按
offset偏移量将value写入Buffer。-
offset:输入一个整数。 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeInt32LE(offset, byteLength)使用小端序按
offset偏移量将value写入Buffer。-
offset:输入一个整数。 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeUInt8(value, offset, byteLength)按
offset偏移量将byteLength的UInt8value写入Buffer。-
value:输入一个整数。 -
offset:输入一个整数 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeUIntBE(value, offset, byteLength)使用大端序按
offset偏移量将value写入Buffer。-
value:输入一个整数。 -
offset:输入一个整数 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeUInt16BE(value, offset, byteLength)使用大端序按
offset偏移量将value写入Buffer。-
value:输入一个整数。 -
offset:输入一个整数 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeUInt32BE(value, offset, byteLength)使用大端序按
offset偏移量将value写入Buffer。-
value:输入一个整数。 -
offset:输入一个整数 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeUIntLE(value, offset, byteLength)使用小端序按
offset偏移量将value写入Buffer。-
value:输入一个整数。 -
offset:输入一个整数 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeUInt16LE(value, offset, byteLength)使用小端序按
offset偏移量将value写入Buffer。-
value:输入一个整数。 -
offset:输入一个整数 -
byteLength:输入一个从1到6的整数。
-
-
Buffer.prototype.writeUInt32LE(value, offset, byteLength)使用小端序按
offset偏移量将value写入Buffer。-
value:输入一个整数。 -
offset:输入一个整数 -
byteLength:输入一个从1到6的整数。
-
-
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处获取和设置八位字节(字节)。-
获取一个从
0到255的数字。或者设置一个从0到255的数字。
-
支持以下实例属性:
-
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)-
创建并返回哈希对象,您可以使用给定的算法:
md5、sha1或sha256通过它生成哈希摘要。 hash.update(data)-
用给定的
data更新哈希内容。 hash.digest([encoding])-
计算使用
hash.update()传递的所有数据的摘要。编码可以是hex、base64或base64url。
HMAC 方法
crypto.createHmac(algorithm, secret key)-
创建并返回使用给定的
algorithm和secret key的 HMAC 对象。算法可以是md5、sha1或sha256。 hmac.update(data)-
用给定的
data更新 HMAC 内容。 hmac.digest([encoding])-
计算使用
hmac.update()传递的所有数据的摘要。编码可以是hex、base64或base64url。
受限功能
由于安全考虑,以下 JavaScript 语言功能或不受支持,或收到限制。
- 动态代码评估
-
不支持动态代码评估。如果尝试,
eval()和Function构造函数都会引发错误。例如,const sum = new Function('a', 'b', 'return a + b')引发错误。 - 计时器
-
不支持
setTimeout()、setImmediate()和clearTimeout()函数。在函数运行中没有可以推迟或生成的预置。您的函数必须同步运行才能完成。 - 日期和时间戳
-
出于安全原因,无法访问高分辨率计时器。在单个函数运行的生命周期内,查询当前时间的所有
Date方法始终返回相同的值。返回的时间戳是函数开始运行的时间。因此,您无法度量函数中的经过时间。 - 文件系统访问
-
没有文件系统访问权限。例如,没有像 Node.js 的
fs模块可以进行文件系统访问。 - 处理访问权限
-
没有处理访问权限。例如,没有像 Node.js 中那样用于处理信息访问权限的
process全局对象。 - 环境变量
-
无法访问环境变量。相反,可以使用 CloudFront KeyValueStore 为 CloudFront Functions 创建集中式的键值对数据存储。借助 CloudFront KeyValueStore,无需部署代码更改即对配置数据进行动态更新。有关更多信息,请参阅 Amazon CloudFront KeyValueStore。
- 网络访问
-
不支持网络调用。例如,不支持 XHR、HTTP (S) 和套接字。