Commit graph

11121 commits

Author SHA1 Message Date
Graciliano Monteiro Passos ab2fe4f5e2 Document the return value of any and every for empty values.
Closes https://github.com/dart-lang/sdk/pull/52847

GitOrigin-RevId: f5382101762582c7d865833e42d9af39fc0a6131
Change-Id: Iafeb53a7e583e0309d08d9dffe3803b7f772b70d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312380
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2023-07-11 13:05:40 +00:00
Vyacheslav Egorov 4fddaf9486 [sdk] Provide Isolate.resolvePackageUriSync
TEST=augmented few existing tests

Bug: https://github.com/dart-lang/sdk/issues/52121
CoreLibraryReviewExempt: VM-only change, other platforms don't support this API.
Change-Id: I95decae6cf1a5c6ad694747313aa0dbe0a13025d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312981
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-07-11 12:59:33 +00:00
fzyzcjy ab2d19c93d Tiny code cleanup: Remove _asyncRunZoned being an alias of runZoned
Closes https://github.com/dart-lang/sdk/pull/52778

GitOrigin-RevId: 025405feaea425604513cf1863a1d3fc9d795292
Change-Id: I70bb5e04996a9f1939571a41e1f41ab0e6c38e6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311157
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2023-07-11 11:37:57 +00:00
M. Javad Pourqavam a0392698bf Fix docs of DateTime.from constructors
Closes https://github.com/dart-lang/sdk/pull/52866

GitOrigin-RevId: bbc99c5f36dde2e53cc68aa3d8a5acfd5dd0fbb2
Change-Id: I9a5cf4b2a9d67fc3567af0f839272a104bf9edc3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312760
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2023-07-11 10:03:48 +00:00
Martin Kustermann 81df36216f Make utf8.encode() have Uint8List return type
Right now `utf8.encode()` has a static return type of `List<int>`
due to extending `Encoding` (which extends `Codec<String, List<int>>`).

We cannot easily change `Encoding` to extend `Codec<String, Uint8List>`
because that would also change `utf8.decode()` to require `Uint8List`
which would be a breaking change.

So instead we override `utf8.encode()` to have more precise return type.

Some parts of our SDK are run using the checked-in SDK, so it cannot
rely on the changed return type yet (until checked-in SDK is rolled).

So we use `const Utf8Encoder().convert()` as a temporary change, as
that already has `Uint8List` return type.

Issue https://github.com/dart-lang/sdk/issues/52801

TEST=ci

CoreLibraryReviewExempt: More precise return type for existing API
Change-Id: I2861d1f0eb3d292d8e3ec8437c0d441a2d2bd193
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/254903
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2023-07-11 08:54:33 +00:00
Joshua Litt 50c810e12c [js|dart2wasm] Add JS backed subtypes of Dart typed array classes.
Change-Id: I19a6d47bf857969abe2205e6b505b3a1dead5e3a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310480
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-07-10 18:11:02 +00:00
Srujan Gaddam e25cd7c182 [dart2wasm] Throw error in JSExportedDartFunction.toDart if not JS function
Currently this throws a Wasm RuntimeError, which is difficult to
recover from.

Change-Id: I747682d6959b19746d6c98f2ea1b3fefd1ed2d03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312891
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-07-10 17:50:07 +00:00
Jess Lally 185f08f606 [dart2wasm] Fix implementation of modulo and remainder for doubles
Change-Id: I6dc8a41da2088a256fde668718e9599b5aed80d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312804
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Jess Lally <jessicalally@google.com>
2023-07-10 14:30:32 +00:00
Nicholas Shahan 8515c4a428 [ddc] Fix check for required named args in new type system
Issue: https://github.com/dart-lang/sdk/issues/48585
Change-Id: I119c0d649461ddfd3879f75ef232ee8010ebf787
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312203
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2023-07-06 22:39:13 +00:00
Nicholas Shahan 1199dc09b7 [ddc] Support extractTypeArguments in new types
Inline calls to the extract function directly with the type arguments
inserted as extractions from the instance.

Issue: https://github.com/dart-lang/sdk/issues/48585
Change-Id: I6b791c59478c2e609df30163835e3fd0863a2d94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307514
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2023-07-06 19:24:54 +00:00
Srujan Gaddam b859e00908 Reland "[dart:html] Throw exception if Window.open opens null window" and
"[dart:html] Move NullWindowException to implementation"

