Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Issue 29829569: Issue 6538, 6781 - Add code injection wrapper to snippets library (Closed)

Created:
July 13, 2018, 2:09 p.m. by Manish Jethani
Modified:
July 18, 2018, 12:09 p.m.
Reviewers:
kzar
CC:
Sebastian Noack
Base URL:
https://hg.adblockplus.org/adblockpluscore/
Visibility:
Public.

Description

There will be at least two kinds of snippets: those that run in the content script context and those that run in the document context. For the latter kind, we need some common functions that make it easy to export a snippet with a wrapper that injects it into the document. The makeInjector function does this. exports.trace = makeInjector(trace, log); Here the "trace" snippet is injected and executed in the document context. It depends on the log function, so we add that as a dependency as well.

Patch Set 1 #

Patch Set 2 : Add trace snippet #

Total comments: 18

Patch Set 3 : Add JSDoc comments for injectCode, stringifyFunctionCall, and makeInjector #

Patch Set 4 : Add JSDoc comments for log and trace snippets #

Total comments: 8

Patch Set 5 : Use Function.prototype.toString for safety #

Patch Set 6 : Remove "safely" from comment, remove unnecessary checks #

Unified diffs Side-by-side diffs Delta from patch set Stats (+100 lines, -0 lines) Patch
M lib/content/snippets.js View 1 2 3 4 5 1 chunk +100 lines, -0 lines 0 comments Download

Messages

Total messages: 12
Manish Jethani
July 13, 2018, 2:09 p.m. (2018-07-13 14:09:48 UTC) #1
Manish Jethani
Patch Set 1 Patch Set 2: Add trace snippet See description. https://codereview.adblockplus.org/29829569/diff/29829572/lib/content/snippets.js File lib/content/snippets.js (right): ...
July 13, 2018, 2:17 p.m. (2018-07-13 14:17:33 UTC) #2
kzar
https://codereview.adblockplus.org/29829569/diff/29829572/lib/content/snippets.js File lib/content/snippets.js (right): https://codereview.adblockplus.org/29829569/diff/29829572/lib/content/snippets.js#newcode56 lib/content/snippets.js:56: function makeInjector(injectable, ...dependencies) Please could you add a JSDoc ...
July 16, 2018, 2:13 p.m. (2018-07-16 14:13:57 UTC) #3
Manish Jethani
https://codereview.adblockplus.org/29829569/diff/29829572/lib/content/snippets.js File lib/content/snippets.js (right): https://codereview.adblockplus.org/29829569/diff/29829572/lib/content/snippets.js#newcode56 lib/content/snippets.js:56: function makeInjector(injectable, ...dependencies) On 2018/07/16 14:13:56, kzar wrote: > ...
July 17, 2018, 10:44 a.m. (2018-07-17 10:44:42 UTC) #4
kzar
https://codereview.adblockplus.org/29829569/diff/29829572/lib/content/snippets.js File lib/content/snippets.js (right): https://codereview.adblockplus.org/29829569/diff/29829572/lib/content/snippets.js#newcode58 lib/content/snippets.js:58: return (...args) => injectCode(stringifyFunctionCall(injectable, ...args), On 2018/07/17 10:44:41, Manish ...
July 17, 2018, 11:11 a.m. (2018-07-17 11:11:12 UTC) #5
Manish Jethani
Patch Set 3: Add JSDoc comments for injectCode, stringifyFunctionCall, and makeInjector Patch Set 4: Add ...
July 17, 2018, 3:42 p.m. (2018-07-17 15:42:37 UTC) #6
kzar
Otherwise LGTM https://codereview.adblockplus.org/29829569/diff/29829572/lib/content/snippets.js File lib/content/snippets.js (right): https://codereview.adblockplus.org/29829569/diff/29829572/lib/content/snippets.js#newcode58 lib/content/snippets.js:58: return (...args) => injectCode(stringifyFunctionCall(injectable, ...args), On 2018/07/17 ...
July 17, 2018, 4:08 p.m. (2018-07-17 16:08:22 UTC) #7
Manish Jethani
Patch Set 5: Use Function.prototype.toString for safety https://codereview.adblockplus.org/29829569/diff/29832569/lib/content/snippets.js File lib/content/snippets.js (right): https://codereview.adblockplus.org/29829569/diff/29832569/lib/content/snippets.js#newcode61 lib/content/snippets.js:61: * Safely ...
July 17, 2018, 4:39 p.m. (2018-07-17 16:39:34 UTC) #8
kzar
https://codereview.adblockplus.org/29829569/diff/29832569/lib/content/snippets.js File lib/content/snippets.js (right): https://codereview.adblockplus.org/29829569/diff/29832569/lib/content/snippets.js#newcode61 lib/content/snippets.js:61: * Safely converts a function and an optional list ...
July 17, 2018, 4:59 p.m. (2018-07-17 16:59:20 UTC) #9
Manish Jethani
https://codereview.adblockplus.org/29829569/diff/29832569/lib/content/snippets.js File lib/content/snippets.js (right): https://codereview.adblockplus.org/29829569/diff/29832569/lib/content/snippets.js#newcode61 lib/content/snippets.js:61: * Safely converts a function and an optional list ...
July 17, 2018, 5:27 p.m. (2018-07-17 17:27:02 UTC) #10
Manish Jethani
Patch Set 6: Remove "safely" from comment, remove unnecessary checks OK, I have come around. ...
July 17, 2018, 5:41 p.m. (2018-07-17 17:41:28 UTC) #11
kzar
July 18, 2018, 7:40 a.m. (2018-07-18 07:40:08 UTC) #12
> OK, I have come around. Let's keep it simple.

Makes sense, LGTM.

https://codereview.adblockplus.org/29829569/diff/29832569/lib/content/snippet...
File lib/content/snippets.js (right):

https://codereview.adblockplus.org/29829569/diff/29832569/lib/content/snippet...
lib/content/snippets.js:61: * Safely converts a function and an optional list of
arguments into a string
On 2018/07/17 17:27:02, Manish Jethani wrote:
> On 2018/07/17 16:59:19, kzar wrote:
> > I guess I don't understand if they are able to mess with `func.toString` how
> > they're not also able to mess with `Function.prototype.toString` (or other
> > things like `Array.prototype.map`).
> 
> You're right, at this point I am merely being overcautious and designing for
> some unknown future. Do you think it's overdone? I don't have a strong
opinion,
> I can roll it back.

Well, I'm all for being cautious, but if we leave other weaknesses there it
seems kind of pointless. From my experience with the other wrappers, hardening
against this kind of stuff properly is a shitload of work too.

Powered by Google App Engine
This is Rietveld