Example #1
0
        public override void Cleanup()
        {
            dataView_ = null;
            typedArray_ = null;
            buffer_ = null;

            engine_.Dispose();
            engine_ = null;
            runtime_.Dispose();
            runtime_ = null;
        }
Example #2
0
        internal JavaScriptValue CreateValueFromHandle(JavaScriptValueSafeHandle handle)
        {
            Debug.Assert(!(handle.IsClosed || handle.IsInvalid));

            JsValueType kind;

            Errors.ThrowIfIs(api_.JsGetValueType(handle, out kind));

            JavaScriptValue result = null;

            switch (kind)
            {
            case JsValueType.JsArray:
                result = new JavaScriptArray(handle, JavaScriptValueType.Array, this);
                break;

            case JsValueType.JsFunction:
                result = new JavaScriptFunction(handle, JavaScriptValueType.Function, this);
                break;

            case JsValueType.JsObject:
            case JsValueType.JsNull:
            case JsValueType.JsError:
                result = new JavaScriptObject(handle, JavaScriptValueType.Object, this);
                break;

            case JsValueType.JsSymbol:
                result = new JavaScriptSymbol(handle, JavaScriptValueType.Symbol, this);
                break;

            case JsValueType.JsArrayBuffer:
                result = new JavaScriptArrayBuffer(handle, JavaScriptValueType.ArrayBuffer, this);
                break;

            case JsValueType.JsTypedArray:
                result = new JavaScriptTypedArray(handle, JavaScriptValueType.TypedArray, this);
                break;

            case JsValueType.JsDataView:
                result = new JavaScriptDataView(handle, JavaScriptValueType.DataView, this);
                break;

            case JsValueType.JsBoolean:
            case JsValueType.JsNumber:
            case JsValueType.JsString:
            case JsValueType.JsUndefined:
            default:
                result = new JavaScriptValue(handle, kind.ToApiValueType(), this);
                break;
            }

            return(result);
        }
Example #3
0
        public override void Setup()
        {
            runtime_ = new JavaScriptRuntime(new JavaScriptRuntimeSettings());
            engine_ = runtime_.CreateEngine();

            var baseline = new ScriptSource("test://init.js", @"(function(global) {
            global.buffer = new ArrayBuffer(1024);
            global.typedArray = new Uint8ClampedArray(buffer);
            global.dataView = new DataView(buffer, 1);
            })(this);");
            engine_.Execute(baseline);
            buffer_ = (JavaScriptArrayBuffer)engine_.GetGlobalVariable("buffer");
            typedArray_ = (JavaScriptTypedArray)engine_.GetGlobalVariable("typedArray");
            dataView_ = (JavaScriptDataView)engine_.GetGlobalVariable("dataView");
        }
Example #4
0
        internal JavaScriptObject CreateObjectFromHandle(JavaScriptValueSafeHandle handle)
        {
            JsValueType kind;

            Errors.ThrowIfIs(api_.JsGetValueType(handle, out kind));

            JavaScriptObject result = null;

            switch (kind)
            {
            case JsValueType.JsArray:
                result = new JavaScriptArray(handle, JavaScriptValueType.Array, this);
                break;

            case JsValueType.JsFunction:
                result = new JavaScriptFunction(handle, JavaScriptValueType.Function, this);
                break;

            case JsValueType.JsObject:
            case JsValueType.JsError:
            case JsValueType.JsNull:
                result = new JavaScriptObject(handle, JavaScriptValueType.Object, this);
                break;

            case JsValueType.JsArrayBuffer:
                result = new JavaScriptArrayBuffer(handle, JavaScriptValueType.ArrayBuffer, this);
                break;

            case JsValueType.JsTypedArray:
                result = new JavaScriptTypedArray(handle, JavaScriptValueType.TypedArray, this);
                break;

            case JsValueType.JsDataView:
                result = new JavaScriptDataView(handle, JavaScriptValueType.DataView, this);
                break;

            case JsValueType.JsBoolean:
            case JsValueType.JsNumber:
            case JsValueType.JsString:
            case JsValueType.JsUndefined:
            case JsValueType.JsSymbol:
            default:
                throw new ArgumentException();
            }

            return(result);
        }