This is a revert of bd3e6fa1a3 and
2b250992f9.

This adds some small code change to avoid a null-assertion being emitted
that would lead to a browser SecurityError.

CoreLibraryReviewExempt: Reland.
Change-Id: Iab52bb728b14fd0b2378b8923b0e1ea8ea930b12
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311922
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-07-06 15:50:48 +00:00
Lasse R.H. Nielsen d8fa6fe255 Fix bug in VM _CompactHashIterable.
The iterable is used for the `keys` and `values` of `LinkedHashMap`.
The original code remembered the internal data list and used-count
when the iterable was created, and if the iterable was modified
between creating and iterating, the iterated values would not match
the map.
The solution is to not cache those values, and read them from the
hash table when creting the `Iterator` instead.

Fixes #48282

Tested: Added regression test to corelib/map_test
Bug: https://dartbug.com/48282
Change-Id: I79310615e7090556e6f45b0d7f297755951ef046
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312263
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-07-04 11:00:50 +00:00
Sergio Martins ea8485e967 [vm] Make Finalizer.attach assert if value is passed as token
It's not supported, as it would prevent the value from being
garbage collected, defeating the purpose of Finalizer.

Not sure if an exception is worth it, so added the assert
as suggested in the bug tracker.

TEST=vm/dart{,_2}/finalizer/finalizer_attach_checks_token_test

Bug: #52731
Change-Id: Id7b457ca1a95e71c1a43d2d2c8569c35659952b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311020
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-07-04 08:28:14 +00:00
Elliott Brooks af8fb2cd73 Support the dart:developer timeline APIs in dart2js and DDC.
Exposes timeline events in the Chrome DevTools performance panel using the  Web APIs performance.mark() and performance.measure(): https://developer.mozilla.org/en-US/docs/Web/API/Performance

CoreLibraryReviewExempt: Only change in sdk/lib is updating a comment.
Bug: https://github.com/flutter/devtools/issues/4652
Change-Id: I4f934bcffeb2920ffaf9b7b3a67fc5fc3b814294
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310974
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Elliott Brooks <elliottbrooks@google.com>
2023-06-30 22:38:11 +00:00
Vyacheslav Egorov a52f2b9617 [vm] Rework awaiter stack unwinding.
The main contribution of this CL is unification of disparate
handling of various functions like `Future.timeout`,
`Future.wait`, `_SuspendState.createAsyncCallbacks` and
`_SuspendState._createAsyncStarCallback` into a single
`@pragma('vm:awaiter-link')` which allows Dart developers
to specify where awaiter unwinder should look for the next
awaiter.

For example this allows unwinding to succeed for the code like this:

    Future<int> outer(Future<int> inner) {
      @pragma('vm:awaiter-link')
      final completer = Completer<int>();

      inner.then((v) => completer.complete(v));

      return completer.future;
   }

This refactoring also ensures that we preserve information
(including Function & Code objects) required for awaiter
unwinding across all modes (JIT, AOT and AOT with DWARF stack
traces). This guarantees users will get the same information
no matter which mode they are running in. Previously
we have been disabling awaiter_stacks tests in some AOT
modes - which led to regressions in the quality of produced
stacks.

This CL also cleans up relationship between debugger and awaiter
stack returned by StackTrace.current - which makes stack trace
displayed by debugger (used for stepping out and determinining
whether exception is caught or not) and `StackTrace.current`
consistent.

Finally we make one user visible change to the stack trace:
awaiter stack will no always include intermediate listeners
created through `Future.then`. Previously we would sometimes
include these listeners at the tail of the stack trace,
which was inconsistent.

Ultimately this means that code like this:

    Future<int> inner() async {
      await null;  // asynchronous gap
      print(StackTrace.current); // (*)
      return 0;
    }

    Future<int> outer() async {
      int process(int v) {
        return v + 1;
      }

      return await inner().then(process);
    }

    void main() async {
      await outer();
    }

Produces stack trace like this:

    inner
    <asynchronous suspension>
    outer.process
    <asynchronous suspension>
    outer
    <asynchronous suspension>
    main
    <asynchronous suspension>

And when stepping out of `inner` execution will stop at `outer.process`
first and the next step out will bring execution to `outer` next.

Fixes https://github.com/dart-lang/sdk/issues/52797
Fixes https://github.com/dart-lang/sdk/issues/52203
Issue https://github.com/dart-lang/sdk/issues/47985

