isJSON should be renamed to parseJSON
Categories
(DevTools :: Netmonitor, task, P3)
Tracking
(Not tracked)
People
(Reporter: Honza, Assigned: dev)
References
Details
This is a follow up for bug 1635835
isJSON
functions should be renamed to parseJSON
and it should be used instead of JSON.parse
in Network panel code base.
isJSON
is defined here:
https://searchfox.org/mozilla-central/rev/598e50d2c3cd81cd616654f16af811adceb08f9f/devtools/client/netmonitor/src/utils/request-utils.js#636
Honza
@Honza please assign this to me as I have already taken care of the rename. I am unable to import this function in other files not in the overall netmonitor folder for some reason, I get the following error:
http://requirejs.org/docs/errors.html#scripterror```
If you have any ideas on how to address this, please let me know.
Reporter | ||
Comment 2•5 years ago
|
||
Thanks for helping with this one!
The problem is that all JSON Viewer files have to use AMD (asynchronous module definition) using
define(function(require, exports, module) {
})
It's consumed by RequireJS which is loading all the modules.
Can you attach your patch? I can take a look and suggest someting.
Honza
For example, in my diff https://phabricator.services.mozilla.com/D80727 and https://phabricator.services.mozilla.com/D80720, if I attempt to do:
const parseJSON = require("devtools/client/netmonitor/src/utils/request-utils");
and then call the parseJSON function, i get the require error.
Do I need to design the parseJSON function to return a promise instead of simply returning the value? As you can see, simply copy-pasting the function into the JSON viewer file allows it run correctly, but that's obviously not ideal.
If someone could also set this bug to depend on Bug 1642764 (I'm not sure if I can do that), that would be much appreciated. The patches for both bugs 1642764 and 1635835 will implement the fix for this bug.
Reporter | ||
Comment 5•5 years ago
|
||
(In reply to Dev Singh from comment #3)
For example, in my diff https://phabricator.services.mozilla.com/D80727 and https://phabricator.services.mozilla.com/D80720, if I attempt to do:
const parseJSON = require("devtools/client/netmonitor/src/utils/request-utils");
and then call the parseJSON function, i get the require error.Do I need to design the parseJSON function to return a promise instead of simply returning the value? As you can see, simply copy-pasting the function into the JSON viewer file allows it run correctly, but that's obviously not ideal.
Please see my comment here:
https://phabricator.services.mozilla.com/D80727#2468257
Does it make more sense?
Reporter | ||
Comment 6•5 years ago
|
||
Dev Singh: we can close this bug, correct?
The renaming happens in this patch:
https://phabricator.services.mozilla.com/D80720
Honza
Reporter | ||
Updated•5 years ago
|
Description
•