Index: compiled/bindings/generator.cpp |
=================================================================== |
--- a/compiled/bindings/generator.cpp |
+++ b/compiled/bindings/generator.cpp |
@@ -217,24 +217,32 @@ namespace bindings_internal |
case TypeCategory::FLOAT: |
case TypeCategory::DOUBLE: |
return " var result = " + call_str + ";\n"; |
case TypeCategory::INT64: |
return " var result = Runtime.makeBigInt(" + call_str + ", " + |
"Runtime.getTempRet0(), " + |
"true);\n"; |
case TypeCategory::DEPENDENT_STRING: |
- case TypeCategory::OWNED_STRING: |
{ |
std::string result; |
result += " var string = createString();\n"; |
result += " " + call_str + ";\n"; |
result += " var result = readString(string);\n"; |
- if (call.returnType == TypeCategory::OWNED_STRING) |
- result += " Module._DestroyString(string);\n"; |
+ // We don't call a destructor here because we know that dependent |
+ // strings don't need to clean up. |
+ return result; |
+ } |
+ case TypeCategory::OWNED_STRING: |
+ { |
+ std::string result; |
+ result += " var string = createOwnedString();\n"; |
+ result += " " + call_str + ";\n"; |
+ result += " var result = readString(string);\n"; |
+ result += " Module._DestroyString(string);\n"; |
return result; |
} |
case TypeCategory::STRING_REF: |
return " var result = readString(" + call_str + ");\n"; |
case TypeCategory::CLASS_PTR: |
{ |
std::string result; |
result += " var result = " + call_str + ";\n"; |
@@ -335,16 +343,23 @@ namespace bindings_internal |
length = copyString(str, buffer); |
} |
var result = Runtime.stackAlloc(sizeofString); |
Module._InitString(result, buffer, length); |
return result; |
} |
+ function createOwnedString() |
+ { |
+ var result = Runtime.stackAlloc(sizeofString); |
+ Module._InitOwnedString(result); |
+ return result; |
+ } |
+ |
function readString(str) |
{ |
var length = Module._GetStringLength(str); |
var pointer = Module._GetStringData(str) >> 1; |
return String.fromCharCode.apply(String, HEAP16.slice(pointer, pointer + length)); |
} |
function createClass(superclass, ref_counted_offset, props) |