TEST=ci

Bug: b/279929839
CoreLibraryReviewExempt: CL just adds @pragma to facilitate unwinding
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-dwarf-linux-product-x64-try
Change-Id: If377d5329d6a11c86effb9369dc603a7ae616fe7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311680
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-06-30 14:03:03 +00:00
Srujan Gaddam bd3e6fa1a3 Revert "[dart:html] Throw exception if Window.open opens null window"
This reverts commit a356f71b71.

Reason for revert: This should be handled by throwing an exception when
the methods of the returned window are called, not when it is opened.
This would be a noisy breaking change that we don't want for 3.1. For
now, revert until the change that affects the individual methods is
landed.

Original change's description:
> [dart:html] Throw exception if Window.open opens null window
>
> Window.open silently allows a null window to be opened, and
> issues arise later when users try to use the non-null wrapper.
> This CL changes that to throw an exception if the window is null.
> This exception can be caught and recovered from. This avoids the
> larger breaking change of making this API nullable.
>
> CoreLibraryReviewExempt: Backend-specific library.
> Change-Id: I9a53a477cb370c3bc6bc26b2162ce66c5af166aa
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306910
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>

CoreLibraryReviewExempt: Revert in backend-specific library.
Change-Id: I5007b7d7aa608bfc8e5827b5f967af5573d0b758
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309000
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-06-28 23:21:32 +00:00
Ivan Inozemtsev 2b250992f9 Revert "[dart:html] Move NullWindowException to implementation"
This reverts commit 14a3051552.

Reason for revert: b/289195983

Original change's description:
> [dart:html] Move NullWindowException to implementation
>
> Window.open may open a null window in more cases than expected.
> Users may not care that the window they get back is invalid if
> they never use it. Therefore, this CL moves the exception to
> the implementation of the returned window in order to reduce
> noise, but still give a way for users to recover if they wish
> to do so.
>
> CoreLibraryReviewExempt: Backend-specific library.
> Change-Id: I005cf80630cfb4db2f5ec2012cfcd0161ad10ff1
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311460
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Sigmund Cherem <sigmund@google.com>

Change-Id: Id7c514a80fdcaa18a7eb0acdcb7f36477a04d966
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311843
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Auto-Submit: Ivan Inozemtsev <iinozemtsev@google.com>
2023-06-28 23:21:32 +00:00
Liam Appelbe 13ec07415b [vm] Async FFI callbacks
More details about the design:
https://docs.google.com/document/d/1QDjyY_6wOTOgURwpeYMKU9qEz0gKxx2MUrdruC6Kp6c/edit?usp=sharing

Change-Id: Ie3985d86dca7f5010044ca46c33ca177588c0f69
Bug: #37022
CoreLibraryReviewExempt: Reviewed by vm and api groups. web and wasm groups not affected because FFI isn't on those platforms.
TEST=async_void_function_callbacks_test.dart, ffi_callback_metadata_test.cc, other front end tests
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305900
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-06-28 01:00:18 +00:00
Nate Bosch 8debcecb85 Mention that IOSink truncates List<int> to bytes
Closes #31670

In `add` and `addStream` mention that int values which are too large are
truncated to bytes.

R=lrn@google.com

Change-Id: Idf276fc65592e21766659e9d89dd687c441b7357
CoreLibraryReviewExempt: Doc changes only.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310768
Auto-Submit: Nate Bosch <nbosch@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
2023-06-27 19:39:01 +00:00
Nate Biggs d9b676b0be [dart2js] Add retry mechanism to deferred loading when file fails to register as loaded.
In order to have the browser send a new request for each retry (each new appended script tag), a query token must be appended to the URI. We don't include any extra tokens on the initial request.

Change-Id: I846660894c16345a441193cd9c7b4784364a3c54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311200
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-06-27 18:18:43 +00:00
Srujan Gaddam 14a3051552 [dart:html] Move NullWindowException to implementation
Window.open may open a null window in more cases than expected.
Users may not care that the window they get back is invalid if
they never use it. Therefore, this CL moves the exception to
the implementation of the returned window in order to reduce
noise, but still give a way for users to recover if they wish
to do so.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I005cf80630cfb4db2f5ec2012cfcd0161ad10ff1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311460
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-06-26 22:58:08 +00:00
Stephen Adams eb2b7c6642 [js_runtime] Avoid reparsing in Uri.base
Repeated calls to Uri.base result in repeated calls to Uri.parse.
Reparsing is necessary only when the location changes.

