QJS 1.1.0
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 2.0
This package targets .NET Framework 2.0. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package QJS --version 1.1.0
NuGet\Install-Package QJS -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="QJS" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="QJS" Version="1.1.0" />
<PackageReference Include="QJS" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add QJS --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: QJS, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=QJS&version=1.1.0
#tool nuget:?package=QJS&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Example
using QJSharp;
using System;
using System.IO;
namespace TestCase
{
public class TestCase1
{
string testFunctionParam = "参数";
string strVal = "字符串值";
public delegate void AddLog(string log);
public event AddLog addLog;
public void run()
{
using (QJS qjs = new QJS())
{
int extId;
extId = qjs.LoadBaseExtend();
if (extId > 0)
addLog?.Invoke("LoadBaseExtend 测试通过");
else
addLog?.Invoke("LoadBaseExtend 测试不通过");
extId = qjs.LoadDebuggerExtend();
if (extId > 0)
{
addLog?.Invoke("LoadDebuggerExtend 测试通过");
qjs.UnloadExtend(extId);
}
else
addLog?.Invoke("LoadDebuggerExtend 测试不通过");
extId = qjs.LoadFileExtend();
if (extId > 0)
addLog?.Invoke("LoadFileExtend 测试通过");
else
addLog?.Invoke("LoadFileExtend 测试不通过");
extId = qjs.LoadPathExtend();
if (extId > 0)
addLog?.Invoke("LoadPathExtend 测试通过");
else
addLog?.Invoke("LoadPathExtend 测试不通过");
extId = qjs.LoadRegExtend();
if (extId > 0)
addLog?.Invoke("LoadRegExtend 测试通过");
else
addLog?.Invoke("LoadRegExtend 测试不通过");
extId = qjs.LoadHttpExtend();
if (extId > 0)
addLog?.Invoke("LoadHttpExtend 测试通过");
else
addLog?.Invoke("LoadHttpExtend 测试不通过");
{
qjs.SetFreeingContextCallback(OnFreeingContext);
}
{
qjs.SetRuntimeUserData(1, strVal);
string userData2 = (string)qjs.GetRuntimeUserData(1);
if (strVal == userData2)
addLog?.Invoke("SetRuntimeUserData/GetRuntimeUserData 测试通过");
else
addLog?.Invoke("SetRuntimeUserData/GetRuntimeUserData 测试不通过");
}
{
qjs.SetContextUserData(1, strVal);
string userData2 = (string)qjs.GetContextUserData(1);
if (strVal == userData2)
addLog?.Invoke("SetContextUserData/GetContextUserData 测试通过");
else
addLog?.Invoke("SetContextUserData/GetContextUserData 测试不通过");
}
{
byte[] loadedData = qjs.LoadFile("QJSharp.dll");
if (loadedData != null)
addLog?.Invoke("LoadFile 测试通过");
else
addLog?.Invoke("LoadFile 测试不通过");
}
{
ValueHandle res = qjs.RunScript("'" + strVal + "'", QJS.TheJsUndefined(), "");
string script2 = qjs.JsValueToString(res);
if (strVal == script2)
addLog?.Invoke("RunScript 测试通过");
else
addLog?.Invoke("RunScript 测试不通过");
}
{
using (StreamWriter textWriter = new StreamWriter("1.js"))
{
textWriter.Write("'" + strVal + "'");
textWriter.Close();
}
ValueHandle res = qjs.RunScriptFile("1.js", QJS.TheJsUndefined());
string script3 = qjs.JsValueToString(res);
if (strVal == script3)
addLog?.Invoke("RunScriptFile 测试通过");
else
addLog?.Invoke("RunScriptFile 测试不通过");
}
{
ValueHandle jFunc = qjs.NewFunction(JsFunction, 1, "123");
ValueHandle[] args = new ValueHandle[1];
args[0] = qjs.NewStringJsValue(testFunctionParam);
qjs.CallJsFunction(jFunc, args, qjs.GetGlobalObject());
qjs.SetNamedJsValue("testFoo1", jFunc, qjs.JsUndefined);
qjs.RunScript("testFoo1('" + testFunctionParam + "')");
}
{
ValueHandle jarr = qjs.NewArrayJsValue();
qjs.SetIndexedJsValue(0, qjs.NewStringJsValue("1"), jarr);
qjs.SetIndexedJsValue(1, qjs.NewStringJsValue("2"), jarr);
qjs.SetIndexedJsValue(2, qjs.NewStringJsValue("3"), jarr);
long size = qjs.GetLength(jarr);
bool bSuccess = true;
for (int i = 0; i < size; i++)
{
ValueHandle jstr = qjs.GetIndexedJsValue((uint)i, jarr);
string s = qjs.JsValueToString(jstr);
if ((i + 1).ToString() != s)
{
bSuccess = false;
break;
}
}
if (bSuccess)
addLog?.Invoke("NewArrayJsValue/SetIndexedJsValue/GetIndexedJsValue 测试通过");
else
addLog?.Invoke("NewArrayJsValue/SetIndexedJsValue/GetIndexedJsValue 测试不通过");
}
{
byte[] bytes = { 0, 1, 2, 3 };
ValueHandle jBuff = qjs.NewArrayBufferJsValueCopy(bytes);
byte[] bytes1 = qjs.GetArrayBuffer(jBuff);
if (bytes.Length == bytes1.Length)
{
bool bSuccess = true;
for (int i = 0; i < bytes.Length; i++)
{
if (bytes[i] != bytes1[i])
{
bSuccess = false;
break;
}
}
if (bSuccess)
addLog?.Invoke("NewArrayBufferJsValueCopy/GetArrayBuffer 测试通过");
else
addLog?.Invoke("NewArrayBufferJsValueCopy/GetArrayBuffer 测试不通过");
}
else
addLog?.Invoke("NewArrayBufferJsValueCopy/GetArrayBuffer 测试不通过");
}
{
string sJson = "{\"a\":123}";
ValueHandle jObj = qjs.JsonParse(sJson);
ValueHandle jstr = qjs.JsonStringify(jObj);
string sJson2 = qjs.JsValueToString(jstr);
if (sJson == sJson2)
addLog?.Invoke("JsonParse/JsonStringify 测试通过");
else
addLog?.Invoke("JsonParse/JsonStringify 测试不通过");
}
{
ValueHandle jobj = qjs.NewObjectJsValue();
if (qjs.SetNamedJsValue("变量名", qjs.NewStringJsValue(strVal), jobj))
{
ValueHandle jv = qjs.GetNamedJsValue("变量名", jobj);
string s = qjs.JsValueToString(jv);
if (s == strVal)
addLog?.Invoke("SetNamedJsValue/GetNamedJsValue 测试通过");
else
addLog?.Invoke("SetNamedJsValue/GetNamedJsValue 测试不通过");
}
else
addLog?.Invoke("SetNamedJsValue 测试不通过");
}
{
qjs.LoadExtend("JsExtendBase.dll", qjs.GetGlobalObject(), IntPtr.Zero);
ValueHandle jAlert = qjs.GetNamedJsValue("alert", qjs.GetGlobalObject());
if (QJS.JsValueIsFunction(jAlert))
addLog?.Invoke("LoadExtend 测试通过");
else
addLog?.Invoke("LoadExtend 测试不通过");
}
{
ValueHandle jobj = qjs.NewObjectJsValue();
ValueHandle jfuncGetter = qjs.NewFunction(JGetter, 0, null);
ValueHandle jfuncSetter = qjs.NewFunction(JSetter, 1, null);
bool b = qjs.DefineGetterSetter(jobj, "gs", jfuncGetter, jfuncSetter);
qjs.SetNamedJsValue("obj", jobj, qjs.GetGlobalObject());
ValueHandle jres = qjs.RunScript("obj.gs='mensong';var a = obj.gs;a", qjs.GetGlobalObject(), "");
string s = qjs.JsValueToString(jres);
if (s == "mensong")
addLog?.Invoke("DefineGetterSetter 测试通过");
else
addLog?.Invoke("DefineGetterSetter 测试不通过");
}
{
bool runed = false;
qjs.SetDebuggerMode(true);
qjs.SetDebuggerLineCallback((UIntPtr ctx, uint line_no, UIntPtr pc, IntPtr user_data) => {
runed = true;
}, IntPtr.Zero);
qjs.RunScript("1");
qjs.SetDebuggerMode(false);
if (runed)
addLog?.Invoke("SetDebuggerMode/SetDebuggerLineCallback 测试通过");
else
addLog?.Invoke("SetDebuggerMode/SetDebuggerLineCallback 测试不通过");
}
{
ValueHandle cs = qjs.CompileScript("function add(a, b){ return a + b; }");
byte[] byteCodes = qjs.JsValueToByteCode(cs);
cs = qjs.ByteCodeToJsValue(byteCodes);
byteCodes = qjs.JsValueToByteCode(cs);
qjs.RunByteCode(byteCodes);
ValueHandle jret = qjs.RunScript("add(1,2)");
int ret = qjs.JsValueToInt(jret);
if (ret == 3)
addLog?.Invoke("CompileScript/JsValueToByteCode/RunByteCode 测试通过");
else
addLog?.Invoke("CompileScript/JsValueToByteCode/RunByteCode 测试不通过");
}
}
}
string gsval = "getter setter value";
ValueHandle JGetter(QJS qjs, ValueHandle this_val, ValueHandle[] args, Object user_data)
{
return qjs.NewStringJsValue(gsval);
}
ValueHandle JSetter(QJS qjs, ValueHandle this_val, ValueHandle[] args, Object user_data)
{
if (args.Length > 0)
{
gsval = qjs.JsValueToString(args[0]);
}
return QJS.TheJsUndefined();
}
void OnFreeingContext(UIntPtr ctx)
{
addLog?.Invoke("SetFreeingContextCallback 测试通过");
}
ValueHandle JsFunction(QJS qjs, ValueHandle this_val, ValueHandle[] args, Object user_data)
{
if (args.Length == 1)
{
string argStr = qjs.JsValueToString(args[0]);
if (argStr == testFunctionParam)
addLog?.Invoke("NewFunction/CallJsFunction 测试通过");
else
addLog?.Invoke("NewFunction/CallJsFunction 测试不通过");
}
else
{
addLog?.Invoke("NewFunction/CallJsFunction 测试不通过");
}
return QJS.TheJsUndefined();
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net20 is compatible. net30 is compatible. net35 is compatible. net40 is compatible. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 2.0
- No dependencies.
-
.NETFramework 3.0
- No dependencies.
-
.NETFramework 3.5
- No dependencies.
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.