Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: compiled/bindings.ipp

Issue 29384673: Issue 4991 - [emscripten] Update to Emscripten 1.37.3 (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Created March 15, 2017, 10:59 a.m.
Right Patch Set: Fixed indentation Created March 21, 2017, 10:17 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compile ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #pragma once 1 #pragma once
2 2
3 #include <cstddef>
3 #include <cstdint> 4 #include <cstdint>
4 #include <cstdio> 5 #include <cstdio>
5 #include <cstdlib> 6 #include <cstdlib>
6 #include <exception> 7 #include <exception>
7 #include <map> 8 #include <map>
8 #include <string> 9 #include <string>
9 #include <type_traits> 10 #include <type_traits>
10 #include <utility> 11 #include <utility>
11 #include <vector> 12 #include <vector>
12 13
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 }; 271 };
271 272
272 struct ClassInfo 273 struct ClassInfo
273 { 274 {
274 ClassInfo* baseClass; 275 ClassInfo* baseClass;
275 std::string name; 276 std::string name;
276 std::vector<PropertyInfo> properties; 277 std::vector<PropertyInfo> properties;
277 std::vector<MethodInfo> methods; 278 std::vector<MethodInfo> methods;
278 std::vector<FunctionInfo> initializers; 279 std::vector<FunctionInfo> initializers;
279 DifferentiatorInfo subclass_differentiator; 280 DifferentiatorInfo subclass_differentiator;
280 int ref_counted_offset; 281 ptrdiff_t ref_counted_offset;
281 }; 282 };
282 283
283 std::map<TYPEID, ClassInfo> classes; 284 std::map<TYPEID, ClassInfo> classes;
284 285
285 void register_class(const char* name, TYPEID classID, TYPEID baseClassID, 286 void register_class(const char* name, TYPEID classID, TYPEID baseClassID,
286 int ref_counted_offset) 287 ptrdiff_t ref_counted_offset)
287 { 288 {
288 auto it = classes.find(classID); 289 auto it = classes.find(classID);
289 if (it != classes.end()) 290 if (it != classes.end())
290 throw std::runtime_error(std::string("Duplicate definition for class ") + name); 291 throw std::runtime_error(std::string("Duplicate definition for class ") + name);
291 292
292 ClassInfo* baseClass = nullptr; 293 ClassInfo* baseClass = nullptr;
293 if (baseClassID != TypeInfo<NoBaseClass>()) 294 if (baseClassID != TypeInfo<NoBaseClass>())
294 { 295 {
295 it = classes.find(baseClassID); 296 it = classes.find(baseClassID);
296 if (it == classes.end()) 297 if (it == classes.end())
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 if (!property.setter.empty()) 479 if (!property.setter.empty())
479 result += ", set: " + wrapCall(property.setter); 480 result += ", set: " + wrapCall(property.setter);
480 return result; 481 return result;
481 } 482 }
482 483
483 void printHelpers() 484 void printHelpers()
484 { 485 {
485 printf("var sizeofString = %i;\n", sizeof(String)); 486 printf("var sizeofString = %i;\n", sizeof(String));
486 487
487 puts(R"( 488 puts(R"(
488 function copyString(str, buffer) 489 function copyString(str, buffer)
489 { 490 {
490 var length = str.length; 491 var length = str.length;
491 for (var i = 0, pointer = (buffer >> 1); i < length; i++, pointer++) 492 for (var i = 0, pointer = (buffer >> 1); i < length; i++, pointer++)
492 HEAP16[pointer] = str.charCodeAt(i); 493 HEAP16[pointer] = str.charCodeAt(i);
493 return length; 494 return length;
494 } 495 }
495 496
496 function createString(str) 497 function createString(str)
497 { 498 {
498 var length = 0; 499 var length = 0;
499 var buffer = 0; 500 var buffer = 0;
500 if (str) 501 if (str)
501 { 502 {
502 buffer = Runtime.stackAlloc(str.length * 2); 503 buffer = Runtime.stackAlloc(str.length * 2);
503 length = copyString(str, buffer); 504 length = copyString(str, buffer);
504 } 505 }
505 506
506 var result = Runtime.stackAlloc(sizeofString); 507 var result = Runtime.stackAlloc(sizeofString);
Wladimir Palant 2017/03/15 11:02:48 We don't need to call this via Module, and above w
507 Module._InitString(result, buffer, length); 508 Module._InitString(result, buffer, length);
508 return result; 509 return result;
509 } 510 }
510 511
511 function readString(str) 512 function readString(str)
512 { 513 {
513 var length = Module._GetStringLength(str); 514 var length = Module._GetStringLength(str);
514 var pointer = Module._GetStringData(str) >> 1; 515 var pointer = Module._GetStringData(str) >> 1;
515 return String.fromCharCode.apply(String, HEAP16.slice(pointer, pointer + len gth)); 516 return String.fromCharCode.apply(String, HEAP16.slice(pointer, pointer + length));
516 } 517 }
517 518
518 function createClass(superclass, ref_counted_offset) 519 function createClass(superclass, ref_counted_offset)
519 { 520 {
520 var result = function(pointer) 521 var result = function(pointer)
521 { 522 {
522 this._pointer = pointer; 523 this._pointer = pointer;
523 }; 524 };
524 if (superclass) 525 if (superclass)
525 result.prototype = Object.create(superclass.prototype); 526 result.prototype = Object.create(superclass.prototype);
526 result.prototype.delete = function() 527 result.prototype.delete = function()
527 { 528 {
528 Module._ReleaseRef(this._pointer + ref_counted_offset); 529 Module._ReleaseRef(this._pointer + ref_counted_offset);
529 }; 530 };
530 return result; 531 return result;
531 } 532 }
532 )"); 533 )");
Wladimir Palant 2017/03/15 11:02:48 Surprisingly, this is the only change that was rea
sergei 2017/03/20 17:41:49 Should spaces at the beginning of ` )");` be re
sergei 2017/03/20 17:41:49 Actually the whole last line is removed. I think i
Wladimir Palant 2017/03/21 10:18:59 Luckily, we don't care about the resulting code be
533 } 534 }
534 535
535 void printClass(const ClassInfo& cls) 536 void printClass(const ClassInfo& cls)
536 { 537 {
537 DifferentiatorInfo differentiator = cls.subclass_differentiator; 538 DifferentiatorInfo differentiator = cls.subclass_differentiator;
538 if (differentiator.offset != SIZE_MAX) 539 if (differentiator.offset != SIZE_MAX)
539 { 540 {
540 printf("var %s_mapping = \n", cls.name.c_str()); 541 printf("var %s_mapping = \n", cls.name.c_str());
541 puts("{"); 542 puts("{");
542 for (const auto& item : differentiator.mapping) 543 for (const auto& item : differentiator.mapping)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 641
641 template<typename ClassType, 642 template<typename ClassType,
642 typename BaseClass = bindings_internal::NoBaseClass, 643 typename BaseClass = bindings_internal::NoBaseClass,
643 typename std::enable_if<std::is_base_of<ref_counted, ClassType>::value>::typ e* = nullptr> 644 typename std::enable_if<std::is_base_of<ref_counted, ClassType>::value>::typ e* = nullptr>
644 class class_ 645 class class_
645 { 646 {
646 public: 647 public:
647 class_(const char* name) 648 class_(const char* name)
648 { 649 {
649 ClassType* ptr = reinterpret_cast<ClassType*>(0x10000000); 650 ClassType* ptr = reinterpret_cast<ClassType*>(0x10000000);
650 int ref_counted_offset = 651 ptrdiff_t ref_counted_offset =
651 reinterpret_cast<int>(dynamic_cast<ref_counted*>(ptr)) - 652 reinterpret_cast<char*>(static_cast<ref_counted*>(ptr)) -
652 reinterpret_cast<int>(ptr); 653 reinterpret_cast<char*>(ptr);
653 bindings_internal::register_class(name, 654 bindings_internal::register_class(name,
654 bindings_internal::TypeInfo<ClassType>(), 655 bindings_internal::TypeInfo<ClassType>(),
655 bindings_internal::TypeInfo<BaseClass>(), 656 bindings_internal::TypeInfo<BaseClass>(),
656 ref_counted_offset 657 ref_counted_offset
657 ); 658 );
658 } 659 }
659 660
660 template<typename FieldType> 661 template<typename FieldType>
661 const class_& property(const char* name, 662 const class_& property(const char* name,
662 FieldType (ClassType::*getter)() const, 663 FieldType (ClassType::*getter)() const,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 719
719 std::vector<std::pair<int, std::string>> mapping; 720 std::vector<std::pair<int, std::string>> mapping;
720 for (const auto& item : list) 721 for (const auto& item : list)
721 mapping.emplace_back(item.first, item.second); 722 mapping.emplace_back(item.first, item.second);
722 723
723 bindings_internal::register_differentiator( 724 bindings_internal::register_differentiator(
724 bindings_internal::TypeInfo<ClassType>(), offset, mapping); 725 bindings_internal::TypeInfo<ClassType>(), offset, mapping);
725 return *this; 726 return *this;
726 } 727 }
727 }; 728 };
LEFTRIGHT
« compile ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld