Closed
Description
When using the "js" package for javascript interop I am seeing a weird case where running in Dartium gives a different result to compiled javascript running in Chrome.
Dart SDK version: 1.17.1 linux_x64
pkg/js version: 0.6.0
Example code:
<!DOCTYPE html>
<html>
<head>
<title>Interop test</title>
<meta charset="utf-8">
</head>
<body>
<script type="application/dart" src="test.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
@JS()
library interop.test;
import 'package:js/js.dart';
@JS('JSON.stringify')
external String toJson(dynamic object);
@JS()
@anonymous
class Simple
{
external List<int> get numbers;
external set numbers(List<int> numbers);
external factory Simple({ List<int> numbers });
}
void main()
{
var simple = new Simple(numbers: [ 1, 2, 3 ]);
print(toJson(simple));
}
When run in Dartium it produces:
{"numbers":{"0":1,"1":2,"2":3}}
When compiled to javascript and run in Chrome it produces (as expected):
{"numbers":[1,2,3]}
Further experimentation in Dartium reveals that whilst the top-level object appears as this (via a console.log()
interop):
Object {numbers: Array[3]}
numbers: Array[3]
__proto__: Object
the numbers member itself appears as:
[1, 2, 3]
[[class]]: List