anchor.diff:  // for details. All rights reserved. Use of this source code is governed by a
   // BSD-style license that can be found in the LICENSE file.
   
  -/**
  - * This part contains helpers for supporting runtime type information.
  - *
  - * The helper use a mixture of Dart and JavaScript objects. To indicate which is
  - * used where we adopt the scheme of using explicit type annotation for Dart
  - * objects and 'var' or omitted return type for JavaScript objects.
  - *
  - * Since bool, int, and String values are represented by the same JavaScript
  - * primitives, type annotations are used for these types in all cases.
  - *
  - * Several methods use a common JavaScript encoding of runtime type information.
  - * This encoding is referred to as the type representation which is one of
  - * these:
  - *  1) a JavaScript constructor for a class C: the represented type is the raw
  - *     type C.
  - *  2) a Dart object: this is the interceptor instance for a native type.
  - *  3) a JavaScript object: this represents a class for which there is no
  - *     JavaScript constructor, because it is only used in type arguments or it
  - *     is native. The represented type is the raw type of this class.
  - *  4) a JavaScript array: the first entry is of type 1, 2 or 3 and contains the
  - *     subtyping flags and the substitution of the type and the rest of the
  - *     array are the type arguments.
  - *  5) `null`: the dynamic type.
  - *
  - *
  - * To check subtype relations between generic classes we use a JavaScript
  - * expression that describes the necessary substitution for type arguments.
  - * Such a substitution expresssion can be:
  - *  1) `null`, if no substituted check is necessary, because the
  - *     type variables are the same or there are no type variables in the class
  - *     that is checked for.
  - *  2) A list expression describing the type arguments to be used in the
  - *     subtype check, if the type arguments to be used in the check do not
  - *     depend on the type arguments of the object.
  - *  3) A function mapping the type variables of the object to be checked to
  - *     a list expression.
  - */
  -
   part of _js_helper;
   
  -Type createRuntimeType(String name) => new TypeImpl(name);
  +setRuntimeTypeInfo(target, typeInfo) {
  +  assert(typeInfo == null || typeInfo is JSArray);
  +  // We have to check for null because factories may return null.
  +  if (target != null) JS('var', r'#.$builtinTypeInfo = #', target, typeInfo);
  +}
  +
  +getRuntimeTypeInfo(target) {
  +  if (target == null) return null;
  +  return JS('var', r'#.$builtinTypeInfo', target);
  +}
  +
  +getRuntimeTypeArgument(target, substitution, index) {
  +  var arguments = substitute(substitution, getRuntimeTypeInfo(target));
  +  return (arguments == null) ? null : getField(arguments, index);
  +}
   
   class TypeImpl implements Type {
     final String _typeName;
   
     TypeImpl(this._typeName);
   
  -  String toString() => _typeName;
  +  toString() => _typeName;
   
     // TODO(ahe): This is a poor hashCode as it collides with its name.
     int get hashCode => _typeName.hashCode;
  
positive.code:   // arguments and no substitution, it is used as raw type.  If [t] has no
    // type arguments, it used as a raw type.  In both cases, [s] is a subtype
    // of [t].
    if ((!isJsArray(s) && isNull(substitution)) || !isJsArray(t)) {
      return true;
    }
    // Recursively check the type arguments.
    return checkArguments(substitution, getArguments(s), getArguments(t));
  }
  
  /**
   * Calls the JavaScript [function] with the [arguments] with the global scope
   * as the [:this:] context.
   */
  invoke(var function, var arguments) {
    assert(isJsFunction(function));
    assert(isNull(arguments) || isJsArray(arguments));
    return JS('var', r'#.apply(null, #)', function, arguments);
  }
  
  /// Calls the property [name] on the JavaScript [object].
  call(var object, String name) => JS('var', r'#[#]()', object, name);
  
  /// Returns the property [name] of the JavaScript object [object].
  getField(var object, String name) => JS('var', r'#[#]', object, name);
  
  /// Returns the property [index] of the JavaScript array [array].
  getIndex(var array, int index) {
    assert(isJsArray(array));
    return JS('var', r'#[#]', array, index);
  }
  
  /// Returns the length of the JavaScript array [array].
  int getLength(var array) {
    assert(isJsArray(array));
    return JS('int', r'#.length', array);
  }
  
  /// Returns [:true:] if [o] is a JavaScript function.
  bool isJsFunction(var o) => JS('bool', r'typeof # == "function"', o);
  
  /**
   * Returns [:true:] if [o] is equal to [:null:], that is either [:null:] or
   * [:undefined:]. We use this helper to avoid generating code under the invalid
   * assumption that [o] is a Dart value.
   */
  bool isNull(var o) => JS('bool', '# == null', o);
  
  /**
   * Returns [:true:] if [o] is not equal to [:null:], that is neither [:null:]
   * nor [:undefined:].  We use this helper to avoid generating code under the
   * invalid assumption that [o] is a Dart value.
   */
  bool isNotNull(var o) => JS('bool', '# != null', o);
  
  /**
   * Returns [:true:] if the JavaScript values [s] and [t] are identical. We use
   * this helper to avoid generating code under the invalid assumption that [s]
   * and [t] are Dart values.
   */
  bool isIdentical(var s, var t) => JS('bool', '# === #', s, t);
  
  /**
   * Returns [:true:] if the JavaScript values [s] and [t] are not identical. We
   * use this helper to avoid generating code under the invalid assumption that
   * [s] and [t] are Dart values.
   */
  bool isNotIdentical(var s, var t) => JS('bool', '# !== #', s, t);
  
negative.code: }
  
  /**
   * Check whether the type represented by [s] is a subtype of the type
   * represented by [t].
   *
   * Type representations can be:
   *  1) a JavaScript constructor for a class C: the represented type is the raw
   *     type C.
   *  2) a Dart object: this is the interceptor instance for a native type.
   *  3) a JavaScript object: this represents a class for which there is no
   *     JavaScript constructor, because it is only used in type arguments or it
   *     is native. The represented type is the raw type of this class.
   *  4) a JavaScript array: the first entry is of type 1, 2 or 3 and contains the
   *     subtyping flags and the substitution of the type and the rest of the
   *     array are the type arguments.
   *  5) [:null:]: the dynamic type.
   */
  bool isSubtype(var s, var t) {
    // If either type is dynamic, [s] is a subtype of [t].
    if (JS('bool', '# == null', s) || JS('bool', '# == null', t)) return true;
    // Subtyping is reflexive.
    if (JS('bool', '# === #', s, t)) return true;
    // Get the object describing the class and check for the subtyping flag
    // constructed from the type of [t].
    var typeOfS = s is JSArray ? s[0] : s;
    var typeOfT = t is JSArray ? t[0] : t;
    // TODO(johnniwinther): replace this with the real function subtype test.
    if (JS('bool', '#.func', s) == true || JS('bool', '#.func', t) == true ) {
      return true;
    }
    // Check for a subtyping flag.
    var test = '${JS_OPERATOR_IS_PREFIX()}${runtimeTypeToString(typeOfT)}';
    if (getField(typeOfS, test) == null) return false;
    // Get the necessary substitution of the type arguments, if there is one.
    var substitution;
    if (JS('bool', '# !== #', typeOfT, typeOfS)) {
      var field = '${JS_OPERATOR_AS_PREFIX()}${runtimeTypeToString(typeOfT)}';
      substitution = getField(typeOfS, field);
    }
  