本文整理汇总了C#中ChakraHost.Hosting.JavaScriptValue类的典型用法代码示例。如果您正苦于以下问题:C# JavaScriptValue类的具体用法?C# JavaScriptValue怎么用?C# JavaScriptValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JavaScriptValue类属于ChakraHost.Hosting命名空间,在下文中一共展示了JavaScriptValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunScript
private static JavaScriptValue RunScript(JavaScriptValue callee, bool isConstructCall, JavaScriptValue[] arguments, ushort argumentCount, IntPtr callbackData)
{
if (argumentCount < 2)
{
ThrowException("not enough arguments");
return JavaScriptValue.Invalid;
}
//
// Convert filename.
//
string filename = arguments[1].ToString();
//
// Load the script from the disk.
//
string script = File.ReadAllText(filename);
if (string.IsNullOrEmpty(script))
{
ThrowException("invalid script");
return JavaScriptValue.Invalid;
}
//
// Run the script.
//
return JavaScriptContext.RunScript(script, currentSourceContext++, filename);
}
示例2: init
public string init()
{
JavaScriptContext context;
if (Native.JsCreateRuntime(JavaScriptRuntimeAttributes.None, null, out runtime) != JavaScriptErrorCode.NoError)
return "failed to create runtime.";
if (Native.JsCreateContext(runtime, out context) != JavaScriptErrorCode.NoError)
return "failed to create execution context.";
if (Native.JsSetCurrentContext(context) != JavaScriptErrorCode.NoError)
return "failed to set current context.";
// ES6 Promise callback
JavaScriptPromiseContinuationCallback promiseContinuationCallback = delegate (JavaScriptValue task, IntPtr callbackState)
{
promiseCallback = task;
};
if (Native.JsSetPromiseContinuationCallback(promiseContinuationCallback, IntPtr.Zero) != JavaScriptErrorCode.NoError)
return "failed to setup callback for ES6 Promise";
if (Native.JsProjectWinRTNamespace("Windows") != JavaScriptErrorCode.NoError)
return "failed to project windows namespace.";
if (Native.JsStartDebugging() != JavaScriptErrorCode.NoError)
return "failed to start debugging.";
return "NoError";
}
示例3: Echo
private static JavaScriptValue Echo(JavaScriptValue callee, bool isConstructCall, JavaScriptValue[] arguments, ushort argumentCount, IntPtr callbackData)
{
for (uint index = 1; index < argumentCount; index++)
{
if (index > 1)
{
Console.Write(" ");
}
Console.Write(arguments[index].ConvertToString().ToString());
}
Console.WriteLine();
return JavaScriptValue.Invalid;
}
示例4: DefineHostCallback
private static void DefineHostCallback(JavaScriptValue globalObject, string callbackName, JavaScriptNativeFunction callback, IntPtr callbackData)
{
//
// Get property ID.
//
JavaScriptPropertyId propertyId = JavaScriptPropertyId.FromString(callbackName);
//
// Create a function
//
JavaScriptValue function = JavaScriptValue.CreateFunction(callback, callbackData);
//
// Set the property
//
globalObject.SetProperty(propertyId, function, true);
}
示例5: JsGetContextOfObject
internal static extern JavaScriptErrorCode JsGetContextOfObject(JavaScriptValue obj, out JavaScriptContext context);
示例6: JsInstanceOf
internal static extern JavaScriptErrorCode JsInstanceOf(JavaScriptValue obj, JavaScriptValue constructor, out bool result);
示例7: JsGetIndexedPropertiesExternalData
internal static extern JavaScriptErrorCode JsGetIndexedPropertiesExternalData(JavaScriptValue obj, IntPtr data, out JavaScriptTypedArrayType arrayType, out uint elementLength);
示例8: JsGetOwnPropertySymbols
internal static extern JavaScriptErrorCode JsGetOwnPropertySymbols(JavaScriptValue obj, out JavaScriptValue propertySymbols);
示例9: JsGetSymbolFromPropertyId
internal static extern JavaScriptErrorCode JsGetSymbolFromPropertyId(JavaScriptPropertyId propertyId, out JavaScriptValue symbol);
示例10: JsGetDataViewStorage
internal static extern JavaScriptErrorCode JsGetDataViewStorage(JavaScriptValue dataView, out byte[] buffer, out uint bufferLength);
示例11: JsGetAndClearException
internal static extern JavaScriptErrorCode JsGetAndClearException(out JavaScriptValue exception);
示例12: JsCreateURIError
internal static extern JavaScriptErrorCode JsCreateURIError(JavaScriptValue message, out JavaScriptValue error);
示例13: JsCreateFunction
internal static extern JavaScriptErrorCode JsCreateFunction(JavaScriptNativeFunction nativeFunction, IntPtr externalData, out JavaScriptValue function);
示例14: JsConstructObject
internal static extern JavaScriptErrorCode JsConstructObject(JavaScriptValue function, JavaScriptValue[] arguments, ushort argumentCount, out JavaScriptValue result);
示例15: JsCallFunction
internal static extern JavaScriptErrorCode JsCallFunction(JavaScriptValue function, JavaScriptValue[] arguments, ushort argumentCount, out JavaScriptValue result);