Skip to content

BUG: call to "evaluate" freeze the application (With repro case) #162

@vd3d

Description

@vd3d

Hi,

I’m using flutter_js and greatly appreciate its capabilities. However, I’ve encountered a critical issue on the Windows desktop version that causes the entire application to freeze when calling the evaluate method with specific JavaScript code.

Issue Description

The freeze occurs when invoking the following function from the flutter_js package (pub.dev/flutter_js-0.8.1/lib/quickjs/quickjs_runtime2.dart):

JsEvalResult evaluate(String command, {String? name, int? evalFlags, String? sourceUrl, })

I’m passing the content of the file ccxt.browser.js to the evaluate function. This issue is reproducible every time under the described conditions.

Steps to Reproduce

flutter_js does not support settings options on QuickJS and this code require BigInt support (Noticed that QuickJS support BigInt).
So, to make it compatible, I transform the code with this flutter code before the evaluation:

String ccxtCode = await rootBundle.loadString('assets/libs/ccxt.browser.js');
ccxtCode = _transformBigIntLiterals(ccxtCode);
ccxtCode = _polyfill(ccxtCode);

JavascriptRuntime _rt = getJavascriptRuntime();
JsEvalResult r = _rt.evaluate(code, sourceUrl: null);

  String _transformBigIntLiterals(String code) {
    final regex = RegExp(r'(?<![a-zA-Z0-9_])(\d+)n\b');
    return code.replaceAllMapped(regex, (match) {
      return 'BigInt(${match.group(1)})';
    });
  }

  String _polyfill(String ccxtCode) {
    ccxtCode = ccxtCode.replaceAll('BigInt(', 'Number(');
    ccxtCode = ccxtCode.replaceAll('bigint', 'number');
    return ccxtCode;
  }

Any guidance or fixes for this issue would be greatly appreciated. Please let me know if additional details or testing are required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions