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

Side by Side Diff: compiled/shell.js

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

Powered by Google App Engine
This is Rietveld