Bug: b/281079996
Change-Id: I091a6f1ac2f454643e95bbfddf59b24172ef7da5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311155
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2023-06-26 21:32:48 +00:00
Nate Biggs fe73f0cf5d [dart2js] Reduce size of Dart2JS deferred loading event logs.
- Only include the script tag src if it differs from the previous log entry.
- Use single letters for each event field's key.
- Fix some typos.
- Remove 'uri' from download event as it can be inferred from script tag src and part file name.

Change-Id: Ib7916ea5e92720a10c7e1e1cab2e535fae2bbf49
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311180
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-06-26 20:43:32 +00:00
Joshua Litt 64290e1052 [js] Add JSStringImpl box for JSString.
Change-Id: I63a2ecdf3fd2331f91632ae5b2cc51813cd44c66
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307961
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-06-26 17:15:24 +00:00
Alexander Aprelev bbdf87d277 [vm/debugger] Have debug step check point after debugger() call.
Fixes https://github.com/dart-lang/sdk/issues/46006
TEST=ci

Change-Id: I89a7ad248b75204d1754668cfb23c8d98f554b28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310779
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2023-06-23 16:53:48 +00:00
Nate Bosch 34d9241a71 Add a notice about HashMap keys changing hashCode
Closes #33384

Similar to a notice in the doc for `HashSet` where it is also unsafe to
change `hashCode` while an object is in the collection.

R=lrn@google.com

Change-Id: I0e609656fccd563ecf71d4be5ecadafc1a6da891
CoreLibraryReviewExempt: Doc changes only.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310774
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2023-06-23 00:10:19 +00:00
Nate Bosch d3f79404ac Expand StreamTransform.fromHandlers docs
Closes #27740

Mention the convenience constructors `fromhandlers` and `fromBind` in
the class level doc.

Describe the default behavior of each handlers.

R=lrn@google.com

Change-Id: Ica55d5a2f531e11106085122aa32173cc436991a
CoreLibraryReviewExempt: Doc changes only.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310765
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
2023-06-22 23:10:28 +00:00
Nate Bosch 1837435273 Mention iteration depth for some Iterable methods
Closes #7797

Most of the other suggestions have already been added, add an explicit
mention of shorcutting for `contains`, `firstWhere`, and `single`,

R=lrn@google.com

Change-Id: I53c254839f198a368fcb8734c3f7983b9b3ccad4
CoreLibraryReviewExempt: Doc changes only.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310767
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
2023-06-22 20:44:09 +00:00
Nate Bosch a282120406 Expand docs for Stream.lastWhere and singleWhere
Closes #30071

Add a template in the `firstWhere` doc for the paragraph about `orElse`
handling. Expand the discussion around error handling in the `lastWhere`
and `singleWhere` docs without relying on reading the `firstWhere` doc
first.

R=lrn@google.com

Change-Id: I302381bb5f4f7daa392ee22bbf667db7d7259ef5
CoreLibraryReviewExempt: Doc changes only.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310761
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2023-06-22 19:07:40 +00:00
Nate Bosch 915c1ed9bc Change some "function" to "method" in IOSink docs
Closes #31722

R=lrn@google.com

Change-Id: Ice7ed1c1ffcc8468f8e61274fa3c4fa880cc04f6
CoreLibraryReviewExempt: Doc changes only.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310763
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2023-06-22 18:00:13 +00:00
Tess Strickland 97a09b90c8 [sdk] Add NativeRuntime.buildId to dart:developer.
TEST=vm/dart/build_id

Issue: https://github.com/dart-lang/sdk/issues/51941
CoreLibraryReviewExempt: Native runtime only API
Change-Id: Ib3757480f0eab6d147385a87adf657f4f709ec4e
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-mac-product-arm64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-win-release-x64-try,vm-aot-win-product-x64-try,vm-aot-win-debug-x64c-try,vm-aot-android-release-arm_x64-try,vm-fuchsia-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307122
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2023-06-22 11:11:11 +00:00
Srujan Gaddam e985d991b1 [dart:js_interop] Fix JSNumber conversions/semantics and JSBoxedDartObject
- Adds toDartInt and toDartDouble to JSNumber
- Changes semantics of int on external functions from truncate to
assert integer value
- Adds tests for number semantics
- Renames JSExportedDartObject -> JSBoxedDartObject to avoid confusion
with @JSExport
- Adds Object.toJSBox

