Skip to content

Commit

Permalink
[unity]GetArgumentValue新增v8::Isolate参数,便于后续运行时指定backend特性的开发
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Mar 22, 2024
1 parent a8e5094 commit e5adf81
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ArgumentCodeGenerator {
}

declareAndGetV8Value() {
return `IntPtr v8Value${this.index} = PuertsDLL.GetArgumentValue(info, ${this.index})`
return `IntPtr v8Value${this.index} = PuertsDLL.GetArgumentValue(isolate, info, ${this.index})`
}

v8Value() {
Expand Down
12 changes: 6 additions & 6 deletions unity/Assets/core/upm/Runtime/Src/Default/JsEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ void RegisterTickHandler(IntPtr isolate, IntPtr info, IntPtr self, int paramLen)
}

IntPtr fn = IntPtr.Zero;
var value1 = PuertsDLL.GetArgumentValue(info, 0);
var value1 = PuertsDLL.GetArgumentValue(isolate, info, 0);
if (PuertsDLL.GetJsValueType(isolate, value1, false) == JsValueType.Function)
{
fn = PuertsDLL.GetFunctionFromValue(isolate, value1, false);
Expand All @@ -503,7 +503,7 @@ void RegisterTickHandler(IntPtr isolate, IntPtr info, IntPtr self, int paramLen)
Type GetTypeFromJs(IntPtr isolate, IntPtr info, IntPtr self, int paramLen)
{
Type type = null;
var value = PuertsDLL.GetArgumentValue(info, 0);
var value = PuertsDLL.GetArgumentValue(isolate, info, 0);
if (PuertsDLL.GetJsValueType(isolate, value, false) == JsValueType.String)
{
string classFullName = PuertsDLL.GetStringFromValue(isolate, value, false);
Expand All @@ -519,7 +519,7 @@ Type GetTypeFromJs(IntPtr isolate, IntPtr info, IntPtr self, int paramLen)
var genericArguments = new Type[paramLen - 1];
for (int i = 1; i < paramLen; i++)
{
value = PuertsDLL.GetArgumentValue(info, i);
value = PuertsDLL.GetArgumentValue(isolate, info, i);
if (PuertsDLL.GetJsValueType(isolate, value, false) != JsValueType.Function) return null;
var argTypeId = PuertsDLL.GetTypeIdFromValue(isolate, value, false);
if (argTypeId == -1) return null;
Expand All @@ -543,17 +543,17 @@ void GetGenericMethod(IntPtr isolate, IntPtr info, IntPtr self, int paramLen)
if (paramLen < 3) {
throw new Exception("invalid arguments length");
}
var csTypeJSValue = PuertsDLL.GetArgumentValue(info, 0);
var csTypeJSValue = PuertsDLL.GetArgumentValue(isolate, info, 0);
if (PuertsDLL.GetJsValueType(isolate, csTypeJSValue, false) != JsValueType.NativeObject) {
throw new Exception("the class must be a constructor");
}
Type type = StaticTranslate<Type>.Get(Index, isolate, NativeValueApi.GetValueFromArgument, csTypeJSValue, false);
string methodName = PuertsDLL.GetStringFromValue(isolate, PuertsDLL.GetArgumentValue(info, 1), false);
string methodName = PuertsDLL.GetStringFromValue(isolate, PuertsDLL.GetArgumentValue(isolate, info, 1), false);

var genericArguments = new Type[paramLen - 2];
for (int i = 2; i < paramLen; i++)
{
var value = PuertsDLL.GetArgumentValue(info, i);
var value = PuertsDLL.GetArgumentValue(isolate, info, i);
if (PuertsDLL.GetJsValueType(isolate, value, false) != JsValueType.Function)
{
throw new Exception("invalid Type for generic arguments " + (i - 2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public static void ReturnCSharpFunctionCallback(IntPtr isolate, IntPtr info, V8F
public static extern void ReturnJSObject(IntPtr isolate, IntPtr info, IntPtr JSObject);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GetArgumentValue(IntPtr info, int index);
public static extern IntPtr GetArgumentValue(IntPtr isolate, IntPtr info, int index);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern JsValueType GetJsValueType(IntPtr isolate, IntPtr value, bool isByRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static T[] GetParams<T>(int jsEnvIdx, IntPtr isolate, IntPtr info, int st

for (int i = start; i < end; i++)
{
var val = i == start ? v8Value : PuertsDLL.GetArgumentValue(info, i);
var val = i == start ? v8Value : PuertsDLL.GetArgumentValue(isolate, info, i);
result[i - start] = StaticTranslate<T>.Get(jsEnvIdx, isolate, NativeValueApi.GetValueFromArgument, val, false);
}

Expand Down Expand Up @@ -47,7 +47,7 @@ ref JsValueType argValueType
}
for (int i = start + 1; i < end; i++)
{
IntPtr value = PuertsDLL.GetArgumentValue(info, i);
IntPtr value = PuertsDLL.GetArgumentValue(isolate, info, i);
object argObj = null;
JsValueType valueType = JsValueType.Invalid;
if (!ArgHelper.IsMatch(jsEnvIdx, isolate, expectJsType, expectCsType, false, false, value, ref argObj, ref valueType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static JSFunctionCallback GenFieldSetter(JsEnv jsEnv, Type type, FieldInf
{
return (IntPtr isolate, IntPtr info, IntPtr self, int argumentsLen) =>
{
var valuePtr = PuertsDLL.GetArgumentValue(info, 0);
var valuePtr = PuertsDLL.GetArgumentValue(isolate, info, 0);
var valueType = PuertsDLL.GetJsValueType(isolate, valuePtr, false);
object value = null;
if (
Expand Down Expand Up @@ -179,7 +179,7 @@ public static JSFunctionCallback GenFieldSetter(JsEnv jsEnv, Type type, FieldInf
{
return (IntPtr isolate, IntPtr info, IntPtr self, int argumentsLen) =>
{
var valuePtr = PuertsDLL.GetArgumentValue(info, 0);
var valuePtr = PuertsDLL.GetArgumentValue(isolate, info, 0);
var valueType = PuertsDLL.GetJsValueType(isolate, valuePtr, false);
object value = null;
if (
Expand Down Expand Up @@ -230,7 +230,7 @@ internal int InitArrayTypeId(int csArrayTypeId)
try
{
Array array = jsEnv.GeneralGetterManager.GetSelf(jsEnv.Idx, self) as Array;
uint index = (uint)PuertsDLL.GetNumberFromValue(isolate1, PuertsDLL.GetArgumentValue(info, 0), false);
uint index = (uint)PuertsDLL.GetNumberFromValue(isolate1, PuertsDLL.GetArgumentValue(isolate, info, 0), false);
if (FastArrayGet(isolate1, info, self, array, index)) return;
var transalteFunc = jsEnv.GeneralSetterManager.GetTranslateFunc(array.GetType().GetElementType());
transalteFunc(jsEnv.Idx, isolate1, NativeValueApi.SetValueToResult, info, array.GetValue((int)index));
Expand All @@ -246,8 +246,8 @@ internal int InitArrayTypeId(int csArrayTypeId)
try
{
Array array = jsEnv.GeneralGetterManager.GetSelf(jsEnv.Idx, self) as Array;
uint index = (uint)PuertsDLL.GetNumberFromValue(isolate1, PuertsDLL.GetArgumentValue(info, 0), false);
var val = PuertsDLL.GetArgumentValue(info, 1);
uint index = (uint)PuertsDLL.GetNumberFromValue(isolate1, PuertsDLL.GetArgumentValue(isolate, info, 0), false);
var val = PuertsDLL.GetArgumentValue(isolate, info, 1);
if (FastArraySet(isolate1, info, self, array, index, val)) return;
var transalteFunc = jsEnv.GeneralGetterManager.GetTranslateFunc(array.GetType().GetElementType());
array.SetValue(transalteFunc(jsEnv.Idx, isolate1, NativeValueApi.GetValueFromArgument, val, false), index);
Expand Down
4 changes: 2 additions & 2 deletions unity/Assets/core/upm/Runtime/Src/Default/Wrapper/LazyWrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private JSFunctionCallback GenFieldSetter(Type type, FieldInfo field)
{
return (IntPtr isolate, IntPtr info, IntPtr self, int argumentsLen) =>
{
var valuePtr = PuertsDLL.GetArgumentValue(info, 0);
var valuePtr = PuertsDLL.GetArgumentValue(isolate, info, 0);
var valueType = PuertsDLL.GetJsValueType(isolate, valuePtr, false);
object value = null;
if (
Expand Down Expand Up @@ -125,7 +125,7 @@ private JSFunctionCallback GenFieldSetter(Type type, FieldInfo field)
{
return (IntPtr isolate, IntPtr info, IntPtr self, int argumentsLen) =>
{
var valuePtr = PuertsDLL.GetArgumentValue(info, 0);
var valuePtr = PuertsDLL.GetArgumentValue(isolate, info, 0);
var valueType = PuertsDLL.GetJsValueType(isolate, valuePtr, false);
object value = null;
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public JSCallInfo(IntPtr isolate, IntPtr info, IntPtr self, int len)

for(int i = 0; i < Length; i++)
{
var nativeValuePtr = PuertsDLL.GetArgumentValue(info, i);
var nativeValuePtr = PuertsDLL.GetArgumentValue(isolate, info, i);
NativePtrs[i] = nativeValuePtr;
var type = PuertsDLL.GetJsValueType(isolate, nativeValuePtr, false);
JsTypes[i] = type;
Expand Down Expand Up @@ -357,7 +357,7 @@ public object Construct(IntPtr isolate, IntPtr info, int argumentsLen)
{
try
{
var arg0 = PuertsDLL.GetArgumentValue(info, 0);
var arg0 = PuertsDLL.GetArgumentValue(isolate, info, 0);
var arg0type = NativeValueApi.GetValueFromArgument.GetJsValueType(isolate, arg0, false);
if (arg0type == JsValueType.Function || arg0type == JsValueType.NativeObject)
{
Expand Down

0 comments on commit e5adf81

Please sign in to comment.