fengari-lua / fengari-web

Provides everything you need to run Fengari in the browser.
MIT License
250 stars 19 forks source link

Fengari+Phonegap: xhr.status is always 0 #38

Closed olueiro closed 5 years ago

olueiro commented 5 years ago

Hi https://github.com/fengari-lua/fengari-web/blob/a9fb130f6851206e8a57be902af061e980be5610/src/fengari-web.js#L188

Reference: https://stackoverflow.com/q/33471547

daurnimator commented 5 years ago

From https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/status

Before the request completes, the value of status is 0. Browsers also report a status of 0 in case of XMLHttpRequest errors.

This sounds like a bug in Phonegap.

olueiro commented 5 years ago

Hmm

I've created a custom fengari(-web) version for PhoneGap with my modifications (xhr.status and error logging)

PS I've tested my package in local browser, Nox emulator and some mobile Android devices (no iOS :cry: ). In any tests, javascript WeakMap is undefined, so I have added a WeakMap polyfill.

You can close this issue. :smile:

daurnimator commented 5 years ago

I have added a WeakMap polyfill.

Weakmap is impossible to polyfill correctly (hence why it remains a hard dependency). Are you sure that your JS engine doesn't support Weakmap? If so it is very old and should be updated.

olueiro commented 5 years ago

I can to reproduce this on Nox App Player (latest version), running on Windows 10 machine. This sounds like a bug in Phonegap too. In my Android devices the JS engine supports WeakMap .

This Map shim emulates the Weakmap (window.WeakMap = window.Map;) and has solved my issue.

daurnimator commented 5 years ago

window.WeakMap = window.Map;

that will end up leaking memory: the longer your page/app runs, the more memory it will use.