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

254 commits

Author SHA1 Message Date
Bartek Iwańczuk
bef50416b9
fix(core): don't allow to import internal code is snapshot is loaded (#17694)
Addressing Luca concerns from
https://github.com/denoland/deno/pull/17648#discussion_r1099352286
2023-02-08 18:13:33 +01:00
Bartek Iwańczuk
161a4fea47
refactor(core): change SourcePair to ExtensionFileSource (#17686) 2023-02-08 00:21:43 +01:00
Leo Kettmeir
b4aa153097
refactor: Use ES modules for internal runtime code (#17648)
This PR refactors all internal js files (except core) to be written as
ES modules.
`__bootstrap`has been mostly replaced with static imports in form in
`internal:[path to file from repo root]`.
To specify if files are ESM, an `esm` method has been added to
`Extension`, similar to the `js` method.
A new ModuleLoader called `InternalModuleLoader` has been added to
enable the loading of internal specifiers, which is used in all
situations except when a snapshot is only loaded, and not a new one is
created from it.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-02-07 20:22:46 +01:00
Bartek Iwańczuk
65500f36e8
chore: upgrade rusty_v8 to 0.62.2 (#17604)
Co-authored-by: Bert Belder <bertbelder@gmail.com>
2023-02-07 13:36:41 +01:00
Leo Kettmeir
fd511d5755
refactor: create JsRuntime outside of run_in_task (#17667) 2023-02-06 13:49:26 +00:00
Leo Kettmeir
84a96110cd
refactor: rename deno specifiers to internal (#17655) 2023-02-05 17:49:20 +01:00
Bartek Iwańczuk
3f8c217bb1
Revert "chore(core): remove have_unpolled_ops on rt state (#17601)" (#17631)
This reverts commit e85ca8be0d.

This commit caused a huge spike in various benchmarks we track at
https://deno.land/benchmarks
2023-02-03 00:24:20 +01:00
Luca Casonato
e85ca8be0d
chore(core): remove have_unpolled_ops on rt state (#17601)
It's not needed - `!state.have_unpolled_ops.is_empty()` does the same
thing.

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-01-31 01:17:51 +01:00
David Sherret
f5840bdcd3
chore: upgrade to Rust 1.67 (#17548)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-01-27 10:43:16 -05:00
Ikko Eltociear Ashimine
67a3b5f72a
chore(core): fix typo in runtime.rs (#17537)
determinstic -> deterministic
2023-01-26 06:54:01 +00:00
Bartek Iwańczuk
8b7023bc7e
Revert "chore: upgrade rusty_v8 to 0.62.0 (#17200)" (#17523)
This reverts commit e2d75491d5.
2023-01-25 15:36:10 +01:00
Bartek Iwańczuk
e2d75491d5
chore: upgrade rusty_v8 to 0.62.0 (#17200) 2023-01-25 12:22:27 +00:00
Leo Kettmeir
f85b006628
refactor: cleanup ModuleMap (#17469)
- changes module id to be usize & 0 based instead of 1 based
- merges `ids_by_handle` & `handles_by_id` to be a single `handles`
vector
- removes `next_module_id`, as vector is used
- turns `info` into a vector
2023-01-19 13:47:41 +01:00
Leo Kettmeir
8dbf7d7866
feat: ES module snapshotting (#17460)
This commit adds support for snapshotting ES modules. This is done by
adding an ability to serialize and deserialize a "ModuleMap" and attach
it
to the snapshot, using "add_context_data" API.

This has been tested with 400 modules and seems to not have a limit on
the number of modules that might be snapshotted.

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-01-19 10:00:35 +01:00
Andreu Botella
f0c79a676c
refactor(core): Move pending_promise_rejections to ContextState (#17447)
This is a requirement before supporting modules in realms.
2023-01-16 22:06:42 +05:30
Bartek Iwańczuk
40134ffc99
refactor(core): rename pending_promise_exception to pending_promise_rejection (#17441)
These are technically rejections - a rejection can then raise an
exception.
2023-01-16 15:19:04 +00:00
Divy Srivastava
d5634164cb
chore: use rustfmt imports_granularity option (#17421)
Closes https://github.com/denoland/deno/issues/2699
Closes https://github.com/denoland/deno/issues/2347

Uses unstable rustfmt features. Since dprint invokes `rustfmt` we do not
need to switch the cargo toolchain to nightly. Do we care about
formatting stability of our codebase across Rust versions? (I don't)
2023-01-14 23:18:58 -05:00
Andreu Botella
05ef925eb0
refactor(core): Move optional callbacks from JsRuntimeState to ContextState (#17422)
The `JsRuntimeState` struct stores a number of JS callbacks that are
used either in the event loop or when interacting with V8. Some of these
callback fields are vectors of callbacks, and therefore could plausibly
store at least one callback per realm. However, some of those fields are
`Option<v8::Global<v8::Function>>`, which would make the callbacks set
by a realm override the one that might have been set by a different
realm.

As it turns out, all of the current such optional callbacks
(`js_promise_reject_cb`, `js_format_exception_cb` and
`js_wasm_streaming_cb`) are only used from inside a realm, and therefore
this change makes it so such callbacks can only be set from inside a
realm, and will only affect that realm.

This is a reland of #15599.

Towards #13239.
2023-01-15 09:09:00 +05:30
Andreu Botella
68782346d0
feat(core): Reland support for async ops in realms (#17204)
Currently realms are supported on `deno_core`, but there was no support
for async ops anywhere other than the main realm. The main issue is that
the `js_recv_cb` callback, which resolves promises corresponding to
async ops, was only set for the main realm, so async ops in other realms
would never resolve. Furthermore, promise ID's are specific to each
realm, which meant that async ops from other realms would result in a
wrong promise from the main realm being resolved.

This change takes the `ContextState` struct added in #17050, and adds to
it a `js_recv_cb` callback for each realm. Combined with the fact that
that same PR also added a list of known realms to `JsRuntimeState`, and
that #17174 made `OpCtx` instances realm-specific and had them include
an index into that list of known realms, this makes it possible to know
the current realm in the `queue_async_op` and `queue_fast_async_op`
methods, and therefore to send the results of promises for each realm to
that realm, and prevent the ID's from getting mixed up.

Additionally, since promise ID's are no longer unique to the isolate,
having a single set of unrefed ops doesn't work. This change therefore
also moves `unrefed_ops` from `JsRuntimeState` to `ContextState`, and
adds the lengths of the unrefed op sets for all known realms to get the
total number of unrefed ops to compare in the event loop.

This PR is a reland of #14734 after it was reverted in #16366, except
that `ContextState` and `JsRuntimeState::known_realms` were previously
relanded in #17050. Another significant difference with the original PR
is passing around an index into `JsRuntimeState::known_realms` instead
of a `v8::Global<v8::Context>` to identify the realm, because async op
queuing in fast calls cannot call into V8, and therefore cannot have
access to V8 globals. This also simplified the implementation of
`resolve_async_ops`.

Co-authored-by: Luis Malheiro <luismalheiro@gmail.com>
2023-01-14 14:40:16 +01:00
Bartek Iwańczuk
636352e0ca
fix(npm): allow to read package.json if permissions are granted (#17209)
This commit changes signature of "deno_core::ModuleLoader::resolve" to pass
an enum indicating whether or not we're resolving a specifier for dynamic import.

Additionally "CliModuleLoader" was changes to store both "parent permissions" (or
"root permissions") as well as "dynamic permissions" that allow to check for permissions
in top-level module load an dynamic imports.

Then all code paths that have anything to do with Node/npm compat are now checking
for permissions which are passed from module loader instance associated with given
worker.
2023-01-10 14:35:44 +01:00
Leo Kettmeir
c41d4ff90e
feat(core): allow specifying name and dependencies of an Extension (#17301) 2023-01-08 23:48:46 +01:00
David Sherret
10e4b2e140
chore: update copyright year to 2023 (#17247)
Yearly tradition of creating extra noise in git.
2023-01-02 21:00:42 +00:00
Andreu Botella
a67fd3e23e
chore(core): Make OpCtx instances be realm-specific (#17174) 2022-12-26 17:00:13 +01:00
Bartek Iwańczuk
208c91b68f
fix(core): run macrotasks and next ticks after polling dynamic imports (#17173)
This commit fixes handling of rejected promises in dynamic imports
evaluation.

Previously we were running callbacks for next ticks and macrotasks
_before_ polling
dynamic imports and checked for unhandled rejections immediately after.
This is wrong,
as `unhandledrejection` event is dispatched and its callbacks are run as
macrotasks.

This commit changes order of actions performed by the event loop to
following:
- poll async ops
- poll dynamic imports
- run next tick callbacks
- run macrotask callbacks
- check for unhandled promise rejections
2022-12-23 19:46:24 +01:00
Andreu Botella
fcca54d3ba
fix(core): Have custom errors be created in the right realm (#17050)
Although PR #16366 did not fully revert `deno_core`'s support for
realms, since `JsRealm` still existed after that, it did remove the
`ContextState` struct, originally introduced in #14734. This change made
`js_build_custom_error_cb`, among other properties, a per-runtime
callback, rather than per-realm, which cause a bug where errors thrown
from an op would always be constructed in the main realm, rather than in
the current one.

This change adds back `ContextState` to fix this bug, adds back the
`known_realms` field of `JsRuntimeState` (needed to be able to drop the
callback when snapshotting), and also relands #14750, which adds the
`js_realm_sync_ops` test for this bug that was removed in #16366.
2022-12-20 20:09:16 +01:00
Leo Kettmeir
1d18b65edc
fix(runtime): expose extensions_with_js from WorkerOptions (#17109)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2022-12-19 03:55:50 +01:00
linbingquan
f46df3e359
chore: update to Rust 1.66.0 (#17078) 2022-12-17 23:20:15 +01:00
Andreu Botella
bb8a49993b
chore(core): Small realm-related fixes (#17044)
- `JsRuntime::built_from_snapshot` was removed because it was redundant
with `JsRuntime::snapshot_options`.
- Updates to stale documentation of `JsRuntime::create_realm`.
- `JsRuntime::create_realm` now calls `JsRuntime::init_extension_js`
unconditionally, since if the runtime was built from a snapshot,
`init_extension_js` will be a no-op.
- Typo fix in the documentation for `JsRealm`.
2022-12-17 00:54:00 +01:00
Andreu Botella
929847c722
chore(core): Deduplicate event_loop_pending_state (#17039) 2022-12-13 23:28:38 +01:00
David Sherret
623dbe7a57
chore: remove unnecessary lifetimes (#16878)
It seems we don't really need to allow these clippy rules.
2022-11-30 19:19:32 +00:00
Bartek Iwańczuk
f526513d74
feat(core): show unresolved promise origin (#16650)
This commit updates unhelpful messages that are raised when event loop
stalls on unresolved top-level promises.

Instead of "Module evaluation is still pending but there are no pending
ops or dynamic imports. This situation is often caused by unresolved
promises." and "Dynamically imported module evaluation is still pending
but there are no pending ops. This situation is often caused by
unresolved promises." we are now printing a message like: 

error: Top-level await promise never resolved
[SOURCE LINE]
^
    at [FUNCTION NAME] ([FILENAME])

eg:
error: Top-level await promise never resolved
await new Promise((_resolve, _reject) => {});
^
at <anonymous>
(file:///Users/ib/dev/deno/cli/tests/testdata/test/unresolved_promise.ts:1:1)

Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
2022-11-28 23:07:23 +01:00
Bartek Iwańczuk
28b5a7e2ec
feat(core): support initializing extensions with and without JS (#16789)
This commit allows to execute more JS code from extensions when
creating a snapshot from an existing snapshot.

"deno_core::RuntimeOptions::extensions_with_js" field was added
that is used to pass a list of extensions whose both "ops" and
associated JS source should be executed upon start.

Co-authored-by: crowlkats <crowlkats@toaxl.com>
2022-11-27 00:58:23 +01:00
Bartek Iwańczuk
d4f659d1d3
feat(core): send "executionContextDestroyed" notification on program end (#16831)
This commit changes "JsRuntime" to send "executionContextDestroyed"
notification when the program finishes and shows a prompt informing 
that runtime is waiting for inspector to disconnect.
2022-11-27 00:44:39 +01:00
Bartek Iwańczuk
3a320db270
fix(inspector): send "isDefault" in aux data (#16836)
With trial and error I found that most debuggers expect "isDefault" to be sent
in "auxData" field of "executionContextCreated" notification. This stems from
the fact that Node.js sends this data and eg. VSCode requires it to close
connection to the debugger when the program finishes execution.
2022-11-26 23:09:48 +01:00
Aaron O'Mullan
238590aa9f
chore: use Rust 1.65.0 (#16688) 2022-11-18 02:59:10 +01:00
Bartek Iwańczuk
b88b7c9244
chore: upgrade rusty_v8 to 0.55.0 (#16604)
<!--
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-11-12 05:37:37 +01:00
Divy Srivastava
5b9620df7a
feat(ops): implement fast lazy async ops (#16579)
Implements fast scheduling of deferred op futures. 

```rs
#[op(fast)]
async fn op_read(
  state: Rc<RefCell<OpState>>,
  rid: ResourceId,
  buf: &mut [u8],
) -> Result<u32, Error> {
  // ...
}
```

The future is scheduled via a fast API call and polled by the event loop
after being woken up by its waker.
2022-11-11 19:14:53 +05:30
Divy Srivastava
110a0ebe69
perf(core): minimize trivial heap allocations in resolve_async_ops (#16584)
* Use stack allocated array for 16 promises and spill rest to heap. the
exact number can change, maybe 128? (tokio's coop budget limit)
* Avoid v8::Global::clone for global context.
* Do not open global opresolve when its not needed.
2022-11-10 17:26:02 +05:30
Ryan Dahl
3019c45f87
refactor: simplify deno_core's grab_global and ensure_objs (#16564)
- refactor: remove JsRuntime::ensure_objs
- refactor: Replace JsRuntime::grab_global with JsRuntime::eval
2022-11-08 02:39:48 +01:00
Bartek Iwańczuk
e202f890f0
feat(core): support creating snapshots from existing snapshots (#14744) 2022-10-28 21:31:01 +02:00
Divy Srivastava
e18950284f
Reland "perf(core): generate inlined wrappers for async ops" (#16455)
Reland https://github.com/denoland/deno/pull/16428
2022-10-28 16:50:17 +05:30
Divy Srivastava
115cc1e6ae
Revert "perf(core): generate inlined wrappers for async ops (#16428)" (#16443) 2022-10-27 16:58:27 +02:00
Divy Srivastava
02187966c1
perf(core): generate inlined wrappers for async ops (#16428)
V8's JIT can do a better job knowing the argument count and also enable
fast call path (in future).

This also lets us call async ops without `opAsync`:

```js
const { ops } = Deno.core;
await ops.op_void_async();
```

this patch: 4405286 ops/sec
main: 3508771 ops/sec
2022-10-27 19:10:48 +05:30
Jan Špaček
642118fdeb
fix(core) Include causes when converting anyhow errors to JS exceptions (#16397)
When an op returns an `anyhow` error with a cause (usually added using
the `.context()` method), the `Error` thrown into JavaScript contains
only the message of the outernmost error in the chain.

This PR simply changes the formatting of `anyhow::Error` from `"{}"` to
`"{:#}"`:

This significantly improves errors for code that embeds Deno and defines
custom ops. For example, in
[chiselstrike/chiselstrike](https://github.com/chiselstrike/chiselstrike),
this PR improves an error message like

```
Error: could not plan migration
```

to

```
Error: could not plan migration: could not migrate table for entity "E": could not add column for field "title": the field does not have a default value
```
2022-10-26 17:30:44 +02:00
Bartek Iwańczuk
a57faa8a0a
core: enable --harmony-change-array-by-copy V8 flag (#16429)
Enables [Change Array by copy
proposal](https://github.com/tc39/proposal-change-array-by-copy) via a
V8 flag.
2022-10-26 16:54:22 +02:00
Divy Srivastava
851db03a6e
perf(core): do not drive JsInspector by default (#16410)
Part of https://github.com/denoland/deno/pull/16377
2022-10-26 17:07:50 +05:30
Divy Srivastava
f242d98280
perf(core): avoid isolate slots for ModuleMap (#16409) 2022-10-25 17:57:33 +05:30
Divy Srivastava
d461a784b2
perf(core): don't access isolate slots for JsRuntimeState (#16376)
example writeFile benchmark:

```
# before
time 188 ms rate 53191
time 168 ms rate 59523
time 167 ms rate 59880
time 166 ms rate 60240
time 168 ms rate 59523
time 173 ms rate 57803
time 183 ms rate 54644

# after
time 157 ms rate 63694
time 152 ms rate 65789
time 151 ms rate 66225
time 151 ms rate 66225
time 152 ms rate 65789
```
2022-10-21 19:43:42 +05:30
Divy Srivastava
c007657cfd
Revert realms from deno_core (#16366)
This revert has been discussed at length out-of-band (including with
@andreubotella). The realms work in impeding ongoing event loop and
performance work. We very much want to land realms but it needs to wait
until these lower-level refactors are complete. We hope to bring realms
back in a couple weeks.
2022-10-21 08:24:22 +05:30
Andreu Botella
8a736d7dc7
fix(docs): Documentation improvements related to JsRealm. (#16247) 2022-10-15 22:44:51 +02:00