JSValue.newString constructor

JSValue.newString(
  1. JSContext _ctx,
  2. String str, {
  3. bool autoDispose = true,
})

JS_NewString

Implementation

JSValue.newString(this._ctx, String str, {bool autoDispose = true}) {
  _str = str.toNativeUtf8();
  _ref = calloc.call<JSValue_>(sizeOf<JSValue_>())
    ..ref = JS_NewStringLen(
        _ctx.ref,
        _str!,
        utf8
            .encode(str)
            .length); // fix qjs-0.8.0 传递长 json string to dart 字符串被截断
  attach(Q_JS_FreeValueAddress.cast(), _ref.cast(), autoDispose: autoDispose);
}