JSNumber.toDart and Object.toJS will be removed in a future CL once
migrations are complete.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I8ff26ee5624c52703e49dd8483f62e829cb6fff0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309081
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-06-22 02:51:13 +00:00
asiva d29341e1ea Ensure HttpClient.setTimelineLogging does not throw an exception in
product mode.

Change-Id: I38097caac847ac5211b1b12f77f342956eaecc6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309823
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2023-06-22 01:16:45 +00:00
Aske Simon Christensen 5838562040 [dart2wasm] Add option and target for stringref.
This adds basic infrastructure for a stringref implementation in
dart2wasm:

- A `--[no-]stringref` option to the compiler
- An option in the `WasmTarget`, controlling the name of the target
- Separate sets of patch files for the two targets
- Separate platform dill files for the two targets

For now, the patch file contents are the same, and the compiler flag
is not used by the backend (only by the `dart2wasm` script to select
the appropriate platform dill file). Both of these will change as the
implementation progresses.

Tested: ci + manual check that the option selects the correct dill
Change-Id: I2c9bb95ba06fd3de3f7007703ef545e3f0c728ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310621
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-06-21 14:25:38 +00:00
Aske Simon Christensen 21d45c0268 [dart2wasm] Put string_patch into its own patch
Change-Id: Iae4c98406eb08fdf39929448bba53879f1fae61e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310580
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-06-21 14:25:38 +00:00
Ömer Sinan Ağacan 2f27fc5ddf [dart2wasm] Update dart2wasm script
When DART_CONFIGURATION is not provided, search in output directory for
a configuration. Code copied from the `dart` script.

Currently the script only works without DART_CONFIGURATION on X64
systems, which is inconvenient when working on macOS or others.

Change-Id: I48c3e32f8824913932aee63e220e5152931b54db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310540
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-06-21 14:15:25 +00:00
Stephen Adams 5cbba84b91 [dart2js] Better const Maps and Sets
Constant Sets now have their own classes rather than being constructed as a wrapper over a const Map. The new scheme is similar to Maps - using a ConstantStringSet backed by a JavaScript Object 'dictionary' when the elements are all suitable String values, otherwise using a GeneralConstantSet backed by a list of elements that is converted to a lookup map on demand.

Constant Sets and Maps with suitable String keys are backed by a JavaScript Object literal 'dictionary'. The use of the Object literal has been changed so that the property values are no longer the values of the Dart Map, but the position of the key in the order of the entries. The values are provided as a List (Array), so there is an additional indexing operation to access the value on lookup. This does not seem to affect performance.

The advantage of the two-level lookup using the 'dictionary' is that Maps with the same keys (in the same order) can share a 'dictionary'. In order to achieve the advantage, the JavaScript Object is modeled as a first class ConstantValue - JavaScriptObjectConstantValue.

These changes achieve a code size benefit of -0.90% (~130K) on the main unit of a certain large app, and -0.35% for flute/benchmarks/lib/complex.dart

Change-Id: Icad2e6136218486a439e3c5ed0296462e3c3c4e6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310020
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-06-20 23:44:08 +00:00
Ömer Sinan Ağacan 87a3de41b1 [dart2wasm] Implement micro-task scheduling
Use JS `setTimeout` for events and `queueMicrotask` for micro-tasks.

dart2js event loop implementation is copied in `run_wasm.js` to be able
to use `clearTimeout`, `setInterval`, `clearInterval`, and
`scheduleMicrotask`, which are not not available in d8, and `setTimeout`
in d8 does not wait before calling a callback.

New passing d8 tests:

- co19/LibTest/async/Future/Future.delayed_A01_t02
- co19/LibTest/async/Stream/Stream.periodic_A01_t01
- co19/LibTest/async/Stream/Stream.periodic_all_t01
- co19/LibTest/async/Stream/Stream.periodic_all_t02
- co19/LibTest/async/Stream/timeout_A04_t01
- co19/LibTest/async/StreamController/stream_all_A01_t01
- co19/LibTest/async/StreamController/stream_all_A01_t02
- co19/LibTest/async/StreamController/stream_all_A02_t01
- co19/LibTest/async/StreamController/stream_all_A02_t02
- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t01
- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t02
- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t01
- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t02
- co19/LibTest/async/Timer/Timer.periodic_A01_t01
- co19/LibTest/async/Timer/Timer_A01_t01
- co19/LibTest/core/Stopwatch/elapsedTicks_A01_t01
- language/async/call_test
- language/regress/regress21795_test
- lib/async/multiple_timer_test
- lib/async/periodic_timer2_test
- lib/async/periodic_timer3_test
- lib/async/periodic_timer4_test
- lib/async/schedule_microtask3_test
- lib/async/schedule_microtask_test
- lib/async/stream_timeout_test
- lib/async/timer_isActive_test
- lib/async/timer_repeat_test
- lib/async/timer_test

