compile method

  1. @override
Uint8List compile(
  1. String script,
  2. String fileName
)
override

Implementation

@override
Uint8List compile(String script, String fileName) {
  _ensureEngine();
  final ctx = _ctx!;
  final scriptPtr = script.toNativeUtf8().cast<Char>();
  final fileNamePtr = fileName.toNativeUtf8().cast<Char>();
  final lengthPtr = calloc<IntPtr>();
  final value = compileFn(ctx, scriptPtr, fileNamePtr, lengthPtr);
  try {
    if (value.address == 0) {
      throw _parseJSException(ctx);
    }
    final length = lengthPtr.value;
    return Uint8List.fromList(value.asTypedList(length));
  } finally {
    if (value.address != 0) {
      calloc.free(value);
    }
    calloc.free(scriptPtr);
    calloc.free(fileNamePtr);
    calloc.free(lengthPtr);
  }
}