pkg:js - drop discontinued example, cleanup min SDK

Delete some very old historical files

Change-Id: I9fffc84d0c1a6b0e4731d360418599390d5470df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279649
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
This commit is contained in:
Kevin Moore
2023-01-24 23:02:39 +00:00
committed by Commit Queue
parent 5c045992bc
commit 25fb2d6cb6
7 changed files with 41 additions and 1757 deletions
+17 -28
View File
@@ -1,53 +1,42 @@
## 0.6.7
- Remove `example` link to discontinued example.
## 0.6.6
* Add `@JSExport` annotation for exporting Dart classes and `@staticInterop`
- Add `@JSExport` annotation for exporting Dart classes and `@staticInterop`
mocking.
* Require Dart 2.19
- Require Dart 2.19
## 0.6.5
* Populate the pubspec repository field.
* Add a dependency on `package:meta`.
* Add an experimental `@trustTypes` annotation.
- Populate the pubspec repository field.
- Add a dependency on `package:meta`.
- Add an experimental `@trustTypes` annotation.
## 0.6.4
* Includes `@staticInterop` to allow interop with native types from `dart:html`.
- Includes `@staticInterop` to allow interop with native types from `dart:html`.
## 0.6.3
* Stable release for null safety.
## 0.6.3-nullsafety.3
* Update SDK constraints to `>=2.12.0-0 <3.0.0` based on beta release
guidelines.
## 0.6.3-nullsafety.2
* Allow prerelease versions of the `2.12` sdk.
## 0.6.3-nullsafety.1
* Allow 2.10 stable and 2.11.0 dev SDK versions.
## 0.6.3-nullsafety
* Opt in to null safety.
- Stable release for null safety.
- Update SDK constraints to `>=2.12.0 <3.0.0`.
## 0.6.2
* Improved documentation.
- Improved documentation.
## 0.6.1+1
* Support Dart 2 final release.
- Support Dart 2 final release.
## 0.6.1
* Add js_util library of utility methods to efficiently manipulate typed
- Add js_util library of utility methods to efficiently manipulate typed
JavaScript interop objects in cases where the member name is not known
statically.
## 0.6.0
* Version 0.6.0 is a complete rewrite of `package:js`.
- Version 0.6.0 is a complete rewrite of `package:js`.
+22 -26
View File
@@ -4,22 +4,17 @@
Use this package when you want to call JavaScript APIs from Dart code, or vice
versa.
This package's main library, `js`, provides annotations and functions
that let you specify how your Dart code interoperates with JavaScript code.
The Dart-to-JavaScript compilers — dartdevc and dart2js — recognize these
This package's main library, `js`, provides annotations and functions that let
you specify how your Dart code interoperates with JavaScript code. The
Dart-to-JavaScript compilers — dartdevc and dart2js — recognize these
annotations, using them to connect your Dart code with JavaScript.
**Important:** This library supersedes `dart:js`, so don't import `dart:js`.
Instead, import `package:js/js.dart`.
A second library in this package, `js_util`, provides low-level utilities
that you can use when it isn't possible to wrap JavaScript with a static,
annotated API.
## Example
See the [Chart.js Dart API](https://github.com/google/chartjs.dart/) for an
end-to-end example.
A second library in this package, `js_util`, provides low-level utilities that
you can use when it isn't possible to wrap JavaScript with a static, annotated
API.
## Usage
@@ -70,9 +65,10 @@ class Location {
### Passing object literals to JavaScript
Many JavaScript APIs take an object literal as an argument. For example:
```js
// JavaScript
printOptions({responsive: true});
printOptions({ responsive: true });
```
If you want to use `printOptions` from Dart a `Map<String, dynamic>` would be
@@ -105,8 +101,8 @@ class Options {
### Making a Dart function callable from JavaScript
If you pass a Dart function to a JavaScript API as an argument,
wrap the Dart function using `allowInterop()` or `allowInteropCaptureThis()`.
If you pass a Dart function to a JavaScript API as an argument, wrap the Dart
function using `allowInterop()` or `allowInteropCaptureThis()`.
To make a Dart function callable from JavaScript _by name_, use a setter
annotated with `@JS()`.
@@ -221,6 +217,7 @@ Note that you can have both `external` and non-`external` members in the
extension.
Compared to non-`@staticInterop` `package:js` classes, `@staticInterop` classes:
- Are more performant
- Have better type guarantees
- Generate less code
@@ -228,11 +225,11 @@ Compared to non-`@staticInterop` `package:js` classes, `@staticInterop` classes:
- Allow `external` extension members to be renamed using `@JS()` e.g.
`@JS('renamedField')`
The only catch is that virtual/dynamic dispatch is *disallowed*. That means
methods are resolved using only the *static* type of the object.
The only catch is that virtual/dynamic dispatch is _disallowed_. That means
methods are resolved using only the _static_ type of the object.
In general, it's advised to use `@staticInterop` wherever you can, as future
JS interop will only target static dispatch.
In general, it's advised to use `@staticInterop` wherever you can, as future JS
interop will only target static dispatch.
### @JSExport and js_util.createDartExport
@@ -302,7 +299,7 @@ getters, setters, and methods. That means you cant export static members,
constructors, factories, operators (the syntax complicates things), and
extension methods. You can still have these members - they just wont be present
in the resulting exported object. Of course, you can use another instance member
to call these members as well, and *that* instance member will be exported.
to call these members as well, and _that_ instance member will be exported.
In order to use `createDartExport`, you need to have a class that uses
`@JSExport`.If you want to export only some members of a class, omit the
@@ -335,7 +332,7 @@ essentially created a mock for `JSCounter`. In the past, to mock a plain `@JS`
or `@anonymous` class, you could create a Dart class that `implements` that
interop class, and due to Dart's virtual dispatch, this would call the Dart
class' members instead. Now that we're using `external` extension members, this
no longer works. We now have to mock at the *JS level* instead. With
no longer works. We now have to mock at the _JS level_ instead. With
`createDartExport`, youre essentially using a Dart object to replace a JS
object. This functionality is equivalent to mocking at the JS level, and you can
also use it to mock the old non-`@staticInterop` `package:js` classes!
@@ -357,7 +354,7 @@ tell you if youve got your mock class right.
This is where `createStaticInteropMock` comes in. It takes in a separate type
argument, e.g. `createStaticInteropMock<JSCounter, Counter>(Counter())`, to
determine whether mocking *conformance* is satisfied. This type argument must be
determine whether mocking _conformance_ is satisfied. This type argument must be
a `@staticInterop` class. With this, youll see an error saying that you havent
implemented all the needed members. If the mock class implements all the needed
members, the function does the same thing as `createDartExport`, and returns an
@@ -386,7 +383,7 @@ extension B on StaticInterop {
```
This present an issue as a single Dart class cannot implement `member` as both a
field and a function. So, what to do? We require that you only implement *one*
field and a function. So, what to do? We require that you only implement _one_
of these members. So, either a Function field or a function are satisfactory.
It is also sometimes desired that the mocking object is the same underlying type
@@ -396,14 +393,14 @@ order to pass `instanceof` checks. In order to do this, we let users pass the JS
prototype of the type they want the mocking object to be as an argument to
`createStaticInteropMock`.
An important note here is that `createStaticInteropMock` looks for *all*
An important note here is that `createStaticInteropMock` looks for _all_
extensions of the `@staticInterop` type in the program, even if they are out of
scope of the current file. In order to avoid a case where other libraries
extending the `@staticInterop` type break your usage of
`createStaticInteropMock`, you should try to only use this API in tests.
`createStaticInteropMock` is meant to detect issues earlier at compile-time, but
if it's too restrictive, you can still use `createDartExport` to workaround
that (and please provide us feedback on why it's restrictive!).
if it's too restrictive, you can still use `createDartExport` to workaround that
(and please provide us feedback on why it's restrictive!).
## Reporting issues
@@ -411,7 +408,6 @@ Please file bugs and feature requests on the [SDK issue tracker][issues].
[issues]: https://goo.gl/j3rzs0
## Known limitations and bugs
<!-- [TODO: add intro. perhaps move this to another page?] -->
-1
View File
@@ -1 +0,0 @@
See the [Chart.js Dart API](https://github.com/google/chartjs.dart/) for a usage example.
-63
View File
@@ -1,63 +0,0 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// Declarations for variable arguments support
/// (rest params and spread operator).
///
/// These are currently *not* supported by dart2js or Dartium.
library js.varargs;
class _Rest {
const _Rest();
}
/// Annotation to tag ES6 rest parameters (https://goo.gl/r0bJ1K).
///
/// This is *not* supported by dart2js or Dartium (yet).
///
/// This is meant to be used by the Dart Dev Compiler
/// when compiling helper functions of its runtime to ES6.
///
/// The following function:
///
/// foo(a, b, @rest others) { ... }
///
/// Will be compiled to ES6 code like the following:
///
/// function foo(a, b, ...others) { ... }
///
/// Which is roughly equivalent to the following ES5 code:
///
/// function foo(a, b/*, ...others*/) {
/// var others = [].splice.call(arguments, 2);
/// ...
/// }
///
const _Rest rest = _Rest();
/// Intrinsic function that maps to the ES6 spread operator
/// (https://goo.gl/NedHKr).
///
/// This is *not* supported by dart2js or Dartium (yet),
/// and *cannot* be called at runtime.
///
/// This is meant to be used by the Dart Dev Compiler when
/// compiling its runtime to ES6.
///
/// The following expression:
///
/// foo(a, b, spread(others))
///
/// Will be compiled to ES6 code like the following:
///
/// foo(a, b, ...others)
///
/// Which is roughly equivalent to the following ES5 code:
///
/// foo.apply(null, [a, b].concat(others))
///
dynamic spread(args) {
throw StateError('The spread function cannot be called, '
'it should be compiled away.');
}
-1636
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,10 +1,10 @@
name: js
version: 0.6.6
version: 0.6.7
description: Annotations to create static Dart interfaces for JavaScript APIs.
repository: https://github.com/dart-lang/sdk/tree/main/pkg/js
environment:
sdk: ">=2.19.0-345.0.dev <3.0.0"
sdk: ">=2.19.0 <3.0.0"
dependencies:
meta: ^1.7.0
@@ -16,7 +16,6 @@ js
dependencies: sdk
lib/js.dart
lib/js_util.dart
lib/src/varargs.dart
main
**main module**