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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | compiled/bindings/runtime_utils.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 return " " + call_str + ";\n"; 215 return " " + call_str + ";\n";
216 case TypeCategory::INT: 216 case TypeCategory::INT:
217 case TypeCategory::FLOAT: 217 case TypeCategory::FLOAT:
218 case TypeCategory::DOUBLE: 218 case TypeCategory::DOUBLE:
219 return " var result = " + call_str + ";\n"; 219 return " var result = " + call_str + ";\n";
220 case TypeCategory::INT64: 220 case TypeCategory::INT64:
221 return " var result = Runtime.makeBigInt(" + call_str + ", " + 221 return " var result = Runtime.makeBigInt(" + call_str + ", " +
222 "Runtime.getTempRet0(), " + 222 "Runtime.getTempRet0(), " +
223 "true);\n"; 223 "true);\n";
224 case TypeCategory::DEPENDENT_STRING: 224 case TypeCategory::DEPENDENT_STRING:
225 case TypeCategory::OWNED_STRING:
226 { 225 {
227 std::string result; 226 std::string result;
228 result += " var string = createString();\n"; 227 result += " var string = createString();\n";
229 result += " " + call_str + ";\n"; 228 result += " " + call_str + ";\n";
230 result += " var result = readString(string);\n"; 229 result += " var result = readString(string);\n";
231 if (call.returnType == TypeCategory::OWNED_STRING) 230 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
232 result += " Module._DestroyString(string);\n"; 231 }
232 case TypeCategory::OWNED_STRING:
233 {
234 std::string result;
235 result += " var string = createOwnedString();\n";
236 result += " " + call_str + ";\n";
237 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.
238 result += " Module._DestroyString(string);\n";
233 return result; 239 return result;
234 } 240 }
235 case TypeCategory::STRING_REF: 241 case TypeCategory::STRING_REF:
236 return " var result = readString(" + call_str + ");\n"; 242 return " var result = readString(" + call_str + ");\n";
237 case TypeCategory::CLASS_PTR: 243 case TypeCategory::CLASS_PTR:
238 { 244 {
239 std::string result; 245 std::string result;
240 result += " var result = " + call_str + ";\n"; 246 result += " var result = " + call_str + ";\n";
241 result += " if (result)\n"; 247 result += " if (result)\n";
242 result += " {\n"; 248 result += " {\n";
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 { 339 {
334 buffer = Runtime.stackAlloc(str.length * 2); 340 buffer = Runtime.stackAlloc(str.length * 2);
335 length = copyString(str, buffer); 341 length = copyString(str, buffer);
336 } 342 }
337 343
338 var result = Runtime.stackAlloc(sizeofString); 344 var result = Runtime.stackAlloc(sizeofString);
339 Module._InitString(result, buffer, length); 345 Module._InitString(result, buffer, length);
340 return result; 346 return result;
341 } 347 }
342 348
349 function createOwnedString()
350 {
351 var result = Runtime.stackAlloc(sizeofString);
352 Module._InitOwnedString(result);
353 return result;
354 }
355
343 function readString(str) 356 function readString(str)
344 { 357 {
345 var length = Module._GetStringLength(str); 358 var length = Module._GetStringLength(str);
346 var pointer = Module._GetStringData(str) >> 1; 359 var pointer = Module._GetStringData(str) >> 1;
347 return String.fromCharCode.apply(String, HEAP16.slice(pointer, pointer + length)); 360 return String.fromCharCode.apply(String, HEAP16.slice(pointer, pointer + length));
348 } 361 }
349 362
350 function createClass(superclass, ref_counted_offset, props) 363 function createClass(superclass, ref_counted_offset, props)
351 { 364 {
352 var result = function(pointer) 365 var result = function(pointer)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 459
447 void printBindings() 460 void printBindings()
448 { 461 {
449 bindings_internal::printHelpers(); 462 bindings_internal::printHelpers();
450 463
451 for (const auto& cls : classes) 464 for (const auto& cls : classes)
452 bindings_internal::printClass(cls); 465 bindings_internal::printClass(cls);
453 for (const auto& cls : classes) 466 for (const auto& cls : classes)
454 bindings_internal::printClassMapping(cls); 467 bindings_internal::printClassMapping(cls);
455 } 468 }
OLDNEW
« 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