예제 #1
0
        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
0
        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
0
        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
0
        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
0
 internal static extern JavaScriptErrorCode JsGetIndexedPropertiesExternalData(JavaScriptValue obj, IntPtr data, out JavaScriptTypedArrayType arrayType, out uint elementLength);
예제 #6
0
        /// <summary>
        ///     Executes a script.
        /// </summary>
        /// <remarks>
        ///     Requires an active script context.
        /// </remarks>
        /// <param name="script">The script to run.</param>
        /// <param name="sourceContext">
        ///     A cookie identifying the script that can be used by script contexts that have debugging enabled.
        /// </param>
        /// <param name="sourceName">The location the script came from.</param>
        /// <returns>The result of the script, if any.</returns>
        public static JavaScriptValue RunScript(string script, JavaScriptSourceContext sourceContext, string sourceName)
        {
            JavaScriptValue result;

            Native.ThrowIfError(Native.JsRun(JavaScriptValue.FromString(script), sourceContext, JavaScriptValue.FromString(sourceName), JavaScriptParseScriptAttributes.JsParseScriptAttributeNone, out result));
            return(result);
        }
예제 #7
0
 internal static extern JavaScriptErrorCode JsGetArrayBufferStorage(JavaScriptValue arrayBuffer, out byte[] buffer, out uint bufferLength);
예제 #8
0
 internal static extern JavaScriptErrorCode JsCreateTypedArray(JavaScriptTypedArrayType arrayType, JavaScriptValue arrayBuffer, uint byteOffset,
     uint elementLength, out JavaScriptValue result);
예제 #9
0
 internal static extern JavaScriptErrorCode JsInspectableToObject([MarshalAs(UnmanagedType.IInspectable)] System.Object inspectable, out JavaScriptValue value);
예제 #10
0
 internal static extern JavaScriptErrorCode JsSetObjectBeforeCollectCallback(JavaScriptValue reference, IntPtr callbackState, JavaScriptObjectBeforeCollectCallback beforeCollectCallback);
예제 #11
0
 /// <summary>
 ///     Set the value at the specified index of an object.
 /// </summary>
 /// <remarks>
 ///     Requires an active script context.
 /// </remarks>
 /// <param name="index">The index to set.</param>
 /// <param name="value">The value to set.</param>
 public void SetIndexedProperty(JavaScriptValue index, JavaScriptValue value)
 {
     Native.ThrowIfError(Native.JsSetIndexedProperty(this, index, value));
 }
예제 #12
0
 internal static extern JavaScriptErrorCode JsGetUndefinedValue(out JavaScriptValue undefinedValue);
예제 #13
0
 internal static extern JavaScriptErrorCode JsRunSerializedScript(string script, byte[] buffer, JavaScriptSourceContext sourceContext, string sourceUrl, out JavaScriptValue result);
예제 #14
0
 internal static extern JavaScriptErrorCode JsRunScript(string script, JavaScriptSourceContext sourceContext, string sourceUrl, out JavaScriptValue result);
예제 #15
0
 internal static extern JavaScriptErrorCode JsRelease(JavaScriptValue reference, out uint count);
예제 #16
0
 internal static extern JavaScriptErrorCode JsAddRef(JavaScriptValue reference, out uint count);
예제 #17
0
 /// <summary>
 ///     Sets the runtime of the current context to an exception state.
 /// </summary>
 /// <remarks>
 ///     <para>
 ///     If the runtime of the current context is already in an exception state, this API will
 ///     throw <c>JsErrorInExceptionState</c>.
 ///     </para>
 ///     <para>
 ///     Requires an active script context.
 ///     </para>
 /// </remarks>
 /// <param name="exception">
 ///     The JavaScript exception to set for the runtime of the current context.
 /// </param>
 public static void SetException(JavaScriptValue exception)
 {
     Native.ThrowIfError(Native.JsSetException(exception));
 }
예제 #18
0
 internal static extern JavaScriptErrorCode JsInstanceOf(JavaScriptValue obj, JavaScriptValue constructor, out bool result);
예제 #19
0
 internal static extern JavaScriptErrorCode JsGetNullValue(out JavaScriptValue nullValue);
예제 #20
0
 internal static extern JavaScriptErrorCode JsGetContextOfObject(JavaScriptValue obj, out JavaScriptContext context);
예제 #21
0
 internal static extern JavaScriptErrorCode JsGetTrueValue(out JavaScriptValue trueValue);
예제 #22
0
 internal static extern JavaScriptErrorCode JsSetException(JavaScriptValue exception);
예제 #23
0
 /// <summary>
 ///     Delete the value at the specified index of an object.
 /// </summary>
 /// <remarks>
 ///     Requires an active script context.
 /// </remarks>
 /// <param name="index">The index to delete.</param>
 public void DeleteIndexedProperty(JavaScriptValue index)
 {
     Native.ThrowIfError(Native.JsDeleteIndexedProperty(this, index));
 }
예제 #24
0
 internal static extern JavaScriptErrorCode JsCreateNamedFunction(JavaScriptValue name, JavaScriptNativeFunction nativeFunction, IntPtr callbackState, out JavaScriptValue function);
예제 #25
0
 internal static extern JavaScriptErrorCode JsGetDataViewStorage(JavaScriptValue dataView, out byte[] buffer, out uint bufferLength);
예제 #26
0
 internal static extern JavaScriptErrorCode JsCreateArrayBuffer(uint byteLength, out JavaScriptValue result);
예제 #27
0
 internal static extern JavaScriptErrorCode JsGetSymbolFromPropertyId(JavaScriptPropertyId propertyId, out JavaScriptValue symbol);
예제 #28
0
 internal static extern JavaScriptErrorCode JsCreateDataView(JavaScriptValue arrayBuffer, uint byteOffset, uint byteOffsetLength, out JavaScriptValue result);
예제 #29
0
 internal static extern JavaScriptErrorCode JsGetOwnPropertySymbols(JavaScriptValue obj, out JavaScriptValue propertySymbols);
예제 #30
0
 internal static extern JavaScriptErrorCode JsGetTypedArrayStorage(JavaScriptValue typedArray, out byte[] buffer, out uint bufferLength, out JavaScriptTypedArrayType arrayType, out int elementSize);
        public static void SetHostUrl(JavaScriptModuleRecord module, string url)
        {
            var value = JavaScriptValue.FromString(url);

            Native.ThrowIfError(Native.JsSetModuleHostInfo(module, JavascriptModuleHostInfoKind.JsModuleHostInfo_Url, value));
        }
예제 #32
0
 internal static extern JavaScriptErrorCode JsCreateSymbol(JavaScriptValue description, out JavaScriptValue symbol);
예제 #33
0
 internal static extern JavaScriptErrorCode JsCallFunction(JavaScriptValue function, JavaScriptValue[] arguments, ushort argumentCount, out JavaScriptValue result);
예제 #34
0
 internal static extern JavaScriptErrorCode JsGetPropertyIdFromSymbol(JavaScriptValue symbol, out JavaScriptPropertyId propertyId);
예제 #35
0
 internal static extern JavaScriptErrorCode JsConstructObject(JavaScriptValue function, JavaScriptValue[] arguments, ushort argumentCount, out JavaScriptValue result);
예제 #36
0
 internal static extern JavaScriptErrorCode JsNumberToInt(JavaScriptValue value, out int intValue);
예제 #37
0
 internal static extern JavaScriptErrorCode JsCreateFunction(JavaScriptNativeFunction nativeFunction, IntPtr externalData, out JavaScriptValue function);
예제 #38
0
 internal static extern JavaScriptErrorCode JsHasIndexedPropertiesExternalData(JavaScriptValue obj, out bool value);
예제 #39
0
 internal static extern JavaScriptErrorCode JsCreateURIError(JavaScriptValue message, out JavaScriptValue error);
예제 #40
0
 internal static extern JavaScriptErrorCode JsGetTypedArrayInfo(JavaScriptValue typedArray, out JavaScriptTypedArrayType arrayType, out JavaScriptValue arrayBuffer, out uint byteOffset, out uint byteLength);
예제 #41
0
 internal static extern JavaScriptErrorCode JsGetAndClearException(out JavaScriptValue exception);
예제 #42
0
 internal static extern JavaScriptErrorCode JsRunSerializedScriptWithCallback(JavaScriptSerializedScriptLoadSourceCallback scriptLoadCallback,
     JavaScriptSerializedScriptUnloadCallback scriptUnloadCallback, byte[] buffer, JavaScriptSourceContext sourceContext, string sourceUrl, out JavaScriptValue result);
예제 #43
0
 /// <summary>
 ///     Sets an object's property.
 /// </summary>
 /// <remarks>
 ///     Requires an active script context.
 /// </remarks>
 /// <param name="id">The ID of the property.</param>
 /// <param name="value">The new value of the property.</param>
 /// <param name="useStrictRules">The property set should follow strict mode rules.</param>
 public void SetProperty(JavaScriptPropertyId id, JavaScriptValue value, bool useStrictRules)
 {
     Native.ThrowIfError(Native.JsSetProperty(this, id, value, useStrictRules));
 }