You can instantiate ArrayBuffer
and Uint8Array
javascript objects directly from Dart.
If you need only a Uint8Array
javascript object :
js.scoped(() {
final charCodes = "test".charCodes;
final bufView = new js.Proxy(js.context.Uint8Array, js.array(charCodes));
// do something with bufView
});
If you need an ArrayBuffer
javascript object:
js.scoped(() {
final charCodes = "test".charCodes;
final buf = new js.Proxy(js.context.ArrayBuffer, charCodes.length);
final bufView = new js.Proxy(js.context.Uint8Array, buf)
..set(js.array(charCodes));
// do something with buf
});
Basically, each time you need to use the new
javascript operator, you have to use new js.Proxy(construtor,...)
.
WARNING : Until a new version has landed containing the pull-request #34 of js-interop, you have to use the following dependency to run the above code snippet.
dependencies:
js:
git: git://github.com/dart-lang/js-interop.git