Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

JsObject API #532

@iskiselev

Description

@iskiselev

I suggest to introduce JsObject API, that will allow easier interop with JS, then using Verbutium without usage of dynamic. Suggested API:

public abstract class JsObject
{
    public abstract JsObject this[string name] { get; set; }

    public abstract JsObject Get(string name);
    public abstract T Get<T>(string name);
    public abstract void Set(string name, object value);

    public abstract JsObject Call(string name, params object[] args);
    public abstract T Call<T>(string name, params object[] args);
    public abstract JsObject Create(string name, params object[] args);

    public abstract T Cast<T>();
}

public abstract class JsFunction : JsObject
{
    public abstract JsObject Invoke(params object[] args);
    public abstract T Invoke<T>(params object[] args);
    public abstract JsObject InvokeCreate(params object[] args);
}

Additionally we can overload some operators in JsObject. Initial implementation could be done with JsReplace attribute, but for proper implementation we should implement it inside JSIL transfromations logic - as we should detect creating new array in params calls and replace it with simple method call. Also we may discuss, if JsFunction should catch original this context or not.

EDITED: Suggested API changed based on @kg feedback

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions