| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 result += " if (result)\n"; | 466 result += " if (result)\n"; |
| 467 result += " {\n"; | 467 result += " {\n"; |
| 468 | 468 |
| 469 auto it = classes.find(call.pointerType); | 469 auto it = classes.find(call.pointerType); |
| 470 if (it == classes.end()) | 470 if (it == classes.end()) |
| 471 throw std::runtime_error("Function " + std::string(call.name) + " retu
rns pointer to unknown class"); | 471 throw std::runtime_error("Function " + std::string(call.name) + " retu
rns pointer to unknown class"); |
| 472 | 472 |
| 473 const ClassInfo& cls = it->second; | 473 const ClassInfo& cls = it->second; |
| 474 auto offset = cls.subclass_differentiator.offset; | 474 auto offset = cls.subclass_differentiator.offset; |
| 475 if (offset == SIZE_MAX) | 475 if (offset == SIZE_MAX) |
| 476 result += " result = " + cls.name + "(result);\n"; | 476 result += " result = exports." + cls.name + "(result);\n"; |
| 477 else | 477 else |
| 478 { | 478 result += " result = exports." + cls.name + ".fromPointer(result);\
n"; |
| 479 result += " var type = HEAP32[result + " + std::to_string(offset)+
" >> 2];\n"; | |
| 480 result += " if (type in " + cls.name + "_mapping)\n"; | |
| 481 result += " result = new (exports[" + cls.name + "_mapping[type]]
)(result);\n"; | |
| 482 result += " else\n"; | |
| 483 result += " throw new Error('Unexpected " + cls.name + " type: '
+ type);\n"; | |
| 484 } | |
| 485 | 479 |
| 486 result += " }\n"; | 480 result += " }\n"; |
| 487 result += " else\n"; | 481 result += " else\n"; |
| 488 result += " result = null;\n"; | 482 result += " result = null;\n"; |
| 489 return result; | 483 return result; |
| 490 } | 484 } |
| 491 default: | 485 default: |
| 492 throw std::runtime_error("Unexpected return type for " + std::string(cal
l.name)); | 486 throw std::runtime_error("Unexpected return type for " + std::string(cal
l.name)); |
| 493 } | 487 } |
| 494 } | 488 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 { | 592 { |
| 599 Module._ReleaseRef(this._pointer + ref_counted_offset); | 593 Module._ReleaseRef(this._pointer + ref_counted_offset); |
| 600 }; | 594 }; |
| 601 return result; | 595 return result; |
| 602 } | 596 } |
| 603 )"); | 597 )"); |
| 604 } | 598 } |
| 605 | 599 |
| 606 void printClass(const ClassInfo& cls) | 600 void printClass(const ClassInfo& cls) |
| 607 { | 601 { |
| 602 printf("exports.%s = createClass(%s, %i);\n", cls.name.c_str(), |
| 603 (cls.baseClass ? ("exports." + cls.baseClass->name).c_str() : "null"), |
| 604 cls.ref_counted_offset); |
| 605 |
| 608 DifferentiatorInfo differentiator = cls.subclass_differentiator; | 606 DifferentiatorInfo differentiator = cls.subclass_differentiator; |
| 609 if (differentiator.offset != SIZE_MAX) | 607 if (differentiator.offset != SIZE_MAX) |
| 610 { | 608 { |
| 611 printf("var %s_mapping = \n", cls.name.c_str()); | 609 printf("var %s_mapping = \n", cls.name.c_str()); |
| 612 puts("{"); | 610 puts("{"); |
| 613 for (const auto& item : differentiator.mapping) | 611 for (const auto& item : differentiator.mapping) |
| 614 printf(" %i: '%s',\n", item.first, item.second.c_str()); | 612 printf(" %i: '%s',\n", item.first, item.second.c_str()); |
| 615 puts("};"); | 613 puts("};"); |
| 614 |
| 615 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str()); |
| 616 puts("{"); |
| 617 printf(" var type = HEAP32[ptr + %i >> 2];\n", differentiator.offset); |
| 618 printf(" if (type in %s_mapping)\n", cls.name.c_str()); |
| 619 printf(" return new (exports[%s_mapping[type]])(ptr);\n", cls.name.c_st
r()); |
| 620 printf(" throw new Error('Unexpected %s type: ' + type);\n", cls.name.c_s
tr()); |
| 621 puts("};"); |
| 616 } | 622 } |
| 617 | 623 else |
| 618 printf("exports.%s = createClass(%s, %i);\n", cls.name.c_str(), | 624 { |
| 619 (cls.baseClass ? ("exports." + cls.baseClass->name).c_str() : "null"), | 625 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str()); |
| 620 cls.ref_counted_offset); | 626 puts("{"); |
| 627 printf(" return new exports.%s(ptr);\n", cls.name.c_str()); |
| 628 puts("};"); |
| 629 } |
| 621 | 630 |
| 622 for (const auto& item : cls.properties) | 631 for (const auto& item : cls.properties) |
| 623 { | 632 { |
| 624 printf("Object.defineProperty(exports.%s.prototype, '%s', {%s});\n", | 633 printf("Object.defineProperty(exports.%s.prototype, '%s', {%s});\n", |
| 625 cls.name.c_str(), item.name.c_str(), | 634 cls.name.c_str(), item.name.c_str(), |
| 626 generatePropertyDescriptor(item).c_str()); | 635 generatePropertyDescriptor(item).c_str()); |
| 627 } | 636 } |
| 628 | 637 |
| 629 for (const auto& item : cls.methods) | 638 for (const auto& item : cls.methods) |
| 630 { | 639 { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 bindings_internal::register_differentiator( | 795 bindings_internal::register_differentiator( |
| 787 bindings_internal::TypeInfo<ClassType>(), offset, mapping); | 796 bindings_internal::TypeInfo<ClassType>(), offset, mapping); |
| 788 return *this; | 797 return *this; |
| 789 } | 798 } |
| 790 }; | 799 }; |
| 791 | 800 |
| 792 void custom_generator(bindings_internal::CustomGenerator generator) | 801 void custom_generator(bindings_internal::CustomGenerator generator) |
| 793 { | 802 { |
| 794 bindings_internal::customGenerators.push_back(generator); | 803 bindings_internal::customGenerators.push_back(generator); |
| 795 } | 804 } |
| OLD | NEW |