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

Delta Between Two Patch Sets: compiled/shell.js

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Left Patch Set: Back to manual approach for API Created Jan. 18, 2016, 12:41 p.m.
Right Patch Set: Addressed comments from Patch Set 28 Created March 21, 2017, 10:04 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/intrusive_ptr.h ('k') | compiled/traceInit.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 "use strict";
2
1 "Compiled from https://hg.adblockplus.org/adblockplus/ with Emscripten {{{EMSCRI PTEN_VERSION}}}"; 3 "Compiled from https://hg.adblockplus.org/adblockplus/ with Emscripten {{{EMSCRI PTEN_VERSION}}}";
2 4
3 var sizeofString = 0; 5 var FilterNotifier = require("filterNotifier").FilterNotifier;
4
5 function createString(str)
6 {
7 var length = 0;
8 var buffer = 0;
9 if (str)
10 {
11 length = str.length;
12 buffer = Runtime.stackAlloc(length * 2);
13 for (var i = 0, pointer = (buffer >> 1); i < length; i++, pointer++)
14 HEAP16[pointer] = str.charCodeAt(i);
15 }
16
17 if (!sizeofString)
18 sizeofString = Module._GetSizeofString();
19 var result = Module.Runtime.stackAlloc(sizeofString);
20 Module._InitString(result, buffer, length);
21 return result;
22 }
23
24 function getStringData(str)
25 {
26 var length = Module._GetStringLength(str);
27 var pointer = Module._GetStringData(str) >> 1;
28 return String.fromCharCode.apply(String, HEAP16.slice(pointer, pointer + lengt h));
29 }
30
31 function convertGetter(call)
32 {
33 return function()
34 {
35 return call(this._pointer);
36 };
37 }
38
39 function convertSetter(call)
40 {
41 return function(value)
42 {
43 call(this._pointer, value);
44 }
45 }
46
47 function convertMethod(call)
48 {
49 return function()
50 {
51 var params = Array.slice(arguments);
52 params.unshift(this._pointer);
53 return call.apply(this, params);
54 };
55 }
56 6
57 var regexps = 7 var regexps =
58 { 8 {
59 _data: Object.create(null), 9 _data: Object.create(null),
60 _counter: 0, 10 _counter: 0,
61 11
62 create: function(source, matchCase) 12 create: function(source, matchCase)
63 { 13 {
64 var id = ++this._counter; 14 var id = ++this._counter;
65 try 15 try
66 { 16 {
67 this._data[id] = new RegExp(getStringData(source), matchCase ? "" : "i"); 17 this._data[id] = new RegExp(readString(source), matchCase ? "" : "i");
18 return id;
68 } 19 }
69 catch (e) 20 catch (e)
70 { 21 {
71 this._data[id] = String(e); 22 return -1;
72 } 23 }
73 return id;
74 },
75
76 getError: function(id)
77 {
78 if (typeof this._data[id] == "string")
79 return createString(this._data[id]);
80 else
81 return 0;
82 }, 24 },
83 25
84 delete: function(id) 26 delete: function(id)
85 { 27 {
86 delete this._data[id]; 28 delete this._data[id];
87 }, 29 },
88 30
89 test: function(id, str) 31 test: function(id, str)
90 { 32 {
91 return this._data[id].test(getStringData(str)); 33 return this._data[id].test(readString(str));
92 } 34 }
93 }; 35 };
94 36
95 var Module = 37 var Module =
96 { 38 {
97 preRun: [], 39 preRun: [],
98 postRun: [], 40 postRun: [],
99 print: console.log.bind(console), 41 print: console.log.bind(console),
100 printErr: console.error.bind(console), 42 printErr: console.error.bind(console),
101 43
102 createClass: function(superclass) 44 getMemoryLayout: function()
103 { 45 {
104 var result = function(pointer) 46 return {
105 { 47 'static_base': STATIC_BASE,
106 this._pointer = pointer; 48 'static_top': STATICTOP,
49 'stack_base': STACK_BASE,
50 'stack_top': STACKTOP,
51 'stack_max': STACK_MAX,
52 'dynamic_base': DYNAMIC_BASE,
53 'dynamic_top': DYNAMICTOP,
54 'total_memory': TOTAL_MEMORY
107 }; 55 };
108 if (superclass)
109 result.prototype = Object.create(superclass.prototype);
110 result.prototype.delete = function()
111 {
112 Module._DeletePointer(this._pointer);
113 };
114 return result;
115 },
116
117 wrapCall: function(call)
118 {
119 return function()
120 {
121 var sp = Module.Runtime.stackSave();
122 try
123 {
124 return call.apply(this, arguments);
125 }
126 catch (e)
127 {
128 throw typeof e == "number" ? new Error(Module.AsciiToString(Module._GetE xception(e))) : e;
129 }
130 finally
131 {
132 Module.Runtime.stackRestore(sp);
133 }
134 };
135 },
136
137 stringArg: function(argPos, call)
138 {
139 return function()
140 {
141 var params = Array.slice(arguments);
142 params[argPos] = createString(params[argPos]);
143 try
144 {
145 return call.apply(this, params);
146 }
147 finally
148 {
149 Module._DestroyString(params[argPos]);
150 }
151 };
152 },
153
154 stringResult: function(call)
155 {
156 return function()
157 {
158 var params = Array.slice(arguments);
159 try
160 {
161 params.unshift(createString());
162 call.apply(this, params);
163 return getStringData(params[0]);
164 }
165 finally
166 {
167 Module._DestroyString(params[0]);
168 }
169 };
170 },
171
172 defineProperty: function(cls, name, getter, setter)
173 {
174 var descriptor =
175 {
176 enumerable: true,
177 get: Module.wrapCall(convertGetter(getter))
178 };
179 if (setter)
180 descriptor.set = Module.wrapCall(convertSetter(setter));
181 Object.defineProperty(cls.prototype, name, descriptor);
182 },
183
184 defineStringProperty: function(cls, name, getter, setter)
185 {
186 Module.defineProperty(cls, name, Module.stringResult(getter),
187 (setter ? Module.stringArg(1, setter) : null));
188 },
189
190 defineMethod: function(cls, name, method)
191 {
192 cls.prototype[name] = Module.wrapCall(convertMethod(method));
193 } 56 }
194 }; 57 };
195 var ENVIRONMENT_IS_WEB = false, ENVIRONMENT_IS_NODE = false, 58 var ENVIRONMENT_IS_WEB = false, ENVIRONMENT_IS_NODE = false,
196 ENVIRONMENT_IS_WORKER = false, ENVIRONMENT_IS_SHELL = true; 59 ENVIRONMENT_IS_WORKER = false, ENVIRONMENT_IS_SHELL = true;
197 60
198 {{BODY}} 61 {{BODY}}
199 62
200 Object.assign(exports, Module); 63 Object.assign(exports, Module);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld