feat(facade/lang): support int

This commit is contained in:
Chirayu Krishnappa 2014-10-01 16:57:38 -07:00
parent c7feaba1cb
commit 3482fb1291
2 changed files with 13 additions and 8 deletions

View File

@ -1,7 +1,7 @@
library angular.core.facade.async; library angular.core.facade.async;
export 'dart:async' show Future; export 'dart:async' show Future;
export 'dart:core' show Type; export 'dart:core' show Type, int;
class FIELD { class FIELD {
const constructor(this.definition); const constructor(this.definition);

View File

@ -13,11 +13,11 @@ export class IMPLEMENTS {}
export class StringWrapper { export class StringWrapper {
static fromCharCode(code:number/*int*/) { static fromCharCode(code:int) {
return String.fromCharCode(code); return String.fromCharCode(code);
} }
static charCodeAt(s:string, index:number/*int*/) { static charCodeAt(s:string, index:int) {
return s.charCodeAt(index); return s.charCodeAt(index);
} }
} }
@ -37,16 +37,16 @@ export class StringJoiner {
} }
export class NumberWrapper { export class NumberWrapper {
static parseIntAutoRadix(text:string):number/*int*/ { static parseIntAutoRadix(text:string):int {
var result:number/*int*/ = parseInt(text); var result:int = parseInt(text);
if (isNaN(result)) { if (isNaN(result)) {
throw new Error("Invalid integer literal when parsing " + text); throw new Error("Invalid integer literal when parsing " + text);
} }
return result; return result;
} }
static parseInt(text:string, radix:number/*int*/):number/*int*/ { static parseInt(text:string, radix:int):int {
var result:number/*int*/ = parseInt(text, radix); var result:int = parseInt(text, radix);
if (isNaN(result)) { if (isNaN(result)) {
throw new Error("Invalid integer literal when parsing " + text + " in base " + radix); throw new Error("Invalid integer literal when parsing " + text + " in base " + radix);
} }
@ -54,7 +54,12 @@ export class NumberWrapper {
} }
// TODO: NaN is a valid literal but is returned by parseFloat to indicate an error. // TODO: NaN is a valid literal but is returned by parseFloat to indicate an error.
static parseFloat(text:string):number/*int*/ { static parseFloat(text:string):number {
return parseFloat(text); return parseFloat(text);
} }
} }
export function int() {};
int.assert = function(value) {
return value == null || typeof value == 'number' && value === Math.floor(value);
}