17
17
#include "gc-common.h"
18
18
19
19
//JS funcs
20
+ extern void mono_wasm_release_cs_owned_object (int js_handle );
21
+ extern void mono_wasm_bind_js_function (MonoString * * function_name , MonoString * * module_name , void * signature , int * function_js_handle , int * is_exception , MonoObject * * result );
22
+ extern void mono_wasm_invoke_bound_function (int function_js_handle , void * data );
23
+ extern void mono_wasm_invoke_import (int fn_handle , void * data );
24
+ extern void mono_wasm_bind_cs_function (MonoString * * fully_qualified_name , int signature_hash , void * signatures , int * is_exception , MonoObject * * result );
25
+ extern void mono_wasm_marshal_promise (void * data );
26
+
27
+ typedef void (* background_job_cb )(void );
28
+ void mono_threads_schedule_background_job (background_job_cb cb );
29
+
30
+ #ifdef ENABLE_LEGACY_JS_INTEROP
20
31
extern void mono_wasm_invoke_js_with_args_ref (int js_handle , MonoString * * method , MonoArray * * args , int * is_exception , MonoObject * * result );
21
32
extern void mono_wasm_get_object_property_ref (int js_handle , MonoString * * propertyName , int * is_exception , MonoObject * * result );
22
- extern void mono_wasm_get_by_index_ref (int js_handle , int property_index , int * is_exception , MonoObject * * result );
23
33
extern void mono_wasm_set_object_property_ref (int js_handle , MonoString * * propertyName , MonoObject * * value , int createIfNotExist , int hasOwnProperty , int * is_exception , MonoObject * * result );
34
+ extern void mono_wasm_get_by_index_ref (int js_handle , int property_index , int * is_exception , MonoObject * * result );
24
35
extern void mono_wasm_set_by_index_ref (int js_handle , int property_index , MonoObject * * value , int * is_exception , MonoObject * * result );
25
36
extern void mono_wasm_get_global_object_ref (MonoString * * global_name , int * is_exception , MonoObject * * result );
26
- extern void mono_wasm_release_cs_owned_object (int js_handle );
27
- extern void mono_wasm_create_cs_owned_object_ref (MonoString * * core_name , MonoArray * * args , int * is_exception , MonoObject * * result );
28
37
extern void mono_wasm_typed_array_to_array_ref (int js_handle , int * is_exception , MonoObject * * result );
38
+ extern void mono_wasm_create_cs_owned_object_ref (MonoString * * core_name , MonoArray * * args , int * is_exception , MonoObject * * result );
29
39
extern void mono_wasm_typed_array_from_ref (int ptr , int begin , int end , int bytes_per_element , int type , int * is_exception , MonoObject * * result );
30
40
31
- extern void mono_wasm_bind_js_function (MonoString * * function_name , MonoString * * module_name , void * signature , int * function_js_handle , int * is_exception , MonoObject * * result );
32
- extern void mono_wasm_invoke_bound_function (int function_js_handle , void * data );
33
- extern void mono_wasm_invoke_import (int fn_handle , void * data );
34
- extern void mono_wasm_bind_cs_function (MonoString * * fully_qualified_name , int signature_hash , void * signatures , int * is_exception , MonoObject * * result );
35
- extern void mono_wasm_marshal_promise (void * data );
41
+ // Blazor specific custom routines - see dotnet_support.js for backing code
42
+ extern void * mono_wasm_invoke_js_blazor (MonoString * * exceptionMessage , void * callInfo , void * arg0 , void * arg1 , void * arg2 );
43
+ #endif /* ENABLE_LEGACY_JS_INTEROP */
36
44
37
-
38
- void core_initialize_internals (void )
45
+ void bindings_initialize_internals (void )
39
46
{
47
+ mono_add_internal_call ("System.Runtime.InteropServices.JavaScript.JSSynchronizationContext::ScheduleBackgroundJob" , mono_threads_schedule_background_job );
48
+
40
49
mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObject" , mono_wasm_release_cs_owned_object );
41
50
mono_add_internal_call ("Interop/Runtime::BindJSFunction" , mono_wasm_bind_js_function );
42
51
mono_add_internal_call ("Interop/Runtime::InvokeJSFunction" , mono_wasm_invoke_bound_function );
@@ -45,7 +54,7 @@ void core_initialize_internals (void)
45
54
mono_add_internal_call ("Interop/Runtime::MarshalPromise" , mono_wasm_marshal_promise );
46
55
mono_add_internal_call ("Interop/Runtime::RegisterGCRoot" , mono_wasm_register_root );
47
56
mono_add_internal_call ("Interop/Runtime::DeregisterGCRoot" , mono_wasm_deregister_root );
48
-
57
+ #ifdef ENABLE_LEGACY_JS_INTEROP
49
58
// legacy
50
59
mono_add_internal_call ("Interop/Runtime::InvokeJSWithArgsRef" , mono_wasm_invoke_js_with_args_ref );
51
60
mono_add_internal_call ("Interop/Runtime::GetObjectPropertyRef" , mono_wasm_get_object_property_ref );
@@ -56,70 +65,8 @@ void core_initialize_internals (void)
56
65
mono_add_internal_call ("Interop/Runtime::TypedArrayToArrayRef" , mono_wasm_typed_array_to_array_ref );
57
66
mono_add_internal_call ("Interop/Runtime::CreateCSOwnedObjectRef" , mono_wasm_create_cs_owned_object_ref );
58
67
mono_add_internal_call ("Interop/Runtime::TypedArrayFromRef" , mono_wasm_typed_array_from_ref );
59
- }
60
-
61
- // Int8Array | int8_t | byte or SByte (signed byte)
62
- // Uint8Array | uint8_t | byte or Byte (unsigned byte)
63
- // Uint8ClampedArray| uint8_t | byte or Byte (unsigned byte)
64
- // Int16Array | int16_t | short (signed short)
65
- // Uint16Array | uint16_t | ushort (unsigned short)
66
- // Int32Array | int32_t | int (signed integer)
67
- // Uint32Array | uint32_t | uint (unsigned integer)
68
- // Float32Array | float | float
69
- // Float64Array | double | double
70
- // typed array marshalling
71
- // Keep in sync with driver.c
72
- #define MARSHAL_ARRAY_BYTE 10
73
- #define MARSHAL_ARRAY_UBYTE 11
74
- #define MARSHAL_ARRAY_UBYTE_C 12 // alias of MARSHAL_ARRAY_UBYTE
75
- #define MARSHAL_ARRAY_SHORT 13
76
- #define MARSHAL_ARRAY_USHORT 14
77
- #define MARSHAL_ARRAY_INT 15
78
- #define MARSHAL_ARRAY_UINT 16
79
- #define MARSHAL_ARRAY_FLOAT 17
80
- #define MARSHAL_ARRAY_DOUBLE 18
81
-
82
- EMSCRIPTEN_KEEPALIVE void
83
- mono_wasm_typed_array_new_ref (char * arr , int length , int size , int type , PPVOLATILE (MonoArray ) result )
84
- {
85
- MONO_ENTER_GC_UNSAFE ;
86
- MonoClass * typeClass = mono_get_byte_class (); // default is Byte
87
- switch (type ) {
88
- case MARSHAL_ARRAY_BYTE :
89
- typeClass = mono_get_sbyte_class ();
90
- break ;
91
- case MARSHAL_ARRAY_SHORT :
92
- typeClass = mono_get_int16_class ();
93
- break ;
94
- case MARSHAL_ARRAY_USHORT :
95
- typeClass = mono_get_uint16_class ();
96
- break ;
97
- case MARSHAL_ARRAY_INT :
98
- typeClass = mono_get_int32_class ();
99
- break ;
100
- case MARSHAL_ARRAY_UINT :
101
- typeClass = mono_get_uint32_class ();
102
- break ;
103
- case MARSHAL_ARRAY_FLOAT :
104
- typeClass = mono_get_single_class ();
105
- break ;
106
- case MARSHAL_ARRAY_DOUBLE :
107
- typeClass = mono_get_double_class ();
108
- break ;
109
- case MARSHAL_ARRAY_UBYTE :
110
- case MARSHAL_ARRAY_UBYTE_C :
111
- typeClass = mono_get_byte_class ();
112
- break ;
113
- default :
114
- printf ("Invalid marshal type %d in mono_wasm_typed_array_new" , type );
115
- abort ();
116
- }
117
-
118
- PVOLATILE (MonoArray ) buffer ;
119
-
120
- buffer = mono_array_new (mono_get_root_domain (), typeClass , length );
121
- memcpy (mono_array_addr_with_size (buffer , sizeof (char ), 0 ), arr , length * size );
122
68
123
- store_volatile ((PPVOLATILE (MonoObject ))result , (MonoObject * )buffer );
124
- MONO_EXIT_GC_UNSAFE ;
69
+ // Blazor specific custom routines - see dotnet_support.js for backing code
70
+ mono_add_internal_call ("WebAssembly.JSInterop.InternalCalls::InvokeJS" , mono_wasm_invoke_js_blazor );
71
+ #endif /* ENABLE_LEGACY_JS_INTEROP */
125
72
}
0 commit comments