예제 #1
0
        public ChakraHost()
        {
            if (Native.JsCreateRuntime(JavaScriptRuntimeAttributes.None, null, out runtime) !=
                JavaScriptErrorCode.NoError)
            {
                throw new Exception("failed to create runtime.");
            }

            if (Native.JsCreateContext(runtime, out context) != JavaScriptErrorCode.NoError)
                throw new Exception("failed to create execution context.");

            ResetContext();

            // ES6 Promise callback
            JavaScriptPromiseContinuationCallback promiseContinuationCallback =
                delegate (JavaScriptValue task, IntPtr callbackState)
                {
                    promiseCallback = task;
                };

            if (Native.JsSetPromiseContinuationCallback(promiseContinuationCallback, IntPtr.Zero) !=
                JavaScriptErrorCode.NoError)
                throw new Exception("failed to setup callback for ES6 Promise");
            
            // Projections
            if (Native.JsProjectWinRTNamespace("ChakraBridge") != JavaScriptErrorCode.NoError)
                throw new Exception("failed to project ChakraBridge namespace.");

//#if DEBUG
//            // Debug
//            if (Native.JsStartDebugging() != JavaScriptErrorCode.NoError)
//                throw new Exception("failed to start debugging.");
//#endif
        }
예제 #2
0
 static async void ExecuteAsync(int delay, JavaScriptValue callbackValue, JavaScriptValue callee)
 {
     await Task.Delay(delay);
     callbackValue.CallFunction(callee);
     uint refCount;
     Native.JsRelease(callbackValue, out refCount);
     Native.JsRelease(callee, out refCount);
 }
예제 #3
0
        public ChakraHost()
        {
            if (Native.JsCreateRuntime(JavaScriptRuntimeAttributes.None, null, out runtime) !=
                JavaScriptErrorCode.NoError)
            {
                throw new Exception("failed to create runtime.");
            }

            if (Native.JsCreateContext(runtime, out context) != JavaScriptErrorCode.NoError)
                throw new Exception("failed to create execution context.");

            if (Native.JsSetCurrentContext(context) != JavaScriptErrorCode.NoError)
                throw new Exception("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)
                throw new Exception("failed to setup callback for ES6 Promise");

            // Bind to global object
            // setTimeout
            SetTimeoutJavaScriptNativeFunction = SetTimeout.SetTimeoutJavaScriptNativeFunction;
            DefineHostCallback("setTimeout", SetTimeoutJavaScriptNativeFunction);

            SendToHostJavaScriptNativeFunction = CommunicationManager.SendToHostJavaScriptNativeFunction;
            DefineHostCallback("sendToHost", SendToHostJavaScriptNativeFunction);

            // Projections
            if (Native.JsProjectWinRTNamespace("ChakraBridge") != JavaScriptErrorCode.NoError)
                throw new Exception("failed to project ChakraBridge namespace.");

            this.window = new Window();

            ProjectObjectToGlobal(new Console(), "console");
            ProjectObjectToGlobal(this.window, "window");
            ProjectObjectToGlobal(this.window.navigator, "navigator");
            ProjectObjectToGlobal(this.window.document, "document");

            // Add references
            RunScript(@"XMLHttpRequest = ChakraBridge.XMLHttpRequest;
HTMLCanvasElement = ChakraBridge.HTMLCanvasElementWrapper;
atob = window.atob;
btoa = window.btoa;");

#if DEBUG
            // Debug
            if (Native.JsStartDebugging() != JavaScriptErrorCode.NoError)
                throw new Exception("failed to start debugging.");
#endif
        }
예제 #4
0
        public static JavaScriptValue SetTimeoutJavaScriptNativeFunction(JavaScriptValue callee, bool isConstructCall, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] JavaScriptValue[] arguments, ushort argumentCount, IntPtr callbackData)
        {
            // setTimeout signature is (callback, after)
            JavaScriptValue callbackValue = arguments[1];

            JavaScriptValue afterValue = arguments[2].ConvertToNumber();
            var after = Math.Max(afterValue.ToDouble(), 1);

            uint refCount;
            Native.JsAddRef(callbackValue, out refCount);
            Native.JsAddRef(callee, out refCount);

            ExecuteAsync((int)after, callbackValue, callee);

            return JavaScriptValue.True;
        }
예제 #5
0
파일: PrintFun.cs 프로젝트: noear/SiteD
        public static JavaScriptValue PrintJavaScriptNativeFunction(JavaScriptValue callee, bool isConstructCall, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] JavaScriptValue[] arguments, ushort argumentCount, IntPtr callbackData)
        {
            // setTimeout signature is (callback, after)
            //JavaScriptValue callbackValue = arguments[1];

            //JavaScriptValue afterValue = arguments[2].ConvertToNumber();
            //var after = Math.Max(afterValue.ToDouble(), 1);

            //uint refCount;
            //Native.JsAddRef(callbackValue, out refCount);
            //Native.JsAddRef(callee, out refCount);

            //ExecuteAsync((int)after, callbackValue, callee);

            if (arguments.Length > 0) {
                String str = arguments[0].ConvertToString().ToString();
                Debug.WriteLine("JsEngine.print", str);
            }

            return JavaScriptValue.True;
        }
