Chromium Code Reviews| Index: lib/compiler/implementation/lib/js_helper.dart |
| =================================================================== |
| --- lib/compiler/implementation/lib/js_helper.dart (revision 7269) |
| +++ lib/compiler/implementation/lib/js_helper.dart (working copy) |
| @@ -777,3 +777,91 @@ |
| if (target === null) return null; |
| return JS('var', @'#.builtin$typeInfo', target); |
| } |
| + |
| +/** |
| + * The following methods are called by the runtime to implement |
| + * checked mode. We specialize each primitive type (eg int, bool), and |
| + * use the compiler's convention to do is checks on regular objects. |
| + */ |
| +stringTypeCheck(value) { |
| + if (value === null) return value; |
| + if (value is String) return value; |
| + throw new TypeError('$value does not implement String'); |
| +} |
| + |
| +doubleTypeCheck(value) { |
| + if (value === null) return value; |
| + if (value is double) return value; |
| + throw new TypeError('$value does not implement double'); |
| +} |
| + |
| +numTypeCheck(value) { |
| + if (value === null) return value; |
| + if (value is num) return value; |
| + throw new TypeError('$value does not implement num'); |
| +} |
| + |
| +boolTypeCheck(value) { |
| + if (value === null) return value; |
| + if (value is bool) return value; |
| + throw new TypeError('$value does not implement bool'); |
| +} |
| + |
| +functionTypeCheck(value) { |
| + if (value === null) return value; |
| + if (value is Function) return value; |
| + throw new TypeError('$value does not implement Function'); |
| +} |
| + |
| +intTypeCheck(value) { |
| + if (value === null) return value; |
| + if (value is int) return value; |
| + throw new TypeError('$value does not implement int'); |
| +} |
| + |
| +stringSuperTypeCheck(value, property) { |
| + if (value === null) return value; |
| + if (value is String) return value; |
| + if (JS('bool', '!!#[#]', value, property)) return value; |
| + String name = property.substring(3, property.length); |
|
floitsch
2012/05/07 09:50:07
explain what is cut off.
maybe assert that the pro
ahe
2012/05/07 11:59:57
Be careful about asserting anything in this code.
ngeoffray
2012/05/07 13:15:42
Very good point.
|
| + throw new TypeError('$value does not implement $name'); |
| +} |
| + |
| +listTypeCheck(value) { |
| + if (value === null) return value; |
| + if (value is List) return value; |
| + throw new TypeError('$value does not implement List'); |
| +} |
| + |
| +listSuperTypeCheck(value, property) { |
| + if (value === null) return value; |
| + if (value is List) return value; |
| + if (JS('bool', '!!#[#]', value, property)) return value; |
| + String name = property.substring(3, property.length); |
| + throw new TypeError('$value does not implement $name'); |
| +} |
| + |
| +listSuperNativeTypeCheck(value, property) { |
|
floitsch
2012/05/07 09:50:07
Explain what this does.
ngeoffray
2012/05/07 13:15:42
Done.
|
| + if (value === null) return value; |
| + if (value is List) return value; |
| + if (JS('bool', '#.#()', value, property)) return value; |
|
floitsch
2012/05/07 11:06:56
#.# won't work.
ngeoffray
2012/05/07 13:15:42
Done.
|
| + String name = property.substring(3, property.length); |
| + throw new TypeError('$value does not implement $name'); |
| +} |
| + |
| +propertyTypeCheck(value, property) { |
|
floitsch
2012/05/07 09:50:07
ditto.
ngeoffray
2012/05/07 13:15:42
Done.
|
| + if (value === null) return value; |
| + if (JS('bool', '!!#[#]', value, property)) return value; |
| + String name = property.substring(3, property.length); |
| + throw new TypeError('$value does not implement $name'); |
| +} |
| + |
| +callTypeCheck(value, property) { |
|
floitsch
2012/05/07 09:50:07
ditto.
ngeoffray
2012/05/07 13:15:42
Done.
|
| + if (value === null) return value; |
| + if ((JS('String', 'typeof #', value) === 'object') |
| + && JS('bool', '#.#()', value, property)) { |
|
floitsch
2012/05/07 11:06:56
#.# won't work.
ngeoffray
2012/05/07 13:15:42
Done.
|
| + return value; |
| + } |
| + String name = property.substring(3, property.length); |
| + throw new TypeError('$value does not implement $name'); |
| +} |