New passing Chrome tests:

- co19/LibTest/async/Stream/timeout_A04_t01
- language/async/call_test
- lib/async/schedule_microtask3_test

Tests below fail because of async* desugaring issues and will be fixed
separately:

- language/async_star/no_cancel2_test
- language/async_star/no_cancel_test

Tests below fail because of an existing issue (#29615):

- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t03
- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t03
- co19/LibTest/async/StreamController/stream_all_A02_t03

Fixes #51599.

Change-Id: Ib313e99bf3b3cb3bebeddc9e47dc77425ef94481
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305201
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-06-19 10:21:35 +00:00
Martin Kustermann 3dd9389c1f [vm] Fix leakage of file system watcher related data structures
Closes https://github.com/dart-lang/sdk/issues/52703

TEST=runtime/tests/vm/dart/regress_52703_test.dart

Change-Id: Ia76c721a3d3a1466ed1c2e7bd847c331cee95ed7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309862
Reviewed-by: Lasse Nielsen <lrn@google.com>
Auto-Submit: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-06-16 12:08:43 +00:00
Stephen Adams 3bdcafca21 [js_runtime] More efficient GeneralConstantMap
Using a custom LinkedHashMap for the backing store was not efficient
for Strings and numbers since it bypassed the efficient storage for
those types and forced hash buckets to be used.

Adding a new JsConstantLinkedHashMap targeting primitive equality allows the efficient path to be used.

JsConstantLinkedHashMap is very similar to the implementation of LinkedHashMap.identity, so this class has been renamed moved to be next to JsConstantLinkedHashMap.


Change-Id: Iff97924dd645071d3ed767ce41c2dc5a41c779a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309640
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-06-16 01:58:33 +00:00
Simon Binder 62488db4da [vm/ffi] Add DynamicLibrary.close()
This adds the `close()` method to `DynamicLibrary`, which uses
`dlclose()` on Unix and `FreeLibrary` on Windows to close a dynamic FFI
library.

TEST=tests/ffi/dylib_close_test.dart
Closes https://github.com/dart-lang/sdk/issues/40159

Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-riscv64-try,vm-ffi-qemu-linux-release-arm-try,dart2wasm-linux-d8-try,dart2wasm-linux-chrome-try,vm-reload-rollback-linux-debug-x64-try,vm-reload-linux-debug-x64-try,vm-win-debug-x64c-try,vm-win-debug-x64-try,vm-aot-android-release-arm_x64-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-asan-linux-release-x64-try,vm-aot-msan-linux-release-x64-try,vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-x64-try,vm-aot-mac-release-arm64-try,vm-aot-win-debug-x64c-try,vm-aot-win-release-x64-try
CoreLibraryReviewExempt: `dart:ffi` VM only API.
Change-Id: I73af98677b481902fe548bdcee56964a0195faf0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307680
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-06-15 17:19:37 +00:00
Aryan More 4d67646eae Removed Non Null Check
Closes https://github.com/dart-lang/sdk/pull/52666

GitOrigin-RevId: 58fb6e98a3f7feb6c7ba933fdbfc408f26ecc6f5
Change-Id: I2f564067475ae68d4d9d18e4c3aafbdee40ed027
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308421
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2023-06-15 13:01:25 +00:00
Stephen Adams e8ce98ac78 [js_runtime] Handle Records in const Maps
Fixes: #52699

Change-Id: I82400b3aa743c93906fabe1743475b7c44775360
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309120
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-06-14 19:44:20 +00:00
Johnni Winther e831cb8510 [cfe] Check @patch annotations
This normalizes the checking of patches so that it matches the checking
of augmentations. This means that the @patch annotation must and can
only be used on patches.

The dart: libraries and patches have been updated accordingly.

TEST=ffi

Change-Id: I78767eebd1a8861859067ae5ff9c0339f0985bb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306041
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-06-13 07:27:08 +00:00
Nate Biggs fdad77376d [dart2js] Reduce code size impact of new event logging on main output unit.
This improves the code size increase from 1490 bytes to 184 bytes (unminified). In either case this is a 1-time cost paid only in the main unit.

Change-Id: Idc2c98e4a8b034d14eb4e1ebfde860c9418dfdce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308720
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-06-12 19:18:40 +00:00
Srujan Gaddam a356f71b71 [dart:html] Throw exception if Window.open opens null window
Window.open silently allows a null window to be opened, and
issues arise later when users try to use the non-null wrapper.
This CL changes that to throw an exception if the window is null.
This exception can be caught and recovered from. This avoids the
larger breaking change of making this API nullable.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I9a53a477cb370c3bc6bc26b2162ce66c5af166aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306910
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-06-12 18:29:56 +00:00
Nate Biggs ac6150c4c0 [dart2js] Improve deferred part file logging.
Adds an "eventLog" property to the global "$__dart_deferred_initializers__" object. The event log is just a JS Array that gets initialized alongside $__dart_deferred_initializers__.

Each event entry is a String->String JS object. I unified the format of these event objects for easier parsing.

Each printed event is now valid JSON (passed through JSON.stringify) so we can more easily post-process the logs if necessary.

Fully replacing the existing "_eventLog" field makes the logging logic simpler. Having a single array allows us to not include a timestamp because the array captures the event ordering (actual timing doesn't matter). It also makes it easier to stringify the logs when there's only 1 data source/format.

Sample output:
```

{"hunkName":"out.js_1.part.js","event":"loadHunk"}
{"uri":"path_to/out.js_1.part.js","hunkName":"out.js_1.part.js","event":"downloadHunk"}
{"file":"out.js_1","event":"beginLoadPart"}
{"file":"out.js_1","event":"endPartLoad","hash":"aCscY7yv4EHodRPmCqYn5BqMelA="}
{"uri":"path_to/out.js_1.part.js","hunkName":"out.js_1.part.js","event":"downloadHunkSuccess"}
{"hunkName":"out.js_1.part.js","hash":"aCscY7yv4EHodRPmCqYn5BqMelA=","event":"initialize"}

```

Change-Id: Ifee73be0bf7dc53a0e7710ff033dd2b0fae9fb0e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307240
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-06-09 17:05:11 +00:00
Nicholas Shahan 80d53a665b [ddc] Coerce undefined to null in record elements
Fixes: https://github.com/dart-lang/sdk/issues/52593
Change-Id: Ic8b05f8a3a0251dd8774af076f6f226c5c652bc5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308245
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2023-06-08 23:54:23 +00:00
Nicholas Shahan ce9b44e604 [ddc] Add JSInterop support in the new type system
Encodes the necessary type rules and adds type identifier
tags to support the legacy JavaScript interop behavior.

Issue: https://github.com/dart-lang/sdk/issues/48585
Change-Id: I933db1c9899711898fb829821f3e051043f33be2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305845
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2023-06-08 23:00:40 +00:00
Vyacheslav Egorov 0b62bb66ed [vm/io] Make sure to write until EAGAIN on POSIX
We are using `epoll()` in edge-triggerred mode, which requires
us to hit `EAGAIN` on `write()` before we are guaranteed
to receive an `EPOLLOUT` event.

`_SocketStreamConsumer` looks at `_NativeSocket.writeAvailable`
after issuing a `write` to decide whether it should continue
writing or pause and wait until event handler sends us `writeEvent`.

However we did not previously set `writeAvailable` to `true` until
the first `writeEvent` arrived, which lead to a hang on some
Linux servers: we would write a small amount of bytes into a pipe
and then wait for `writeEvent`, which would never come, as `epoll()`
is only guaranteed to wake up with `EPOLLOUT` if we hit `EAGAIN`
on `write()`.

This CL also changes `_NativeSocket.nativeWrite` implementation
to write bytes into the file descriptor until it gets EAGAIN.
This reduces the number of roundtrips between Dart and
native.

Unfortunately this CL does not come with a regression test
because it is relying on concrete `epoll()` behaviour and it this
behaviour does not reproduce for me.

TEST=Tested manually on the affected servers.

FIXED=b/286346121

Fixed: 286346121
Change-Id: I37fef9aa12b1da724b035aa9577b414a8057217e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308101
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-06-08 13:17:28 +00:00