kriskowal / q

A promise library for JavaScript
MIT License
14.94k stars 1.2k forks source link

Use within mozilla addon-sdk #562

Open cadorn opened 10 years ago

cadorn commented 10 years ago

To get q.js working within mozilla addon-sdk I had to declare setTimeout:

const { setTimeout } = require("sdk/timers");

The question is whether the above line should be run by q.js if the addon-sdk environment is detected; or; alternatively; add-on developers must configure/patch the default loader to make setTimeout available as a global.

If we can reliably sniff the environment then I would vote for that. It would make the user experience nicer for add-on developers that wish to use stock q.js.

kriskowal commented 10 years ago

For version 1, we would need to take into consideration that the require call would be discovered by static analyzers in other environments, which would in turn fail to find the module. I know that Mr can be tricked but not sure about Browserify et al.

For version 2, does the addon-sdk still support overlays?

cadorn commented 10 years ago

For version 1, we would need to take into consideration that the require call would be discovered by static analyzers in other environments, which would in turn fail to find the module. I know that Mr can be tricked but not sure about Browserify et al.

Yeah. Its unspecified ground. This is a common issue and requires a transformation/override step at some level.

For version 2, does the addon-sdk still support overlays?

No.

One solution that would make sense from my POV is to specify some annotation that can be put at the top of module files that specifies the expected globals and points to a spec for their implementation. Each environment can then map these common spec uris to their respective implementations and provide the requested globals to the module.

I think mozilla would accept such a solution into their loader as it can be secured.

I guess I am trying to arrive at a solution that is portable to other libraries. I can always put the one line into the top of q.js using an automated patch; but that does not help the JS component ecosystem because its a common problem.

darkwing commented 9 years ago

Wanted to ping in on this :) Any progress or new thoughts?

@cadorn What file did you add setTimeout to? q.js is a dependency of another npm module and adding setTimeout just about everywhere within my codebase results in no improvement. :(