async executeJsCode()

in src/js-executor/index.js [32:94]


  async executeJsCode(
    jsCode,
    wasm,
    jsLibs,
    platform,
    outputHeight,
    theme,
    onError,
    additionalRequestsResults,
  ) {
    if (platform === TargetPlatforms.SWIFT_EXPORT) {
      return `<span class="standard-output ${theme}"><div class="result-code">${jsCode}</span>`;
    }
    if (platform === TargetPlatforms.CANVAS) {
      this.iframe.style.display = 'block';
      if (outputHeight) this.iframe.style.height = `${outputHeight}px`;
    }
    if (isWasmRelated(platform)) {
      if (platform === TargetPlatforms.WASM) {
        return await this.executeWasm(
          jsCode,
          wasm,
          executeWasmCode,
          theme,
          onError,
        );
      }

      if (platform === TargetPlatforms.COMPOSE_WASM) {
        let exception = false;

        const processError = () => {
          exception = true;
          return onError && onError.apply(this, arguments);
        };

        // It is necessary to work in Firefox
        // for some reason resize function in Compose does not work in Firefox in invisible block
        this.iframe.style.display = 'block';

        const additionalRequestsResult = additionalRequestsResults[0];
        const result = await this.executeWasm(
          jsCode,
          wasm,
          executeWasmCodeWithStdlib,
          theme,
          processError,
          additionalRequestsResult.stdlib,
          additionalRequestsResult.output,
        );

        if (exception) {
          this.iframe.style.display = 'none';
        } else {
          this.iframe.style.display = 'block';
          if (outputHeight) this.iframe.style.height = `${outputHeight}px`;
        }

        return result;
      }
    }
    return await this.execute(jsCode, jsLibs, theme, onError, platform);
  }