예제 #6
0
        internal static JavaScriptValue SendToHostJavaScriptNativeFunction(JavaScriptValue callee, bool isConstructCall, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] JavaScriptValue[] arguments, ushort argumentCount, IntPtr callbackData)
        {
            // sendToHost signature is (json, type)
            JavaScriptValue jsonValue = arguments[1];
            string json = jsonValue.ConvertToString().ToString();

            JavaScriptValue typeValue = arguments[2];
            string typename = typeValue.ConvertToString().ToString();

            if (!RegisteredTypes.ContainsKey(typename))
            {
                throw new Exception("Not registered type found: " + typename);
            }

            var type = RegisteredTypes[typename];

            var poco = JsonConvert.DeserializeObject(json, type);

            OnObjectReceived?.Invoke(poco);

            return JavaScriptValue.True;
        }
예제 #7
0
 public static extern JavaScriptErrorCode JsCreateNamedFunction(JavaScriptValue name, JavaScriptNativeFunction nativeFunction, IntPtr callbackState, out JavaScriptValue function);
예제 #8
0
 public static extern JavaScriptErrorCode JsGetAndClearException(out JavaScriptValue exception);
예제 #9
0
 public static extern JavaScriptErrorCode JsCreateFunction(JavaScriptNativeFunction nativeFunction, IntPtr externalData, out JavaScriptValue function);
예제 #10
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsGetNullValue(out JavaScriptValue nullValue);
예제 #11
0
 public static extern JavaScriptErrorCode JsConstructObject(JavaScriptValue function, JavaScriptValue[] arguments, ushort argumentCount, out JavaScriptValue result);
예제 #12
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsNumberToInt(JavaScriptValue value, out int intValue);
예제 #13
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsRelease(JavaScriptValue reference, out uint count);
예제 #14
0
 public static extern JavaScriptErrorCode JsGetTypedArrayStorage(JavaScriptValue typedArray, out byte[] buffer, out uint bufferLength, out JavaScriptTypedArrayType arrayType, out int elementSize);
예제 #15
0
 public static extern JavaScriptErrorCode JsGetDataViewStorage(JavaScriptValue dataView, out byte[] buffer, out uint bufferLength);
예제 #16
0
 public static extern JavaScriptErrorCode JsCreateDataView(JavaScriptValue arrayBuffer, uint byteOffset, uint byteOffsetLength, out JavaScriptValue result);
예제 #17
0
 public static extern JavaScriptErrorCode JsGetArrayBufferStorage(JavaScriptValue arrayBuffer, out byte[] buffer, out uint bufferLength);
예제 #18
0
 public static extern JavaScriptErrorCode JsCreateTypedArray(JavaScriptTypedArrayType arrayType, JavaScriptValue arrayBuffer, uint byteOffset,
                                                             uint elementLength, out JavaScriptValue result);
예제 #19
0
 public static extern JavaScriptErrorCode JsCreateArrayBuffer(uint byteLength, out JavaScriptValue result);
예제 #20
0
 public static extern JavaScriptErrorCode JsInspectableToObject([MarshalAs(UnmanagedType.IInspectable)] System.Object inspectable, out JavaScriptValue value);
예제 #21
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsCreateSymbol(JavaScriptValue description, out JavaScriptValue symbol);
예제 #22
0
 public static extern JavaScriptErrorCode JsCreateSymbol(JavaScriptValue description, out JavaScriptValue symbol);
예제 #23
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsGetPropertyIdFromSymbol(JavaScriptValue symbol, out JavaScriptPropertyId propertyId);
예제 #24
0
 public static extern JavaScriptErrorCode JsGetSymbolFromPropertyId(JavaScriptPropertyId propertyId, out JavaScriptValue symbol);
예제 #25
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsHasIndexedPropertiesExternalData(JavaScriptValue obj, out bool value);
예제 #26
0
 public static extern JavaScriptErrorCode JsGetPropertyIdFromSymbol(JavaScriptValue symbol, out JavaScriptPropertyId propertyId);
