Ejemplo n.º 1
0
        public static JSTypedArray CreateFromArrayBuffer(JavaScriptTypedArrayType type, JSArrayBuffer source, uint position, uint unitCount)
        {
            JSTypedArray result = new JSTypedArray(type, source, position, unitCount);

            result.InitWindow(source.Buffer, position);
            return(result);
        }
Ejemplo n.º 2
0
        internal static JSTypedArray CreateFromJS(JavaScriptTypedArrayType type, IntPtr data, uint unitCount, JavaScriptValue source, IContextSwitchService context)
        {
            JSTypedArray result = new JSTypedArray(type, 0, unitCount);

            result.SetJSSource(source, context);
            result.InitWindow(data, false);
            return(result);
        }
Ejemplo n.º 3
0
        public static JSTypedArray CreateInJS(JavaScriptTypedArrayType type, uint unitCount, Action <SharedMemoryBuffer> init)
        {
            var result = new JSTypedArray(type, 0, unitCount, init);

            if (init != null)
            {
                result.SetupInitValueAction(init);
            }
            return(result);
        }
Ejemplo n.º 4
0
        public static JavaScriptValue CreateTypedArray(this IJSValueService valueService, JSTypedArray source, JavaScriptValue?arrayBufferSource)
        {
            IContextSwitchService switchService = valueService.CurrentNode.GetService <IRuntimeService>().InternalContextSwitchService;

            if (source.JSSource.IsValid)
            {
                return(source.JSSource);
            }
            switch (source.BufferSource)
            {
            case SharedBufferSourceEnum.CreateByDotnet:
                return(switchService.With <JavaScriptValue>(
                           () =>
                {
                    if (arrayBufferSource == null)
                    {
                        throw new ArgumentNullException(nameof(arrayBufferSource));
                    }
                    var result = JavaScriptValue.CreateTypedArray(source.ArrayType, arrayBufferSource.Value, source.Position, source.UnitCount);
                    source.SetJSSource(result, switchService);
                    return result;
                }
                           ));

            case SharedBufferSourceEnum.CreateByJavascript:
                throw new InvalidOperationException("invalid source typed array");    //create by javascript should already have JavaScriptValue assigned

            case SharedBufferSourceEnum.CreateInJavascript:
                return(switchService.With <JavaScriptValue>(
                           () =>
                {
                    var result = JavaScriptValue.CreateTypedArray(source.ArrayType, JavaScriptValue.Invalid, source.Position, source.UnitCount);
                    source.SetJSSource(result, switchService);        //hold the objec
                    //get the internal storage
                    JavaScriptValue.GetTypedArrayStorage(result, out IntPtr data, out uint bufferLength, out JavaScriptTypedArrayType type, out int elementSize);
                    source.InitWindow(data, false);
                    source.InitBeforeConvert(source.Buffer);
                    return result;
                }
                           ));

            case SharedBufferSourceEnum.CreateByExternal:
                throw new ArgumentException("TypedArray does not support create from external");

            default:
                throw new ArgumentOutOfRangeException("Invalid BufferSource property in JSTypedArray object");
            }
        }