Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
beyaz committed Nov 17, 2024
1 parent e2b1a35 commit b9e9150
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 14 deletions.
28 changes: 14 additions & 14 deletions ReactWithDotNet.WebSite/Deneme45.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,20 +489,20 @@ static void StructCreationGenericTest()

public static string Abc5()
{
StructCreationTest();
StructCreationGenericTest();

BoxTest1();
ExternalCallTest.Static_Void_Call();
ExternalCallTest.Static_NonVoid_Call();
LdInd();
NullableIntTest();
TryCatch_0();
TryCatch_1();
TryCatch_HandlerType();
TryCatchFinaly_0();
TryCatchFinaly_1();
//AutomaticallyLoadType();
//StructCreationTest();
//StructCreationGenericTest();

//BoxTest1();
//ExternalCallTest.Static_Void_Call();
//ExternalCallTest.Static_NonVoid_Call();
//LdInd();
//NullableIntTest();
//TryCatch_0();
//TryCatch_1();
//TryCatch_HandlerType();
//TryCatchFinaly_0();
//TryCatchFinaly_1();
AutomaticallyLoadType();

return "E N D";
}
Expand Down
134 changes: 134 additions & 0 deletions ReactWithDotNet/JsClientEngine/clr.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ GlobalMetadata.Methods.pop();

function ImportMetadata(metadata)
{
const globalTypes = GlobalMetadata.Types;
const globalMethods = GlobalMetadata.Methods;

if(GlobalMetadata.Types.length === 0)
{
GlobalMetadata.MetadataScopes = metadata.MetadataScopes;
Expand All @@ -53,8 +56,139 @@ function ImportMetadata(metadata)
GlobalMetadata.Methods = metadata.Methods;
GlobalMetadata.Properties = metadata.Properties;
GlobalMetadata.Events = metadata.Events;

return;
}

const typeIndexMap = { };
const methodIndexMap = {};


const methods = metadata.Methods;

// arrange operands of opcode
{
const OpCode_Call = 39;

const methodsLength = methods.length;

for( let i = 0; i < methodsLength; i++ )
{
let method = methods[i];

if(!method.Body)
{
continue;
}

const operands = method.Body.Operands;

const instructions = method.Body.Instructions;

const instructionsLength = instructions.length;

for( let j = 0; j < instructionsLength; j++ )
{
const instruction = instructions[j];

if (instruction === OpCode_Call)
{
operands[j] = getOrCalculateNewMethodIndex(operands[j]);
}
}
}
}


function getOrCalculateNewMethodIndex(methodIndex)
{
let newIndex = methodIndexMap[methodIndex];
if ( newIndex >= 0)
{
return newIndex;
}

newIndex = null;

let targetMethod = metadata.Methods[methodIndex];

let length = globalMethods.length;

for (let i = 0; i < length; i++)
{
const methodItem = globalMethods[i];

if (methodItem.Name !== targetMethod.Name)
{
continue;
}

if (methodItem.DeclaringType !== getOrCalculateNewTypeIndex(targetMethod.DeclaringType))
{
continue;
}

// found
newIndex = i;
break;
}

if (newIndex === null)
{
newIndex = globalMethods.length;

globalMethods.push(targetMethod);
}

methodIndexMap[methodIndex] = newIndex;

return newIndex;
}


function getOrCalculateNewTypeIndex(typeIndex)
{
let newIndex = typeIndexMap[typeIndex];
if ( newIndex >= 0)
{
return newIndex;
}

newIndex = null;

let targetType = metadata.Types[typeIndex];

let length = globalTypes.length;

for (let i = 0; i < length; i++)
{
const typeItem = globalTypes[i];
if (typeItem.Name !== targetType.Name)
{
continue;
}

if (typeItem.Namespace !== targetType.Namespace)
{
continue;
}

// found
newIndex = i;
break;
}

if (newIndex === null)
{
newIndex = globalTypes.length;

globalTypes.push(targetType);
}

typeIndexMap[typeIndex] = newIndex;

return newIndex;
}
}

const InterpreterBridge_NewArr = 0;
Expand Down

0 comments on commit b9e9150

Please sign in to comment.