Skip to content

Dart2js minified vs non-minified treats shifts differently if value < 0 #30841

Closed
@nex3

Description

@nex3

From @stephan-gruen on September 12, 2017 13:0

I ran into this while testing out the BZip2Encoder class from the widely used archive library, which does not work if minified.
At the end of the day this is why: the shift result from unminified and minified JavaScript is not the same if the value is negativ. So this is bad as the behavior should be the same.

print('1 >> 0  = ${1 >> 0}');
print('0 >> 0  = ${0 >> 0}');
print('-1 >> 0  = ${-1 >> 0}');
print('-2 >> 0  = ${-2 >> 0}');

print('1 >> 1  = ${1 >> 1}');
print('0 >> 1  = ${0 >> 1}');
print('-1 >> 1  = ${-1 >> 1}');
print('-2 >> 1  = ${-2 >> 1}');

print('1 << 0  = ${1 << 0}');
print('0 << 0  = ${0 << 0}');
print('-1 << 0  = ${-1 << 0}');
print('-2 << 0  = ${-2 << 0}');

print('1 << 1  = ${1 << 1}');
print('0 << 1  = ${0 << 1}');
print('-1 << 1  = ${-1 << 1}');
print('-2 << 1  = ${-2 << 1}');

pub build mode Debug (uses dart2js to generate unminified JavaScript):

 1 >> 0  = 1
 0 >> 0  = 0
-1 >> 0  = -1
-2 >> 0  = -2
 1 >> 1  = 0
 0 >> 1  = 0
-1 >> 1  = -1
-2 >> 1  = -1
 1 << 0  = 1
 0 << 0  = 0
-1 << 0  = -1
-2 << 0  = -2 
 1 << 1  = 2
 0 << 1  = 0
-1 << 1  = -2
-2 << 1  = -4

pub build mode Release (uses dart2js to generate minified JavaScript):

1 >> 0  = 1
0 >> 0  = 0
-1 >> 0  = 4294967295
-2 >> 0  = 4294967294
1 >> 1  = 0
0 >> 1  = 0
-1 >> 1  = 4294967295
-2 >> 1  = 4294967295
1 << 0  = 1
0 << 0  = 0
-1 << 0  = 4294967295
-2 << 0  = 4294967294
1 << 1  = 2
0 << 1  = 0
-1 << 1  = 4294967294
-2 << 1  = 4294967292

Copied from original issue: dart-lang/pub#1703

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)web-dart2js

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions