0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-01 09:24:20 -04:00
Commit graph

146 commits

Author SHA1 Message Date
Giovanny Gutiérrez
2929ddabaa
fix(core): Register external references for imports to the SnapshotCreator (#15621)
Several functions used for handling of dynamic imports and "import.meta"
object were not registered as external references and caused V8 to crash
during snapshotting. These functions are now registered as external refs
and aborts are no longer happening.
2022-09-06 14:35:04 +02:00
Andreu Botella
307d84cfa5
refactor(core): Move optional callbacks from JsRuntimeState to ContextState (#15599)
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.
2022-09-01 23:01:05 +02:00
Divy Srivastava
906aa78af3
feat(ops): V8 Fast Calls (#15291) 2022-08-21 17:37:53 +05:30
Bartek Iwańczuk
5a4f84a0e1
chore: upgrade rusty_v8 to 0.48.1 (#15310) 2022-08-15 14:12:11 +02:00
Bartek Iwańczuk
2e1d6d3508
refactor(core): remove unneeded ops for uncaughtException (#15296) 2022-07-25 01:10:56 +02:00
Bartek Iwańczuk
504d2936ec
fix: unhandledrejection handling for sync throw in top level (#15279)
Fixes an edge in "unhandledrejection" event that prevent synchronous
errors being surfaced when throw from a top-level scope.
2022-07-23 00:40:42 +02:00
Divy Srivastava
4db650ddd5
Revert "feat(ops): V8 Fast Calls (#15122)" (#15276)
This reverts commit 03dc3b8972.
2022-07-22 19:06:32 +05:30
Divy Srivastava
03dc3b8972
feat(ops): V8 Fast Calls (#15122)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2022-07-22 17:54:22 +05:30
Bartek Iwańczuk
d53936eb7d
Reland "feat: add "unhandledrejection" event support" (#15211) 2022-07-20 20:28:19 +02:00
Bartek Iwańczuk
9eb70bdb5f
reland: "fix(core): unhandled rejection in top-level scope" (#15236)
Reland #15204
2022-07-18 21:20:38 +02:00
Bartek Iwańczuk
999cbfb52b
feat: import.meta.resolve() (#15074)
This commit adds new "import.meta.resolve()" API which
allows to resolve specifiers relative to the module the API
is called in. This API supports resolving using import maps.
2022-07-18 20:05:26 +02:00
Bartek Iwańczuk
0f6b455c96
Revert "fix(core): unhandled rejection in top-level scope (#15204)" (#15226)
This reverts commit 48a7312f38.
2022-07-18 12:52:54 +02:00
Bartek Iwańczuk
f9b692e68e
Revert "feat: add "unhandledrejection" event support (#12994) (#15080)" (#15210)
This reverts commit 1a7259b04b.
2022-07-15 01:06:20 +02:00
Bartek Iwańczuk
1a7259b04b
feat: add "unhandledrejection" event support (#12994) (#15080)
Relanding #12994 

This commit adds support for "unhandledrejection" event.

This event will trigger event listeners registered using:

"globalThis.addEventListener("unhandledrejection")
"globalThis.onunhandledrejection"
This is done by registering a default handler using
"Deno.core.setPromiseRejectCallback" that allows to
handle rejected promises in JavaScript instead of Rust.

This commit will make it possible to polyfill
"process.on("unhandledRejection")" in the Node compat
layer.

Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
2022-07-14 22:39:20 +02:00
Bartek Iwańczuk
48a7312f38
fix(core): unhandled rejection in top-level scope (#15204)
Update "deno_core" to not forward rejection of top level module
if it was already handled by appropriate handlers.

Co-authored-by: Colin Ihrig cjihrig@gmail.com
2022-07-14 21:01:08 +02:00
Bartek Iwańczuk
06934db883
Revert "feat: add "unhandledrejection" event support (#12994)" (#15075)
This reverts commit f7af0b01a5.
2022-07-04 23:34:39 +02:00
Bartek Iwańczuk
f7af0b01a5
feat: add "unhandledrejection" event support (#12994)
This commit adds support for "unhandledrejection" event.

This event will trigger event listeners registered using:

"globalThis.addEventListener("unhandledrejection")
"globalThis.onunhandledrejection"
This is done by registering a default handler using
"Deno.core.setPromiseRejectCallback" that allows to
handle rejected promises in JavaScript instead of Rust.

This commit will make it possible to polyfill
"process.on("unhandledRejection")" in the Node compat
layer.

Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
2022-07-04 21:14:58 +02:00
Luca Casonato
8d82ba7299
build: require safety comments on unsafe code (#13870)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
2022-06-26 00:13:24 +02:00
Nayeem Rahman
9385a91312
refactor(core): Move Deno.core bindings to ops (#14793) 2022-06-07 11:25:10 +02:00
Nayeem Rahman
e3eae662f3
fix: Format non-error exceptions (#14604)
This commit adds "Deno.core.setFormatExceptionCallback" which
can be used to provide custom formatting for errors. It is useful
in cases when user throws something that is non-Error (eg.
a string, plain object, etc).
2022-06-06 20:26:57 +02:00
Mark Ladyshau
402b497299
fix(core): rethrow exception during structured cloning serialization (#14671)
- Introduced optional callback for Deno.core.serialize API, that returns
cloning error if there is one.
- Removed try/catch in seralize structured clone function and throw error from
callback.
- Removed "Object with a getter that throws" assertion from WPT.
2022-05-26 17:14:38 +02:00
Aaron O'Mullan
5e62ee31d7
fix(core): op metrics op_names mismatch (#14716) 2022-05-24 22:21:32 +02:00
Aaron O'Mullan
8744ee883e
perf(core): optimize encode on large strings (#14619)
Follow up to serde_v8's #14450
2022-05-15 17:52:32 +02:00
Bartek Iwańczuk
bcd875030a
refactor(core): add AssertedModuleType enum (#14501)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2022-05-07 18:46:35 +02:00
Bartek Iwańczuk
3f08a40412
refactor: add core.formatLocationFilename, remove op_format_filename (#14474)
This commit moves "op_format_location" to "core/ops_builtin.rs"
and removes "Deno.core.createPrepareStackTrace" in favor of
"Deno.core.prepareStackTrace".

Co-authored-by: Aaron O'Mullan <aaron.omullan@gmail.com>
2022-05-03 19:45:57 +02:00
Nayeem Rahman
8b31fc23cd
refactor: Move source map lookups to core (#14274)
The following transformations gradually faced by "JsError" have all been 
moved up front to "JsError::from_v8_exception()": 

- finding the first non-"deno:" source line; 
- moving "JsError::script_resource_name" etc. into the first error stack 
in case of syntax errors; 
- source mapping "JsError::script_resource_name" etc. when wrapping 
the error even though the frame locations are source mapped earlier; 
- removing "JsError::{script_resource_name,line_number,start_column,end_column}"
entirely in favour of "js_error.frames.get(0)". 

We also no longer pass a js-side callback to "core/02_error.js" from cli. 
I avoided doing this on previous occasions because the source map lookups 
were in an awkward place.
2022-04-15 16:08:09 +02:00
Nayeem Rahman
4d18f558e4
feat(ext/web): Add error events for event listener and timer errors (#14159)
- feat: Add handleable error event for even listener errors
- feat: Add handleable error event for setTimeout()/setInterval() errors
- feat: Add Deno.core.destructureError()
- feat: Add Deno.core.terminate()
- fix: Don't throw listener errors from dispatchEvent()
- fix: Use biased mode when selecting between mod_evaluate() and
  run_event_loop() results
2022-04-13 11:50:57 +02:00
Aaron O'Mullan
f5f7b56aca
refactor(core): OpCtx (#14228) 2022-04-08 10:32:48 +02:00
Divy Srivastava
b18216a0d4
perf: micro-optimize core.encode (#14120) 2022-03-27 13:10:54 +05:30
Andreu Botella
12d28dffc6
fix(fetch): Fix uncaught rejection panic with WebAssembly.instantiateStreaming (#13925)
When an exception is thrown during the processing of streaming WebAssembly,
`op_wasm_streaming_abort` is called. This op calls into V8, which synchronously
rejects the promise and calls into the promise rejection handler, if applicable.
But calling an op borrows the isolate's `JsRuntimeState` for the duration of the
op, which means it is borrowed when V8 calls into `promise_reject_callback`,
which tries to borrow it again, panicking.

This change changes `op_wasm_streaming_abort` from an op to a binding
(`Deno.core.abortWasmStreaming`). Although that binding must borrow the
`JsRuntimeState` in order to access the `WasmStreamingResource` stored in the
`OpTable`, it also takes ownership of that `WasmStreamingResource` instance,
which means it can drop any borrows of the `JsRuntimeState` before calling into
V8.
2022-03-22 11:33:29 +01:00
Aaron O'Mullan
895e474295
cleanup(core): recursive get & ensure helpers (#13972) 2022-03-16 09:04:38 +01:00
Aaron O'Mullan
bb53135ed8
cleanup(core): OpPair => OpDecl (#13952) 2022-03-15 23:43:17 +01:00
Aaron O'Mullan
07d8431f10
fix(core): nuke Deno.core.ops pre-snapshot (#13970)
To avoid OOB & other ExternalReference snapshot serialization issues

Co-authored-by: Bert Belder <bertbelder@gmail.com>
2022-03-15 22:50:17 +01:00
Andreu Botella
c6bf07ec6d
fix(core): Don't override structured clone error messages from V8 (#13942)
In the implementation of structured serialization in
`Deno.core.serialize`, whenever there is a serialization error, an
exception will be thrown with the message "Failed to serialize
response", even though V8 provides a message to use in such cases.
This change instead throws an exception with the V8-provided message,
if there is one.
2022-03-14 19:35:15 +01:00
Divy Srivastava
b4e42953e1
feat(core): codegen ops (#13861)
Co-authored-by: Aaron O'Mullan <aaron.omullan@gmail.com>
2022-03-14 18:44:15 +01:00
Yoshiya Hinosawa
b198bfd795
refactor(core): validate promise id in refOp (#13905) 2022-03-12 01:18:49 +09:00
Divy Srivastava
189e2f617e
chore: update rusty_v8 to 0.41.0 (#13909) 2022-03-11 19:59:01 +05:30
Ryan Dahl
1fb5858009
chore: update copyright to 2022 (#13306)
Co-authored-by: Erfan Safari <erfanshield@outlook.com>
2022-01-07 22:09:52 -05:00
Divy Srivastava
6de53b631f
refactor: use once_cell instead of lazy_static (#13135) 2021-12-18 16:14:42 -05:00
Bartek Iwańczuk
a1f0796fcc
feat: Add support for import assertions and JSON modules (#12866)
This commit adds proper support for import assertions and JSON modules.

Implementation of "core/modules.rs" was changed to account for multiple possible
module types, instead of always assuming that the code is an "ES module". In
effect "ModuleMap" now has knowledge about each modules' type (stored via
"ModuleType" enum). Module loading pipeline now stores information about
expected module type for each request and validates that expected type matches
discovered module type based on file's "MediaType".

Relevant tests were added to "core/modules.rs" and integration tests,
additionally multiple WPT tests were enabled.

There are still some rough edges in the implementation and not all WPT were
enabled, due to:
a) unclear BOM handling in source code by "FileFetcher"
b) design limitation of Deno's "FileFetcher" that doesn't download the same
module multiple times in a single run

Co-authored-by: Kitson Kelly <me@kitsonkelly.com>
2021-12-15 19:22:36 +01:00
Bartek Iwańczuk
34f05f673e
fix(core): improve error on invalid op id (#13056) 2021-12-12 17:11:41 +01:00
Aaron O'Mullan
f6d4a63c7f
fix(core): throw on invalid callConsole args (#12973)
Instead of panicking via asserts, since JS-callable code (even Deno.core ...) should not cause process crashes/panics
2021-12-03 11:55:14 +01:00
Ben Noordhuis
2d830c263b
feat(core): intercept unhandled promise rejections (#12910)
Provide a programmatic means of intercepting rejected promises without a
.catch() handler. Needed for Node compat mode.

Also do a first pass at uncaughtException support because they're
closely intertwined in Node. It's like that Frank Sinatra song:
you can't have one without the other.

Stepping stone for #7013.
2021-11-28 00:46:12 +01:00
Bartek Iwańczuk
f3c0f0565b
feat(core): Add ability to "ref" and "unref" pending ops (#12889)
This commit adds an ability to "ref" or "unref" pending ops.

Up to this point Deno had a notion of "async ops" and "unref async ops";
the former keep event loop alive, while the latter do not block event loop
from finishing. It was not possible to change between op types after
dispatching, one had to decide which type to use before dispatch.

Instead of storing ops in two separate "FuturesUnordered" collections,
now ops are stored in a single collection, with supplemental "HashSet"
storing ids of promises that were "unrefed".

Two APIs were added to "Deno.core":

"Deno.core.refOp(promiseId)" which allows to mark promise id
to be "refed" and keep event loop alive (the default behavior)
"Deno.core.unrefOp(promiseId)" which allows to mark promise
id as "unrefed" which won't block event loop from exiting
2021-11-25 19:49:09 +01:00
Bartek Iwańczuk
fd78953e1c
feat(core): Deno.core.setNextTickCallback (#12771)
This commit adds several new "Deno.core" bindings:
* "setNextTickCallback"
* "hasScheduledTick"
* "setHasScheduledTick"
* "runMicrotasks"
Additionally it changes "Deno.core.setMacrotaskCallback" to
allow registering multiple callbacks. All these changes were necessary
to polyfill "process.nextTick" in Node compat layer.

Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
2021-11-16 20:23:12 +01:00
Ryan Dahl
b2036a4db7
refactor: re-export anyhow from deno_core (#12777) 2021-11-16 09:02:28 -05:00
Yoshiya Hinosawa
8e010b6844
feat(compat): add .code to dyn import error (#12633) 2021-11-08 16:02:40 +09:00
Bartek Iwańczuk
8e31bbbe55
chore: update to Rust edition 2021 (#12578) 2021-11-02 10:03:37 -04:00
Luca Casonato
be68b82eb4
chore: update to rusty_v8 0.33.0 (#12564) 2021-10-27 23:26:15 +02:00
Aaron O'Mullan
439a2914db
fix(core): avoid op_state.borrow_mut() for OpsTracker (#12525)
By allowing interior mutability in OpsTracker (owning a RefCell<Vec> instead of just a Vec)

Fixes #12453
2021-10-24 19:30:55 +02:00