@@ -727,7 +727,17 @@ bindNative(["cn1_com_codename1_html5_js_core_JSArray_create_int_R_com_codename1_
727727} ) ;
728728
729729bindNative ( [ "cn1_com_codename1_html5_js_browser_Window_current_R_com_codename1_html5_js_browser_Window" , "cn1_com_codename1_html5_js_browser_Window_current___R_com_codename1_html5_js_browser_Window" ] , function * ( ) {
730- const wrapper = jvm . wrapJsObject ( global . window || global . self || global , "com_codename1_html5_js_browser_Window" ) ;
730+ const nativeWindow = global . window ;
731+ const hasDomWindow = ! ! ( nativeWindow && nativeWindow . document ) ;
732+ if ( ! hasDomWindow && typeof jvm . invokeHostNative === "function" ) {
733+ const hostWindow = yield jvm . invokeHostNative ( "__cn1_dom_window_current__" , [ ] ) ;
734+ if ( hostWindow != null ) {
735+ const workerWrapper = jvm . wrapJsObject ( hostWindow , "com_codename1_html5_js_browser_Window" ) ;
736+ jvm . enhanceJsWrapper ( workerWrapper , "com_codename1_impl_html5_JSOImplementations_WindowExt" ) ;
737+ return workerWrapper ;
738+ }
739+ }
740+ const wrapper = jvm . wrapJsObject ( ( hasDomWindow ? nativeWindow : null ) || global . self || global , "com_codename1_html5_js_browser_Window" ) ;
731741 jvm . enhanceJsWrapper ( wrapper , "com_codename1_impl_html5_JSOImplementations_WindowExt" ) ;
732742 return wrapper ;
733743} ) ;
@@ -737,6 +747,27 @@ bindNative([
737747 "cn1_com_codename1_html5_js_browser_Window_getDocument___R_com_codename1_html5_js_dom_HTMLDocument"
738748] , function * ( __cn1ThisObject ) {
739749 const win = jvm . unwrapJsValue ( __cn1ThisObject ) ;
750+ if ( win && win . __cn1HostRef != null && typeof jvm . invokeHostNative === "function" ) {
751+ const hostResult = yield jvm . invokeHostNative ( "__cn1_jso_bridge__" , [ {
752+ receiver : win ,
753+ kind : "getter" ,
754+ member : "document" ,
755+ args : [ ]
756+ } ] ) ;
757+ return hostResult == null ? null : jvm . wrapJsObject ( hostResult , "com_codename1_html5_js_dom_HTMLDocument" ) ;
758+ }
759+ if ( typeof jvm . invokeHostNative === "function" && ( ! win || ! win . document ) ) {
760+ const hostWindow = yield jvm . invokeHostNative ( "__cn1_dom_window_current__" , [ ] ) ;
761+ if ( hostWindow != null ) {
762+ const hostDocument = yield jvm . invokeHostNative ( "__cn1_jso_bridge__" , [ {
763+ receiver : hostWindow ,
764+ kind : "getter" ,
765+ member : "document" ,
766+ args : [ ]
767+ } ] ) ;
768+ return hostDocument == null ? null : jvm . wrapJsObject ( hostDocument , "com_codename1_html5_js_dom_HTMLDocument" ) ;
769+ }
770+ }
740771 if ( ! win || ! win . document ) {
741772 return null ;
742773 }
@@ -748,19 +779,47 @@ bindNative([
748779 "cn1_com_codename1_html5_js_dom_HTMLDocument_createElement___java_lang_String_R_com_codename1_html5_js_dom_HTMLElement"
749780] , function * ( __cn1ThisObject , tagName ) {
750781 const doc = jvm . unwrapJsValue ( __cn1ThisObject ) ;
782+ const tag = tagName == null ? "" : jvm . toNativeString ( tagName ) ;
783+ const canvasClass = "com_codename1_html5_js_dom_HTMLCanvasElement" ;
784+ if ( doc && doc . __cn1HostRef != null && typeof jvm . invokeHostNative === "function" ) {
785+ const hostResult = yield jvm . invokeHostNative ( "__cn1_jso_bridge__" , [ {
786+ receiver : doc ,
787+ kind : "method" ,
788+ member : "createElement" ,
789+ args : [ tag ]
790+ } ] ) ;
791+ if ( hostResult == null ) {
792+ return null ;
793+ }
794+ const expectedClass = String ( tag ) . toLowerCase ( ) === "canvas"
795+ ? canvasClass
796+ : jvm . inferJsObjectClass ( hostResult , "com_codename1_html5_js_dom_HTMLElement" ) ;
797+ return jvm . wrapJsObject ( hostResult , expectedClass ) ;
798+ }
751799 if ( ! doc || typeof doc . createElement !== "function" ) {
752800 return null ;
753801 }
754- const tag = tagName == null ? "" : jvm . toNativeString ( tagName ) ;
755802 const element = doc . createElement ( tag ) ;
756- return jvm . wrapJsObject ( element , jvm . inferJsObjectClass ( element , "com_codename1_html5_js_dom_HTMLElement" ) ) ;
803+ const expectedClass = String ( tag ) . toLowerCase ( ) === "canvas"
804+ ? canvasClass
805+ : jvm . inferJsObjectClass ( element , "com_codename1_html5_js_dom_HTMLElement" ) ;
806+ return jvm . wrapJsObject ( element , expectedClass ) ;
757807} ) ;
758808
759809bindNative ( [
760810 "cn1_com_codename1_html5_js_dom_HTMLDocument_getBody_R_com_codename1_html5_js_dom_HTMLElement" ,
761811 "cn1_com_codename1_html5_js_dom_HTMLDocument_getBody___R_com_codename1_html5_js_dom_HTMLElement"
762812] , function * ( __cn1ThisObject ) {
763813 const doc = jvm . unwrapJsValue ( __cn1ThisObject ) ;
814+ if ( doc && doc . __cn1HostRef != null && typeof jvm . invokeHostNative === "function" ) {
815+ const hostResult = yield jvm . invokeHostNative ( "__cn1_jso_bridge__" , [ {
816+ receiver : doc ,
817+ kind : "getter" ,
818+ member : "body" ,
819+ args : [ ]
820+ } ] ) ;
821+ return hostResult == null ? null : jvm . wrapJsObject ( hostResult , "com_codename1_html5_js_dom_HTMLBodyElement" ) ;
822+ }
764823 if ( ! doc || ! doc . body ) {
765824 return null ;
766825 }
@@ -772,10 +831,32 @@ bindNative([
772831 "cn1_com_codename1_html5_js_dom_HTMLDocument_getElementById___java_lang_String_R_com_codename1_html5_js_dom_HTMLElement"
773832] , function * ( __cn1ThisObject , id ) {
774833 const doc = jvm . unwrapJsValue ( __cn1ThisObject ) ;
834+ const nativeId = id == null ? "" : jvm . toNativeString ( id ) ;
835+ const canvasClass = "com_codename1_html5_js_dom_HTMLCanvasElement" ;
836+ if ( doc && doc . __cn1HostRef != null && typeof jvm . invokeHostNative === "function" ) {
837+ const hostResult = yield jvm . invokeHostNative ( "__cn1_jso_bridge__" , [ {
838+ receiver : doc ,
839+ kind : "method" ,
840+ member : "getElementById" ,
841+ args : [ nativeId ]
842+ } ] ) ;
843+ if ( hostResult == null ) {
844+ return null ;
845+ }
846+ const tagName = yield jvm . invokeHostNative ( "__cn1_jso_bridge__" , [ {
847+ receiver : hostResult ,
848+ kind : "getter" ,
849+ member : "tagName" ,
850+ args : [ ]
851+ } ] ) ;
852+ const expectedClass = String ( tagName || "" ) . toUpperCase ( ) === "CANVAS"
853+ ? canvasClass
854+ : jvm . inferJsObjectClass ( hostResult , "com_codename1_html5_js_dom_HTMLElement" ) ;
855+ return jvm . wrapJsObject ( hostResult , expectedClass ) ;
856+ }
775857 if ( ! doc || typeof doc . getElementById !== "function" ) {
776858 return null ;
777859 }
778- const nativeId = id == null ? "" : jvm . toNativeString ( id ) ;
779860 const element = doc . getElementById ( nativeId ) ;
780861 return element == null ? null : jvm . wrapJsObject ( element , jvm . inferJsObjectClass ( element , "com_codename1_html5_js_dom_HTMLElement" ) ) ;
781862} ) ;
0 commit comments