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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 std::string result; | 252 std::string result; |
253 result += " var result = " + call_str + ";\n"; | 253 result += " var result = " + call_str + ";\n"; |
254 result += " if (result)\n"; | 254 result += " if (result)\n"; |
255 | 255 |
256 const ClassInfo* cls = find_class(call.pointerType); | 256 const ClassInfo* cls = find_class(call.pointerType); |
257 if (!cls) | 257 if (!cls) |
258 throw std::runtime_error("Function " + call.name + " returns pointer t
o unknown class"); | 258 throw std::runtime_error("Function " + call.name + " returns pointer t
o unknown class"); |
259 | 259 |
260 auto offset = cls->subclass_differentiator.offset; | 260 auto offset = cls->subclass_differentiator.offset; |
261 if (offset == SIZE_MAX) | 261 if (offset == SIZE_MAX) |
262 result += " result = exports." + cls->name + "(result);\n"; | 262 result += " result = new exports." + cls->name + "(result);\n"; |
263 else | 263 else |
264 result += " result = exports." + cls->name + ".fromPointer(result);
\n"; | 264 result += " result = exports." + cls->name + ".fromPointer(result);
\n"; |
265 | 265 |
266 result += " else\n"; | 266 result += " else\n"; |
267 result += " result = null;\n"; | 267 result += " result = null;\n"; |
268 return result; | 268 return result; |
269 } | 269 } |
270 default: | 270 default: |
271 throw std::runtime_error("Unexpected return type for " + call.name); | 271 throw std::runtime_error("Unexpected return type for " + call.name); |
272 } | 272 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 if (differentiator.offset != SIZE_MAX) | 442 if (differentiator.offset != SIZE_MAX) |
443 { | 443 { |
444 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str()); | 444 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str()); |
445 puts("{"); | 445 puts("{"); |
446 printf(" var type = HEAP32[ptr + %i >> 2];\n", differentiator.offset); | 446 printf(" var type = HEAP32[ptr + %i >> 2];\n", differentiator.offset); |
447 printf(" if (type in %s_mapping)\n", cls.name.c_str()); | 447 printf(" if (type in %s_mapping)\n", cls.name.c_str()); |
448 printf(" return new %s_mapping[type](ptr);\n", cls.name.c_str()); | 448 printf(" return new %s_mapping[type](ptr);\n", cls.name.c_str()); |
449 printf(" throw new Error('Unexpected %s type: ' + type);\n", cls.name.c_s
tr()); | 449 printf(" throw new Error('Unexpected %s type: ' + type);\n", cls.name.c_s
tr()); |
450 puts("};"); | 450 puts("};"); |
451 } | 451 } |
452 else | |
453 { | |
454 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str()); | |
455 puts("{"); | |
456 printf(" return new exports.%s(ptr);\n", cls.name.c_str()); | |
457 puts("};"); | |
458 } | |
459 | 452 |
460 for (const auto& method : cls.methods) | 453 for (const auto& method : cls.methods) |
461 { | 454 { |
462 if (!method.call.instance_function) | 455 if (!method.call.instance_function) |
463 { | 456 { |
464 printf("exports.%s.%s = %s;\n", cls.name.c_str(), method.name.c_str(), | 457 printf("exports.%s.%s = %s;\n", cls.name.c_str(), method.name.c_str(), |
465 wrapCall(method.call).c_str()); | 458 wrapCall(method.call).c_str()); |
466 } | 459 } |
467 } | 460 } |
468 } | 461 } |
(...skipping 14 matching lines...) Expand all Loading... |
483 | 476 |
484 void printBindings() | 477 void printBindings() |
485 { | 478 { |
486 bindings_internal::printHelpers(); | 479 bindings_internal::printHelpers(); |
487 | 480 |
488 for (const auto& cls : classes) | 481 for (const auto& cls : classes) |
489 bindings_internal::printClass(cls); | 482 bindings_internal::printClass(cls); |
490 for (const auto& cls : classes) | 483 for (const auto& cls : classes) |
491 bindings_internal::printClassMapping(cls); | 484 bindings_internal::printClassMapping(cls); |
492 } | 485 } |
OLD | NEW |