-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement first class mixins #2073
Changes from 33 commits
ef23769
0b9f3a8
63c1f5e
f9badfa
010ad35
b908e27
7d6757c
f715c22
c0eced3
91ac279
194e171
154e12e
ca57cb0
4093914
eb33c56
eeb14ee
1cfd14b
5e1774c
faba24a
52a1e6f
ff3d80e
89ef731
93b812a
6e85d50
2738c00
80fd8bb
9485b4f
3144e02
f1c1d5a
895b2ca
96bbca2
679e1bd
65f2d2d
75ccdfb
6277d5d
f1b4ff3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2019 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
/// A registry of some `T` indexed by ID so that the host can invoke | ||
/// them. | ||
final class OpaqueRegistry<T> { | ||
/// Instantiations of `T` that have been sent to the host. | ||
/// | ||
/// The values are located at indexes in the list matching their IDs. | ||
final _elementsById = <T>[]; | ||
|
||
/// A reverse map from elements to their indexes in [_elementsById]. | ||
final _idsByElement = <T, int>{}; | ||
|
||
/// Returns the compiler-side id associated with [element]. | ||
int getId(T element) { | ||
var id = _idsByElement.putIfAbsent(element, () { | ||
_elementsById.add(element); | ||
return _elementsById.length - 1; | ||
}); | ||
|
||
return id; | ||
} | ||
|
||
/// Returns the compiler-side element associated with [id]. | ||
/// | ||
/// If no such element exists, returns `null`. | ||
T? operator [](int id) => _elementsById[id]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2021 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'package:node_interop/js.dart'; | ||
|
||
import '../../callable.dart'; | ||
import '../../value.dart'; | ||
import '../reflection.dart'; | ||
import '../utils.dart'; | ||
|
||
/// The JavaScript `SassMixin` class. | ||
final JSClass mixinClass = () { | ||
var jsClass = createJSClass('sass.SassMixin', () { | ||
jsThrow(JsError( | ||
'It is not possible to construct a SassMixin through the JavaScript API')); | ||
}); | ||
|
||
getJSClass(SassMixin(Callable('f', '', (_) => sassNull))) | ||
.injectSuperclass(jsClass); | ||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also this does not make much sense. If I understand it correctly the reason we have this for Sass Function type is to allow the "JS" type to inherit the prototype of dart-converted-JS type? If so here the argument passed into SassMixin (the dart type) should be some argument necessary to construct an actual Mixin object. @nex3 I don't fully understand how the JS-interop works so please correct me if I'm wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind. Looks like Mixin just takes AsyncCallable so this is probably fine. |
||
return jsClass; | ||
}(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it is related to the browser failure, but I think the argument is missing
Object self
here when looking at all other values.