Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 case TypeCategory::CLASS_REF: | 250 case TypeCategory::CLASS_REF: |
251 { | 251 { |
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 result += " result = exports." + cls->name + ".fromPointer(result);\n "; | 260 auto offset = cls->subclass_differentiator.offset; |
sergei
2017/09/13 17:09:10
Another option here could be to keep the if and fo
Wladimir Palant
2017/09/19 08:51:48
Trouble is, bindings overhead is very much non-neg
sergei
2017/09/19 09:14:35
I have uploaded the version without fromPointer fo
| |
261 if (offset == SIZE_MAX) | |
262 result += " result = new exports." + cls->name + "(result);\n"; | |
263 else | |
264 result += " result = exports." + cls->name + ".fromPointer(result); \n"; | |
261 | 265 |
262 result += " else\n"; | 266 result += " else\n"; |
263 result += " result = null;\n"; | 267 result += " result = null;\n"; |
264 return result; | 268 return result; |
265 } | 269 } |
266 default: | 270 default: |
267 throw std::runtime_error("Unexpected return type for " + call.name); | 271 throw std::runtime_error("Unexpected return type for " + call.name); |
268 } | 272 } |
269 } | 273 } |
270 | 274 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 if (differentiator.offset != SIZE_MAX) | 442 if (differentiator.offset != SIZE_MAX) |
439 { | 443 { |
440 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str()); | 444 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str()); |
441 puts("{"); | 445 puts("{"); |
442 printf(" var type = HEAP32[ptr + %i >> 2];\n", differentiator.offset); | 446 printf(" var type = HEAP32[ptr + %i >> 2];\n", differentiator.offset); |
443 printf(" if (type in %s_mapping)\n", cls.name.c_str()); | 447 printf(" if (type in %s_mapping)\n", cls.name.c_str()); |
444 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()); |
445 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()); |
446 puts("};"); | 450 puts("};"); |
447 } | 451 } |
448 else | |
449 { | |
450 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str()); | |
451 puts("{"); | |
452 printf(" return new exports.%s(ptr);\n", cls.name.c_str()); | |
453 puts("};"); | |
454 } | |
455 | 452 |
456 for (const auto& method : cls.methods) | 453 for (const auto& method : cls.methods) |
457 { | 454 { |
458 if (!method.call.instance_function) | 455 if (!method.call.instance_function) |
459 { | 456 { |
460 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(), |
461 wrapCall(method.call).c_str()); | 458 wrapCall(method.call).c_str()); |
462 } | 459 } |
463 } | 460 } |
464 } | 461 } |
(...skipping 14 matching lines...) Expand all Loading... | |
479 | 476 |
480 void printBindings() | 477 void printBindings() |
481 { | 478 { |
482 bindings_internal::printHelpers(); | 479 bindings_internal::printHelpers(); |
483 | 480 |
484 for (const auto& cls : classes) | 481 for (const auto& cls : classes) |
485 bindings_internal::printClass(cls); | 482 bindings_internal::printClass(cls); |
486 for (const auto& cls : classes) | 483 for (const auto& cls : classes) |
487 bindings_internal::printClassMapping(cls); | 484 bindings_internal::printClassMapping(cls); |
488 } | 485 } |
LEFT | RIGHT |