MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / collect_files

Function collect_files

scripts/mangle-javascript-port-identifiers.py:146–203  ·  view source on GitHub ↗

Return the set of JS files that share the translator's worker-side identifier namespace. The mangler rewrites cn1_* / class-name identifiers in every file that the web worker loads against the *same* mapping, because the worker links these symbols together (bindNative overrides tran

(out_dir: Path)

Source from the content-addressed store, hash-verified

144
145
146def collect_files(out_dir: Path) -> list[Path]:
147 """Return the set of JS files that share the translator's worker-side
148 identifier namespace.
149
150 The mangler rewrites cn1_* / class-name identifiers in every file that
151 the web worker loads against the *same* mapping, because the worker
152 links these symbols together (bindNative overrides translated method
153 names, translated code calls global ``cn1_iv*`` helpers, etc.).
154
155 We skip:
156 * browser_bridge.js — main-thread host-bridge dispatcher. Uses
157 plain ``cn1HostBridge.register`` symbol strings that the worker
158 side sends via ``jvm.invokeHostNative(...)``; those symbols are
159 application-chosen identifiers, not translator-owned names.
160 * worker.js / sw.js — tiny shells that just ``importScripts`` the
161 mangled files; no identifiers of their own worth mangling.
162
163 We *do* mangle:
164 * translated_app*.js — raw translator output.
165 * parparvm_runtime.js — hosts ``resolveVirtual``, ``classes``, the
166 cn1_iv* helpers, and a handful of inline method-name literals
167 (e.g. ``"cn1_java_lang_Object_toString_R_java_lang_String"``)
168 that must match the mangled identifier on the worker.
169 * port.js — imported by worker.js. Contains 300+ cn1_* /
170 class-name literals passed to ``bindCiFallback`` / ``bindNative``
171 to install method overrides by name. These names are ONLY
172 meaningful against the translator's emitted symbols, so they
173 must move in lockstep with the mangler's output.
174 * App-supplied ``*_native_bindings.js`` — worker-side
175 ``bindNative([...])`` calls that register overrides on the
176 generated WebsiteThemeNativeImpl static natives; their string
177 arguments must match the mangled identifier.
178
179 App-supplied main-thread ``*_native_handlers.js`` are skipped — they
180 pair with files under native/ which we never mangle (their JS-visible
181 keys in ``cn1_get_native_interfaces()`` are public API).
182 """
183 keep: list[Path] = []
184 for entry in sorted(out_dir.iterdir()):
185 if not entry.is_file():
186 continue
187 if entry.suffix != ".js":
188 continue
189 name = entry.name
190 if name in {
191 "browser_bridge.js",
192 "worker.js",
193 "sw.js",
194 }:
195 continue
196 # Main-thread host-bridge handlers pair up with files under native/
197 # which we don't mangle — their JS-visible keys (e.g.
198 # ``com_codename1_initializr_WebsiteThemeNative``) must remain
199 # stable so cn1_get_native_interfaces() lookups keep working.
200 if name.endswith("_native_handlers.js"):
201 continue
202 keep.append(entry)
203 return keep

Callers 1

mainFunction · 0.85

Calls 1

appendMethod · 0.65

Tested by

no test coverage detected