Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8ce637c
thenable and datetime cleanup
pavelsavara Aug 9, 2021
d8326dd
removed ownsHandle for readability, removed AnyRef from hierarchy, re…
pavelsavara Aug 9, 2021
4b96785
rename _csOwnedObjects
pavelsavara Aug 9, 2021
0a4c611
rename _csOwnedObjects
pavelsavara Aug 9, 2021
99b05bb
redirect to Inflight counter
pavelsavara Aug 9, 2021
0d218f9
renames
pavelsavara Aug 9, 2021
151a059
rename and move
pavelsavara Aug 9, 2021
0f3d6d0
rename
pavelsavara Aug 9, 2021
dca5d5e
New+BindCoreObject -> CreateCsOwnedObject single call
pavelsavara Aug 9, 2021
4783438
remove refcount frames
pavelsavara Aug 9, 2021
c2fd18e
differentiate gcHandles
pavelsavara Aug 9, 2021
d30c4a8
get rid of weak GCHandle
pavelsavara Aug 9, 2021
53e2eb9
feedback
pavelsavara Aug 10, 2021
36e864a
added MappedType enum
pavelsavara Aug 10, 2021
e0b3b53
naming consistency
pavelsavara Aug 10, 2021
7c743b1
feedback
pavelsavara Aug 10, 2021
efcd1a9
rename _cs_owned_objects_by_js_handle
pavelsavara Aug 10, 2021
a9212b7
split and rename files
pavelsavara Aug 10, 2021
4f24a9d
shouldAddInflight to more methods
pavelsavara Aug 10, 2021
c5f22be
improved in-flight references
pavelsavara Aug 10, 2021
7d23f76
assert for JSObject not disposed
pavelsavara Aug 10, 2021
cce3ccc
introduce in-flight assert
pavelsavara Aug 10, 2021
e29416a
move should_add_in_flight arg to fisrt position, so that we could bin…
pavelsavara Aug 10, 2021
e4dd539
doc
pavelsavara Aug 10, 2021
3897513
cleanup
pavelsavara Aug 10, 2021
d7345bc
doc
pavelsavara Aug 10, 2021
6ee696a
implement fallback for missing support of FInalizationRegistry/WeakRe…
pavelsavara Aug 16, 2021
92b9a3b
feedback
pavelsavara Aug 16, 2021
685d2a5
no polyfill feedback
pavelsavara Aug 16, 2021
a6f7eda
feedback
pavelsavara Aug 16, 2021
4a388ed
name consistency feedback
pavelsavara Aug 16, 2021
f5cede0
use symbols for helper fields
pavelsavara Aug 16, 2021
b8ad165
feedback
pavelsavara Aug 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added MappedType enum
  • Loading branch information
pavelsavara committed Aug 16, 2021
commit 36e864ad5f63eef1ca23402c2169280a847a1664
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,28 @@ internal static IntPtr CreateCsOwnedObject(JSObject proxy, string typeName, para
return (IntPtr)jsHandle;
}

public static JSObject CreateCsOwnedProxy(IntPtr jsHandle, int mappedType)
// please keep BINDING wasm_type_symbol in sync
public enum MappedType
{
JSObject = 0,
Array = 1,
ArrayBuffer = 2,
DataView = 3,
Function = 4,
Map = 5,
SharedArrayBuffer = 6,
Int8Array = 10,
Uint8Array = 11,
Uint8ClampedArray = 12,
Int16Array = 13,
Uint16Array = 14,
Int32Array = 15,
Uint32Array = 16,
Float32Array = 17,
Float64Array = 18,
}

