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

Side by Side Diff: lib/compiledTools.js

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: Created Jan. 14, 2016, 4:40 p.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 | « compiled/tools.cpp ('k') | lib/filterClassesNew.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 "use strict";
2
3 let {
4 Runtime, AsciiToString, HEAP16, HEAP32, _free, _getException
5 } = require("./compiled");
6
7 function wrapCall(call)
8 {
9 return function()
10 {
11 let sp = Runtime.stackSave();
12 try
13 {
14 return call.apply(this, arguments);
15 }
16 catch (e)
17 {
18 throw typeof e == "number" ? new Error(AsciiToString(_getException(e))) : e;
19 }
20 finally
21 {
22 Runtime.stackRestore(sp);
23 }
24 };
25 }
26 exports.wrapCall = wrapCall;
27
28 function convertString(str)
29 {
30 let length = str.length;
31 let buffer = Runtime.stackAlloc(length * 2);
32 for (let i = 0, pointer = (buffer >> 1); i < length; i++, pointer++)
33 HEAP16[pointer] = str.charCodeAt(i);
34 return buffer;
35 }
36
37 function stringArg(argNumber, call)
38 {
39 return function()
40 {
41 let params = Array.slice(arguments);
42 let str = params[argNumber];
43 if (str != null)
44 params.splice(argNumber, 1, convertString(str), str.length);
45 else
46 params.splice(argNumber, 1, 0, 0);
47 return call.apply(this, params);
48 };
49 }
50 exports.stringArg = stringArg;
51
52 function stringResult(call)
53 {
54 return function()
55 {
56 let params = Array.slice(arguments);
57 let resultLen = Runtime.stackAlloc(4);
58 params.push(resultLen);
59
60 let buffer = call.apply(this, params);
61 if (buffer)
62 {
63 let length = HEAP32[resultLen >> 2];
64 let pointer = buffer >> 1;
65 let str = String.fromCharCode.apply(String, HEAP16.slice(pointer, pointer + length));
66 _free(buffer);
67 return str;
68 }
69 else
70 return null;
71 };
72 }
73 exports.stringResult = stringResult;
OLDNEW
« no previous file with comments | « compiled/tools.cpp ('k') | lib/filterClassesNew.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld