Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
beyaz committed Dec 5, 2024
1 parent a5633a4 commit e80e1e0
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 19 deletions.
4 changes: 2 additions & 2 deletions ReactWithDotNet/ILCodeGeneration/MetadataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sealed record MetadataResponse
{
public string ErrorMessage { get; init; }
public MetadataTable Metadata { get; init; }
public bool Success { get; init; }
public int Success { get; init; }
}

static partial class Mixin
Expand Down Expand Up @@ -219,7 +219,7 @@ static MetadataResponse GetMetadata(IEnumerable<MetadataRequest.Item> requests,

return new()
{
Success = true,
Success = 1,
Metadata = metadataTable
};
}
Expand Down
2 changes: 1 addition & 1 deletion ReactWithDotNet/ILCodeGeneration/Models.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,5 @@ sealed record GenericInstanceMethodModel : MethodReferenceModel

public required IReadOnlyList<int> GenericArguments { get; init; }

public required bool IsGenericInstance;
public required int IsGenericInstance;
}
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ static MethodReferenceModel AsModel(this MethodReference methodReference, Metada
{
return new GenericInstanceMethodModel
{
IsGenericInstance = genericInstanceMethod.IsGenericInstance,
IsGenericInstance = 1,

ElementMethod = genericInstanceMethod.ElementMethod.IndexAt(metadataTable),
GenericArguments = genericInstanceMethod.GenericArguments.ToListOf(x => x.IndexAt(metadataTable)),
Expand Down
102 changes: 87 additions & 15 deletions ReactWithDotNet/JsClientEngine/clr.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
*/

/**
* @typedef {Object} TypeReferenceModel
* @property {string} Name
* @property {number | null} DeclaringType
* @property {number} IsDefinition
*
* @typedef {MemberReference} TypeReferenceModel
* @property {string} Namespace
* @property {number} Scope
* @property {number} IsValueType
Expand All @@ -30,6 +26,16 @@
*
*/

/**
* @typedef {TypeReferenceModel} TypeDefinitionModel
* @property {number} BaseType
* @property {number} Methods
* @property {number} Fields
* @property {number} Properties
* @property {number} NestedTypes
* @property {number} Events
*/


/**
* @enum {number}
Expand All @@ -52,12 +58,57 @@ const ExceptionHandlerType =
* @property {ExceptionHandlerType} HandlerType
*/


/**
* @typedef {Object} MethodBodyModel
* @property {number[]} Instructions
* @property {Object[]} Operands
* @property {ExceptionHandler[]} ExceptionHandlers
*/


/**
* @typedef {Object} ParameterDefinitionModel
* @property {number} Index
* @property {string} Name
* @property {number} ParameterType
*/


/**
* @typedef {Object} MethodReferenceModel
* @property {number} ReturnType
* @property {ParameterDefinitionModel[]} Parameters
*/

/**
* @typedef {Object} CustomAttributeModel
* @property {number} ReturnType
* @property {Object[]} Parameters
*/

/**
* @typedef {Object} MethodDefinitionModel
* @property {MethodBodyModel} Body
* @property {CustomAttributeModel[]} CustomAttributes
* @property {number} IsStatic
* @property {number} IsConstructor
*/


/**
* @typedef {Object} GenericInstanceMethodModel
* @property {number} ElementMethod
* @property {number[]} GenericArguments
* @property {number} IsGenericInstance
*/

/**
* @typedef {Object} Metadata
* @property {MetadataScopeModel[]} MetadataScopes
* @property {MemberReference[]} Types
* @property {Array<TypeReferenceModel>} Types
* @property {MemberReference[]} Fields
* @property {MemberReference[]} Methods
* @property {Array<MethodDefinitionModel | MethodReferenceModel | GenericInstanceMethodModel>} Methods
* @property {MemberReference[]} Properties
* @property {MemberReference[]} Events
*/
Expand Down Expand Up @@ -3085,7 +3136,7 @@ function Interpret(thread)
query.MethodName = methodReference.Name;
function onSuccess(response)
{
if (response.Success === false)
if (response.Success === 0)
{
throw response.ErrorMessage;
}
Expand All @@ -3096,6 +3147,10 @@ function Interpret(thread)

Interpret(thread);
}
function onFail(exception)
{
throw exception;
}

let request =
{
Expand All @@ -3106,7 +3161,7 @@ function Interpret(thread)
]
};

GetMetadata(request, onSuccess);
GetMetadata(request, onSuccess, onFail);

thread.IsSuspended = 1;

Expand All @@ -3128,7 +3183,7 @@ function Interpret(thread)

GetMetadata(request, response =>
{
if (response.Success === false)
if (response.Success === 0)
{
throw response.ErrorMessage;
}
Expand All @@ -3138,7 +3193,7 @@ function Interpret(thread)
thread.IsSuspended = 0;

Interpret(thread);
});
}, e=>throw e);

thread.IsSuspended = 1;

Expand Down Expand Up @@ -3222,6 +3277,11 @@ function SerializeTypeReference(typeReference)
}
}

/**
* @param request
* @param {(response: MetadataResponse) => void} onSuccess
* @param {(e: Error) => void} onFail
*/
function GetMetadata(request, onSuccess, onFail)
{
const url = "/GetMetadata";
Expand Down Expand Up @@ -3279,16 +3339,28 @@ function CallManagedStaticMethod(methodDefinition, args, success, fail)
}
}

/**
* @typedef {Object} MetadataResponse
* @property {string | null} ErrorMessage
* @property {Metadata | null} Metadata
* @property {number} Success
*/

setTimeout(function ()
{
/**
* @param {MetadataResponse} response
*/
function onSuccess(response)
{

if (response.Success === false)
{
if (response.Success === 0)
{
throw response.ErrorMessage;
}


/**
* @type {Metadata}
*/
let metadataTable = response.Metadata;

TryInitialize_InterpreterBridge(metadataTable);
Expand Down

0 comments on commit e80e1e0

Please sign in to comment.