mozilla / positron

a experimental, Electron-compatible runtime on top of Gecko
Other
562 stars 64 forks source link

warn once for each stub (fixes #32) #57

Closed mykmelez closed 8 years ago

mykmelez commented 8 years ago

This fixes #32 by adding positronUtil.makeStub(), which makes a "stub function" that warns the first time it's called, and then replacing all function() { /* stub */ } occurrences with functions created by makeStub().

Modules that are themselves stubs call makeStub()() to make a stub function and then immediately call it to output a warning (so we see the warning when the module is first evaluated).

Stub functions that need to return a value pass the return value to makeStub(), which then returns it each time the stub is called (although it still only warns once). Stubs that need to generate a return value (or do something else when the stub is called) pass a function argument for the returnValue property, which the "warn once" function will then call to generate the return value.

This is essentially the same as addUnimplementedNative() from PluotSorbet, except for a project-specific detail (it returns the stub instead of assigning it to a global map of stubs, since there is no such global map in Positron). Plus, let is the new var.

@marcoscaceres How does this look to you?

marcoscaceres commented 8 years ago

My only concern is the one I commented on... but apart from that, lgtm.

marcoscaceres commented 8 years ago

@mykmelez, thanks for fixing those! I'm about to go 💤, as it's 1:30am here. Feel free to merge or I will merge in 10 hours.