예제 #27
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsRunSerializedScript(string script, byte[] buffer, JavaScriptSourceContext sourceContext, string sourceUrl, out JavaScriptValue result);
예제 #28
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsCreateNamedFunction(JavaScriptValue name, JavaScriptNativeFunction nativeFunction, IntPtr callbackState, out JavaScriptValue function);
예제 #29
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsGetFalseValue(out JavaScriptValue falseValue);
예제 #30
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsCreateArrayBuffer(uint byteLength, out JavaScriptValue result);
예제 #31
0
 public static extern JavaScriptErrorCode JsSetException(JavaScriptValue exception);
예제 #32
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsCreateDataView(JavaScriptValue arrayBuffer, uint byteOffset, uint byteOffsetLength, out JavaScriptValue result);
예제 #33
0
 public static extern JavaScriptErrorCode JsCreateURIError(JavaScriptValue message, out JavaScriptValue error);
예제 #34
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsGetTypedArrayStorage(JavaScriptValue typedArray, out byte[] buffer, out uint bufferLength, out JavaScriptTypedArrayType arrayType, out int elementSize);
예제 #35
0
 public static extern JavaScriptErrorCode JsGetOwnPropertySymbols(JavaScriptValue obj, out JavaScriptValue propertySymbols);
예제 #36
0
 public static extern JavaScriptErrorCode JsSetObjectBeforeCollectCallback(JavaScriptValue reference, IntPtr callbackState, JavaScriptObjectBeforeCollectCallback beforeCollectCallback);
예제 #37
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsInspectableToObject([MarshalAs(UnmanagedType.IInspectable)] System.Object inspectable, out JavaScriptValue value);
예제 #38
0
 public static extern JavaScriptErrorCode JsNumberToInt(JavaScriptValue value, out int intValue);
예제 #39
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsCreateTypedArray(JavaScriptTypedArrayType arrayType, JavaScriptValue arrayBuffer, uint byteOffset,
     uint elementLength, out JavaScriptValue result);
예제 #40
0
 public static extern JavaScriptErrorCode JsGetIndexedPropertiesExternalData(JavaScriptValue obj, IntPtr data, out JavaScriptTypedArrayType arrayType, out uint elementLength);
예제 #41
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsGetArrayBufferStorage(JavaScriptValue arrayBuffer, out byte[] buffer, out uint bufferLength);
예제 #42
0
 public static extern JavaScriptErrorCode JsHasIndexedPropertiesExternalData(JavaScriptValue obj, out bool value);
예제 #43
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsGetDataViewStorage(JavaScriptValue dataView, out byte[] buffer, out uint bufferLength);
예제 #44
0
 public static extern JavaScriptErrorCode JsAddRef(JavaScriptValue reference, out uint count);
예제 #45
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsGetSymbolFromPropertyId(JavaScriptPropertyId propertyId, out JavaScriptValue symbol);
예제 #46
0
 public static extern JavaScriptErrorCode JsRelease(JavaScriptValue reference, out uint count);
예제 #47
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsGetOwnPropertySymbols(JavaScriptValue obj, out JavaScriptValue propertySymbols);
예제 #48
0
 public static extern JavaScriptErrorCode JsRunScript(string script, JavaScriptSourceContext sourceContext, string sourceUrl, out JavaScriptValue result);
예제 #49
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsGetIndexedPropertiesExternalData(JavaScriptValue obj, IntPtr data, out JavaScriptTypedArrayType arrayType, out uint elementLength);
예제 #50
0
 public static extern JavaScriptErrorCode JsRunSerializedScript(string script, byte[] buffer, JavaScriptSourceContext sourceContext, string sourceUrl, out JavaScriptValue result);
예제 #51
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsAddRef(JavaScriptValue reference, out uint count);
예제 #52
0
 public static extern JavaScriptErrorCode JsGetUndefinedValue(out JavaScriptValue undefinedValue);
예제 #53
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsRunScript(string script, JavaScriptSourceContext sourceContext, string sourceUrl, out JavaScriptValue result);
예제 #54
0
 public static extern JavaScriptErrorCode JsGetNullValue(out JavaScriptValue nullValue);
예제 #55
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsGetUndefinedValue(out JavaScriptValue undefinedValue);
예제 #56
0
 public static extern JavaScriptErrorCode JsGetTrueValue(out JavaScriptValue trueValue);
예제 #57
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsGetTrueValue(out JavaScriptValue trueValue);
예제 #58
0
 public static extern JavaScriptErrorCode JsGetFalseValue(out JavaScriptValue falseValue);
예제 #59
0
파일: Native.cs 프로젝트: scaPEGoatno/SiteD
 internal static extern JavaScriptErrorCode JsBoolToBoolean(bool value, out JavaScriptValue booleanValue);
예제 #60
0
 public static extern JavaScriptErrorCode JsBoolToBoolean(bool value, out JavaScriptValue booleanValue);