Skip to content

Instantly share code, notes, and snippets.

@Ticore
Created May 17, 2017 17:33
Show Gist options
  • Select an option

  • Save Ticore/58128c76f5fa772dc6fd6d721fc63221 to your computer and use it in GitHub Desktop.

Select an option

Save Ticore/58128c76f5fa772dc6fd6d721fc63221 to your computer and use it in GitHub Desktop.
Dart JS Interop Test
import 'package:js/js.dart';
void main() {
int count = 10000;
var startTime = new DateTime.now();
var jsonStrList = [];
for (int i = 0; i < count; ++i) {
jsonStrList.add(testJSInterop());
}
var endTime = new DateTime.now();
print('${endTime.difference(startTime).inMilliseconds / count} ms/js call');
}
@JS("JSON.stringify")
external String stringify(obj);
String testJSInterop() {
return stringify({'time': new DateTime.now()});
}
<!DOCTYPE html>
<html>
<body>
<script type="application/dart" src="js_interop_test.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
name: js_interop
description: A sample web application
dependencies:
browser: any
js: any
dart_to_js_script_rewriter: ^1.0.1
transformers:
- dart_to_js_script_rewriter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment