Closed Bug 1643696 Opened 4 years ago Closed 4 years ago

isJSON should be renamed to parseJSON

Categories

(DevTools :: Netmonitor, task, P3)

task

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1635835

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.
Flags: needinfo?(odvarko)

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) {
})

See e.g.
https://searchfox.org/mozilla-central/rev/a87a1c3b543475276e6d57a7a80cb02f3e42b6ed/devtools/client/jsonview/components/Headers.js#7

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

Assignee: nobody → dev
Status: NEW → ASSIGNED
Flags: needinfo?(odvarko) → needinfo?(dev)

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.

Flags: needinfo?(dev)

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.

(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?

Dev Singh: we can close this bug, correct?

The renaming happens in this patch:
https://phabricator.services.mozilla.com/D80720

Honza

Flags: needinfo?(dev)

That's correct

Flags: needinfo?(dev)
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.