| Index: lib/compiler/implementation/lib/js_helper.dart
|
| ===================================================================
|
| --- lib/compiler/implementation/lib/js_helper.dart (revision 7371)
|
| +++ lib/compiler/implementation/lib/js_helper.dart (working copy)
|
| @@ -261,8 +261,6 @@
|
| }
|
|
|
| String stringConcat(String receiver, String other) {
|
| - assert(receiver is String);
|
| - assert(other is String);
|
| return JS('String', @'# + #', receiver, other);
|
| }
|
|
|
| @@ -779,3 +777,117 @@
|
| 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');
|
| +}
|
| +
|
| +void propertyTypeError(value, property) {
|
| + // Cuts the property name to the class name.
|
| + String name = property.substring(3, property.length);
|
| + throw new TypeError('$value does not implement $name');
|
| +}
|
| +
|
| +/**
|
| + * For types that are not supertypes of native (eg DOM) types,
|
| + * we emit a simple property check to check that an object implements
|
| + * that type.
|
| + */
|
| +propertyTypeCheck(value, property) {
|
| + if (value === null) return value;
|
| + if (JS('bool', '!!#[#]', value, property)) return value;
|
| + propertyTypeError(value, property);
|
| +}
|
| +
|
| +/**
|
| + * For types that are supertypes of native (eg DOM) types, we emit a
|
| + * call because we cannot add a JS property to their prototype at load
|
| + * time.
|
| + */
|
| +callTypeCheck(value, property) {
|
| + if (value === null) return value;
|
| + if ((JS('String', 'typeof #', value) === 'object')
|
| + && JS('bool', '#[#]()', value, property)) {
|
| + return value;
|
| + }
|
| + propertyTypeError(value, property);
|
| +}
|
| +
|
| +/**
|
| + * Specialization of the type check for String and its supertype
|
| + * since [value] can be a JS primitive.
|
| + */
|
| +stringSuperTypeCheck(value, property) {
|
| + if (value === null) return value;
|
| + if (value is String) return value;
|
| + if (JS('bool', '!!#[#]', value, property)) return value;
|
| + propertyTypeError(value, property);
|
| +}
|
| +
|
| +stringSuperNativeTypeCheck(value, property) {
|
| + if (value === null) return value;
|
| + if (value is String) return value;
|
| + if (JS('bool', '#[#]()', value, property)) return value;
|
| + propertyTypeError(value, property);
|
| +}
|
| +
|
| +/**
|
| + * Specialization of the type check for List and its supertypes,
|
| + * since [value] can be a JS array.
|
| + */
|
| +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;
|
| + propertyTypeError(value, property);
|
| +}
|
| +
|
| +listSuperNativeTypeCheck(value, property) {
|
| + if (value === null) return value;
|
| + if (value is List) return value;
|
| + if (JS('bool', '#[#]()', value, property)) return value;
|
| + propertyTypeError(value, property);
|
| +}
|
|
|