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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 return " " + call_str + ";\n"; | 215 return " " + call_str + ";\n"; |
216 case TypeCategory::INT: | 216 case TypeCategory::INT: |
217 case TypeCategory::FLOAT: | 217 case TypeCategory::FLOAT: |
218 case TypeCategory::DOUBLE: | 218 case TypeCategory::DOUBLE: |
219 return " var result = " + call_str + ";\n"; | 219 return " var result = " + call_str + ";\n"; |
220 case TypeCategory::INT64: | 220 case TypeCategory::INT64: |
221 return " var result = Runtime.makeBigInt(" + call_str + ", " + | 221 return " var result = Runtime.makeBigInt(" + call_str + ", " + |
222 "Runtime.getTempRet0(), " + | 222 "Runtime.getTempRet0(), " + |
223 "true);\n"; | 223 "true);\n"; |
224 case TypeCategory::DEPENDENT_STRING: | 224 case TypeCategory::DEPENDENT_STRING: |
225 case TypeCategory::OWNED_STRING: | |
226 { | 225 { |
227 std::string result; | 226 std::string result; |
228 result += " var string = createString();\n"; | 227 result += " var string = createString();\n"; |
229 result += " " + call_str + ";\n"; | 228 result += " " + call_str + ";\n"; |
230 result += " var result = readString(string);\n"; | 229 result += " var result = readString(string);\n"; |
231 if (call.returnType == TypeCategory::OWNED_STRING) | 230 // We don't call a destructor here because we know that dependent |
232 result += " Module._DestroyString(string);\n"; | 231 // strings don't need to clean up. |
| 232 return result; |
| 233 } |
| 234 case TypeCategory::OWNED_STRING: |
| 235 { |
| 236 std::string result; |
| 237 result += " var string = createOwnedString();\n"; |
| 238 result += " " + call_str + ";\n"; |
| 239 result += " var result = readString(string);\n"; |
| 240 result += " Module._DestroyString(string);\n"; |
233 return result; | 241 return result; |
234 } | 242 } |
235 case TypeCategory::STRING_REF: | 243 case TypeCategory::STRING_REF: |
236 return " var result = readString(" + call_str + ");\n"; | 244 return " var result = readString(" + call_str + ");\n"; |
237 case TypeCategory::CLASS_PTR: | 245 case TypeCategory::CLASS_PTR: |
238 { | 246 { |
239 std::string result; | 247 std::string result; |
240 result += " var result = " + call_str + ";\n"; | 248 result += " var result = " + call_str + ";\n"; |
241 result += " if (result)\n"; | 249 result += " if (result)\n"; |
242 result += " {\n"; | 250 result += " {\n"; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 { | 341 { |
334 buffer = Runtime.stackAlloc(str.length * 2); | 342 buffer = Runtime.stackAlloc(str.length * 2); |
335 length = copyString(str, buffer); | 343 length = copyString(str, buffer); |
336 } | 344 } |
337 | 345 |
338 var result = Runtime.stackAlloc(sizeofString); | 346 var result = Runtime.stackAlloc(sizeofString); |
339 Module._InitString(result, buffer, length); | 347 Module._InitString(result, buffer, length); |
340 return result; | 348 return result; |
341 } | 349 } |
342 | 350 |
| 351 function createOwnedString() |
| 352 { |
| 353 var result = Runtime.stackAlloc(sizeofString); |
| 354 Module._InitOwnedString(result); |
| 355 return result; |
| 356 } |
| 357 |
343 function readString(str) | 358 function readString(str) |
344 { | 359 { |
345 var length = Module._GetStringLength(str); | 360 var length = Module._GetStringLength(str); |
346 var pointer = Module._GetStringData(str) >> 1; | 361 var pointer = Module._GetStringData(str) >> 1; |
347 return String.fromCharCode.apply(String, HEAP16.slice(pointer, pointer +
length)); | 362 return String.fromCharCode.apply(String, HEAP16.slice(pointer, pointer +
length)); |
348 } | 363 } |
349 | 364 |
350 function createClass(superclass, ref_counted_offset, props) | 365 function createClass(superclass, ref_counted_offset, props) |
351 { | 366 { |
352 var result = function(pointer) | 367 var result = function(pointer) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 461 |
447 void printBindings() | 462 void printBindings() |
448 { | 463 { |
449 bindings_internal::printHelpers(); | 464 bindings_internal::printHelpers(); |
450 | 465 |
451 for (const auto& cls : classes) | 466 for (const auto& cls : classes) |
452 bindings_internal::printClass(cls); | 467 bindings_internal::printClass(cls); |
453 for (const auto& cls : classes) | 468 for (const auto& cls : classes) |
454 bindings_internal::printClassMapping(cls); | 469 bindings_internal::printClassMapping(cls); |
455 } | 470 } |
OLD | NEW |