Skip to content

Commit

Permalink
update spec & wpts (nodejs#2482)
Browse files Browse the repository at this point in the history
* update spec & wpts

restore fetch error

debug time

* fix some test failures for others!!

* fix some test failures for others!!

* fix most remaining failures

* fix remaining WPT fail

* fix fetching blob

* mark websocket WPTs as failing
  • Loading branch information
KhafraDev authored and crysmags committed Feb 27, 2024
1 parent 1b66374 commit 54d263c
Show file tree
Hide file tree
Showing 218 changed files with 4,367 additions and 1,489 deletions.
7 changes: 4 additions & 3 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ async function * convertIterableToBuffer (iterable) {
}
}

/** @type {globalThis['ReadableStream']} */
let ReadableStream
function ReadableStreamFrom (iterable) {
if (!ReadableStream) {
Expand Down Expand Up @@ -395,9 +396,9 @@ function ReadableStreamFrom (iterable) {
},
async cancel (reason) {
await iterator.return()
}
},
0
},
type: 'bytes'
}
)
}

Expand Down
21 changes: 14 additions & 7 deletions lib/fetch/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@ function extractBody (object, keepalive = false) {
stream = object.stream()
} else {
// 4. Otherwise, set stream to a new ReadableStream object, and set
// up stream.
// up stream with byte reading support.
stream = new ReadableStream({
async pull (controller) {
controller.enqueue(
typeof source === 'string' ? textEncoder.encode(source) : source
)
const buffer = typeof source === 'string' ? textEncoder.encode(source) : source

if (buffer.byteLength) {
controller.enqueue(buffer)
}

queueMicrotask(() => readableStreamClose(controller))
},
start () {},
type: undefined
type: 'bytes'
})
}

Expand Down Expand Up @@ -223,21 +226,25 @@ function extractBody (object, keepalive = false) {
// When running action is done, close stream.
queueMicrotask(() => {
controller.close()
controller.byobRequest?.respond(0)
})
} else {
// Whenever one or more bytes are available and stream is not errored,
// enqueue a Uint8Array wrapping an ArrayBuffer containing the available
// bytes into stream.
if (!isErrored(stream)) {
controller.enqueue(new Uint8Array(value))
const buffer = new Uint8Array(value)
if (buffer.byteLength) {
controller.enqueue(buffer)
}
}
}
return controller.desiredSize > 0
},
async cancel (reason) {
await iterator.return()
},
type: undefined
type: 'bytes'
})
}

Expand Down
8 changes: 7 additions & 1 deletion lib/fetch/dataURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ function URLSerializer (url, excludeFragment = false) {
const href = url.href
const hashLength = url.hash.length

return hashLength === 0 ? href : href.substring(0, href.length - hashLength)
const serialized = hashLength === 0 ? href : href.substring(0, href.length - hashLength)

if (!hashLength && href.endsWith('#')) {
return serialized.slice(0, -1)
}

return serialized
}

// https://infra.spec.whatwg.org/#collect-a-sequence-of-code-points
Expand Down

0 comments on commit 54d263c

Please sign in to comment.