// avoid infinite recursion
this.init = true;
-
+
Array.prototype[Symbol.for("wasm type")] = 1;
ArrayBuffer.prototype[Symbol.for("wasm type")] = 2;
DataView.prototype[Symbol.for("wasm type")] = 3;
this.mono_wasm_try_unbox_primitive_and_get_type = Module.cwrap ('mono_wasm_try_unbox_primitive_and_get_type', 'number', ['number', 'number']);
this.mono_wasm_box_primitive = Module.cwrap ('mono_wasm_box_primitive', 'number', ['number', 'number', 'number']);
this.assembly_get_entry_point = Module.cwrap ('mono_wasm_assembly_get_entry_point', 'number', ['number']);
-
+
this._box_buffer = Module._malloc(16);
this._unbox_buffer = Module._malloc(16);
this._class_int32 = this.find_corlib_class ("System", "Int32");
var binding_fqn_asm = this.BINDING_ASM.substring(this.BINDING_ASM.indexOf ("[") + 1, this.BINDING_ASM.indexOf ("]")).trim();
var binding_fqn_class = this.BINDING_ASM.substring (this.BINDING_ASM.indexOf ("]") + 1).trim();
-
+
this.binding_module = this.assembly_load (binding_fqn_asm);
if (!this.binding_module)
throw "Can't find bindings module assembly: " + binding_fqn_asm;
Module._free (buffer);
return result;
},
-
+
mono_array_to_js_array: function (mono_array) {
if (mono_array === 0)
return null;
_mono_array_to_js_array_rooted: function (arrayRoot) {
if (arrayRoot.value === 0)
return null;
-
- let elemRoot = MONO.mono_wasm_new_root ();
+
+ let elemRoot = MONO.mono_wasm_new_root ();
try {
var len = this.mono_array_length (arrayRoot.value);
for (var i = 0; i < len; ++i)
{
elemRoot.value = this.mono_array_get (arrayRoot.value, i);
-
+
if (this.is_nested_array (elemRoot.value))
res[i] = this._mono_array_to_js_array_rooted (elemRoot);
else
js_array_to_mono_array: function (js_array) {
var mono_array = this.mono_obj_array_new (js_array.length);
let [arrayRoot, elemRoot] = MONO.mono_wasm_new_roots ([mono_array, 0]);
-
+
try {
for (var i = 0; i < js_array.length; ++i) {
elemRoot.value = this.js_to_mono_obj (js_array [i]);
case 7: // ref type
return this.extract_js_obj (mono_obj);
case 10: // arrays
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- case 16:
- case 17:
+ case 11:
+ case 12:
+ case 13:
+ case 14:
+ case 15:
+ case 16:
+ case 17:
case 18:
- throw new Error ("Marshalling of primitive arrays are not supported. Use the corresponding TypedArray instead.");
+ throw new Error ("Marshalling of primitive arrays are not supported. Use the corresponding TypedArray instead.");
case 20: // clr .NET DateTime
var dateValue = this.call_method(this.get_date_value, null, "md", [ mono_obj ]);
return new Date(dateValue);
var mono_obj = root.value;
if (mono_obj === 0)
return undefined;
-
+
var type = this.mono_wasm_try_unbox_primitive_and_get_type (mono_obj, this._unbox_buffer);
switch (type) {
case 1: // int
this.bindings_lazy_init ();
// determines if the javascript object is a Promise or Promise like which can happen
- // when using an external Promise library. The javascript object should be marshalled
+ // when using an external Promise library. The javascript object should be marshalled
// as managed Task objects.
- //
- // Example is when Bluebird is included in a web page using a script tag, it overwrites the
+ //
+ // Example is when Bluebird is included in a web page using a script tag, it overwrites the
// global Promise object by default with its own version of Promise.
function isThenable() {
// When using an external Promise library the Promise.resolve may not be sufficient
// to identify the object as a Promise.
- return Promise.resolve(js_obj) === js_obj ||
+ return Promise.resolve(js_obj) === js_obj ||
((typeof js_obj === "object" || typeof js_obj === "function") && typeof js_obj.then === "function")
}
result = this._box_js_uint (js_obj);
else
result = this._box_js_double (js_obj);
-
+
if (!result)
throw new Error (`Boxing failed for ${js_obj}`);
js_typed_array_to_array : function (js_obj) {
- // JavaScript typed arrays are array-like objects and provide a mechanism for accessing
- // raw binary data. (...) To achieve maximum flexibility and efficiency, JavaScript typed arrays
+ // JavaScript typed arrays are array-like objects and provide a mechanism for accessing
+ // raw binary data. (...) To achieve maximum flexibility and efficiency, JavaScript typed arrays
// split the implementation into buffers and views. A buffer (implemented by the ArrayBuffer object)
- // is an object representing a chunk of data; it has no format to speak of, and offers no
- // mechanism for accessing its contents. In order to access the memory contained in a buffer,
- // you need to use a view. A view provides a context — that is, a data type, starting offset,
+ // is an object representing a chunk of data; it has no format to speak of, and offers no
+ // mechanism for accessing its contents. In order to access the memory contained in a buffer,
+ // you need to use a view. A view provides a context — that is, a data type, starting offset,
// and number of elements — that turns the data into an actual typed array.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
if (!!(this.has_backing_array_buffer(js_obj) && js_obj.BYTES_PER_ELEMENT))
}
else {
throw new Error("Object '" + js_obj + "' is not a typed array");
- }
+ }
},
// typed array memory -> copy to heap -> address of managed pinned array
typedarray_copy_to : function (typed_array, pinned_array, begin, end, bytes_per_element) {
- // JavaScript typed arrays are array-like objects and provide a mechanism for accessing
- // raw binary data. (...) To achieve maximum flexibility and efficiency, JavaScript typed arrays
+ // JavaScript typed arrays are array-like objects and provide a mechanism for accessing
+ // raw binary data. (...) To achieve maximum flexibility and efficiency, JavaScript typed arrays
// split the implementation into buffers and views. A buffer (implemented by the ArrayBuffer object)
- // is an object representing a chunk of data; it has no format to speak of, and offers no
- // mechanism for accessing its contents. In order to access the memory contained in a buffer,
- // you need to use a view. A view provides a context — that is, a data type, starting offset,
+ // is an object representing a chunk of data; it has no format to speak of, and offers no
+ // mechanism for accessing its contents. In order to access the memory contained in a buffer,
+ // you need to use a view. A view provides a context — that is, a data type, starting offset,
// and number of elements — that turns the data into an actual typed array.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
if (!!(this.has_backing_array_buffer(typed_array) && typed_array.BYTES_PER_ELEMENT))
}
else {
throw new Error("Object '" + typed_array + "' is not a typed array");
- }
+ }
- },
+ },
// Copy the pinned array address from pinned_array allocated on the heap to the typed array.
// adress of managed pinned array -> copy from heap -> typed array memory
typedarray_copy_from : function (typed_array, pinned_array, begin, end, bytes_per_element) {
- // JavaScript typed arrays are array-like objects and provide a mechanism for accessing
- // raw binary data. (...) To achieve maximum flexibility and efficiency, JavaScript typed arrays
+ // JavaScript typed arrays are array-like objects and provide a mechanism for accessing
+ // raw binary data. (...) To achieve maximum flexibility and efficiency, JavaScript typed arrays
// split the implementation into buffers and views. A buffer (implemented by the ArrayBuffer object)
- // is an object representing a chunk of data; it has no format to speak of, and offers no
- // mechanism for accessing its contents. In order to access the memory contained in a buffer,
- // you need to use a view. A view provides a context — that is, a data type, starting offset,
+ // is an object representing a chunk of data; it has no format to speak of, and offers no
+ // mechanism for accessing its contents. In order to access the memory contained in a buffer,
+ // you need to use a view. A view provides a context — that is, a data type, starting offset,
// and number of elements — that turns the data into an actual typed array.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
if (!!(this.has_backing_array_buffer(typed_array) && typed_array.BYTES_PER_ELEMENT))
}
else {
throw new Error("Object '" + typed_array + "' is not a typed array");
- }
+ }
- },
+ },
// Creates a new typed array from pinned array address from pinned_array allocated on the heap to the typed array.
// adress of managed pinned array -> copy from heap -> typed array memory
typed_array_from : function (pinned_array, begin, end, bytes_per_element, type) {
switch (type)
{
- case 5:
+ case 5:
newTypedArray = new Int8Array(end - begin);
break;
- case 6:
+ case 6:
newTypedArray = new Uint8Array(end - begin);
break;
- case 7:
+ case 7:
newTypedArray = new Int16Array(end - begin);
break;
- case 8:
+ case 8:
newTypedArray = new Uint16Array(end - begin);
break;
- case 9:
+ case 9:
newTypedArray = new Int32Array(end - begin);
break;
- case 10:
+ case 10:
newTypedArray = new Uint32Array(end - begin);
break;
- case 13:
+ case 13:
newTypedArray = new Float32Array(end - begin);
break;
case 14:
},
js_to_mono_enum: function (js_obj, method, parmIdx) {
this.bindings_lazy_init ();
-
+
if (typeof (js_obj) !== "number")
throw new Error (`Expected numeric value for enum argument, got '${js_obj}'`);
-
+
return js_obj | 0;
},
wasm_binding_obj_new: function (js_obj_id, ownsHandle, type)
var lineBreakRE = /\r(\n?)/g;
- rawFunctionText =
- uriPrefix + strictPrefix +
- rawFunctionText.replace(lineBreakRE, "\r\n ") +
+ rawFunctionText =
+ uriPrefix + strictPrefix +
+ rawFunctionText.replace(lineBreakRE, "\r\n ") +
` return ${escapedFunctionIdentifier};\r\n`;
var result = null, keys = null;
size += conv.size;
}
- return {
- steps: steps, size: size, args_marshal: args_marshal,
+ return {
+ steps: steps, size: size, args_marshal: args_marshal,
is_result_definitely_unmarshaled: is_result_definitely_unmarshaled,
is_result_possibly_unmarshaled: is_result_possibly_unmarshaled,
result_unmarshaled_if_argc: result_unmarshaled_if_argc,
var converterName = args_marshal.replace("!", "_result_unmarshaled");
converter.name = converterName;
-
+
var body = [];
var argumentNames = ["buffer", "rootBuffer", "method"];
for (let i = 0; i < converter.steps.length; i++) {
body.push(
- " args[" + i +
+ " args[" + i +
(
- (i == converter.steps.length - 1)
- ? "]"
+ (i == converter.steps.length - 1)
+ ? "]"
: "], "
)
);
_get_buffer_for_method_call: function (converter) {
if (!converter)
return 0;
-
+
var result = converter.scratchBuffer;
converter.scratchBuffer = 0;
return result;
return true;
if (
- converter.is_result_possibly_unmarshaled &&
+ converter.is_result_possibly_unmarshaled &&
(argc === converter.result_unmarshaled_if_argc)
) {
if (argc < converter.result_unmarshaled_if_argc)
i: int32
j: int32 - Enum with underlying type of int32
- l: int64
+ l: int64
k: int64 - Enum with underlying type of int64
f: float
d: double
converter = this._compile_converter_for_marshal_string (args_marshal);
is_result_marshaled = this._decide_if_result_is_marshaled (converter, args.length);
-
+
argsRootBuffer = this._get_args_root_buffer_for_method_call (converter);
var scratchBuffer = this._get_buffer_for_method_call (converter);
body.push(
" " + argName +
(
- (i == converter.steps.length - 1)
- ? ""
+ (i == converter.steps.length - 1)
+ ? ""
: ", "
)
);
}
body.push(");");
-
+
} else {
body.push("var argsRootBuffer = null, buffer = 0;");
}
}
var displayName = "managed_" + (friendly_name || method);
-
+
if (this_arg)
displayName += "_with_this_" + this_arg;
MONO.mono_wasm_release_roots (delegateRoot, argsRoot);
}
},
-
+
resolve_method_fqn: function (fqn) {
this.bindings_lazy_init ();
-
+
var assembly = fqn.substring(fqn.indexOf ("[") + 1, fqn.indexOf ("]")).trim();
fqn = fqn.substring (fqn.indexOf ("]") + 1).trim();
return BINDING.bind_method (method, null, signature, fqn);
},
-
+
bind_assembly_entry_point: function (assembly) {
this.bindings_lazy_init ();
mono_wasm_register_obj: function(obj) {
var gc_handle = undefined;
- if (obj !== null && typeof obj !== "undefined")
+ if (obj !== null && typeof obj !== "undefined")
{
gc_handle = obj.__mono_gchandle__;
obj.__owns_handle__ = true;
gc_handle = obj.__mono_gchandle__ = this.wasm_binding_obj_new(handle + 1, obj.__owns_handle__, typeof wasm_type === "undefined" ? -1 : wasm_type);
this.mono_wasm_object_registry[handle] = obj;
-
+
}
}
return gc_handle;
var m = obj [js_name];
if (m === Object(m) && obj.__is_mono_proxied__)
m.__is_mono_proxied__ = true;
-
+
return BINDING.js_to_mono_obj (m);
} catch (e) {
var res = e.toString ();
requireObject[property] = js_value;
result = true;
}
-
+
}
BINDING.mono_wasm_unwind_LMF();
return BINDING._box_js_bool (result);
BINDING.bindings_lazy_init ();
BINDING.mono_wasm_free_handle(js_handle);
- },
+ },
mono_wasm_release_object: function(js_handle, is_exception) {
BINDING.bindings_lazy_init ();
BINDING.mono_wasm_free_raw_object(js_handle);
- },
+ },
mono_wasm_bind_core_object: function(js_handle, gc_handle, is_exception) {
BINDING.bindings_lazy_init ();
}
var js_args = BINDING.mono_wasm_parse_args(args);
-
+
try {
-
+
// This is all experimental !!!!!!
var allocator = function(constructor, js_args) {
// Not sure if we should be checking for anything here
var obj = new tempCtor ();
return obj;
};
-
+
var res = allocator(coreObj, js_args);
var gc_handle = BINDING.mono_wasm_free_list.length ? BINDING.mono_wasm_free_list.pop() : BINDING.mono_wasm_ref_counter++;
BINDING.mono_wasm_object_registry[gc_handle] = res;
if (res === null || res === undefined)
res = "Error allocating object.";
return BINDING.js_string_to_mono_string (res);
- }
+ }
},