Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove deprecated features.

  • Loading branch information...
commit 93c149ecc235d88613bb61b4f6b1abe2940020f9 1 parent 9f16053
@justinfagnani justinfagnani authored
View
8 example/google-chart/bubblechart.dart
@@ -32,15 +32,15 @@ void drawVisualization() {
var tableData = gviz.arrayToDataTable(arrayData);
var options = js.map({
- 'title': 'Correlation between life expectancy, fertility rate and population of some world countries (2010)',
+ 'title': 'Correlation between life expectancy, '
+ 'fertility rate and population of some world countries (2010)',
'hAxis': {'title': 'Life Expectancy'},
'vAxis': {'title': 'Fertility Rate'},
'bubble': {'textStyle': {'fontSize': 11}}
});
// Create and draw the visualization.
- var chart = new js.Proxy(gviz.BubbleChart,
- query('#visualization'));
+ var chart = new js.Proxy(gviz.BubbleChart, querySelector('#visualization'));
chart.draw(tableData, options);
}
@@ -48,6 +48,6 @@ main() {
js.context.google.load('visualization', '1', js.map(
{
'packages': ['corechart'],
- 'callback': new js.Callback.once(drawVisualization)
+ 'callback': drawVisualization,
}));
}
View
41 example/google-maps/directions.dart
@@ -9,14 +9,13 @@
import 'dart:html';
import 'package:js/js.dart' as js;
-var maps;
+// Save the JS google.maps namespace for convenience.
+final maps = js.context.google.maps;
+
var directionsDisplay;
var directionsService;
void main() {
- // Save the JS google.maps namespace for convenience. It must be retained
- // as it's used beyond this scope.
- maps = js.retain(js.context.google.maps);
// Allocate a new JS Map with the following options. See:
// https://developers.google.com/maps/documentation/javascript/reference#Map
@@ -25,34 +24,34 @@ void main() {
'mapTypeId': maps.MapTypeId.ROADMAP,
'center': new js.Proxy(maps.LatLng, 47.6097, -122.3331)
});
- var map = new js.Proxy(maps.Map, query('#map_canvas'), myOptions);
+
+ var map = new js.Proxy(maps.Map, querySelector('#map_canvas'), myOptions);
// Allocate a new JS DirectionsRenderer to display directions on the page.
// See
// https://developers.google.com/maps/documentation/javascript/reference#DirectionsRenderer
- directionsDisplay =
- js.retain(new js.Proxy(maps.DirectionsRenderer,
- js.map({'map': map})));
- directionsDisplay.setPanel(query('#directions_panel'));
+ directionsDisplay = new js.Proxy(maps.DirectionsRenderer,
+ js.map({'map': map}));
+ directionsDisplay.setPanel(querySelector('#directions_panel'));
// Allocate a new JS DirectionService to forward requests to the server.
// See:
// https://developers.google.com/maps/documentation/javascript/reference#DirectionsService
- directionsService = js.retain(new js.Proxy((maps.DirectionsService)));
+ directionsService = new js.Proxy(maps.DirectionsService);
- var control = query('#control');
+ var control = querySelector('#control');
control.style.display = 'block';
map.controls[maps.ControlPosition.TOP].push(control);
// Recalculate the route when the start or end points are changed.
- query('#start').onChange.listen(calcRoute);
- query('#end').onChange.listen(calcRoute);
+ querySelector('#start').onChange.listen(calcRoute);
+ querySelector('#end').onChange.listen(calcRoute);
}
void calcRoute(e) {
- final panel = query('#directions_panel');
- final SelectElement start = query('#start');
- final SelectElement end = query('#end');
+ final panel = querySelector('#directions_panel');
+ final SelectElement start = querySelector('#start');
+ final SelectElement end = querySelector('#end');
panel.innerHtml = "<b>Thinking...</b>";
@@ -63,14 +62,12 @@ void calcRoute(e) {
'travelMode': maps.DirectionsTravelMode.DRIVING
});
- // The routing callback is only called once.
- directionsService.route(request, new js.Callback.once((response, status) {
+ directionsService.route(request, (response, status) {
if (status == maps.DirectionsStatus.OK) {
- document.query('#directions_panel').innerHtml = "";
+ querySelector('#directions_panel').innerHtml = "";
directionsDisplay.setDirections(response);
} else {
- document.query('#directions_panel').innerHtml = "<b>Err, try flying.</b>";
+ querySelector('#directions_panel').innerHtml = "<b>Err, try flying.</b>";
}
- }));
- print('Live ${js.proxyCount()} proxies out of ${js.proxyCount(all: true)} ever allocated.');
+ });
}
View
30 example/google-maps/marker_simple.dart
@@ -13,7 +13,7 @@
import 'dart:html';
import 'package:js/js.dart' as js;
-final maps = js.retain(js.context.google.maps);
+final maps = js.context.google.maps;
class LatLng implements js.Serializable<js.Proxy> {
final js.Proxy _proxy;
@@ -86,19 +86,17 @@ class Marker implements js.Serializable<js.Proxy> {
}
void main() {
- js.scoped(() {
- final myLatlng = new LatLng(-25.363882,131.044922);
- final mapOptions = new MapOptions()
- ..zoom = 4
- ..center = myLatlng
- ..mapTypeId = MapTypeId.ROADMAP
- ;
- final map = new GMap(query("#map_canvas"), mapOptions);
-
- final marker = new Marker(new MarkerOptions()
- ..position = myLatlng
- ..map = map
- ..title = "Hello World!"
- );
- });
+ final myLatlng = new LatLng(-25.363882,131.044922);
+ final mapOptions = new MapOptions()
+ ..zoom = 4
+ ..center = myLatlng
+ ..mapTypeId = MapTypeId.ROADMAP
+ ;
+ final map = new GMap(query("#map_canvas"), mapOptions);
+
+ final marker = new Marker(new MarkerOptions()
+ ..position = myLatlng
+ ..map = map
+ ..title = "Hello World!"
+ );
}
View
2  example/twitter/twitter.dart
@@ -10,7 +10,7 @@ import 'package:js/js.dart' as js;
void main() {
// Create a JavaScript function called display that forwards to the Dart
// function.
- js.context.display = new js.Callback.once(display);
+ js.context.display = display;
// Inject a JSONP request to Twitter invoking the JavaScript display
// function.
View
139 lib/js.dart
@@ -13,7 +13,7 @@
* with cross-runtime interoperation.
*
* The top-level [context] getter provides a [Proxy] to the global JavaScript
- * context for the page your Dart code is running on. In the following example:
+ * context for the page your Dart code is running on. In the following example:
*
* import 'package:js/js.dart' as js;
*
@@ -23,27 +23,24 @@
*
* js.context.alert creates a proxy to the top-level alert function in
* JavaScript. It is invoked from Dart as a regular function that forwards to
- * the underlying JavaScript one. By default, proxies are released when
+ * the underlying JavaScript one. By default, proxies are released when
* the currently executing event completes, e.g., when main is completes
* in this example.
*
* The library also enables JavaScript proxies to Dart objects and functions.
* For example, the following Dart code:
*
- * js.context.dartCallback = new Callback.once((x) => print(x*2));
+ * js.context.dartCallback = (x) => print(x*2);
*
* defines a top-level JavaScript function 'dartCallback' that is a proxy to
- * the corresponding Dart function. The [Callback.once] constructor allows the
- * proxy to the Dart function to be retained across multiple events;
- * instead it is released after the first invocation. (This is a common
- * pattern for asychronous callbacks.)
+ * the corresponding Dart function.
*
* Note, parameters and return values are intuitively passed by value for
- * primitives and by reference for non-primitives. In the latter case, the
+ * primitives and by reference for non-primitives. In the latter case, the
* references are automatically wrapped and unwrapped as proxies by the library.
*
* This library also allows construction of JavaScripts objects given a [Proxy]
- * to a corresponding JavaScript constructor. For example, if the following
+ * to a corresponding JavaScript constructor. For example, if the following
* JavaScript is loaded on the page:
*
* function Foo(x) {
@@ -79,49 +76,11 @@ import 'package:meta/meta.dart' show proxy;
/**
- * Returns a proxy to the global JavaScript context for this page.
+ * A proxy on the global JavaScript context for this page.
*/
final Proxy context = new Proxy._(js.context);
/**
- * Executes the closure [f] within a scope. Any proxies created within this
- * scope are invalidated afterward unless they are converted to a global proxy.
- */
-@deprecated
-scoped(f) => f();
-
-/*
- * Enters a scope and returns the depth of the scope stack.
- */
-/// WARNING: This API is experimental and may be removed.
-@deprecated
-int $experimentalEnterScope() => 0;
-
-/*
- * Exits a scope. The [depth] must match that returned by the corresponding
- * enter scope call.
- */
-/// WARNING: This API is experimental and may be removed.
-@deprecated
-void $experimentalExitScope(int depth) {}
-
-/**
- * Retains the given [object] beyond the current scope.
- * Instead, it will need to be explicitly released.
- * The given [object] is returned for convenience.
- */
-// TODO(aa) : change to "<T extends Serializable<Proxy>> T retain(T object)"
-// once generic methods have landed.
-@deprecated
-dynamic retain(Serializable<Proxy> object) => object;
-
-/**
- * Releases a retained [object].
- */
-@deprecated
-void release(Serializable<Proxy> object) {}
-
-/**
* Check if [proxy] is instance of [type].
*/
bool instanceof(Serializable<Proxy> proxy, Serializable<FunctionProxy> type) =>
@@ -150,62 +109,13 @@ Proxy map(Map data) => new Proxy._json(data);
*/
Proxy array(Iterable data) => new Proxy._json(data);
-/**
- * Converts a local Dart function to a callback that can be passed to
- * JavaScript.
- *
- * A callback can either be:
- *
- * - single-fire, in which case it is automatically invalidated after the first
- * invocation, or
- * - multi-fire, in which case it must be explicitly disposed.
- *
- * *Deprecated* Use the callback directly or use [FunctionProxy.withThis(f)] to
- * capture the js `this`.
- */
-@deprecated
-class Callback implements Serializable<FunctionProxy> {
- final FunctionProxy _functionProxy;
-
- Callback._(this._functionProxy);
-
- factory Callback(Function f) => new Callback._(new FunctionProxy(f));
-
- factory Callback.withThis(Function f) =>
- new Callback._(new FunctionProxy.withThis(f));
-
-
- /**
- * Creates a single-fire [Callback] that invokes [f]. The callback is
- * automatically disposed after the first invocation.
- */
- @deprecated
- factory Callback.once(Function f, {bool withThis: false}) => withThis ?
- new Callback.withThis(f) : new Callback(f);
-
- /**
- * Creates a multi-fire [Callback] that invokes [f]. The callback must be
- * explicitly disposed to avoid memory leaks.
- */
- @deprecated
- factory Callback.many(Function f, {bool withThis: false}) => withThis ?
- new Callback.withThis(f) : new Callback(f);
-
- FunctionProxy toJs() => _functionProxy;
-
- /**
- * Disposes this [Callback] so that it may be collected.
- * Once a [Callback] is disposed, it is an error to invoke it from JavaScript.
- */
- @deprecated
- dispose() {}
-}
-
// Detect unspecified arguments.
class _Undefined {
const _Undefined();
}
+
const _undefined = const _Undefined();
+
List _pruneUndefined(arg1, arg2, arg3, arg4, arg5, arg6) {
// This assumes no argument
final args = [arg1, arg2, arg3, arg4, arg5, arg6];
@@ -323,6 +233,7 @@ class _CallbackFunction implements Function {
call() => throw new StateError('There should always been at least 1 parameter'
'(js this).');
+
noSuchMethod(Invocation invocation) {
final args = invocation.positionalArguments.skip(
withThis != null && withThis ? 0 : 1);
@@ -348,19 +259,10 @@ class FunctionProxy extends Proxy
factory FunctionProxy.withThis(Function f) => new FunctionProxy._(
new js.JsFunction.withThis(new _CallbackFunction(f, withThis: true)));
- // TODO(vsm): This allows calls with a limited number of arguments
- // in the context of dartbug.com/9283. Eliminate pending the resolution
- // of this bug. Note, if this Proxy is called with more arguments then
- // allowed below, it will trigger the 'call' path in Proxy.noSuchMethod
- // - and still work correctly in unminified mode.
- call([arg1 = _undefined, arg2 = _undefined,
- arg3 = _undefined, arg4 = _undefined,
- arg5 = _undefined, arg6 = _undefined]) {
- var arguments = _pruneUndefined(arg1, arg2, arg3, arg4, arg5, arg6);
- return _deserialize(_jsFunction.apply(
- arguments.map(_serialize).toList(), thisArg: _serialize(_thisArg))
- , thisArg: this);
- }
+ // We need to implement call() to satisfy the Function "interface"
+ // This handles the no-arg case, noSuchMethod handles the rest.
+ call() => _deserialize(_jsFunction.apply([], thisArg: _serialize(_thisArg)),
+ thisArg: this);
noSuchMethod(Invocation invocation) {
String member = MirrorSystem.getName(invocation.memberName);
@@ -414,16 +316,3 @@ _deserialize(var o, {thisArg}) {
return o;
}
}
-
-/**
- * Returns the number of allocated proxy objects matching the given
- * conditions. By default, the total number of live proxy objects are
- * return. In a well behaved program, this should stay below a small
- * bound.
- *
- * Set [all] to true to return the total number of proxies ever allocated.
- * Set [dartOnly] to only count proxies to Dart objects (live or all).
- * Set [jsOnly] to only count proxies to JavaScript objects (live or all).
- */
-@deprecated
-int proxyCount({all: false, dartOnly: false, jsOnly: false}) => 0;
View
2  pubspec.yaml
@@ -1,5 +1,5 @@
name: js
-version: 0.0.26
+version: 0.1.0
authors:
- Dart Team <misc@dartlang.org>
- Alexandre Ardhuin <alexandre.ardhuin@gmail.com>
View
39 test/js/browser_tests.dart
@@ -70,19 +70,18 @@ main() {
expect(a.getTime(), isNotNull);
});
- test('js instantiation : new Date(12345678)', () {
+ test('js instantiation : new Date(int)', () {
final a = new js.Proxy(js.context.Date, 12345678);
expect(a.getTime(), equals(12345678));
});
- test('js instantiation : new Date("December 17, 1995 03:24:00 GMT+01:00")',
- () {
+ test('js instantiation : new Date(String)', () {
final a = new js.Proxy(js.context.Date,
- "December 17, 1995 03:24:00 GMT+01:00");
+ "December 17, 1995 03:24:00 GMT+01:00");
expect(a.getTime(), equals(819167040000));
});
- test('js instantiation : new Date(1995,11,17)', () {
+ test('js instantiation : new Date(int, int, int)', () {
// Note: JS Date counts months from 0 while Dart counts from 1.
final a = new js.Proxy(js.context.Date, 1995, 11, 17);
final b = new DateTime(1995, 12, 17);
@@ -92,7 +91,7 @@ main() {
test('js instantiation : new Date(1995,11,17,3,24,0)', () {
// Note: JS Date counts months from 0 while Dart counts from 1.
final a = new js.Proxy.withArgList(js.context.Date,
- [1995, 11, 17, 3, 24, 0]);
+ [1995, 11, 17, 3, 24, 0]);
final b = new DateTime(1995, 12, 17, 3, 24, 0);
expect(a.getTime(), equals(b.millisecondsSinceEpoch));
});
@@ -231,8 +230,8 @@ main() {
test('invoke Dart callback from JS(with js.Callback)', () {
expect(() => js.context.invokeCallback(), throws);
- js.context.callback = new js.Callback.once(() => 42);
- expect(js.context.invokeCallback(), equals(42));
+ js.context.callback = () => 42;
+ expect(js.context.invokeCallback(), 42);
js.deleteProperty(js.context, 'callback');
});
@@ -250,17 +249,6 @@ main() {
expect(js.context.getTypeOf(js.context.razzle), equals("function"));
});
- test('invoke Dart callback from JS with this(with js.Callback)', () {
- final constructor = new js.Callback.once(($this, arg1) {
- $this.a = 42;
- $this.b = js.array(["a", arg1]);
- }, withThis: true);
- var o = new js.Proxy(constructor, "b");
- expect(o.a, equals(42));
- expect(o.b[0], equals("a"));
- expect(o.b[1], equals("b"));
- });
-
test('invoke Dart callback from JS with this', () {
final constructor = new js.FunctionProxy.withThis(($this, arg1) {
$this.a = 42;
@@ -272,13 +260,6 @@ main() {
expect(o.b[1], equals("b"));
});
- test('invoke Dart callback from JS with 11 parameters(with js.Callback)', () {
- js.context.callbackWith11params = new js.Callback.once((p1, p2, p3, p4,
- p5, p6, p7, p8, p9, p10, p11) => '$p1$p2$p3$p4$p5$p6$p7$p8$p9$p10'
- '$p11');
- expect(js.context.invokeCallbackWith11params(), equals('1234567891011'));
- });
-
test('invoke Dart callback from JS with 11 parameters', () {
js.context.callbackWith11params = (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10,
p11) => '$p1$p2$p3$p4$p5$p6$p7$p8$p9$p10$p11';
@@ -359,12 +340,6 @@ main() {
expect(!document.documentElement.contains(result), isTrue);
});
- test('return a JS proxy to JavaScript(with js.Callback)', () {
- var result = js.context.testJsMap(
- new js.Callback.once(() => js.map({ 'value': 42 })));
- expect(result, 42);
- });
-
test('return a JS proxy to JavaScript', () {
var result = js.context.testJsMap(() => js.map({ 'value': 42 }));
expect(result, 42);
View
472 test/js_wrapping/browser_tests.dart
@@ -10,6 +10,7 @@ abstract class _Person {
String sayHello();
}
+
class PersonMP extends jsw.MagicProxy implements _Person {
PersonMP(String firstname, String lastname) :
super(js.context.Person, [firstname, lastname]);
@@ -55,326 +56,289 @@ main() {
useHtmlConfiguration();
test('TypedProxy', () {
- js.scoped(() {
- final john = new PersonTP('John', 'Doe');
- expect(john.firstname, equals('John'));
- john.firstname = 'Joe';
- expect(john.firstname, equals('Joe'));
- });
+ final john = new PersonTP('John', 'Doe');
+ expect(john.firstname, equals('John'));
+ john.firstname = 'Joe';
+ expect(john.firstname, equals('Joe'));
});
test('MagicProxy', () {
- js.scoped(() {
- final john = new PersonMP('John', 'Doe');
- expect(john.firstname, equals('John'));
- expect(john['firstname'], equals('John'));
- john.firstname = 'Joe';
- expect(john.firstname, equals('Joe'));
- expect(john['firstname'], equals('Joe'));
- john['firstname'] = 'John';
- expect(john.firstname, equals('John'));
- expect(john['firstname'], equals('John'));
- });
+ final john = new PersonMP('John', 'Doe');
+ expect(john.firstname, equals('John'));
+ expect(john['firstname'], equals('John'));
+ john.firstname = 'Joe';
+ expect(john.firstname, equals('Joe'));
+ expect(john['firstname'], equals('Joe'));
+ john['firstname'] = 'John';
+ expect(john.firstname, equals('John'));
+ expect(john['firstname'], equals('John'));
});
test('function call', () {
- js.scoped(() {
- final john = new PersonTP('John', 'Doe');
- expect(john.sayHello(), equals("Hello, I'm John Doe"));
- });
+ final john = new PersonTP('John', 'Doe');
+ expect(john.sayHello(), equals("Hello, I'm John Doe"));
});
test('JsDateToDateTimeAdapter', () {
- js.scoped(() {
- final date = new DateTime.now();
- final jsDate = new jsw.JsDateToDateTimeAdapter(date);
- expect(jsDate.millisecondsSinceEpoch,
- equals(date.millisecondsSinceEpoch));
- jsDate.$unsafe.setFullYear(2000);
- expect(jsDate.year, equals(2000));
- });
+ final date = new DateTime.now();
+ final jsDate = new jsw.JsDateToDateTimeAdapter(date);
+ expect(jsDate.millisecondsSinceEpoch,
+ equals(date.millisecondsSinceEpoch));
+ jsDate.$unsafe.setFullYear(2000);
+ expect(jsDate.year, equals(2000));
});
group('JsArrayToListAdapter', () {
test('iterator', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["e0", "e1", "e2"]));
-
- final iterator = m.iterator;
- iterator.moveNext();
- expect(iterator.current, equals("e0"));
- iterator.moveNext();
- expect(iterator.current, equals("e1"));
- iterator.moveNext();
- expect(iterator.current, equals("e2"));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["e0", "e1", "e2"]));
+
+ final iterator = m.iterator;
+ iterator.moveNext();
+ expect(iterator.current, equals("e0"));
+ iterator.moveNext();
+ expect(iterator.current, equals("e1"));
+ iterator.moveNext();
+ expect(iterator.current, equals("e2"));
});
+
test('get length', () {
- js.scoped(() {
- final m1 = new jsw.JsArrayToListAdapter<String>.fromProxy(js.array([]));
- expect(m1.length, equals(0));
- final m2 = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b"]));
- expect(m2.length, equals(2));
- });
+ final m1 = new jsw.JsArrayToListAdapter<String>.fromProxy(js.array([]));
+ expect(m1.length, equals(0));
+ final m2 = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b"]));
+ expect(m2.length, equals(2));
});
+
test('add', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(js.array([]));
- expect(m.length, equals(0));
- m.add("a");
- expect(m.length, equals(1));
- expect(m[0], equals("a"));
- m.add("b");
- expect(m.length, equals(2));
- expect(m[0], equals("a"));
- expect(m[1], equals("b"));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(js.array([]));
+ expect(m.length, equals(0));
+ m.add("a");
+ expect(m.length, equals(1));
+ expect(m[0], equals("a"));
+ m.add("b");
+ expect(m.length, equals(2));
+ expect(m[0], equals("a"));
+ expect(m[1], equals("b"));
});
+
test('clear', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b"]));
- expect(m.length, equals(2));
- m.clear();
- expect(m.length, equals(0));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b"]));
+ expect(m.length, equals(2));
+ m.clear();
+ expect(m.length, equals(0));
});
+
test('remove', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b"]));
- expect(m.length, equals(2));
- m.remove("a");
- expect(m.length, equals(1));
- expect(m[0], equals("b"));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b"]));
+ expect(m.length, equals(2));
+ m.remove("a");
+ expect(m.length, equals(1));
+ expect(m[0], equals("b"));
});
+
test('operator []', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b"]));
- expect(() => m[-1], throwsA(isRangeError));
- expect(() => m[2], throwsA(isRangeError));
- expect(m[0], equals("a"));
- expect(m[1], equals("b"));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b"]));
+ expect(() => m[-1], throwsA(isRangeError));
+ expect(() => m[2], throwsA(isRangeError));
+ expect(m[0], equals("a"));
+ expect(m[1], equals("b"));
});
+
test('operator []=', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b"]));
- expect(() => m[-1] = "c", throwsA(isRangeError));
- expect(() => m[2] = "c", throwsA(isRangeError));
- m[0] = "d";
- m[1] = "e";
- expect(m[0], equals("d"));
- expect(m[1], equals("e"));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b"]));
+ expect(() => m[-1] = "c", throwsA(isRangeError));
+ expect(() => m[2] = "c", throwsA(isRangeError));
+ m[0] = "d";
+ m[1] = "e";
+ expect(m[0], equals("d"));
+ expect(m[1], equals("e"));
});
+
test('set length', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b"]));
- m.length = 10;
- expect(m.length, equals(10));
- expect(m[5], equals(null));
- m.length = 1;
- expect(m.length, equals(1));
- expect(m[0], equals("a"));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b"]));
+ m.length = 10;
+ expect(m.length, equals(10));
+ expect(m[5], equals(null));
+ m.length = 1;
+ expect(m.length, equals(1));
+ expect(m[0], equals("a"));
});
+
test('sort', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["c", "a", "b"]));
- m.sort();
- expect(m.length, equals(3));
- expect(m[0], equals("a"));
- expect(m[1], equals("b"));
- expect(m[2], equals("c"));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["c", "a", "b"]));
+ m.sort();
+ expect(m.length, equals(3));
+ expect(m[0], equals("a"));
+ expect(m[1], equals("b"));
+ expect(m[2], equals("c"));
});
+
test('insert', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b", "c"]));
- m.insert(1, "d");
- expect(m.length, equals(4));
- expect(m[0], equals("a"));
- expect(m[1], equals("d"));
- expect(m[2], equals("b"));
- expect(m[3], equals("c"));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b", "c"]));
+ m.insert(1, "d");
+ expect(m.length, equals(4));
+ expect(m[0], equals("a"));
+ expect(m[1], equals("d"));
+ expect(m[2], equals("b"));
+ expect(m[3], equals("c"));
});
+
test('removeAt', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b", "c"]));
- expect(m.removeAt(1), equals("b"));
- expect(m.length, equals(2));
- expect(m[0], equals("a"));
- expect(m[1], equals("c"));
- expect(() => m.removeAt(2), throwsA(isRangeError));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b", "c"]));
+ expect(m.removeAt(1), equals("b"));
+ expect(m.length, equals(2));
+ expect(m[0], equals("a"));
+ expect(m[1], equals("c"));
+ expect(() => m.removeAt(2), throwsA(isRangeError));
});
+
test('removeLast', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b", "c", null]));
- expect(m.removeLast(), isNull);
- expect(m.removeLast(), equals("c"));
- expect(m.removeLast(), equals("b"));
- expect(m.removeLast(), equals("a"));
- expect(m.length, equals(0));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b", "c", null]));
+ expect(m.removeLast(), isNull);
+ expect(m.removeLast(), equals("c"));
+ expect(m.removeLast(), equals("b"));
+ expect(m.removeLast(), equals("a"));
+ expect(m.length, equals(0));
});
+
test('sublist', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b", "c", null]));
- final sl1 = m.sublist(2);
- expect(sl1.length, equals(2));
- expect(sl1[0], equals("c"));
- expect(sl1[1], isNull);
- final sl2 = m.sublist(1, 3);
- expect(sl2.length, equals(2));
- expect(sl2[0], equals("b"));
- expect(sl2[1], equals("c"));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b", "c", null]));
+ final sl1 = m.sublist(2);
+ expect(sl1.length, equals(2));
+ expect(sl1[0], equals("c"));
+ expect(sl1[1], isNull);
+ final sl2 = m.sublist(1, 3);
+ expect(sl2.length, equals(2));
+ expect(sl2[0], equals("b"));
+ expect(sl2[1], equals("c"));
});
+
test('setRange', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b", "c", null]));
- m.setRange(1, 2, [null, null]);
- expect(m.length, equals(4));
- expect(m[0], equals("a"));
- expect(m[1], isNull);
- expect(m[2], isNull);
- expect(m[3], isNull);
- m.setRange(3, 1, [null, "c", null], 1);
- expect(m[0], equals("a"));
- expect(m[1], isNull);
- expect(m[2], isNull);
- expect(m[3], equals("c"));
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b", "c", null]));
+ m.setRange(1, 2, [null, null]);
+ expect(m.length, equals(4));
+ expect(m[0], equals("a"));
+ expect(m[1], isNull);
+ expect(m[2], isNull);
+ expect(m[3], isNull);
+ m.setRange(3, 1, [null, "c", null], 1);
+ expect(m[0], equals("a"));
+ expect(m[1], isNull);
+ expect(m[2], isNull);
+ expect(m[3], equals("c"));
});
+
test('removeRange', () {
- js.scoped(() {
- final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
- js.array(["a", "b", "c", null]));
- m.removeRange(1, 3);
- expect(m.length, equals(2));
- expect(m[0], equals("a"));
- expect(m[1], isNull);
- });
+ final m = new jsw.JsArrayToListAdapter<String>.fromProxy(
+ js.array(["a", "b", "c", null]));
+ m.removeRange(1, 3);
+ expect(m.length, equals(2));
+ expect(m[0], equals("a"));
+ expect(m[1], isNull);
});
test('bidirectionnal serialization of Proxy', () {
- js.scoped(() {
- js.context.myArray = js.array([]);
- final myList = new jsw.JsArrayToListAdapter<PersonTP>.fromProxy(
- js.context.myArray, new jsw.TranslatorForSerializable<PersonTP>(
- (p) => new PersonTP.fromProxy(p)));
-
- myList.add(new PersonTP('John', 'Doe'));
- myList.add(null);
- expect(myList[0].firstname, 'John');
- expect(myList[1], isNull);
- });
+ js.context.myArray = js.array([]);
+ final myList = new jsw.JsArrayToListAdapter<PersonTP>.fromProxy(
+ js.context.myArray, new jsw.TranslatorForSerializable<PersonTP>(
+ (p) => new PersonTP.fromProxy(p)));
+
+ myList.add(new PersonTP('John', 'Doe'));
+ myList.add(null);
+ expect(myList[0].firstname, 'John');
+ expect(myList[1], isNull);
});
test('family', () {
- js.scoped(() {
- final father = new PersonTP("John", "Doe");
- final child1 = new PersonTP("Lewis", "Doe")
- ..father = father;
- final child2 = new PersonTP("Andy", "Doe")
- ..father = father;
- father.children.addAll([child1, child2]);
- expect(father.children.length, 2);
- expect(father.children.map((p) => p.firstname).join(","), "Lewis,Andy");
- expect(child1.father.firstname, "John");
- });
+ final father = new PersonTP("John", "Doe");
+ final child1 = new PersonTP("Lewis", "Doe")
+ ..father = father;
+ final child2 = new PersonTP("Andy", "Doe")
+ ..father = father;
+ father.children.addAll([child1, child2]);
+ expect(father.children.length, 2);
+ expect(father.children.map((p) => p.firstname).join(","), "Lewis,Andy");
+ expect(child1.father.firstname, "John");
});
test('bidirectionnal serialization of Serializable', () {
- js.scoped(() {
- js.context.myArray = js.array([]);
- final myList = new jsw.JsArrayToListAdapter<Color>.fromProxy(
- js.context.myArray,
- new jsw.Translator<Color>(
- (e) => e != null ? new Color._(e) : null,
- (e) => e != null ? e.toJs() : null
- )
- );
-
- myList.add(Color.BLUE);
- myList.add(null);
- expect(myList[0], Color.BLUE);
- expect(myList[1], isNull);
- });
+ js.context.myArray = js.array([]);
+ final myList = new jsw.JsArrayToListAdapter<Color>.fromProxy(
+ js.context.myArray,
+ new jsw.Translator<Color>(
+ (e) => e != null ? new Color._(e) : null,
+ (e) => e != null ? e.toJs() : null
+ )
+ );
+
+ myList.add(Color.BLUE);
+ myList.add(null);
+ expect(myList[0], Color.BLUE);
+ expect(myList[1], isNull);
});
});
group('JsObjectToMapAdapter', () {
test('get keys', () {
- js.scoped(() {
- final m = new jsw.JsObjectToMapAdapter<int>.fromProxy(
- js.map({"a": 1, "b": 2}));
- final keys = m.keys;
- expect(keys.length, equals(2));
- expect(keys, contains("a"));
- expect(keys, contains("b"));
- });
+ final m = new jsw.JsObjectToMapAdapter<int>.fromProxy(
+ js.map({"a": 1, "b": 2}));
+ final keys = m.keys;
+ expect(keys.length, equals(2));
+ expect(keys, contains("a"));
+ expect(keys, contains("b"));
});
+
test('containsKey', () {
- js.scoped(() {
- final m = new jsw.JsObjectToMapAdapter.fromProxy(
- js.map({"a": 1, "b": "c"}));
- expect(m.containsKey("a"), equals(true));
- expect(m.containsKey("d"), equals(false));
- });
+ final m = new jsw.JsObjectToMapAdapter.fromProxy(
+ js.map({"a": 1, "b": "c"}));
+ expect(m.containsKey("a"), equals(true));
+ expect(m.containsKey("d"), equals(false));
});
+
test('operator []', () {
- js.scoped(() {
- final m = new jsw.JsObjectToMapAdapter.fromProxy(
- js.map({"a": 1, "b": "c"}));
- expect(m["a"], equals(1));
- expect(m["b"], equals("c"));
- });
+ final m = new jsw.JsObjectToMapAdapter.fromProxy(
+ js.map({"a": 1, "b": "c"}));
+ expect(m["a"], equals(1));
+ expect(m["b"], equals("c"));
});
+
test('operator []=', () {
- js.scoped(() {
- final m = new jsw.JsObjectToMapAdapter.fromProxy(js.map({}));
- m["a"] = 1;
- expect(m["a"], equals(1));
- expect(m.length, equals(1));
- m["b"] = "c";
- expect(m["b"], equals("c"));
- expect(m.length, equals(2));
- });
+ final m = new jsw.JsObjectToMapAdapter.fromProxy(js.map({}));
+ m["a"] = 1;
+ expect(m["a"], equals(1));
+ expect(m.length, equals(1));
+ m["b"] = "c";
+ expect(m["b"], equals("c"));
+ expect(m.length, equals(2));
});
+
test('remove', () {
- js.scoped(() {
- final m = new jsw.JsObjectToMapAdapter.fromProxy(
- js.map({"a": 1, "b": "c"}));
- expect(m.remove("a"), equals(1));
- expect(m["b"], equals("c"));
- expect(m.length, equals(1));
- });
+ final m = new jsw.JsObjectToMapAdapter.fromProxy(
+ js.map({"a": 1, "b": "c"}));
+ expect(m.remove("a"), equals(1));
+ expect(m["b"], equals("c"));
+ expect(m.length, equals(1));
});
test('bidirectionnal serialization of Proxy', () {
- js.scoped(() {
- final myMap = new jsw.JsObjectToMapAdapter<PersonTP>.fromProxy(
- js.map({}), new jsw.TranslatorForSerializable<PersonTP>((p) =>
- new PersonTP.fromProxy(p)));
- myMap["a"] = new PersonTP('John', 'Doe');
- expect(myMap["a"].firstname, 'John');
- });
+ final myMap = new jsw.JsObjectToMapAdapter<PersonTP>.fromProxy(
+ js.map({}), new jsw.TranslatorForSerializable<PersonTP>((p) =>
+ new PersonTP.fromProxy(p)));
+ myMap["a"] = new PersonTP('John', 'Doe');
+ expect(myMap["a"].firstname, 'John');
});
+
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.