OLD | NEW |
1 #pragma once | 1 #pragma once |
2 | 2 |
3 #include <cstddef> | 3 #include <cstddef> |
4 #include <cstdint> | 4 #include <cstdint> |
5 #include <cstdio> | 5 #include <cstdio> |
6 #include <cstdlib> | 6 #include <cstdlib> |
7 #include <exception> | 7 #include <exception> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <type_traits> | 10 #include <type_traits> |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 if (!property.setter.empty()) | 479 if (!property.setter.empty()) |
480 result += ", set: " + wrapCall(property.setter); | 480 result += ", set: " + wrapCall(property.setter); |
481 return result; | 481 return result; |
482 } | 482 } |
483 | 483 |
484 void printHelpers() | 484 void printHelpers() |
485 { | 485 { |
486 printf("var sizeofString = %i;\n", sizeof(String)); | 486 printf("var sizeofString = %i;\n", sizeof(String)); |
487 | 487 |
488 puts(R"( | 488 puts(R"( |
489 function copyString(str, buffer) | 489 function copyString(str, buffer) |
490 { | 490 { |
491 var length = str.length; | 491 var length = str.length; |
492 for (var i = 0, pointer = (buffer >> 1); i < length; i++, pointer++) | 492 for (var i = 0, pointer = (buffer >> 1); i < length; i++, pointer++) |
493 HEAP16[pointer] = str.charCodeAt(i); | 493 HEAP16[pointer] = str.charCodeAt(i); |
494 return length; | 494 return length; |
495 } | 495 } |
496 | 496 |
497 function createString(str) | 497 function createString(str) |
498 { | 498 { |
499 var length = 0; | 499 var length = 0; |
500 var buffer = 0; | 500 var buffer = 0; |
501 if (str) | 501 if (str) |
502 { | 502 { |
503 buffer = Runtime.stackAlloc(str.length * 2); | 503 buffer = Runtime.stackAlloc(str.length * 2); |
504 length = copyString(str, buffer); | 504 length = copyString(str, buffer); |
505 } | 505 } |
506 | 506 |
507 var result = Module.Runtime.stackAlloc(sizeofString); | 507 var result = Runtime.stackAlloc(sizeofString); |
508 Module._InitString(result, buffer, length); | 508 Module._InitString(result, buffer, length); |
509 return result; | 509 return result; |
510 } | 510 } |
511 | 511 |
512 function readString(str) | 512 function readString(str) |
513 { | 513 { |
514 var length = Module._GetStringLength(str); | 514 var length = Module._GetStringLength(str); |
515 var pointer = Module._GetStringData(str) >> 1; | 515 var pointer = Module._GetStringData(str) >> 1; |
516 return String.fromCharCode.apply(String, HEAP16.slice(pointer, pointer + len
gth)); | 516 return String.fromCharCode.apply(String, HEAP16.slice(pointer, pointer +
length)); |
517 } | 517 } |
518 | 518 |
519 function createClass(superclass, ref_counted_offset) | 519 function createClass(superclass, ref_counted_offset) |
520 { | 520 { |
521 var result = function(pointer) | 521 var result = function(pointer) |
522 { | 522 { |
523 this._pointer = pointer; | 523 this._pointer = pointer; |
524 }; | 524 }; |
525 if (superclass) | 525 if (superclass) |
526 result.prototype = Object.create(superclass.prototype); | 526 result.prototype = Object.create(superclass.prototype); |
527 result.prototype.delete = function() | 527 result.prototype.delete = function() |
528 { | 528 { |
529 Module._ReleaseRef(this._pointer + ref_counted_offset); | 529 Module._ReleaseRef(this._pointer + ref_counted_offset); |
530 }; | 530 }; |
531 return result; | 531 return result; |
532 })"); | 532 } |
| 533 )"); |
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 }; |
OLD | NEW |