code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function isErrorLike (object) {
return object instanceof Error || (
object?.constructor?.name === 'Error' ||
object?.constructor?.name === 'DOMException'
)
}
|
@see https://tools.ietf.org/html/rfc7230#section-3.2.6
@param {number} c
|
isErrorLike
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isTokenCharCode (c) {
switch (c) {
case 0x22:
case 0x28:
case 0x29:
case 0x2c:
case 0x2f:
case 0x3a:
case 0x3b:
case 0x3c:
case 0x3d:
case 0x3e:
case 0x3f:
case 0x40:
case 0x5b:
case 0x5c:
case 0x5d:
case 0x7b:
case 0x7d:
// DQUOTE and "(),/:;<=>?@[\]{}"
return false
default:
// VCHAR %x21-7E
return c >= 0x21 && c <= 0x7e
}
}
|
@see https://fetch.spec.whatwg.org/#header-value
@param {string} potentialValue
|
isTokenCharCode
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isValidHTTPToken (characters) {
if (characters.length === 0) {
return false
}
for (let i = 0; i < characters.length; ++i) {
if (!isTokenCharCode(characters.charCodeAt(i))) {
return false
}
}
return true
}
|
@see https://fetch.spec.whatwg.org/#header-value
@param {string} potentialValue
|
isValidHTTPToken
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isValidHeaderName (potentialValue) {
return isValidHTTPToken(potentialValue)
}
|
@see https://fetch.spec.whatwg.org/#header-value
@param {string} potentialValue
|
isValidHeaderName
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isValidHeaderValue (potentialValue) {
// - Has no leading or trailing HTTP tab or space bytes.
// - Contains no 0x00 (NUL) or HTTP newline bytes.
if (
potentialValue.startsWith('\t') ||
potentialValue.startsWith(' ') ||
potentialValue.endsWith('\t') ||
potentialValue.endsWith(' ')
) {
return false
}
if (
potentialValue.includes('\0') ||
potentialValue.includes('\r') ||
potentialValue.includes('\n')
) {
return false
}
return true
}
|
@see https://fetch.spec.whatwg.org/#header-value
@param {string} potentialValue
|
isValidHeaderValue
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function crossOriginResourcePolicyCheck () {
// TODO
return 'allowed'
}
|
@see https://fetch.spec.whatwg.org/#header-value
@param {string} potentialValue
|
crossOriginResourcePolicyCheck
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function corsCheck () {
// TODO
return 'success'
}
|
@see https://fetch.spec.whatwg.org/#header-value
@param {string} potentialValue
|
corsCheck
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function TAOCheck () {
// TODO
return 'success'
}
|
@see https://fetch.spec.whatwg.org/#header-value
@param {string} potentialValue
|
TAOCheck
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function coarsenedSharedCurrentTime (crossOriginIsolatedCapability) {
// TODO
return performance.now()
}
|
@see https://fetch.spec.whatwg.org/#header-value
@param {string} potentialValue
|
coarsenedSharedCurrentTime
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function createOpaqueTimingInfo (timingInfo) {
return {
startTime: timingInfo.startTime ?? 0,
redirectStartTime: 0,
redirectEndTime: 0,
postRedirectStartTime: timingInfo.startTime ?? 0,
finalServiceWorkerStartTime: 0,
finalNetworkResponseStartTime: 0,
finalNetworkRequestStartTime: 0,
endTime: 0,
encodedBodySize: 0,
decodedBodySize: 0,
finalConnectionTimingInfo: null
}
}
|
@see https://fetch.spec.whatwg.org/#header-value
@param {string} potentialValue
|
createOpaqueTimingInfo
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function makePolicyContainer () {
// Note: the fetch spec doesn't make use of embedder policy or CSP list
return {
referrerPolicy: 'strict-origin-when-cross-origin'
}
}
|
@see https://fetch.spec.whatwg.org/#header-value
@param {string} potentialValue
|
makePolicyContainer
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function clonePolicyContainer (policyContainer) {
return {
referrerPolicy: policyContainer.referrerPolicy
}
}
|
@see https://fetch.spec.whatwg.org/#header-value
@param {string} potentialValue
|
clonePolicyContainer
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isURLPotentiallyTrustworthy (url) {
if (!(url instanceof URL)) {
return false
}
// If child of about, return true
if (url.href === 'about:blank' || url.href === 'about:srcdoc') {
return true
}
// If scheme is data, return true
if (url.protocol === 'data:') return true
// If file, return true
if (url.protocol === 'file:') return true
return isOriginPotentiallyTrustworthy(url.origin)
function isOriginPotentiallyTrustworthy (origin) {
// If origin is explicitly null, return false
if (origin == null || origin === 'null') return false
const originAsURL = new URL(origin)
// If secure, return true
if (originAsURL.protocol === 'https:' || originAsURL.protocol === 'wss:') {
return true
}
// If localhost or variants, return true
if (/^127(?:\.[0-9]+){0,2}\.[0-9]+$|^\[(?:0*:)*?:?0*1\]$/.test(originAsURL.hostname) ||
(originAsURL.hostname === 'localhost' || originAsURL.hostname.includes('localhost.')) ||
(originAsURL.hostname.endsWith('.localhost'))) {
return true
}
// If any other, return false
return false
}
}
|
@see https://w3c.github.io/webappsec-referrer-policy/#strip-url
@param {URL} url
@param {boolean|undefined} originOnly
|
isURLPotentiallyTrustworthy
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isOriginPotentiallyTrustworthy (origin) {
// If origin is explicitly null, return false
if (origin == null || origin === 'null') return false
const originAsURL = new URL(origin)
// If secure, return true
if (originAsURL.protocol === 'https:' || originAsURL.protocol === 'wss:') {
return true
}
// If localhost or variants, return true
if (/^127(?:\.[0-9]+){0,2}\.[0-9]+$|^\[(?:0*:)*?:?0*1\]$/.test(originAsURL.hostname) ||
(originAsURL.hostname === 'localhost' || originAsURL.hostname.includes('localhost.')) ||
(originAsURL.hostname.endsWith('.localhost'))) {
return true
}
// If any other, return false
return false
}
|
@see https://w3c.github.io/webappsec-subresource-integrity/#does-response-match-metadatalist
@param {Uint8Array} bytes
@param {string} metadataList
|
isOriginPotentiallyTrustworthy
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function bytesMatch (bytes, metadataList) {
// If node is not built with OpenSSL support, we cannot check
// a request's integrity, so allow it by default (the spec will
// allow requests if an invalid hash is given, as precedence).
/* istanbul ignore if: only if node is built with --without-ssl */
if (crypto === undefined) {
return true
}
// 1. Let parsedMetadata be the result of parsing metadataList.
const parsedMetadata = parseMetadata(metadataList)
// 2. If parsedMetadata is no metadata, return true.
if (parsedMetadata === 'no metadata') {
return true
}
// 3. If parsedMetadata is the empty set, return true.
if (parsedMetadata.length === 0) {
return true
}
// 4. Let metadata be the result of getting the strongest
// metadata from parsedMetadata.
const list = parsedMetadata.sort((c, d) => d.algo.localeCompare(c.algo))
// get the strongest algorithm
const strongest = list[0].algo
// get all entries that use the strongest algorithm; ignore weaker
const metadata = list.filter((item) => item.algo === strongest)
// 5. For each item in metadata:
for (const item of metadata) {
// 1. Let algorithm be the alg component of item.
const algorithm = item.algo
// 2. Let expectedValue be the val component of item.
let expectedValue = item.hash
// See https://github.com/web-platform-tests/wpt/commit/e4c5cc7a5e48093220528dfdd1c4012dc3837a0e
// "be liberal with padding". This is annoying, and it's not even in the spec.
if (expectedValue.endsWith('==')) {
expectedValue = expectedValue.slice(0, -2)
}
// 3. Let actualValue be the result of applying algorithm to bytes.
let actualValue = crypto.createHash(algorithm).update(bytes).digest('base64')
if (actualValue.endsWith('==')) {
actualValue = actualValue.slice(0, -2)
}
// 4. If actualValue is a case-sensitive match for expectedValue,
// return true.
if (actualValue === expectedValue) {
return true
}
let actualBase64URL = crypto.createHash(algorithm).update(bytes).digest('base64url')
if (actualBase64URL.endsWith('==')) {
actualBase64URL = actualBase64URL.slice(0, -2)
}
if (actualBase64URL === expectedValue) {
return true
}
}
// 6. Return false.
return false
}
|
@see https://w3c.github.io/webappsec-subresource-integrity/#does-response-match-metadatalist
@param {Uint8Array} bytes
@param {string} metadataList
|
bytesMatch
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function tryUpgradeRequestToAPotentiallyTrustworthyURL (request) {
// TODO
}
|
@link {https://html.spec.whatwg.org/multipage/origin.html#same-origin}
@param {URL} A
@param {URL} B
|
tryUpgradeRequestToAPotentiallyTrustworthyURL
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function sameOrigin (A, B) {
// 1. If A and B are the same opaque origin, then return true.
if (A.origin === B.origin && A.origin === 'null') {
return true
}
// 2. If A and B are both tuple origins and their schemes,
// hosts, and port are identical, then return true.
if (A.protocol === B.protocol && A.hostname === B.hostname && A.port === B.port) {
return true
}
// 3. Return false.
return false
}
|
@link {https://html.spec.whatwg.org/multipage/origin.html#same-origin}
@param {URL} A
@param {URL} B
|
sameOrigin
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function createDeferredPromise () {
let res
let rej
const promise = new Promise((resolve, reject) => {
res = resolve
rej = reject
})
return { promise, resolve: res, reject: rej }
}
|
@see https://fetch.spec.whatwg.org/#concept-method-normalize
@param {string} method
|
createDeferredPromise
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isAborted (fetchParams) {
return fetchParams.controller.state === 'aborted'
}
|
@see https://fetch.spec.whatwg.org/#concept-method-normalize
@param {string} method
|
isAborted
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isCancelled (fetchParams) {
return fetchParams.controller.state === 'aborted' ||
fetchParams.controller.state === 'terminated'
}
|
@see https://fetch.spec.whatwg.org/#concept-method-normalize
@param {string} method
|
isCancelled
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function normalizeMethod (method) {
return normalizeMethodRecord[method.toLowerCase()] ?? method
}
|
@see https://webidl.spec.whatwg.org/#dfn-iterator-prototype-object
@param {() => unknown[]} iterator
@param {string} name name of the instance
@param {'key'|'value'|'key+value'} kind
|
normalizeMethod
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isReadableStreamLike (stream) {
if (!ReadableStream) {
ReadableStream = (__nccwpck_require__(3774).ReadableStream)
}
return stream instanceof ReadableStream || (
stream[Symbol.toStringTag] === 'ReadableStream' &&
typeof stream.tee === 'function'
)
}
|
@see https://infra.spec.whatwg.org/#isomorphic-encode
@param {string} input
|
isReadableStreamLike
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function readableStreamClose (controller) {
try {
controller.close()
} catch (err) {
// TODO: add comment explaining why this error occurs.
if (!err.message.includes('Controller is already closed')) {
throw err
}
}
}
|
@see https://streams.spec.whatwg.org/#readablestreamdefaultreader-read-all-bytes
@see https://streams.spec.whatwg.org/#read-loop
@param {ReadableStreamDefaultReader} reader
|
readableStreamClose
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
async function readAllBytes (reader) {
const bytes = []
let byteLength = 0
while (true) {
const { done, value: chunk } = await reader.read()
if (done) {
// 1. Call successSteps with bytes.
return Buffer.concat(bytes, byteLength)
}
// 1. If chunk is not a Uint8Array object, call failureSteps
// with a TypeError and abort these steps.
if (!isUint8Array(chunk)) {
throw new TypeError('Received non-Uint8Array chunk')
}
// 2. Append the bytes represented by chunk to bytes.
bytes.push(chunk)
byteLength += chunk.length
// 3. Read-loop given reader, bytes, successSteps, and failureSteps.
}
}
|
@see https://fetch.spec.whatwg.org/#http-scheme
@param {URL} url
|
readAllBytes
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function urlIsLocal (url) {
assert('protocol' in url) // ensure it's a url object
const protocol = url.protocol
return protocol === 'about:' || protocol === 'blob:' || protocol === 'data:'
}
|
Fetch supports node >= 16.8.0, but Object.hasOwn was added in v16.9.0.
|
urlIsLocal
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function urlHasHttpsScheme (url) {
if (typeof url === 'string') {
return url.startsWith('https:')
}
return url.protocol === 'https:'
}
|
Fetch supports node >= 16.8.0, but Object.hasOwn was added in v16.9.0.
|
urlHasHttpsScheme
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function urlIsHttpHttpsScheme (url) {
assert('protocol' in url) // ensure it's a url object
const protocol = url.protocol
return protocol === 'http:' || protocol === 'https:'
}
|
Fetch supports node >= 16.8.0, but Object.hasOwn was added in v16.9.0.
|
urlIsHttpHttpsScheme
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function getEncoding (label) {
if (!label) {
return 'failure'
}
// 1. Remove any leading and trailing ASCII whitespace from label.
// 2. If label is an ASCII case-insensitive match for any of the
// labels listed in the table below, then return the
// corresponding encoding; otherwise return failure.
switch (label.trim().toLowerCase()) {
case 'unicode-1-1-utf-8':
case 'unicode11utf8':
case 'unicode20utf8':
case 'utf-8':
case 'utf8':
case 'x-unicode20utf8':
return 'UTF-8'
case '866':
case 'cp866':
case 'csibm866':
case 'ibm866':
return 'IBM866'
case 'csisolatin2':
case 'iso-8859-2':
case 'iso-ir-101':
case 'iso8859-2':
case 'iso88592':
case 'iso_8859-2':
case 'iso_8859-2:1987':
case 'l2':
case 'latin2':
return 'ISO-8859-2'
case 'csisolatin3':
case 'iso-8859-3':
case 'iso-ir-109':
case 'iso8859-3':
case 'iso88593':
case 'iso_8859-3':
case 'iso_8859-3:1988':
case 'l3':
case 'latin3':
return 'ISO-8859-3'
case 'csisolatin4':
case 'iso-8859-4':
case 'iso-ir-110':
case 'iso8859-4':
case 'iso88594':
case 'iso_8859-4':
case 'iso_8859-4:1988':
case 'l4':
case 'latin4':
return 'ISO-8859-4'
case 'csisolatincyrillic':
case 'cyrillic':
case 'iso-8859-5':
case 'iso-ir-144':
case 'iso8859-5':
case 'iso88595':
case 'iso_8859-5':
case 'iso_8859-5:1988':
return 'ISO-8859-5'
case 'arabic':
case 'asmo-708':
case 'csiso88596e':
case 'csiso88596i':
case 'csisolatinarabic':
case 'ecma-114':
case 'iso-8859-6':
case 'iso-8859-6-e':
case 'iso-8859-6-i':
case 'iso-ir-127':
case 'iso8859-6':
case 'iso88596':
case 'iso_8859-6':
case 'iso_8859-6:1987':
return 'ISO-8859-6'
case 'csisolatingreek':
case 'ecma-118':
case 'elot_928':
case 'greek':
case 'greek8':
case 'iso-8859-7':
case 'iso-ir-126':
case 'iso8859-7':
case 'iso88597':
case 'iso_8859-7':
case 'iso_8859-7:1987':
case 'sun_eu_greek':
return 'ISO-8859-7'
case 'csiso88598e':
case 'csisolatinhebrew':
case 'hebrew':
case 'iso-8859-8':
case 'iso-8859-8-e':
case 'iso-ir-138':
case 'iso8859-8':
case 'iso88598':
case 'iso_8859-8':
case 'iso_8859-8:1988':
case 'visual':
return 'ISO-8859-8'
case 'csiso88598i':
case 'iso-8859-8-i':
case 'logical':
return 'ISO-8859-8-I'
case 'csisolatin6':
case 'iso-8859-10':
case 'iso-ir-157':
case 'iso8859-10':
case 'iso885910':
case 'l6':
case 'latin6':
return 'ISO-8859-10'
case 'iso-8859-13':
case 'iso8859-13':
case 'iso885913':
return 'ISO-8859-13'
case 'iso-8859-14':
case 'iso8859-14':
case 'iso885914':
return 'ISO-8859-14'
case 'csisolatin9':
case 'iso-8859-15':
case 'iso8859-15':
case 'iso885915':
case 'iso_8859-15':
case 'l9':
return 'ISO-8859-15'
case 'iso-8859-16':
return 'ISO-8859-16'
case 'cskoi8r':
case 'koi':
case 'koi8':
case 'koi8-r':
case 'koi8_r':
return 'KOI8-R'
case 'koi8-ru':
case 'koi8-u':
return 'KOI8-U'
case 'csmacintosh':
case 'mac':
case 'macintosh':
case 'x-mac-roman':
return 'macintosh'
case 'iso-8859-11':
case 'iso8859-11':
case 'iso885911':
case 'tis-620':
case 'windows-874':
return 'windows-874'
case 'cp1250':
case 'windows-1250':
case 'x-cp1250':
return 'windows-1250'
case 'cp1251':
case 'windows-1251':
case 'x-cp1251':
return 'windows-1251'
case 'ansi_x3.4-1968':
case 'ascii':
case 'cp1252':
case 'cp819':
case 'csisolatin1':
case 'ibm819':
case 'iso-8859-1':
case 'iso-ir-100':
case 'iso8859-1':
case 'iso88591':
case 'iso_8859-1':
case 'iso_8859-1:1987':
case 'l1':
case 'latin1':
case 'us-ascii':
case 'windows-1252':
case 'x-cp1252':
return 'windows-1252'
case 'cp1253':
case 'windows-1253':
case 'x-cp1253':
return 'windows-1253'
case 'cp1254':
case 'csisolatin5':
case 'iso-8859-9':
case 'iso-ir-148':
case 'iso8859-9':
case 'iso88599':
case 'iso_8859-9':
case 'iso_8859-9:1989':
case 'l5':
case 'latin5':
case 'windows-1254':
case 'x-cp1254':
return 'windows-1254'
case 'cp1255':
case 'windows-1255':
case 'x-cp1255':
return 'windows-1255'
case 'cp1256':
case 'windows-1256':
case 'x-cp1256':
return 'windows-1256'
case 'cp1257':
case 'windows-1257':
case 'x-cp1257':
return 'windows-1257'
case 'cp1258':
case 'windows-1258':
case 'x-cp1258':
return 'windows-1258'
case 'x-mac-cyrillic':
case 'x-mac-ukrainian':
return 'x-mac-cyrillic'
case 'chinese':
case 'csgb2312':
case 'csiso58gb231280':
case 'gb2312':
case 'gb_2312':
case 'gb_2312-80':
case 'gbk':
case 'iso-ir-58':
case 'x-gbk':
return 'GBK'
case 'gb18030':
return 'gb18030'
case 'big5':
case 'big5-hkscs':
case 'cn-big5':
case 'csbig5':
case 'x-x-big5':
return 'Big5'
case 'cseucpkdfmtjapanese':
case 'euc-jp':
case 'x-euc-jp':
return 'EUC-JP'
case 'csiso2022jp':
case 'iso-2022-jp':
return 'ISO-2022-JP'
case 'csshiftjis':
case 'ms932':
case 'ms_kanji':
case 'shift-jis':
case 'shift_jis':
case 'sjis':
case 'windows-31j':
case 'x-sjis':
return 'Shift_JIS'
case 'cseuckr':
case 'csksc56011987':
case 'euc-kr':
case 'iso-ir-149':
case 'korean':
case 'ks_c_5601-1987':
case 'ks_c_5601-1989':
case 'ksc5601':
case 'ksc_5601':
case 'windows-949':
return 'EUC-KR'
case 'csiso2022kr':
case 'hz-gb-2312':
case 'iso-2022-cn':
case 'iso-2022-cn-ext':
case 'iso-2022-kr':
case 'replacement':
return 'replacement'
case 'unicodefffe':
case 'utf-16be':
return 'UTF-16BE'
case 'csunicode':
case 'iso-10646-ucs-2':
case 'ucs-2':
case 'unicode':
case 'unicodefeff':
case 'utf-16':
case 'utf-16le':
return 'UTF-16LE'
case 'x-user-defined':
return 'x-user-defined'
default: return 'failure'
}
}
|
@see https://encoding.spec.whatwg.org/#concept-encoding-get
@param {string|undefined} label
|
getEncoding
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
constructor () {
super()
this[kState] = 'empty'
this[kResult] = null
this[kError] = null
this[kEvents] = {
loadend: null,
error: null,
abort: null,
load: null,
progress: null,
loadstart: null
}
}
|
@see https://w3c.github.io/FileAPI/#readAsBinaryString
@param {import('buffer').Blob} blob
|
constructor
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
readAsArrayBuffer (blob) {
webidl.brandCheck(this, FileReader)
webidl.argumentLengthCheck(arguments, 1, { header: 'FileReader.readAsArrayBuffer' })
blob = webidl.converters.Blob(blob, { strict: false })
// The readAsArrayBuffer(blob) method, when invoked,
// must initiate a read operation for blob with ArrayBuffer.
readOperation(this, blob, 'ArrayBuffer')
}
|
@see https://w3c.github.io/FileAPI/#readAsDataText
@param {import('buffer').Blob} blob
@param {string?} encoding
|
readAsArrayBuffer
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
readAsBinaryString (blob) {
webidl.brandCheck(this, FileReader)
webidl.argumentLengthCheck(arguments, 1, { header: 'FileReader.readAsBinaryString' })
blob = webidl.converters.Blob(blob, { strict: false })
// The readAsBinaryString(blob) method, when invoked,
// must initiate a read operation for blob with BinaryString.
readOperation(this, blob, 'BinaryString')
}
|
@see https://w3c.github.io/FileAPI/#dfn-readAsDataURL
@param {import('buffer').Blob} blob
|
readAsBinaryString
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
readAsText (blob, encoding = undefined) {
webidl.brandCheck(this, FileReader)
webidl.argumentLengthCheck(arguments, 1, { header: 'FileReader.readAsText' })
blob = webidl.converters.Blob(blob, { strict: false })
if (encoding !== undefined) {
encoding = webidl.converters.DOMString(encoding)
}
// The readAsText(blob, encoding) method, when invoked,
// must initiate a read operation for blob with Text and encoding.
readOperation(this, blob, 'Text', encoding)
}
|
@see https://w3c.github.io/FileAPI/#dfn-abort
|
readAsText
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
readAsDataURL (blob) {
webidl.brandCheck(this, FileReader)
webidl.argumentLengthCheck(arguments, 1, { header: 'FileReader.readAsDataURL' })
blob = webidl.converters.Blob(blob, { strict: false })
// The readAsDataURL(blob) method, when invoked, must
// initiate a read operation for blob with DataURL.
readOperation(this, blob, 'DataURL')
}
|
@see https://w3c.github.io/FileAPI/#dfn-abort
|
readAsDataURL
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
abort () {
// 1. If this's state is "empty" or if this's state is
// "done" set this's result to null and terminate
// this algorithm.
if (this[kState] === 'empty' || this[kState] === 'done') {
this[kResult] = null
return
}
// 2. If this's state is "loading" set this's state to
// "done" and set this's result to null.
if (this[kState] === 'loading') {
this[kState] = 'done'
this[kResult] = null
}
// 3. If there are any tasks from this on the file reading
// task source in an affiliated task queue, then remove
// those tasks from that task queue.
this[kAborted] = true
// 4. Terminate the algorithm for the read method being processed.
// TODO
// 5. Fire a progress event called abort at this.
fireAProgressEvent('abort', this)
// 6. If this's state is not "loading", fire a progress
// event called loadend at this.
if (this[kState] !== 'loading') {
fireAProgressEvent('loadend', this)
}
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-readystate
|
abort
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get readyState () {
webidl.brandCheck(this, FileReader)
switch (this[kState]) {
case 'empty': return this.EMPTY
case 'loading': return this.LOADING
case 'done': return this.DONE
}
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
readyState
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get onloadend () {
webidl.brandCheck(this, FileReader)
return this[kEvents].loadend
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onloadend
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
set onloadend (fn) {
webidl.brandCheck(this, FileReader)
if (this[kEvents].loadend) {
this.removeEventListener('loadend', this[kEvents].loadend)
}
if (typeof fn === 'function') {
this[kEvents].loadend = fn
this.addEventListener('loadend', fn)
} else {
this[kEvents].loadend = null
}
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onloadend
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get onerror () {
webidl.brandCheck(this, FileReader)
return this[kEvents].error
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onerror
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
set onerror (fn) {
webidl.brandCheck(this, FileReader)
if (this[kEvents].error) {
this.removeEventListener('error', this[kEvents].error)
}
if (typeof fn === 'function') {
this[kEvents].error = fn
this.addEventListener('error', fn)
} else {
this[kEvents].error = null
}
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onerror
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get onloadstart () {
webidl.brandCheck(this, FileReader)
return this[kEvents].loadstart
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onloadstart
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
set onloadstart (fn) {
webidl.brandCheck(this, FileReader)
if (this[kEvents].loadstart) {
this.removeEventListener('loadstart', this[kEvents].loadstart)
}
if (typeof fn === 'function') {
this[kEvents].loadstart = fn
this.addEventListener('loadstart', fn)
} else {
this[kEvents].loadstart = null
}
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onloadstart
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get onprogress () {
webidl.brandCheck(this, FileReader)
return this[kEvents].progress
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onprogress
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
set onprogress (fn) {
webidl.brandCheck(this, FileReader)
if (this[kEvents].progress) {
this.removeEventListener('progress', this[kEvents].progress)
}
if (typeof fn === 'function') {
this[kEvents].progress = fn
this.addEventListener('progress', fn)
} else {
this[kEvents].progress = null
}
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onprogress
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get onload () {
webidl.brandCheck(this, FileReader)
return this[kEvents].load
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onload
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
set onload (fn) {
webidl.brandCheck(this, FileReader)
if (this[kEvents].load) {
this.removeEventListener('load', this[kEvents].load)
}
if (typeof fn === 'function') {
this[kEvents].load = fn
this.addEventListener('load', fn)
} else {
this[kEvents].load = null
}
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onload
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get onabort () {
webidl.brandCheck(this, FileReader)
return this[kEvents].abort
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onabort
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
set onabort (fn) {
webidl.brandCheck(this, FileReader)
if (this[kEvents].abort) {
this.removeEventListener('abort', this[kEvents].abort)
}
if (typeof fn === 'function') {
this[kEvents].abort = fn
this.addEventListener('abort', fn)
} else {
this[kEvents].abort = null
}
}
|
@see https://w3c.github.io/FileAPI/#dom-filereader-error
|
onabort
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
constructor (type, eventInitDict = {}) {
type = webidl.converters.DOMString(type)
eventInitDict = webidl.converters.ProgressEventInit(eventInitDict ?? {})
super(type, eventInitDict)
this[kState] = {
lengthComputable: eventInitDict.lengthComputable,
loaded: eventInitDict.loaded,
total: eventInitDict.total
}
}
|
@see https://xhr.spec.whatwg.org/#progressevent
|
constructor
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function fireAProgressEvent (e, reader) {
// The progress event e does not bubble. e.bubbles must be false
// The progress event e is NOT cancelable. e.cancelable must be false
const event = new ProgressEvent(e, {
bubbles: false,
cancelable: false
})
reader.dispatchEvent(event)
}
|
@see https://w3c.github.io/FileAPI/#blob-package-data
@param {Uint8Array[]} bytes
@param {string} type
@param {string?} mimeType
@param {string?} encodingName
|
fireAProgressEvent
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
assertNoPendingInterceptors ({ pendingInterceptorsFormatter = new PendingInterceptorsFormatter() } = {}) {
const pending = this.pendingInterceptors()
if (pending.length === 0) {
return
}
const pluralizer = new Pluralizer('interceptor', 'interceptors').pluralize(pending.length)
throw new UndiciError(`
${pluralizer.count} ${pluralizer.noun} ${pluralizer.is} pending:
${pendingInterceptorsFormatter.format(pending)}
`.trim())
}
|
MockClient provides an API that extends the Client to influence the mockDispatches.
|
assertNoPendingInterceptors
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
intercept (opts) {
return new MockInterceptor(opts, this[kDispatches])
}
|
Defines the scope API for an interceptor reply
|
intercept
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
constructor (message) {
super(message)
Error.captureStackTrace(this, MockNotMatchedError)
this.name = 'MockNotMatchedError'
this.message = message || 'The request does not match any registered mock dispatches'
this.code = 'UND_MOCK_ERR_MOCK_NOT_MATCHED'
}
|
For a defined reply, never mark as consumed.
|
constructor
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
createMockScopeDispatchData (statusCode, data, responseOptions = {}) {
const responseData = getResponseData(data)
const contentLength = this[kContentLength] ? { 'content-length': responseData.length } : {}
const headers = { ...this[kDefaultHeaders], ...contentLength, ...responseOptions.headers }
const trailers = { ...this[kDefaultTrailers], ...responseOptions.trailers }
return { statusCode, data, headers, trailers }
}
|
Mock an undici request with a defined reply.
|
createMockScopeDispatchData
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
validateReplyParameters (statusCode, data, responseOptions) {
if (typeof statusCode === 'undefined') {
throw new InvalidArgumentError('statusCode must be defined')
}
if (typeof data === 'undefined') {
throw new InvalidArgumentError('data must be defined')
}
if (typeof responseOptions !== 'object') {
throw new InvalidArgumentError('responseOptions must be an object')
}
}
|
Mock an undici request with a defined reply.
|
validateReplyParameters
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
reply (replyData) {
// Values of reply aren't available right now as they
// can only be available when the reply callback is invoked.
if (typeof replyData === 'function') {
// We'll first wrap the provided callback in another function,
// this function will properly resolve the data from the callback
// when invoked.
const wrappedDefaultsCallback = (opts) => {
// Our reply options callback contains the parameter for statusCode, data and options.
const resolvedData = replyData(opts)
// Check if it is in the right format
if (typeof resolvedData !== 'object') {
throw new InvalidArgumentError('reply options callback must return an object')
}
const { statusCode, data = '', responseOptions = {} } = resolvedData
this.validateReplyParameters(statusCode, data, responseOptions)
// Since the values can be obtained immediately we return them
// from this higher order function that will be resolved later.
return {
...this.createMockScopeDispatchData(statusCode, data, responseOptions)
}
}
// Add usual dispatch data, but this time set the data parameter to function that will eventually provide data.
const newMockDispatch = addMockDispatch(this[kDispatches], this[kDispatchKey], wrappedDefaultsCallback)
return new MockScope(newMockDispatch)
}
// We can have either one or three parameters, if we get here,
// we should have 1-3 parameters. So we spread the arguments of
// this function to obtain the parameters, since replyData will always
// just be the statusCode.
const [statusCode, data = '', responseOptions = {}] = [...arguments]
this.validateReplyParameters(statusCode, data, responseOptions)
// Send in-already provided data like usual
const dispatchData = this.createMockScopeDispatchData(statusCode, data, responseOptions)
const newMockDispatch = addMockDispatch(this[kDispatches], this[kDispatchKey], dispatchData)
return new MockScope(newMockDispatch)
}
|
Mock an undici request with a defined reply.
|
reply
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
wrappedDefaultsCallback = (opts) => {
// Our reply options callback contains the parameter for statusCode, data and options.
const resolvedData = replyData(opts)
// Check if it is in the right format
if (typeof resolvedData !== 'object') {
throw new InvalidArgumentError('reply options callback must return an object')
}
const { statusCode, data = '', responseOptions = {} } = resolvedData
this.validateReplyParameters(statusCode, data, responseOptions)
// Since the values can be obtained immediately we return them
// from this higher order function that will be resolved later.
return {
...this.createMockScopeDispatchData(statusCode, data, responseOptions)
}
}
|
Mock an undici request with a defined reply.
|
wrappedDefaultsCallback
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
wrappedDefaultsCallback = (opts) => {
// Our reply options callback contains the parameter for statusCode, data and options.
const resolvedData = replyData(opts)
// Check if it is in the right format
if (typeof resolvedData !== 'object') {
throw new InvalidArgumentError('reply options callback must return an object')
}
const { statusCode, data = '', responseOptions = {} } = resolvedData
this.validateReplyParameters(statusCode, data, responseOptions)
// Since the values can be obtained immediately we return them
// from this higher order function that will be resolved later.
return {
...this.createMockScopeDispatchData(statusCode, data, responseOptions)
}
}
|
Mock an undici request with a defined reply.
|
wrappedDefaultsCallback
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
defaultReplyTrailers (trailers) {
if (typeof trailers === 'undefined') {
throw new InvalidArgumentError('trailers must be defined')
}
this[kDefaultTrailers] = trailers
return this
}
|
MockPool provides an API that extends the Pool to influence the mockDispatches.
|
defaultReplyTrailers
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
replyContentLength () {
this[kContentLength] = true
return this
}
|
MockPool provides an API that extends the Pool to influence the mockDispatches.
|
replyContentLength
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function deleteMockDispatch (mockDispatches, key) {
const index = mockDispatches.findIndex(dispatch => {
if (!dispatch.consumed) {
return false
}
return matchKey(dispatch, key)
})
if (index !== -1) {
mockDispatches.splice(index, 1)
}
}
|
Mock dispatch function used to simulate undici dispatches
|
deleteMockDispatch
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function buildKey (opts) {
const { path, method, body, headers, query } = opts
return {
path,
method,
body,
headers,
query
}
}
|
Mock dispatch function used to simulate undici dispatches
|
buildKey
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function generateKeyValues (data) {
return Object.entries(data).reduce((keyValuePairs, [key, value]) => [
...keyValuePairs,
Buffer.from(`${key}`),
Array.isArray(value) ? value.map(x => Buffer.from(`${x}`)) : Buffer.from(`${value}`)
], [])
}
|
Mock dispatch function used to simulate undici dispatches
|
generateKeyValues
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function getStatusText (statusCode) {
return STATUS_CODES[statusCode] || 'unknown'
}
|
Mock dispatch function used to simulate undici dispatches
|
getStatusText
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
async function getResponse (body) {
const buffers = []
for await (const data of body) {
buffers.push(data)
}
return Buffer.concat(buffers).toString('utf8')
}
|
Mock dispatch function used to simulate undici dispatches
|
getResponse
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function mockDispatch (opts, handler) {
// Get mock dispatch from built key
const key = buildKey(opts)
const mockDispatch = getMockDispatch(this[kDispatches], key)
mockDispatch.timesInvoked++
// Here's where we resolve a callback if a callback is present for the dispatch data.
if (mockDispatch.data.callback) {
mockDispatch.data = { ...mockDispatch.data, ...mockDispatch.data.callback(opts) }
}
// Parse mockDispatch data
const { data: { statusCode, data, headers, trailers, error }, delay, persist } = mockDispatch
const { timesInvoked, times } = mockDispatch
// If it's used up and not persistent, mark as consumed
mockDispatch.consumed = !persist && timesInvoked >= times
mockDispatch.pending = timesInvoked < times
// If specified, trigger dispatch error
if (error !== null) {
deleteMockDispatch(this[kDispatches], key)
handler.onError(error)
return true
}
// Handle the request with a delay if necessary
if (typeof delay === 'number' && delay > 0) {
setTimeout(() => {
handleReply(this[kDispatches])
}, delay)
} else {
handleReply(this[kDispatches])
}
function handleReply (mockDispatches, _data = data) {
// fetch's HeadersList is a 1D string array
const optsHeaders = Array.isArray(opts.headers)
? buildHeadersFromArray(opts.headers)
: opts.headers
const body = typeof _data === 'function'
? _data({ ...opts, headers: optsHeaders })
: _data
// util.types.isPromise is likely needed for jest.
if (isPromise(body)) {
// If handleReply is asynchronous, throwing an error
// in the callback will reject the promise, rather than
// synchronously throw the error, which breaks some tests.
// Rather, we wait for the callback to resolve if it is a
// promise, and then re-run handleReply with the new body.
body.then((newData) => handleReply(mockDispatches, newData))
return
}
const responseData = getResponseData(body)
const responseHeaders = generateKeyValues(headers)
const responseTrailers = generateKeyValues(trailers)
handler.abort = nop
handler.onHeaders(statusCode, responseHeaders, resume, getStatusText(statusCode))
handler.onData(Buffer.from(responseData))
handler.onComplete(responseTrailers)
deleteMockDispatch(mockDispatches, key)
}
function resume () {}
return true
}
|
Mock dispatch function used to simulate undici dispatches
|
mockDispatch
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function handleReply (mockDispatches, _data = data) {
// fetch's HeadersList is a 1D string array
const optsHeaders = Array.isArray(opts.headers)
? buildHeadersFromArray(opts.headers)
: opts.headers
const body = typeof _data === 'function'
? _data({ ...opts, headers: optsHeaders })
: _data
// util.types.isPromise is likely needed for jest.
if (isPromise(body)) {
// If handleReply is asynchronous, throwing an error
// in the callback will reject the promise, rather than
// synchronously throw the error, which breaks some tests.
// Rather, we wait for the callback to resolve if it is a
// promise, and then re-run handleReply with the new body.
body.then((newData) => handleReply(mockDispatches, newData))
return
}
const responseData = getResponseData(body)
const responseHeaders = generateKeyValues(headers)
const responseTrailers = generateKeyValues(trailers)
handler.abort = nop
handler.onHeaders(statusCode, responseHeaders, resume, getStatusText(statusCode))
handler.onData(Buffer.from(responseData))
handler.onComplete(responseTrailers)
deleteMockDispatch(mockDispatches, key)
}
|
Mock dispatch function used to simulate undici dispatches
|
handleReply
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function buildMockDispatch () {
const agent = this[kMockAgent]
const origin = this[kOrigin]
const originalDispatch = this[kOriginalDispatch]
return function dispatch (opts, handler) {
if (agent.isMockActive) {
try {
mockDispatch.call(this, opts, handler)
} catch (error) {
if (error instanceof MockNotMatchedError) {
const netConnect = agent[kGetNetConnect]()
if (netConnect === false) {
throw new MockNotMatchedError(`${error.message}: subsequent request to origin ${origin} was not allowed (net.connect disabled)`)
}
if (checkNetConnect(netConnect, origin)) {
originalDispatch.call(this, opts, handler)
} else {
throw new MockNotMatchedError(`${error.message}: subsequent request to origin ${origin} was not allowed (net.connect is not enabled for this origin)`)
}
} else {
throw error
}
}
} else {
originalDispatch.call(this, opts, handler)
}
}
}
|
Mock dispatch function used to simulate undici dispatches
|
buildMockDispatch
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
dispatch (opts, handler) {
const { host } = new URL(opts.origin)
const headers = buildHeaders(opts.headers)
throwIfProxyAuthIsSent(headers)
return this[kAgent].dispatch(
{
...opts,
headers: {
...headers,
host
}
},
handler
)
}
|
@param {Record<string, string>} headers
Previous versions of ProxyAgent suggests the Proxy-Authorization in request headers
Nevertheless, it was changed and to avoid a security vulnerability by end users
this check was created.
It should be removed in the next major version for performance reasons
|
dispatch
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function onSocketData (chunk) {
if (!this.ws[kByteParser].write(chunk)) {
this.pause()
}
}
|
@see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
@see https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.4
|
onSocketData
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function onSocketClose () {
const { ws } = this
// If the TCP connection was closed after the
// WebSocket closing handshake was completed, the WebSocket connection
// is said to have been closed _cleanly_.
const wasClean = ws[kSentClose] && ws[kReceivedClose]
let code = 1005
let reason = ''
const result = ws[kByteParser].closingInfo
if (result) {
code = result.code ?? 1005
reason = result.reason
} else if (!ws[kSentClose]) {
// If _The WebSocket
// Connection is Closed_ and no Close control frame was received by the
// endpoint (such as could occur if the underlying transport connection
// is lost), _The WebSocket Connection Close Code_ is considered to be
// 1006.
code = 1006
}
// 1. Change the ready state to CLOSED (3).
ws[kReadyState] = states.CLOSED
// 2. If the user agent was required to fail the WebSocket
// connection, or if the WebSocket connection was closed
// after being flagged as full, fire an event named error
// at the WebSocket object.
// TODO
// 3. Fire an event named close at the WebSocket object,
// using CloseEvent, with the wasClean attribute
// initialized to true if the connection closed cleanly
// and false otherwise, the code attribute initialized to
// the WebSocket connection close code, and the reason
// attribute initialized to the result of applying UTF-8
// decode without BOM to the WebSocket connection close
// reason.
fireEvent('close', ws, CloseEvent, {
wasClean, code, reason
})
if (channels.close.hasSubscribers) {
channels.close.publish({
websocket: ws,
code,
reason
})
}
}
|
@see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
@see https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.4
|
onSocketClose
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
constructor (type, eventInitDict = {}) {
webidl.argumentLengthCheck(arguments, 1, { header: 'MessageEvent constructor' })
type = webidl.converters.DOMString(type)
eventInitDict = webidl.converters.MessageEventInit(eventInitDict)
super(type, eventInitDict)
this.#eventInit = eventInitDict
}
|
@see https://html.spec.whatwg.org/multipage/comms.html#messageevent
|
constructor
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get data () {
webidl.brandCheck(this, MessageEvent)
return this.#eventInit.data
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
data
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get origin () {
webidl.brandCheck(this, MessageEvent)
return this.#eventInit.origin
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
origin
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get lastEventId () {
webidl.brandCheck(this, MessageEvent)
return this.#eventInit.lastEventId
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
lastEventId
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get source () {
webidl.brandCheck(this, MessageEvent)
return this.#eventInit.source
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
source
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get ports () {
webidl.brandCheck(this, MessageEvent)
if (!Object.isFrozen(this.#eventInit.ports)) {
Object.freeze(this.#eventInit.ports)
}
return this.#eventInit.ports
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
ports
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
initMessageEvent (
type,
bubbles = false,
cancelable = false,
data = null,
origin = '',
lastEventId = '',
source = null,
ports = []
) {
webidl.brandCheck(this, MessageEvent)
webidl.argumentLengthCheck(arguments, 1, { header: 'MessageEvent.initMessageEvent' })
return new MessageEvent(type, {
bubbles, cancelable, data, origin, lastEventId, source, ports
})
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
initMessageEvent
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
constructor (type, eventInitDict = {}) {
webidl.argumentLengthCheck(arguments, 1, { header: 'CloseEvent constructor' })
type = webidl.converters.DOMString(type)
eventInitDict = webidl.converters.CloseEventInit(eventInitDict)
super(type, eventInitDict)
this.#eventInit = eventInitDict
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
constructor
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get wasClean () {
webidl.brandCheck(this, CloseEvent)
return this.#eventInit.wasClean
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
wasClean
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get code () {
webidl.brandCheck(this, CloseEvent)
return this.#eventInit.code
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
code
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get reason () {
webidl.brandCheck(this, CloseEvent)
return this.#eventInit.reason
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
reason
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
constructor (type, eventInitDict) {
webidl.argumentLengthCheck(arguments, 1, { header: 'ErrorEvent constructor' })
super(type, eventInitDict)
type = webidl.converters.DOMString(type)
eventInitDict = webidl.converters.ErrorEventInit(eventInitDict ?? {})
this.#eventInit = eventInitDict
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
constructor
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get message () {
webidl.brandCheck(this, ErrorEvent)
return this.#eventInit.message
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
message
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get filename () {
webidl.brandCheck(this, ErrorEvent)
return this.#eventInit.filename
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
filename
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get lineno () {
webidl.brandCheck(this, ErrorEvent)
return this.#eventInit.lineno
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
lineno
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get colno () {
webidl.brandCheck(this, ErrorEvent)
return this.#eventInit.colno
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
colno
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get error () {
webidl.brandCheck(this, ErrorEvent)
return this.#eventInit.error
}
|
@see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
error
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
constructor (ws) {
super()
this.ws = ws
}
|
Runs whenever a new chunk is received.
Callback is called whenever there are no more chunks buffering,
or not enough bytes are buffered to parse.
|
constructor
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
_write (chunk, _, callback) {
this.#buffers.push(chunk)
this.#byteOffset += chunk.length
this.run(callback)
}
|
Runs whenever a new chunk is received.
Callback is called whenever there are no more chunks buffering,
or not enough bytes are buffered to parse.
|
_write
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
run (callback) {
while (true) {
if (this.#state === parserStates.INFO) {
// If there aren't enough bytes to parse the payload length, etc.
if (this.#byteOffset < 2) {
return callback()
}
const buffer = this.consume(2)
this.#info.fin = (buffer[0] & 0x80) !== 0
this.#info.opcode = buffer[0] & 0x0F
// If we receive a fragmented message, we use the type of the first
// frame to parse the full message as binary/text, when it's terminated
this.#info.originalOpcode ??= this.#info.opcode
this.#info.fragmented = !this.#info.fin && this.#info.opcode !== opcodes.CONTINUATION
if (this.#info.fragmented && this.#info.opcode !== opcodes.BINARY && this.#info.opcode !== opcodes.TEXT) {
// Only text and binary frames can be fragmented
failWebsocketConnection(this.ws, 'Invalid frame type was fragmented.')
return
}
const payloadLength = buffer[1] & 0x7F
if (payloadLength <= 125) {
this.#info.payloadLength = payloadLength
this.#state = parserStates.READ_DATA
} else if (payloadLength === 126) {
this.#state = parserStates.PAYLOADLENGTH_16
} else if (payloadLength === 127) {
this.#state = parserStates.PAYLOADLENGTH_64
}
if (this.#info.fragmented && payloadLength > 125) {
// A fragmented frame can't be fragmented itself
failWebsocketConnection(this.ws, 'Fragmented frame exceeded 125 bytes.')
return
} else if (
(this.#info.opcode === opcodes.PING ||
this.#info.opcode === opcodes.PONG ||
this.#info.opcode === opcodes.CLOSE) &&
payloadLength > 125
) {
// Control frames can have a payload length of 125 bytes MAX
failWebsocketConnection(this.ws, 'Payload length for control frame exceeded 125 bytes.')
return
} else if (this.#info.opcode === opcodes.CLOSE) {
if (payloadLength === 1) {
failWebsocketConnection(this.ws, 'Received close frame with a 1-byte body.')
return
}
const body = this.consume(payloadLength)
this.#info.closeInfo = this.parseCloseBody(false, body)
if (!this.ws[kSentClose]) {
// If an endpoint receives a Close frame and did not previously send a
// Close frame, the endpoint MUST send a Close frame in response. (When
// sending a Close frame in response, the endpoint typically echos the
// status code it received.)
const body = Buffer.allocUnsafe(2)
body.writeUInt16BE(this.#info.closeInfo.code, 0)
const closeFrame = new WebsocketFrameSend(body)
this.ws[kResponse].socket.write(
closeFrame.createFrame(opcodes.CLOSE),
(err) => {
if (!err) {
this.ws[kSentClose] = true
}
}
)
}
// Upon either sending or receiving a Close control frame, it is said
// that _The WebSocket Closing Handshake is Started_ and that the
// WebSocket connection is in the CLOSING state.
this.ws[kReadyState] = states.CLOSING
this.ws[kReceivedClose] = true
this.end()
return
} else if (this.#info.opcode === opcodes.PING) {
// Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in
// response, unless it already received a Close frame.
// A Pong frame sent in response to a Ping frame must have identical
// "Application data"
const body = this.consume(payloadLength)
if (!this.ws[kReceivedClose]) {
const frame = new WebsocketFrameSend(body)
this.ws[kResponse].socket.write(frame.createFrame(opcodes.PONG))
if (channels.ping.hasSubscribers) {
channels.ping.publish({
payload: body
})
}
}
this.#state = parserStates.INFO
if (this.#byteOffset > 0) {
continue
} else {
callback()
return
}
} else if (this.#info.opcode === opcodes.PONG) {
// A Pong frame MAY be sent unsolicited. This serves as a
// unidirectional heartbeat. A response to an unsolicited Pong frame is
// not expected.
const body = this.consume(payloadLength)
if (channels.pong.hasSubscribers) {
channels.pong.publish({
payload: body
})
}
if (this.#byteOffset > 0) {
continue
} else {
callback()
return
}
}
} else if (this.#state === parserStates.PAYLOADLENGTH_16) {
if (this.#byteOffset < 2) {
return callback()
}
const buffer = this.consume(2)
this.#info.payloadLength = buffer.readUInt16BE(0)
this.#state = parserStates.READ_DATA
} else if (this.#state === parserStates.PAYLOADLENGTH_64) {
if (this.#byteOffset < 8) {
return callback()
}
const buffer = this.consume(8)
const upper = buffer.readUInt32BE(0)
// 2^31 is the maxinimum bytes an arraybuffer can contain
// on 32-bit systems. Although, on 64-bit systems, this is
// 2^53-1 bytes.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/common/globals.h;drc=1946212ac0100668f14eb9e2843bdd846e510a1e;bpv=1;bpt=1;l=1275
// https://source.chromium.org/chromium/chromium/src/+/main:v8/src/objects/js-array-buffer.h;l=34;drc=1946212ac0100668f14eb9e2843bdd846e510a1e
if (upper > 2 ** 31 - 1) {
failWebsocketConnection(this.ws, 'Received payload length > 2^31 bytes.')
return
}
const lower = buffer.readUInt32BE(4)
this.#info.payloadLength = (upper << 8) + lower
this.#state = parserStates.READ_DATA
} else if (this.#state === parserStates.READ_DATA) {
if (this.#byteOffset < this.#info.payloadLength) {
// If there is still more data in this chunk that needs to be read
return callback()
} else if (this.#byteOffset >= this.#info.payloadLength) {
// If the server sent multiple frames in a single chunk
const body = this.consume(this.#info.payloadLength)
this.#fragments.push(body)
// If the frame is unfragmented, or a fragmented frame was terminated,
// a message was received
if (!this.#info.fragmented || (this.#info.fin && this.#info.opcode === opcodes.CONTINUATION)) {
const fullMessage = Buffer.concat(this.#fragments)
websocketMessageReceived(this.ws, this.#info.originalOpcode, fullMessage)
this.#info = {}
this.#fragments.length = 0
}
this.#state = parserStates.INFO
}
}
if (this.#byteOffset > 0) {
continue
} else {
callback()
break
}
}
}
|
Runs whenever a new chunk is received.
Callback is called whenever there are no more chunks buffering,
or not enough bytes are buffered to parse.
|
run
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isEstablished (ws) {
// If the server's response is validated as provided for above, it is
// said that _The WebSocket Connection is Established_ and that the
// WebSocket Connection is in the OPEN state.
return ws[kReadyState] === states.OPEN
}
|
@see https://dom.spec.whatwg.org/#concept-event-fire
@param {string} e
@param {EventTarget} target
@param {EventInit | undefined} eventInitDict
|
isEstablished
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isClosing (ws) {
// Upon either sending or receiving a Close control frame, it is said
// that _The WebSocket Closing Handshake is Started_ and that the
// WebSocket connection is in the CLOSING state.
return ws[kReadyState] === states.CLOSING
}
|
@see https://dom.spec.whatwg.org/#concept-event-fire
@param {string} e
@param {EventTarget} target
@param {EventInit | undefined} eventInitDict
|
isClosing
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isClosed (ws) {
return ws[kReadyState] === states.CLOSED
}
|
@see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
@param {import('./websocket').WebSocket} ws
@param {number} type Opcode
@param {Buffer} data application data
|
isClosed
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
function isValidSubprotocol (protocol) {
// If present, this value indicates one
// or more comma-separated subprotocol the client wishes to speak,
// ordered by preference. The elements that comprise this value
// MUST be non-empty strings with characters in the range U+0021 to
// U+007E not including separator characters as defined in
// [RFC2616] and MUST all be unique strings.
if (protocol.length === 0) {
return false
}
for (const char of protocol) {
const code = char.charCodeAt(0)
if (
code < 0x21 ||
code > 0x7E ||
char === '(' ||
char === ')' ||
char === '<' ||
char === '>' ||
char === '@' ||
char === ',' ||
char === ';' ||
char === ':' ||
char === '\\' ||
char === '"' ||
char === '/' ||
char === '[' ||
char === ']' ||
char === '?' ||
char === '=' ||
char === '{' ||
char === '}' ||
code === 32 || // SP
code === 9 // HT
) {
return false
}
}
return true
}
|
@see https://datatracker.ietf.org/doc/html/rfc6455#section-7-4
@param {number} code
|
isValidSubprotocol
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
close (code = undefined, reason = undefined) {
webidl.brandCheck(this, WebSocket)
if (code !== undefined) {
code = webidl.converters['unsigned short'](code, { clamp: true })
}
if (reason !== undefined) {
reason = webidl.converters.USVString(reason)
}
// 1. If code is present, but is neither an integer equal to 1000 nor an
// integer in the range 3000 to 4999, inclusive, throw an
// "InvalidAccessError" DOMException.
if (code !== undefined) {
if (code !== 1000 && (code < 3000 || code > 4999)) {
throw new DOMException('invalid code', 'InvalidAccessError')
}
}
let reasonByteLength = 0
// 2. If reason is present, then run these substeps:
if (reason !== undefined) {
// 1. Let reasonBytes be the result of encoding reason.
// 2. If reasonBytes is longer than 123 bytes, then throw a
// "SyntaxError" DOMException.
reasonByteLength = Buffer.byteLength(reason)
if (reasonByteLength > 123) {
throw new DOMException(
`Reason must be less than 123 bytes; received ${reasonByteLength}`,
'SyntaxError'
)
}
}
// 3. Run the first matching steps from the following list:
if (this[kReadyState] === WebSocket.CLOSING || this[kReadyState] === WebSocket.CLOSED) {
// If this's ready state is CLOSING (2) or CLOSED (3)
// Do nothing.
} else if (!isEstablished(this)) {
// If the WebSocket connection is not yet established
// Fail the WebSocket connection and set this's ready state
// to CLOSING (2).
failWebsocketConnection(this, 'Connection was closed before it was established.')
this[kReadyState] = WebSocket.CLOSING
} else if (!isClosing(this)) {
// If the WebSocket closing handshake has not yet been started
// Start the WebSocket closing handshake and set this's ready
// state to CLOSING (2).
// - If neither code nor reason is present, the WebSocket Close
// message must not have a body.
// - If code is present, then the status code to use in the
// WebSocket Close message must be the integer given by code.
// - If reason is also present, then reasonBytes must be
// provided in the Close message after the status code.
const frame = new WebsocketFrameSend()
// If neither code nor reason is present, the WebSocket Close
// message must not have a body.
// If code is present, then the status code to use in the
// WebSocket Close message must be the integer given by code.
if (code !== undefined && reason === undefined) {
frame.frameData = Buffer.allocUnsafe(2)
frame.frameData.writeUInt16BE(code, 0)
} else if (code !== undefined && reason !== undefined) {
// If reason is also present, then reasonBytes must be
// provided in the Close message after the status code.
frame.frameData = Buffer.allocUnsafe(2 + reasonByteLength)
frame.frameData.writeUInt16BE(code, 0)
// the body MAY contain UTF-8-encoded data with value /reason/
frame.frameData.write(reason, 2, 'utf-8')
} else {
frame.frameData = emptyBuffer
}
/** @type {import('stream').Duplex} */
const socket = this[kResponse].socket
socket.write(frame.createFrame(opcodes.CLOSE), (err) => {
if (!err) {
this[kSentClose] = true
}
})
// Upon either sending or receiving a Close control frame, it is said
// that _The WebSocket Closing Handshake is Started_ and that the
// WebSocket connection is in the CLOSING state.
this[kReadyState] = states.CLOSING
} else {
// Otherwise
// Set this's ready state to CLOSING (2).
this[kReadyState] = WebSocket.CLOSING
}
}
|
@see https://websockets.spec.whatwg.org/#dom-websocket-close
@param {number|undefined} code
@param {string|undefined} reason
|
close
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get onclose () {
webidl.brandCheck(this, WebSocket)
return this.#events.close
}
|
@see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
onclose
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
set onclose (fn) {
webidl.brandCheck(this, WebSocket)
if (this.#events.close) {
this.removeEventListener('close', this.#events.close)
}
if (typeof fn === 'function') {
this.#events.close = fn
this.addEventListener('close', fn)
} else {
this.#events.close = null
}
}
|
@see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
onclose
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get onmessage () {
webidl.brandCheck(this, WebSocket)
return this.#events.message
}
|
@see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
onmessage
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
set onmessage (fn) {
webidl.brandCheck(this, WebSocket)
if (this.#events.message) {
this.removeEventListener('message', this.#events.message)
}
if (typeof fn === 'function') {
this.#events.message = fn
this.addEventListener('message', fn)
} else {
this.#events.message = null
}
}
|
@see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
onmessage
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
get binaryType () {
webidl.brandCheck(this, WebSocket)
return this[kBinaryType]
}
|
@see https://websockets.spec.whatwg.org/#feedback-from-the-protocol
|
binaryType
|
javascript
|
vercel/next.js
|
.github/actions/next-integration-stat/dist/index.js
|
https://github.com/vercel/next.js/blob/master/.github/actions/next-integration-stat/dist/index.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.