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: Created May 9, 2017, 10:37 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,30 @@ 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";
+ return result;
sergei 2017/08/23 10:06:15 Strictly speaking, despite destructor of Dependent
Wladimir Palant 2017/08/23 10:26:41 Ok, I added a comment. In fact, we might need to c
sergei 2017/08/23 10:39:19 Yeah, I thought about similar debug needs too. If
+ }
+ case TypeCategory::OWNED_STRING:
+ {
+ std::string result;
+ result += " var string = createOwnedString();\n";
+ result += " " + call_str + ";\n";
+ result += " var result = readString(string);\n";
sergei 2017/08/23 10:06:15 Since anyway we have separate calls of Module._Ini
Wladimir Palant 2017/08/23 10:26:41 I tried that but it makes the code here less obvio
sergei 2017/08/23 10:39:19 Acknowledged.
+ 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 +341,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