Skip to content

Commit

Permalink
[wasm][debugger] Implement Runtime.callFunctionOn, and support arra…
Browse files Browse the repository at this point in the history
…y expansion (#35156)

- This was prompted by vscode/vs requiring this for array expansion.
- It runs a given js function string, on a given object id.
- We handle the case for dotnet object ids.

Implementation:

- We build a proxy object that reflects the details of the real dotnet object/array
- And run the js function on that proxy object

- Then if `returnByValue` was requested, the result is returned as-is
- Else we cache that object, with a new special object id (`dotnet:cfo_res:..`),
  and return that id in the response.

- Subsequently, we would get `Runtime.getProperties` request on this new object id
- And a `Runtime.releaseObject` request, to free that function result.

- All this is handled currently

Tests:

- A few tests were added which invoke `callFunctionOn`, on JS objects, and checks the result
  - And the same checks are performed on equivalent dotnet objects, with the same js function
  - This should help stay in sync with what we think `callFunctionOn` should work as

  - These tests have an additional parameter - `roundtrip`, which calls a simple function
	`function () { return this; }`
    .. on a dotnet object, and gets the result object id. If `roundtrip == true`, then it
    runs that same function on the result object, and gets a new result object id. And the
    tests run their checks on that.

    - this helps to check that outside of the proxy, the result object behaves same as any
      other dotnet object.

- Also, most of the tests were modified to support an additional mode (`use_cfo`).
  - With this, whenever a test wants to run `Runtime.getProperties on an object, we pass that
    object through the earlier "identity" function, and then run `getProperties` on that
    resultant object.

  - This helps to take advantage most of the existing tests, and use them for `callFunctionOn`
    testing too, by ensuring that the results of CFO returns results same as any other object.

Fixes mono/mono#19229, mono/mono#19531

Co-authored-by: radical <radical@users.noreply.github.com>
  • Loading branch information
monojenkins and radical authored Apr 20, 2020
1 parent 629dba5 commit a637d3e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/mono/mono/mini/mini-wasm-debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,10 @@ static gboolean describe_value(MonoType * type, gpointer addr, gboolean expandVa
int obj_id = get_object_id (obj);

if (type-> type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY) {
mono_wasm_add_typed_value ("array", class_name, obj_id);
MonoArray *array = (MonoArray *)obj;
EM_ASM ({
MONO.mono_wasm_add_typed_value ('array', $0, { objectId: $1, length: $2 });
}, class_name, obj_id, mono_array_length_internal (array));
} else if (m_class_is_delegate (klass) || (type->type == MONO_TYPE_GENERICINST && m_class_is_delegate (type->data.generic_class->container_class))) {
MonoMethod *method;

Expand Down

0 comments on commit a637d3e

Please sign in to comment.