JSString.fromString constructor

JSString.fromString(
  1. String? string, {
  2. bool autoDispose = true,
})

Creates a JavaScript string from dart String. string The dart String.

Implementation

JSString.fromString(String? string, {bool autoDispose = true}) {
  if (string == null) {
    _ref = nullptr;
  } else {
    final cString = string.toNativeUtf8();
    try {
      // [string] (char*) The null-terminated UTF8 string to copy into the new JSString.
      _ref = JSStringCreateWithUTF8CString(cString);
    } finally {
      malloc.free(cString);
    }
  }
  attach(
    JSStringReleaseAddress.cast(),
    _ref.cast(),
    autoDispose: autoDispose,
  );
}