Skip to content

Commit 2506c3c

Browse files
committed
Fixed compilation on newer JDKs and new native bindings
1 parent b04abeb commit 2506c3c

3 files changed

Lines changed: 59 additions & 3 deletions

File tree

Ports/JavaScriptPort/STATUS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ Current State
2222
- Bundle generation ordering bug identified and fixed for worker mode:
2323
- Cause: `worker.js` was generated before `port.js` was copied into the output bundle, so worker never imported JavaScriptPort natives.
2424
- Fix: copy JavaScriptPort assets before `worker.js` generation and keep service-worker/shell scripts excluded from worker imports.
25+
- Latest CI artifact confirms `worker.js` now imports `port.js`, but startup still fails in `HTML5Implementation.__init`:
26+
- first failure remains `TypeError: Cannot read properties of null (reading '__classDef')`
27+
- crash site moved to `HTMLDocument.createElement(...)` invocation with null document target.
28+
- Added explicit worker-native bindings for initial DOM bridge path:
29+
- `Window.getDocument()`
30+
- `HTMLDocument.createElement(String)`
31+
- `HTMLDocument.getBody()`
32+
- `HTMLDocument.getElementById(String)`
2533
- Latest CI artifacts now run worker mode but fail early before suite start with:
2634
- `PARPAR:DIAG:FIRST_FAILURE:category=runtime_error`
2735
- `TypeError: Cannot read properties of null (reading '__classDef')`

Ports/JavaScriptPort/src/main/webapp/port.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,54 @@ bindNative(["cn1_com_codename1_html5_js_browser_Window_current_R_com_codename1_h
732732
return wrapper;
733733
});
734734

735+
bindNative([
736+
"cn1_com_codename1_html5_js_browser_Window_getDocument_R_com_codename1_html5_js_dom_HTMLDocument",
737+
"cn1_com_codename1_html5_js_browser_Window_getDocument___R_com_codename1_html5_js_dom_HTMLDocument"
738+
], function*(__cn1ThisObject) {
739+
const win = jvm.unwrapJsValue(__cn1ThisObject);
740+
if (!win || !win.document) {
741+
return null;
742+
}
743+
return jvm.wrapJsObject(win.document, "com_codename1_html5_js_dom_HTMLDocument");
744+
});
745+
746+
bindNative([
747+
"cn1_com_codename1_html5_js_dom_HTMLDocument_createElement_java_lang_String_R_com_codename1_html5_js_dom_HTMLElement",
748+
"cn1_com_codename1_html5_js_dom_HTMLDocument_createElement___java_lang_String_R_com_codename1_html5_js_dom_HTMLElement"
749+
], function*(__cn1ThisObject, tagName) {
750+
const doc = jvm.unwrapJsValue(__cn1ThisObject);
751+
if (!doc || typeof doc.createElement !== "function") {
752+
return null;
753+
}
754+
const tag = tagName == null ? "" : jvm.toNativeString(tagName);
755+
const element = doc.createElement(tag);
756+
return jvm.wrapJsObject(element, jvm.inferJsObjectClass(element, "com_codename1_html5_js_dom_HTMLElement"));
757+
});
758+
759+
bindNative([
760+
"cn1_com_codename1_html5_js_dom_HTMLDocument_getBody_R_com_codename1_html5_js_dom_HTMLElement",
761+
"cn1_com_codename1_html5_js_dom_HTMLDocument_getBody___R_com_codename1_html5_js_dom_HTMLElement"
762+
], function*(__cn1ThisObject) {
763+
const doc = jvm.unwrapJsValue(__cn1ThisObject);
764+
if (!doc || !doc.body) {
765+
return null;
766+
}
767+
return jvm.wrapJsObject(doc.body, "com_codename1_html5_js_dom_HTMLBodyElement");
768+
});
769+
770+
bindNative([
771+
"cn1_com_codename1_html5_js_dom_HTMLDocument_getElementById_java_lang_String_R_com_codename1_html5_js_dom_HTMLElement",
772+
"cn1_com_codename1_html5_js_dom_HTMLDocument_getElementById___java_lang_String_R_com_codename1_html5_js_dom_HTMLElement"
773+
], function*(__cn1ThisObject, id) {
774+
const doc = jvm.unwrapJsValue(__cn1ThisObject);
775+
if (!doc || typeof doc.getElementById !== "function") {
776+
return null;
777+
}
778+
const nativeId = id == null ? "" : jvm.toNativeString(id);
779+
const element = doc.getElementById(nativeId);
780+
return element == null ? null : jvm.wrapJsObject(element, jvm.inferJsObjectClass(element, "com_codename1_html5_js_dom_HTMLElement"));
781+
});
782+
735783
bindNative([
736784
"cn1_com_codename1_html5_js_ajax_XMLHttpRequest_create_R_com_codename1_html5_js_ajax_XMLHttpRequest",
737785
"cn1_com_codename1_html5_js_ajax_XMLHttpRequest_create___R_com_codename1_html5_js_ajax_XMLHttpRequest"

vm/JavaAPI/src/java/lang/Integer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private static String intToBinaryString(int i) {
206206
} while ((i >>>= 1) != 0);
207207

208208
//return new String(cursor, bufLen - cursor, buf);
209-
return new String(cursor, bufLen - cursor, buf);
209+
return new String(buf, cursor, bufLen - cursor);
210210
}
211211

212212

@@ -233,7 +233,7 @@ public static String intToHexString(int i, int minWidth) {
233233
buf[--cursor] = digits[i & 0xf];
234234
} while ((i >>>= 4) != 0 || (bufLen - cursor < minWidth));
235235

236-
return new String(cursor, bufLen - cursor, buf);
236+
return new String(buf, cursor, bufLen - cursor);
237237
}
238238

239239
public static String intToOctalString(int i) {
@@ -245,7 +245,7 @@ public static String intToOctalString(int i) {
245245
buf[--cursor] = DIGITS[i & 7];
246246
} while ((i >>>= 3) != 0);
247247

248-
return new String(cursor, bufLen - cursor, buf);
248+
return new String(buf, cursor, bufLen - cursor);
249249
}
250250

251251
/**

0 commit comments

Comments
 (0)