Create Dart class that maps to the JS Type, add the JsObject as an expando on the Dart class and return the created Dart class.

Source

wrap_jso(jsObject) {
  try {
    if (jsObject is! js.JsObject || jsObject == null) {
      // JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
      // or it's a simple type.
      return jsObject;
    }

    // TODO(alanknight): With upgraded custom elements this causes a failure because
    // we need a new wrapper after the type changes. We could possibly invalidate this
    // if the constructor name didn't match?
    var wrapper = js.getDartHtmlWrapperFor(jsObject);
    if (wrapper != null) {
      return wrapper;
    }

    if (jsObject is js.JsArray) {
      var wrappingList = new _DartHtmlWrappingList(jsObject);
      js.setDartHtmlWrapperFor(jsObject, wrappingList);
      return wrappingList;
    }

    // Try the most general type conversions on it.
    // TODO(alanknight): We may be able to do better. This maintains identity,
    // which is useful, but expensive. And if we nest something that only
    // this conversion handles, how does that work? e.g. a list of maps of elements.
    var converted = convertNativeToDart_SerializedScriptValue(jsObject);
    if (!identical(converted, jsObject)) {
      return converted;
    }
    var constructor = jsObject['constructor'];
    if (__interop_checks) {
      debug_or_assert("constructor != null", constructor != null);
    }
    var jsTypeName = constructor['name'];
    if (__interop_checks) {
      debug_or_assert("constructor != null && jsTypeName.length > 0", constructor != null && jsTypeName.length > 0);
    }

    var dartClass_instance;
    if (jsObject.hasProperty('dart_class')) {
      // Got a dart_class (it's a custom element) use it it's already set up.
      dartClass_instance = jsObject['dart_class'];
    } else {
      var localName = jsObject['localName'];
      var customElementClass = _knownCustomeElements[localName];
      // Custom Element to upgrade.
      if (jsTypeName == 'HTMLElement' && customElementClass != null) {
        try {
          dartClass_instance = _blink.Blink_Utils.constructElement(customElementClass, jsObject);
        } finally {
          dartClass_instance.blink_jsObject = jsObject;
          jsObject['dart_class'] = dartClass_instance;
          js.setDartHtmlWrapperFor(jsObject, dartClass_instance);
       }
      } else {
        var func = getHtmlCreateFunction(jsTypeName);
        if (func != null) {
          dartClass_instance = func();
          dartClass_instance.blink_jsObject = jsObject;
          js.setDartHtmlWrapperFor(jsObject, dartClass_instance);
        }
      }
    }
    return dartClass_instance;
  } catch(e, stacktrace){
    if (__interop_checks) {
      if (e is DebugAssertException)
        window.console.log("${e.message}\n ${stacktrace}");
      else
        window.console.log("${stacktrace}");
    }
  }

  return null;
}