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

Unified Diff: compiled/bindings/generator.cpp

Issue 29434561: Noissue - [emscripten] Call the correct constructor for strings created from JavaScript (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Added comment Created Aug. 23, 2017, 10:26 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | compiled/bindings/runtime_utils.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « no previous file | compiled/bindings/runtime_utils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld