dart2js

Bitwise operations, wrong result in Dart2Js

淺唱寂寞╮ 提交于 2021-02-19 04:51:56
问题 I'm doing ZigZag encoding on 32bit integers with Dart. This is the source code that I'm using: int _encodeZigZag(int instance) => (instance << 1) ^ (instance >> 31); int _decodeZigZag(int instance) => (instance >> 1) ^ (-(instance & 1)); The code works as expected in the DartVM. But in dart2js the _decodeZigZag function is returning invalid results if I input negativ numbers. For example -10 . -10 is encoded to 19 and should be decoded back to -10 , but it is decoded to 4294967286 . If I run

Bitwise operations, wrong result in Dart2Js

折月煮酒 提交于 2021-02-19 04:51:52
问题 I'm doing ZigZag encoding on 32bit integers with Dart. This is the source code that I'm using: int _encodeZigZag(int instance) => (instance << 1) ^ (instance >> 31); int _decodeZigZag(int instance) => (instance >> 1) ^ (-(instance & 1)); The code works as expected in the DartVM. But in dart2js the _decodeZigZag function is returning invalid results if I input negativ numbers. For example -10 . -10 is encoded to 19 and should be decoded back to -10 , but it is decoded to 4294967286 . If I run

Dart2js numeric types: determining if a value is an int or a double

心不动则不痛 提交于 2020-04-14 01:10:49
问题 I'm trying to determine if a dynamic parameter to a function is really an int or a double and I'm finding surprising behavior (at least to me). Can anyone explain this output (produced on dartpad)? foo(value) { print("$value is int: ${value is int}"); print("$value is double: ${value is double}"); print("$value runtimetype: ${value.runtimeType}"); } void main() { foo(1); foo(2.0); int x = 10; foo(x); double y = 3.1459; foo(y); double z = 2.0; foo(z); } The output: 1 is int: true 1 is double:

Polymer + Dart2js Not Working

不想你离开。 提交于 2020-01-24 12:04:56
问题 When I create a new application using the Polymer library, it generates a sample project. The project works just fine in Dartium, but when I compile it (using pub build ), it doesn't work anymore. I get two 404's and an uncaught typeerror. Here is my console output in Chrome. GET file:///home/michael/Code/sample/build/web/packages/shadow_dom/shadow_dom.debug.js sample.html:1 GET file:///home/michael/Code/sample/build/web/packages/custom_element/custom-elements.debug.js sample.html:2 Uncaught

Is there a way to check if the script is running in the dart vm or dart2js?

北城余情 提交于 2020-01-03 09:05:08
问题 Is there a way to check if the script is running in the dart vm or dart2js? Maybe using mirrors API? 回答1: There is no official way, as far as I know. The intent is that for all practical purposes, you shouldn't have to know if you are running native or compiled to JavaScript. That said, there are few hacks you can use. The easiest one is probably to exploit the fact that Dart has two numeric types, int and double , while JavaScript has only one, which is equivalent to Dart's double , and

Getting error converting dart2js on polymer project

£可爱£侵袭症+ 提交于 2020-01-02 08:17:15
问题 Unsupported operation: Can't use ownerName in reflection because it is not included in a @MirrorsUsed annotation. ownerName is just an published attribute on the polymer element. I understand there are a few things out there (on web, not on here) like this but none have a solid answer... I also get this below it: NoSuchMethodError : method not found: 'Symbol("title")' Anyone got any ideas. Been wrestling with this for 3 hours and ready to dump polymer. Though It was fun in dartium, if it

Which files are generated when executing `dart2js`? and why?

▼魔方 西西 提交于 2020-01-02 02:14:09
问题 dart2js probably generates .js.map , .js.deps and .precompiled.js . What's the purpose of them? and I donno why dart2js doens't remove them after finishing compile. 回答1: All files are generated by dart2js on purpose: .js : The JavaScript output of your application .precompiled.js : The JavaScript output but with content security policy (CSP) support .js.map : source map file used for debugging the JavaScript code in the browser. It contains a mapping from JavaScript to Dart code lines. .js

dart check if is building

自古美人都是妖i 提交于 2019-12-23 18:42:13
问题 I would like to skip some specific code on pub build. example: Log.print('something ${StackTrace.current}'); I would like that the code above was not transpilled to JS in production. 回答1: Asserts are only executed in checked mode and won't be included by pub build in production mode by default: assert(() { Log.print('something ${StackTrace.current}'); return true; }) DartPad example doesn't print it because it builds in production mode. You can also pass "environment" (not mix up with OS

Dart Package Management via dart2js

时光毁灭记忆、已成空白 提交于 2019-12-23 15:37:25
问题 I'm learning Dart and its dependency manager pub and am having a tough time seeing the "forest through the trees" here. Say I want to use Polymer.dart in my project. So, in my project root, I create the following pubspec.yaml : name: test_dart description: A sample web application dependencies: browser: any polymer: ">=0.9.0 <0.10.0" I then run pub get , which goes to the pub repo and fetches the browser and polymer dependencies that I've specified. It then creates a packages directory in my

Chrome content scripts in Dart

不羁的心 提交于 2019-12-23 03:28:10
问题 Is it possible to use dart for chrome extension content scripts? The following does not seem to call anything in main() import 'dart:html'; import 'package:js/js.dart' as js; void main() { js.context.alert('Hello from Dart via JavaScript'); window.console.log("START!!!"); window.alert("alert"); } manifest.json... "content_scripts": [ { "matches": [ "http://docs.google.com/*", "https://docs.google.com/*" ], "js": [ "packages/browser/dart.js", "packages/browser/interop.js", "packages/js/dart