public static JSObject CreateCsOwnedProxy(IntPtr jsHandle, MappedType mappedType)
{
JSObject? target = null;

Expand All @@ -90,22 +111,22 @@ public static JSObject CreateCsOwnedProxy(IntPtr jsHandle, int mappedType)
{
target = mappedType switch
{
0 => new JSObject(jsHandle),
1 => new Array(jsHandle),
2 => new ArrayBuffer(jsHandle),
3 => new DataView(jsHandle),
4 => new Function(jsHandle),
5 => new Map(jsHandle),
6 => new SharedArrayBuffer(jsHandle),
10 => new Int8Array(jsHandle),
11 => new Uint8Array(jsHandle),
12 => new Uint8ClampedArray(jsHandle),
13 => new Int16Array(jsHandle),
14 => new Uint16Array(jsHandle),
15 => new Int32Array(jsHandle),
16 => new Uint32Array(jsHandle),
17 => new Float32Array(jsHandle),
18 => new Float64Array(jsHandle),
MappedType.JSObject => new JSObject(jsHandle),
MappedType.Array => new Array(jsHandle),
MappedType.ArrayBuffer => new ArrayBuffer(jsHandle),
MappedType.DataView => new DataView(jsHandle),
MappedType.Function => new Function(jsHandle),
MappedType.Map => new Map(jsHandle),
MappedType.SharedArrayBuffer => new SharedArrayBuffer(jsHandle),
MappedType.Int8Array => new Int8Array(jsHandle),
MappedType.Uint8Array => new Uint8Array(jsHandle),
MappedType.Uint8ClampedArray => new Uint8ClampedArray(jsHandle),
MappedType.Int16Array => new Int16Array(jsHandle),
MappedType.Uint16Array => new Uint16Array(jsHandle),
MappedType.Int32Array => new Int32Array(jsHandle),
MappedType.Uint32Array => new Uint32Array(jsHandle),
MappedType.Float32Array => new Float32Array(jsHandle),
MappedType.Float64Array => new Float64Array(jsHandle),
_ => throw new ArgumentOutOfRangeException(nameof(mappedType))
};
_csOwnedObjects[(int)jsHandle] = new WeakReference<JSObject>(target, trackResurrection: true);
Expand Down
44 changes: 22 additions & 22 deletions src/mono/wasm/runtime/binding_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,26 @@ var BindingSupportLib = {

// avoid infinite recursion
this.init = true;

Object.prototype[Symbol.for("wasm type")] = 0;
Array.prototype[Symbol.for("wasm type")] = 1;
ArrayBuffer.prototype[Symbol.for("wasm type")] = 2;
DataView.prototype[Symbol.for("wasm type")] = 3;
Function.prototype[Symbol.for("wasm type")] = 4;
Map.prototype[Symbol.for("wasm type")] = 5;
this.wasm_type_symbol = Symbol.for("wasm type");

// please keep System.Runtime.InteropServices.JavaScript.Runtime.MappedType in sync
Object.prototype[this.wasm_type_symbol] = 0;
Array.prototype[this.wasm_type_symbol] = 1;
ArrayBuffer.prototype[this.wasm_type_symbol] = 2;
DataView.prototype[this.wasm_type_symbol] = 3;
Function.prototype[this.wasm_type_symbol] = 4;
Map.prototype[this.wasm_type_symbol] = 5;
if (typeof SharedArrayBuffer !== 'undefined')
SharedArrayBuffer.prototype[Symbol.for("wasm type")] = 6;
Int8Array.prototype[Symbol.for("wasm type")] = 10;
Uint8Array.prototype[Symbol.for("wasm type")] = 11;
Uint8ClampedArray.prototype[Symbol.for("wasm type")] = 12;
Int16Array.prototype[Symbol.for("wasm type")] = 13;
Uint16Array.prototype[Symbol.for("wasm type")] = 14;
Int32Array.prototype[Symbol.for("wasm type")] = 15;
Uint32Array.prototype[Symbol.for("wasm type")] = 16;
Float32Array.prototype[Symbol.for("wasm type")] = 17;
Float64Array.prototype[Symbol.for("wasm type")] = 18;
SharedArrayBuffer.prototype[this.wasm_type_symbol] = 6;
Int8Array.prototype[this.wasm_type_symbol] = 10;
Uint8Array.prototype[this.wasm_type_symbol] = 11;
Uint8ClampedArray.prototype[this.wasm_type_symbol] = 12;
Int16Array.prototype[this.wasm_type_symbol] = 13;
Uint16Array.prototype[this.wasm_type_symbol] = 14;
Int32Array.prototype[this.wasm_type_symbol] = 15;
Uint32Array.prototype[this.wasm_type_symbol] = 16;
Float32Array.prototype[this.wasm_type_symbol] = 17;
Float64Array.prototype[this.wasm_type_symbol] = 18;

this.assembly_load = Module.cwrap ('mono_wasm_assembly_load', 'number', ['string']);
this.find_corlib_class = Module.cwrap ('mono_wasm_find_corlib_class', 'number', ['string', 'string']);
Expand Down Expand Up @@ -125,11 +127,8 @@ var BindingSupportLib = {
this._get_cs_owned_object_by_js_handle = bind_runtime_method ("GetCSOwnedObjectByJsHandle", "ii!");
this._get_cs_owned_object_js_handle = bind_runtime_method ("GetCsOwnedObjectJsHandle", 'mi');
this._try_get_cs_owned_object_js_handle = bind_runtime_method ("TryGetCsOwnedObjectJsHandle", "m");

this._create_cs_owned_proxy = bind_runtime_method ("CreateCsOwnedProxy", "ii!");

this._is_simple_array = bind_runtime_method ("IsSimpleArray", "m");

this._get_js_owned_object_by_gc_handle = bind_runtime_method ("GetJSOwnedObjectByGcHandle", "i!");
this._get_js_owned_object_gc_handle = bind_runtime_method ("GetJSOwnedObjectGCHandle", "m");
this._release_js_owned_object_by_gc_handle = bind_runtime_method ("ReleaseJSOwnedObjectByGcHandle", "i");
Expand All @@ -144,6 +143,7 @@ var BindingSupportLib = {
this._get_date_value = bind_runtime_method ("GetDateValue", "m");
this._create_date_time = bind_runtime_method ("CreateDateTime", "d!");
this._create_uri = bind_runtime_method ("CreateUri","s!");
this._is_simple_array = bind_runtime_method ("IsSimpleArray", "m");

this._are_promises_supported = ((typeof Promise === "object") || (typeof Promise === "function")) && (typeof Promise.resolve === "function");
this.isThenable = (js_obj) => {
Expand Down Expand Up @@ -726,7 +726,7 @@ var BindingSupportLib = {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
if (!!(this.has_backing_array_buffer(js_obj) && js_obj.BYTES_PER_ELEMENT))
{
var arrayType = js_obj[Symbol.for("wasm type")];
var arrayType = js_obj[this.wasm_type_symbol];
var heapBytes = this.js_typedarray_to_heap(js_obj);
var bufferArray = this.mono_typed_array_new(heapBytes.byteOffset, js_obj.length, js_obj.BYTES_PER_ELEMENT, arrayType);
Module._free(heapBytes.byteOffset);
Expand Down Expand Up @@ -929,7 +929,7 @@ var BindingSupportLib = {

if (!result) {
// Obtain the JS -> C# type mapping.
const wasm_type = js_obj[Symbol.for("wasm type")];
const wasm_type = js_obj[this.wasm_type_symbol];
const wasm_type_id = typeof wasm_type === "undefined" ? 0 : wasm_type;

var js_handle = BINDING.mono_wasm_get_js_handle(js_obj);
Expand Down