Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/angular2/src/facade/collection.es6
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ export class ListWrapper {
static isEmpty(list) {
return list.length == 0;
}
static fill(list:List, value, start:int = 0, end:int = undefined) {
list.fill(value, start, end);
static fill(list:List, value, start:int = 0, end:int = null) {
list.fill(value, start, end === null ? undefined: end);
}
static equals(a:List, b:List):boolean {
if(a.length != b.length) return false;
Expand Down
47 changes: 27 additions & 20 deletions modules/angular2/src/facade/lang.es6
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import {assert} from 'rtts_assert/rtts_assert';
export {proxy} from 'rtts_assert/rtts_assert';

export var Type = Function;
export var Math = window.Math;

var assertionsEnabled_ = typeof assert !== 'undefined';

var int;
// global assert support, as Dart has it...
// TODO: `assert` calls need to be removed in production code!
window.assert = assert;
if (assertionsEnabled_) {
window.assert = assert;
// `int` is not a valid JS type
int = assert.define('int', function(value) {
return typeof value === 'number' && value%1 === 0;
});
} else {
int = {};
window.assert = function() {};
}
export {int};

export class FIELD {
constructor(definition) {
Expand Down Expand Up @@ -71,8 +83,8 @@ export class StringWrapper {
return s.startsWith(start);
}

static substring(s:string, start:int, end:int = undefined) {
return s.substring(start, end);
static substring(s:string, start:int, end:int = null) {
return s.substring(start, end === null ? undefined: end);
}

static replaceAllMapped(s:string, from:RegExp, cb:Function): string {
Expand Down Expand Up @@ -157,18 +169,18 @@ export class NumberWrapper {
}
}

export function int() {};
int.assert = function(value) {
return value == null || typeof value == 'number' && value === Math.floor(value);
var RegExp;
if (assertionsEnabled_) {
RegExp = assert.define('RegExp', function(obj) {
assert(obj).is(assert.structure({
single: window.RegExp,
multiple: window.RegExp
}));
});
} else {
RegExp = {};
}

export var RegExp = assert.define('RegExp', function(obj) {
assert(obj).is(assert.structure({
single: window.RegExp,
multiple: window.RegExp
}));
});

export class RegExpWrapper {
static create(regExpStr, flags:string = ''):RegExp {
flags = flags.replace(/g/g, '');
Expand Down Expand Up @@ -224,12 +236,7 @@ export function isJsObject(o):boolean {
}

export function assertionsEnabled():boolean {
try {
var x:int = "string";
return false;
} catch (e) {
return true;
}
return assertionsEnabled_;
}

export function print(obj) {
Expand Down
8 changes: 0 additions & 8 deletions modules/rtts_assert/src/rtts_assert.es6
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,6 @@ function returnType(actual, T) {
return actual;
}

// `int` is not a valid JS type, and traceur will leave
// it untouched. However, we want to be able to use it,
// so we provide it as a global
var intType = _global['int'] = define('int', function(value) {
return typeof value === 'number' && value%1 === 0;
});

// TODO(vojta): define these with DSL?
var string = type.string = define('string', function(value) {
return typeof value === 'string';
Expand Down Expand Up @@ -362,7 +355,6 @@ assert.fail = fail;
assert.string = string;
assert.number = number;
assert.boolean = boolean;
assert.int = intType;

// custom types
assert.arrayOf = arrayOf;
Expand Down
24 changes: 1 addition & 23 deletions modules/rtts_assert/test/rtts_assert_spec.es6
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
// - [assert.structure](#assert-structure)
// - [Integrating with Traceur](#integrating-with-traceur)

import {assert} from 'rtts_assert/rtts_assert';

// Note: `assert` gets automatically included by traceur!

export function main() {

Expand Down Expand Up @@ -370,27 +369,6 @@ describe('Traceur', function() {
});
});

// Note: `int` is not part of JS types, but rtts_assert exposes a global
// so that it can be used as well.
describe('int', function() {

it('should pass', function() {
var x:int = 10;
});

it('should fail', function() {
expect(() => {
var x:int = 'ok';
}).toThrowError('Expected an instance of int, got "ok"!');
});

it('should fail', function() {
expect(() => {
var x:int = 12.3;
}).toThrowError('Expected an instance of int, got 12.3!');
});

});

describe('generics', function() {

Expand Down