Skip to content

Commit

Permalink
feat(Jint): Int32Array is used instead of bitwise operator
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppe-santoro committed Jul 20, 2017
1 parent 82b6322 commit 6b2bf71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/java.lang/src/jint_primitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import { JRelational } from '../../java.lang.native.operator/src/jrelational';
* Note: To retrieve the actual boolean value of a jint you have to use {@code .value} syntax.
*/
export class Jint implements JEquality<Jint>, JRelational<Jint> {
private _value: number;
private _value: Int32Array;

constructor(value: number = 0) {
this._value = new Int32Array(1);
this.value = value;
}

get value() {
return this._value;
return this._value[0];
}

/**
Expand All @@ -32,7 +33,7 @@ export class Jint implements JEquality<Jint>, JRelational<Jint> {
* bitwise operation `| 0`.
*/
set value(value: number) {
this._value = value | 0;
this._value[0] = value;
}

public eq(expr: Jint): Jboolean {
Expand Down
6 changes: 6 additions & 0 deletions packages/java.lang/test/jint_primitive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ describe('Jint', () => {
expect(i.value).to.be.eq(0);
});

it('should be 1 when set to 1.9', () => {
const i = new Jint(1.9);

expect(i.value).to.be.eq(1);
});

it('should overflow when a number grater then 2^31-1 is set.', () => {
const i = new Jint(Math.pow(2, 31));

Expand Down

0 comments on commit 6b2bf71

Please sign in to comment.