0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
Commit graph

674 commits

Author SHA1 Message Date
Luca Casonato
c061538417
refactor(ext/net): clean up variadic network ops (#16392)
Previously `op_net_listen`, `op_net_accept`, and various other ops in
ext/net where variadic on the transport. This created a lot of code
bloat. This commit updates the code to instead have separate ops for
each transport.
2022-10-24 14:55:39 +02:00
Marcos Casagrande
f38666f5a3
fix(ext/fetch): fix size_hint on response body resource (#16254) 2022-10-24 13:26:41 +02:00
Marcos Casagrande
b7d86b4bed
perf(ext/streams): fast path when consuming body of tee'd stream (#16329)
Add a fast path for consuming the body of cloned `Request`/`Response`,
which is very common specially when using `cache` API.
2022-10-24 13:13:20 +02:00
Gianluca Oldani
873a5ce2ed
feat(ext/net): add reuseAddress option for UDP (#13849)
This commit adds a `reuseAddress` option for UDP sockets. When this
option is enabled, one can listen on an address even though it is
already being listened on from a different process or thread. The new
socket will steal the address from the existing socket.

On Windows and Linux this uses the `SO_REUSEADDR` option, while on other
Unixes this is done with `SO_REUSEPORT`.

This behavior aligns with what libuv does.

TCP sockets still unconditionally set the `SO_REUSEADDR` flag - this
behavior matches Node.js and Go. This PR does not change this behaviour.

Co-authored-by: Luca Casonato <hello@lcas.dev>
2022-10-24 09:05:07 +00:00
Luca Casonato
38213f1142
fix(ext/net): don't remove sockets on unix listen (#16394)
When listening on a UNIX socket path, Deno currently tries to unlink
this path prior to actually listening. The implementation of this
behaviour is VERY racy, involves 2 additional syscalls, and does not
match the behaviour of any other runtime (Node.js, Go, Rust, etc).

This commit removes this behaviour. If a user wants to listen on an
existing socket, they must now unlink the file themselves prior to
listening.

This change in behaviour only impacts --unstable APIs, so it is not
a breaking change.
2022-10-24 00:45:45 +02:00
Marcos Casagrande
0e1167d12d
perf(ext/web/encoding): avoid copy in decode (#16364) 2022-10-23 21:09:15 +02:00
David Sherret
bcfe279fba
feat(unstable/npm): initial type checking of npm specifiers (#16332) 2022-10-21 15:20:18 +00:00
Divy Srivastava
0f27b84a5c
chore(core): remove core.opSync (#16379)
This patch removes the last uses of `core.opSync` from Deno.

The new and JIT-friendly way to call sync ops is `core.ops.op_name()`.
2022-10-21 19:35:23 +05:30
Bartek Iwańczuk
869acee8fb
chore: upgrade rusty_v8 to 0.54.0 (#16368)
<!--
Before submitting a PR, please read http://deno.land/manual/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
-->
2022-10-20 21:01:49 +02:00
Divy Srivastava
bfc1fb8d68
perf(serde_v8): serde_v8::StringOrBuffer return JS ArrayBuffer instead of Uint8Array (#16360)
Towards #16315
2022-10-20 16:03:57 +05:30
Aapo Alasuutari
e2be70b035
feat(ext/ffi): Make op_ffi_ptr_of fast (#16297)
Makes `op_ffi_ptr_of` fast. One of the tests changed from printing
`false` to `true` as the fast `&[u8]` slice path creates the slice with
a null pointer. Thus the `op_ffi_ptr_of` will now return a null pointer
value whereas previously it returned a dangling pointer value.
2022-10-20 09:37:37 +05:30
Aapo Alasuutari
722ea20e86
perf(ext/ffi): Fast UnsafePointerView read functions (#16351)
This PR makes pointer read methods of `Deno.UnsafePointerView` Fast API
compliant, with the exception of `getCString` which cannot be made fast
with current V8 Fast API.
2022-10-20 09:35:56 +05:30
Divy Srivastava
e3a3095481
perf(ext/websocket): optimize op_ws_next_event (#16325)
Towards https://github.com/denoland/deno/issues/16315
2022-10-19 17:20:41 +05:30
Divy Srivastava
743fcc0668
perf(ext/flash): optimize path response streams (#16284)
Regression caused by https://github.com/denoland/deno/pull/15591
2022-10-19 16:41:47 +05:30
Divy Srivastava
36307c45e9
perf(ext/websocket): optimize socket.send (#16320)
Towards #16315
2022-10-19 16:23:13 +05:30
Yusuke Tanaka
44a89dd6dc
fix(ext/net): return an error from startTls and serveHttp if the original connection is captured elsewhere (#16242)
This commit removes the calls to `expect()` on `std::rc::Rc`, which caused
Deno to panic under certain situations. We now return an error if `Rc`
is referenced by other variables.

Fixes #9360
Fixes #13345
Fixes #13926
Fixes #16241

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2022-10-18 11:28:27 +09:00
Bartek Iwańczuk
204c46dcc1
chore: forward v1.26.2 to main (#16331)
Co-authored-by: bartlomieju <bartlomieju@users.noreply.github.com>

<!--
Before submitting a PR, please read http://deno.land/manual/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
-->

Co-authored-by: denobot <33910674+denobot@users.noreply.github.com>
Co-authored-by: bartlomieju <bartlomieju@users.noreply.github.com>
2022-10-17 23:11:16 +02:00
Marcos Casagrande
d0e78ca5c6
fix(ext/fetch): set accept-encoding: identity if range header is present (#16197)
https://fetch.spec.whatwg.org/#http-network-or-cache-fetch

> If httpRequest’s header list contains `Range`, then append
(`Accept-Encoding`, `identity`)
> to httpRequest’s header list.
> 
> This avoids a failure when handling content codings with a part of an
encoded response.
> Additionally, many servers mistakenly ignore `Range` headers if a
non-identity encoding is accepted.
2022-10-17 15:39:41 +02:00
Divy Srivastava
4c9dd33e27
perf(ext/web): optimize timer cancellation (#16316)
Towards #16315 

It created a bunch of Error objects and rejected the promise. This patch
changes `op_sleep` to resolve with `true` if it was cancelled.
2022-10-17 16:59:16 +05:30
Divy Srivastava
0dc2f02dfa
perf(ext/web): optimize op_cancel_handle (#16318)
Towards #16315
2022-10-17 16:12:05 +05:30
Marcos Casagrande
5252ff5dbd
fix(ext/cache): illegal constructor (#16205) 2022-10-16 23:03:17 +05:30
Bartek Iwańczuk
40009ebc94
fix(npm): disable loading native module for "fsevents" package (#16273)
Currently causes a hang in Vite, disable this one specific package
as remaining tests for NAPI in various modules work fine.
2022-10-16 15:03:38 +02:00
David Sherret
4ea4d3ad60
chore: fix windows-only clippy errors (#16289) 2022-10-15 13:56:54 +00:00
Aapo Alasuutari
75acec0aea
fix(ext/ffi): Fix UnsafeCallback ref'ing making Deno enter a live-loop (#16216)
Fixes #15136

Currently `UnsafeCallback` class' `ref()` and `unref()` methods rely on
the `event_loop_middleware` implementation in core. If even a single
`UnsafeCallback` is ref'ed, then the FFI event loop middleware will
always return `true` to signify that there may still be more work for
the event loop to do.

The middleware handling in core does not wait a moment to check again,
but will instead synchronously directly re-poll the event loop and
middlewares for more work. This becomes a live-loop.

This PR introduces a `Future` implementation for the `CallbackInfo`
struct that acts as the intermediary data storage between an
`UnsafeCallback` and the `libffi` C callback. Ref'ing a callback now
means calling an async op that binds to the `CallbackInfo` Future and
only resolves once the callback is unref'ed. The `libffi` C callback
will call the waker of this Future when it fires to make sure that the
main thread wakes up to receive the callback.
2022-10-15 19:19:46 +05:30
Aapo Alasuutari
9c7a5c0c61
fix(ext/websocket): panic on no next ws message from an already closed stream (#16004) 2022-10-15 11:08:09 +02:00
Filip Skokan
225d516466
fix(ext/crypto): correct HMAC get key length op (#16201)
fixes #16180

`HMAC`'s `get key length` `op` uses the hash function's block size, not
output size.

refs
https://github.com/cloudflare/workerd/issues/68#issuecomment-1271189657
2022-10-15 10:53:35 +05:30
Marcos Casagrande
e6e2898190
fix(ext/web/streams): enqueue to second branch before closing (#16269)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2022-10-14 09:51:39 +00:00
Marcos Casagrande
0d6dbc08be
fix(ext/fetch): throw TypeError on non-Uint8Array chunk (#16262) 2022-10-14 11:38:17 +02:00
Marcos Casagrande
50c7b89369
fix(ext/web/streams): resolve cancelPromise in ReadableStreamTee (#16266) 2022-10-14 11:29:01 +02:00
Aapo Alasuutari
17271532d4
fix(ext/ffi): Invalid 'function' return type check logic, remove U32x2 as unnecessary (#16259)
The return type checking for `"function"` type FFI values was incorrect
and presumed that functions were still being registered as objects
containing a "function" key.

While here, I also removed the whole return type checking logic as it
was needed for optionally creating BigInts on return when needed, but
serde_v8 does this automatically now (I think).
2022-10-13 17:36:52 +05:30
Xiao Xiao
ba3d0da6ab
chore(ext/web): fix typo (#16248)
implictly -> implicitly
assiging -> assigning
2022-10-12 07:47:15 +00:00
Marcos Casagrande
d47b17d37d
fix(ext/fetch): throw TypeError on read failure (#16219) 2022-10-12 09:23:33 +02:00
Marcos Casagrande
0cd05d7377
fix(ext/fetch): fix illegal header regex (#16236)
This PR fixes invalid header parsing which is flaky because `g` flag is
being used in the regex, which keeps track of `lastIndex`

```javascript
try {
  new Headers([["x", "\u0000x"]]);  // error
} catch(e) {}
new Headers([["x", "\u0000x"]]); // no error
```

This issue affects `Response` & `Request` constructors as well
2022-10-10 12:06:50 -04:00
sigmaSd
70ad6717df
fix sparse array inspection (#16204)
fix https://github.com/denoland/deno/issues/16202
2022-10-10 10:22:21 -04:00
Luca Casonato
1ab3691b09
feat(core): add Deno.core.writeAll(rid, chunk) (#16228)
This commit adds a new op_write_all to core that allows writing an
entire chunk in a single async op call. Internally this calls
`Resource::write_all`.

The `writableStreamForRid` has been moved to `06_streams.js` now, and
uses this new op. Various other code paths now also use this new op.

Closes #16227
2022-10-10 10:28:35 +02:00
Satya Rohith
4d6aed1b52
perf(ext/cache): set journal_mode=wal (#16231) 2022-10-10 13:05:57 +05:30
Luca Casonato
3b6b75bb46
feat(core): improve resource read & write traits (#16115)
This commit introduces two new buffer wrapper types to `deno_core`. The
main benefit of these new wrappers is that they can wrap a number of
different underlying buffer types. This allows for a more flexible read
and write API on resources that will require less copying of data
between different buffer representations.

- `BufView` is a read-only view onto a buffer. It can be backed by
`ZeroCopyBuf`, `Vec<u8>`, and `bytes::Bytes`.
- `BufViewMut` is a read-write view onto a buffer. It can be cheaply
converted into a `BufView`. It can be backed by `ZeroCopyBuf` or
`Vec<u8>`.

Both new buffer views have a cursor. This means that the start point of
the view can be constrained to write / read from just a slice of the
view. Only the start point of the slice can be adjusted. The end point
is fixed. To adjust the end point, the underlying buffer needs to be
truncated.

Readable resources have been changed to better cater to resources that
do not support BYOB reads. The basic `read` method now returns a
`BufView` instead of taking a `ZeroCopyBuf` to fill. This allows the
operation to return buffers that the resource has already allocated,
instead of forcing the caller to allocate the buffer. BYOB reads are
still very useful for resources that support them, so a new `read_byob`
method has been added that takes a `BufViewMut` to fill. `op_read`
attempts to use `read_byob` if the resource supports it, which falls
back to `read` and performs an additional copy if it does not. For
Rust->JS reads this change should have no impact, but for Rust->Rust
reads, this allows the caller to avoid an additional copy in many
scenarios. This combined with the support for `BufView` to be backed by
`bytes::Bytes` allows us to avoid one data copy when piping from a
`fetch` response into an `ext/http` response.

Writable resources have been changed to take a `BufView` instead of a
`ZeroCopyBuf` as an argument. This allows for less copying of data in
certain scenarios, as described above. Additionally a new
`Resource::write_all` method has been added that takes a `BufView` and
continually attempts to write the resource until the entire buffer has
been written. Certain resources like files can override this method to
provide a more efficient `write_all` implementation.
2022-10-09 14:49:25 +00:00
Divy Srivastava
a622c5df27
perf(ext/crypto): optimize getRandomValues (#16212) 2022-10-09 15:38:38 +05:30
Marcos Casagrande
cc3e2b9b1a
fix(ext/fetch): reject immediately on aborted signal (#16190)
Enabled the following test:

edc428e8e2/fetch/api/abort/general.any.js (L185-L201)
2022-10-08 16:08:47 -04:00
Marcos Casagrande
a5d55fe6ea
fix(ext/fetch): support empty formdata (#16165)
This PR adds support for empty `FormData` parsing in
`Response`/`Request`

```js
new Response(new FormData()).formData()
```

ref: https://github.com/web-platform-tests/wpt/issues/28607
2022-10-07 13:59:30 +02:00
Aapo Alasuutari
19e4e821d5
fix(ext/ffi): Fix usize and isize FFI callback parameters missing match arm (#16172)
Mea culpa. Back when I re-introduced parameter and return value types to
FFI callbacks I failed to properly account for the change in match arm
logic. As a result, usize and isize parameters in FFI callbacks
currently enter the branch meant for void only.

This PR changes the match arms to all be explicit, making sure that void
is the only arm marked unreachable and that it stays that way.
2022-10-07 10:20:18 +05:30
Colin Ihrig
c27234888f
fix(napi): move napi symbols file (#16179)
The current location was causing failures during v1.26.1 publication.

<!--
Before submitting a PR, please read http://deno.land/manual/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
-->
2022-10-07 09:21:43 +05:30
Divy Srivastava
5a1ea586b4
refactor(napi): simplify napi_value interface (#16170) 2022-10-07 09:21:08 +05:30
denobot
afeacb8328
chore: forward v1.26.1 release commit to main (#16178)
This is the release commit being forwarded back to main for 1.26.1

Please ensure:
- [x] Everything looks ok in the PR
- [x] The release has been published

To make edits to this PR:
```shell
git fetch upstream forward_v1.26.1 && git checkout -b forward_v1.26.1 upstream/forward_v1.26.1
```

Don't need this PR? Close it.

cc @cjihrig

Co-authored-by: cjihrig <cjihrig@users.noreply.github.com>
2022-10-06 16:49:40 -04:00
Marcos Casagrande
b487027b45
refactor(ext/fetch): simplify parseContentDisposition (#16162)
Replaced `forEach`, `map`, `filter`, `map` with a single `for` loop
2022-10-05 12:31:36 -04:00
Divy Srivastava
0b016a7fb8
feat(npm): implement Node API (#13633)
This PR implements the NAPI for loading native modules into Deno. 

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: DjDeveloper <43033058+DjDeveloperr@users.noreply.github.com>
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
2022-10-05 19:36:44 +05:30
Marcos Casagrande
3a3a848406
fix(ext/cache): prevent cache insert if body is not fully written (#16138) 2022-10-05 16:31:24 +05:30
ayame113
b5425ae2d3
fix(ext/flash): Avoid sending Content-Length when status code is 204 (#15901)
Currently Content-Length is sent when the status code is 204. However,
according to the spec, this should not be sent.
Modify the if statement below to prevent the Content-Length from being
sent.
2022-10-05 12:21:59 +05:30
Marcos Casagrande
569287b15b
perf(ext/fetch): consume body using ops (#16038)
This commit adds a fast path to `Request` and `Response` that
make consuming request bodies much faster when using `Body#text`,
`Body#arrayBuffer`, and `Body#blob`, if the body is a FastStream.
Because the response bodies for `fetch` are FastStream, this speeds up
consuming `fetch` response bodies significantly.
2022-10-04 15:48:50 +02:00
Filip Skokan
0d042d8e54
fix(ext/crypto): interoperable import/export (#16153)
This PR updates RSA key import/export to a state which is interoperable
with other implementations.

For RSA the only OID in and out is `rsaEncryption`.
For EC the only OID in and out is `id-ecpublickey` (fixed in #16152).

see https://github.com/w3c/webcrypto/issues/307#issuecomment-995813032
see https://github.com/w3c/webcrypto/issues/307
see https://github.com/w3c/webcrypto/pull/305
see https://github.com/nodejs/node/pull/42816
2022-10-04 17:37:59 +05:30