Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 | 122 |
123 if (character == ";" && call.length > 0) | 123 if (character == ";" && call.length > 0) |
124 { | 124 { |
125 tree.push(call); | 125 tree.push(call); |
126 call = []; | 126 call = []; |
127 } | 127 } |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 return tree; | 131 return tree; |
132 }, | |
133 | |
134 /** | |
135 * Compiles a script against a given list of libraries into executable code | |
136 * @param {string} script | |
137 * @param {string[]} libraries | |
138 * @return {string} | |
139 */ | |
140 compileScript(script, libraries) | |
141 { | |
142 return ` | |
143 "use strict"; | |
144 { | |
145 const libraries = ${JSON.stringify(libraries)}; | |
146 | |
147 const script = ${JSON.stringify(Snippets.parseScript(script))}; | |
148 | |
149 let imports = Object.create(null); | |
Manish Jethani
2018/04/26 13:46:00
There's an imports object and it gets populated by
| |
150 for (let library of libraries) | |
151 new Function("exports", library)(imports); | |
152 | |
153 for (let [name, ...args] of script) | |
154 { | |
155 if (Object.prototype.hasOwnProperty.call(imports, name)) | |
156 { | |
157 let value = imports[name]; | |
Manish Jethani
2018/04/26 13:46:00
Note that the function must exist directly on the
| |
158 if (typeof value == "function") | |
159 value(...args); | |
Manish Jethani
2018/04/26 13:46:00
Also note that the function is called without a "t
| |
160 } | |
161 } | |
162 } | |
163 `; | |
132 } | 164 } |
133 }; | 165 }; |
134 | 166 |
135 exports.Snippets = Snippets; | 167 exports.Snippets = Snippets; |
OLD | NEW |