var proxy = function (tt, name) {
    return new Proxy(tt, {
        get(target, p, receiver) {
            let res = Reflect.get(target, p, receiver);
            console.log(`${name} get`, p, typeof res)
            return res;
        }
    })
}
var v_saf;
!function () {
    var n = Function.toString, t = [], i = [], o = [].indexOf.bind(t), e = [].push.bind(t), r = [].push.bind(i);

    function u(n, t, tag) {
        return -1 == o(n) && (e(n), r(`function ${tag ? tag : ""}${t || n.name || ""}() { [native code] }`.replaceAll("get get", 'get'))), n
    }

    Object.defineProperty(Function.prototype, "toString", {
        enumerable: !1,
        configurable: !0,
        writable: !0,
        value: function () {
            return "function" == typeof this && i[o(this)] || n.call(this)
        }
    }), u(Function.prototype.toString, "toString"), v_saf = u
}();
"use strict";
const HTMLElementImpl = require("./HTMLElement-impl").implementation;
const notImplemented = require("../../browser/not-implemented");
const idlUtils = require("../generated/utils");
const {Canvas} = require("../../utils");

function randInt(a, b) {
    return parseInt(Math.random() * (b - a) + a)
}

class HTMLCanvasElementImpl extends HTMLElementImpl {
    _attrModified(name, value, oldValue) {
        if (this._canvas && (name === "width" || name === "height")) {
            this._canvas[name] = parseInt(value);
        }

        super._attrModified(name, value, oldValue);
    }

    _getCanvas() {
        if (Canvas && !this._canvas) {
            this._canvas = Canvas.createCanvas(this.width, this.height);
        }
        return this._canvas;
    }

    getContext(contextId) {
        // console.log('contextId', contextId)
        const canvas = this._getCanvas();
        if (canvas) {
            if (!this._context) {
                this._context = canvas.getContext(contextId) || null;
                if (this._context) {
                    // Override the native canvas reference with our wrapper. This is the
                    // reason why we need to locally cache _context, since each call to
                    // canvas.getContext(contextId) would replace this reference again.
                    // Perhaps in the longer term, a better solution would be to create a
                    // full wrapper for the Context object as well.
                    this._context.canvas = idlUtils.wrapperForImpl(this);
                    wrapNodeCanvasMethod(this._context, "createPattern");
                    wrapNodeCanvasMethod(this._context, "drawImage");
                }
            }
            if (contextId === 'webgl' || contextId === 'webgl2') {
                var v_new_toggle = true
                var v_new = function (v) {
                    var temp = v_new_toggle;
                    v_new_toggle = true;
                    var r = new v;
                    v_new_toggle = temp;
                    return r
                }

                function WebGLBuffer() {
    }

                function WebGLProgram() {
                }

                function WebGLShader() {
                }
                var WebGLRenderingContext = class  WebGLRenderingContext {
                    constructor(aaa) {
                        console.log('new WebGLRenderingContext', aaa)
                    }

                    createBuffer () {
        v_console_log('  [*] WebGLRenderingContext -> createBuffer[func]');
        return v_new(WebGLBuffer)
    }
                    bindBuffer (target, buffer) {
                        v_console_log('  [*] WebGLRenderingContext -> bindBuffer[func]', target, buffer);
                        return v_new(WebGLBuffer)
                    }
                    getAttribLocation (program, name) {
                        v_console_log('  [*] WebGLRenderingContext -> getAttribLocation[func]', program, name);
                    }
                    vertexAttribPointer (index, size, type, normalized, stride, offset) {
                        v_console_log('  [*] WebGLRenderingContext -> vertexAttribPointer[func]', index, size, type, normalized, stride, offset);
                    }
                    enableVertexAttribArray (index) {
                        v_console_log('  [*] WebGLRenderingContext -> enableVertexAttribArray[func]', index);
                    }
                    useProgram (index) {
                        v_console_log('  [*] WebGLRenderingContext -> useProgram[func]', index);
                    }
                    getUniformLocation (program, name) {
                        v_console_log('  [*] WebGLRenderingContext -> getUniformLocation[func]', program, name);
                    }
                    uniform4fv (program, name) {
                        v_console_log('  [*] WebGLRenderingContext -> uniform4fv[func]', program, name);
                    }
                    drawArrays (mode, first, count) {
                        v_console_log('  [*] WebGLRenderingContext -> drawArrays[func]', mode, first, count);
                    }
                    readPixels (x, y, width, height, format, type, pixels) {
                        for (let i = 0; i < pixels.length - 1; i++) {
                            pixels.fill(parseInt(Math.random() * 210 + 10), i, i + 1)
                        }
                        v_console_log('  [*] WebGLRenderingContext -> readPixels[func]', x, y, width, height, format, type, pixels)
                    }

                    bufferData (target, size, srcData, usage, srcOffSet, length) {
                        v_console_log('  [*] WebGLRenderingContext -> bufferData[func]', target, size, srcData, usage, srcOffSet, length);
                        return v_new(WebGLBuffer)
                    }
                    createProgram () {
                        v_console_log('  [*] WebGLRenderingContext -> createProgram[func]');
                        return v_new(WebGLProgram)
                    }
                    createShader (a) {
                        v_console_log('  [*] WebGLRenderingContext -> createShader[func]', a);
                        return v_new(WebGLShader)
                    }
                    shaderSource (shader, originalSource) {
                        v_console_log('  [*] WebGLRenderingContext -> shaderSource[func]', shader, originalSource);
                        this._originalSource = originalSource;
                    }
                    compileShader (shader) {
                        v_console_log('  [*] WebGLRenderingContext -> compileShader[func]', shader);
                        // this._originalSource = originalSource;
                    }
                    getShaderParameter (shader, pname) {
                        v_console_log('  [*] WebGLRenderingContext -> getShaderParameter[func]', shader, pname);
                        switch (pname) {
                            case 35713:
                                return true;
                                break;
                        }
                    }

                    attachShader (program, shader) {
                        v_console_log('  [*] WebGLRenderingContext -> attachShader[func]', program, shader);

                    }
                    linkProgram (program, shader) {
                        v_console_log('  [*] WebGLRenderingContext -> linkProgram[func]', program, shader);

                    }

                    getProgramParameter (program, pname) {
                        v_console_log('  [*] WebGLRenderingContext -> getProgramParameter[func]', program, pname);
                        if (pname === 35714) {
                            return true;
                        }

                    }
                    getSupportedExtensions () {
                        // window.debug = true;
                        v_console_log('  [*] WebGLRenderingContext -> getSupportedExtensions[func]')
                        return [
                            "ANGLE_instanced_arrays", "EXT_blend_minmax", "EXT_color_buffer_half_float", "EXT_disjoint_timer_query", "EXT_float_blend", "EXT_frag_depth",
                            "EXT_shader_texture_lod", "EXT_texture_compression_bptc", "EXT_texture_compression_rgtc", "EXT_texture_filter_anisotropic", "WEBKIT_EXT_texture_filter_anisotropic", "EXT_sRGB",
                            "KHR_parallel_shader_compile", "OES_element_index_uint", "OES_fbo_render_mipmap", "OES_standard_derivatives", "OES_texture_float", "OES_texture_float_linear",
                            "OES_texture_half_float", "OES_texture_half_float_linear", "OES_vertex_array_object", "WEBGL_color_buffer_float", "WEBGL_compressed_texture_s3tc",
                            "WEBKIT_WEBGL_compressed_texture_s3tc", "WEBGL_compressed_texture_s3tc_srgb", "WEBGL_debug_renderer_info", "WEBGL_debug_shaders",
                            "WEBGL_depth_texture", "WEBKIT_WEBGL_depth_texture", "WEBGL_draw_buffers", "WEBGL_lose_context", "WEBKIT_WEBGL_lose_context", "WEBGL_multi_draw",
                        ]
                    }
                    getExtension (key) {
                        v_console_log('  [*] WebGLRenderingContext -> getExtension[func]:', key)

                        class WebGLDebugRendererInfo {
                            get UNMASKED_VENDOR_WEBGL() {
                                return 37445
                            }

                            get UNMASKED_RENDERER_WEBGL() {
                                return 37446
                            }
                        }

                        class EXTTextureFilterAnisotropic {
                        }

                        class WebGLLoseContext {
                            loseContext() {
                            }

                            restoreContext() {
                            }
                        }

                        if (key == 'WEBGL_debug_renderer_info') {
                            var r = new WebGLDebugRendererInfo
                        }
                        if (key == 'EXT_texture_filter_anisotropic') {
                            var r = new EXTTextureFilterAnisotropic
                        }
                        if (key == 'WEBGL_lose_context') {
                            var r = new WebGLLoseContext
                        } else {
                            var r = new WebGLDebugRendererInfo
                        }
                        return proxy(r, 'new ' + key)
                    }
                    getParameter (key) {
                        v_console_log('  [*] WebGLRenderingContext -> getParameter[func]:', key)
                        let res;
                        let _toggle = {
                            3413: 8,
                            3412: 8,
                            3411: 8,
                            3410: 8,
                            3414: 24,
                            35661: 32,
                            34076: 16384,
                            36349: 1024,
                            34024: 16384,
                            34930: 16,
                            3379: 16384,
                            36348: 31,
                            34921: 16,
                            35660: 16,
                            36347: 1024,
                            7937: 'WebKit:WebGL',
                            35724: 'WebGL:GLSL:ES:1.0:(OpenGL:ES:GLSL:ES:1.0:Chromium)',
                            3415: 0,
                            7936: 'WebKit',
                            7938: 'WebGL:1.0:(OpenGL:ES:2.0:Chromium)',
                            37445: 'Google Inc. (Apple)',
                            37446: 'ANGLE (Apple, Apple M1 Max, OpenGL 4.1)',
                            34047: null
                        }
                        if (_toggle[key]) {
                            res =  _toggle[key]

                        } else {
                            if (key == 33902) {
                                return new Float32Array([1, 1])
                            }
                            if (key == 33901) {
                                return new Float32Array([1, 64])
                            }
                            if (key == 35661) {
                                return 32
                            }
                            if (key == 34047) {
                                return null
                            }
                            if (key == 34076) {
                                return 16384
                            }
                            if (key == 36349) {
                                return 1024
                            }
                            if (key == 34024) {
                                return 16384
                            }
                            if (key == 34930) {
                                return 16
                            }
                            if (key == 3379) {
                                return 16384
                            }
                            if (key == 36348) {
                                return 30
                            }
                            if (key == 34921) {
                                return 16
                            }
                            if (key == 35660) {
                                return 16
                            }
                            if (key == 36347) {
                                return 4095
                            }
                            if (key == 3386) {
                                return new Int32Array([16384, 16384])
                            }
                            if (key == 3410) {
                                return 8
                            }
                            if (key == 7937) {
                                return "WebKit WebGL"
                            }
                            if (key == 35724) {
                                return "WebGL GLSL ES 1.0 (OpenGL ES GLSL ES 1.0 Chromium)"
                            }
                            if (key == 3415) {
                                return 0
                            }
                            if (key == 7936) {
                                return "WebKit"
                            }
                            if (key == 7938) {
                                return "WebGL 1.0 (OpenGL ES 2.0 Chromium)"
                            }
                            if (key == 3411) {
                                return 8
                            }
                            if (key == 3412) {
                                return 8
                            }
                            if (key == 3413) {
                                return 8
                            }
                            if (key == 3414) {
                                return 24
                            }
                        }
                        v_console_log('  [*] WebGLRenderingContext -> getParameter[func]:', key, res)

                        return res;
                    }
                    getContextAttributes () {
                        v_console_log('  [*] WebGLRenderingContext -> getContextAttributes[func]')
                        return {
                            alpha: true,
                            antialias: true,
                            depth: true,
                            desynchronized: false,
                            failIfMajorPerformanceCaveat: false,
                            powerPreference: "default",
                            premultipliedAlpha: true,
                            preserveDrawingBuffer: false,
                            stencil: false,
                            xrCompatible: false,
                        }
                    }
                    getShaderPrecisionFormat (a, b) {
                        v_console_log('  [*] WebGLRenderingContext -> getShaderPrecisionFormat[func]', a, b)

                        function WebGLShaderPrecisionFormat() {
                        }

                        var r1 = v_new(WebGLShaderPrecisionFormat)
                        r1.rangeMin = 127
                        r1.rangeMax = 127
                        r1.precision = 23
                        var r2 = v_new(WebGLShaderPrecisionFormat)
                        r2.rangeMin = 31
                        r2.rangeMax = 30
                        r2.precision = 0
                        if (a == 35633 && b == 36338) {
                            return r1
                        }
                        if (a == 35633 && b == 36337) {
                            return r1
                        }
                        if (a == 35633 && b == 36336) {
                            return r1
                        }
                        if (a == 35633 && b == 36341) {
                            return r2
                        }
                        if (a == 35633 && b == 36340) {
                            return r2
                        }
                        if (a == 35633 && b == 36339) {
                            return r2
                        }
                        if (a == 35632 && b == 36338) {
                            return r1
                        }
                        if (a == 35632 && b == 36337) {
                            return r1
                        }
                        if (a == 35632 && b == 36336) {
                            return r1
                        }
                        if (a == 35632 && b == 36341) {
                            return r2
                        }
                        if (a == 35632 && b == 36340) {
                            return r2
                        }
                        if (a == 35632 && b == 36339) {
                            return r2
                        }
                        throw Error('getShaderPrecisionFormat')
                    }
                }
                Object.defineProperties(WebGLRenderingContext.prototype, {
                    // getSupportedExtensions: {value: WebGLRenderingContext.getSupportedExtensions, writable:true, configurable:true, enumerable: true},
                    DEPTH_BUFFER_BIT: {"value": 256, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_BUFFER_BIT: {"value": 1024, "writable": false, "enumerable": true, "configurable": false},
                    COLOR_BUFFER_BIT: {"value": 16384, "writable": false, "enumerable": true, "configurable": false},
                    POINTS: {"value": 0, "writable": false, "enumerable": true, "configurable": false},
                    LINES: {"value": 1, "writable": false, "enumerable": true, "configurable": false},
                    LINE_LOOP: {"value": 2, "writable": false, "enumerable": true, "configurable": false},
                    LINE_STRIP: {"value": 3, "writable": false, "enumerable": true, "configurable": false},
                    TRIANGLES: {"value": 4, "writable": false, "enumerable": true, "configurable": false},
                    TRIANGLE_STRIP: {"value": 5, "writable": false, "enumerable": true, "configurable": false},
                    TRIANGLE_FAN: {"value": 6, "writable": false, "enumerable": true, "configurable": false},
                    ZERO: {"value": 0, "writable": false, "enumerable": true, "configurable": false},
                    ONE: {"value": 1, "writable": false, "enumerable": true, "configurable": false},
                    SRC_COLOR: {"value": 768, "writable": false, "enumerable": true, "configurable": false},
                    ONE_MINUS_SRC_COLOR: {"value": 769, "writable": false, "enumerable": true, "configurable": false},
                    SRC_ALPHA: {"value": 770, "writable": false, "enumerable": true, "configurable": false},
                    ONE_MINUS_SRC_ALPHA: {"value": 771, "writable": false, "enumerable": true, "configurable": false},
                    DST_ALPHA: {"value": 772, "writable": false, "enumerable": true, "configurable": false},
                    ONE_MINUS_DST_ALPHA: {"value": 773, "writable": false, "enumerable": true, "configurable": false},
                    DST_COLOR: {"value": 774, "writable": false, "enumerable": true, "configurable": false},
                    ONE_MINUS_DST_COLOR: {"value": 775, "writable": false, "enumerable": true, "configurable": false},
                    SRC_ALPHA_SATURATE: {"value": 776, "writable": false, "enumerable": true, "configurable": false},
                    FUNC_ADD: {"value": 32774, "writable": false, "enumerable": true, "configurable": false},
                    BLEND_EQUATION: {"value": 32777, "writable": false, "enumerable": true, "configurable": false},
                    BLEND_EQUATION_RGB: {"value": 32777, "writable": false, "enumerable": true, "configurable": false},
                    BLEND_EQUATION_ALPHA: {
                        "value": 34877,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FUNC_SUBTRACT: {"value": 32778, "writable": false, "enumerable": true, "configurable": false},
                    FUNC_REVERSE_SUBTRACT: {
                        "value": 32779,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    BLEND_DST_RGB: {"value": 32968, "writable": false, "enumerable": true, "configurable": false},
                    BLEND_SRC_RGB: {"value": 32969, "writable": false, "enumerable": true, "configurable": false},
                    BLEND_DST_ALPHA: {"value": 32970, "writable": false, "enumerable": true, "configurable": false},
                    BLEND_SRC_ALPHA: {"value": 32971, "writable": false, "enumerable": true, "configurable": false},
                    CONSTANT_COLOR: {"value": 32769, "writable": false, "enumerable": true, "configurable": false},
                    ONE_MINUS_CONSTANT_COLOR: {
                        "value": 32770,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    CONSTANT_ALPHA: {"value": 32771, "writable": false, "enumerable": true, "configurable": false},
                    ONE_MINUS_CONSTANT_ALPHA: {
                        "value": 32772,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    BLEND_COLOR: {"value": 32773, "writable": false, "enumerable": true, "configurable": false},
                    ARRAY_BUFFER: {"value": 34962, "writable": false, "enumerable": true, "configurable": false},
                    ELEMENT_ARRAY_BUFFER: {
                        "value": 34963,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    ARRAY_BUFFER_BINDING: {
                        "value": 34964,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    ELEMENT_ARRAY_BUFFER_BINDING: {
                        "value": 34965,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    STREAM_DRAW: {"value": 35040, "writable": false, "enumerable": true, "configurable": false},
                    STATIC_DRAW: {"value": 35044, "writable": false, "enumerable": true, "configurable": false},
                    DYNAMIC_DRAW: {"value": 35048, "writable": false, "enumerable": true, "configurable": false},
                    BUFFER_SIZE: {"value": 34660, "writable": false, "enumerable": true, "configurable": false},
                    BUFFER_USAGE: {"value": 34661, "writable": false, "enumerable": true, "configurable": false},
                    CURRENT_VERTEX_ATTRIB: {
                        "value": 34342,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FRONT: {"value": 1028, "writable": false, "enumerable": true, "configurable": false},
                    BACK: {"value": 1029, "writable": false, "enumerable": true, "configurable": false},
                    FRONT_AND_BACK: {"value": 1032, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE_2D: {"value": 3553, "writable": false, "enumerable": true, "configurable": false},
                    CULL_FACE: {"value": 2884, "writable": false, "enumerable": true, "configurable": false},
                    BLEND: {"value": 3042, "writable": false, "enumerable": true, "configurable": false},
                    DITHER: {"value": 3024, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_TEST: {"value": 2960, "writable": false, "enumerable": true, "configurable": false},
                    DEPTH_TEST: {"value": 2929, "writable": false, "enumerable": true, "configurable": false},
                    SCISSOR_TEST: {"value": 3089, "writable": false, "enumerable": true, "configurable": false},
                    POLYGON_OFFSET_FILL: {"value": 32823, "writable": false, "enumerable": true, "configurable": false},
                    SAMPLE_ALPHA_TO_COVERAGE: {
                        "value": 32926,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    SAMPLE_COVERAGE: {"value": 32928, "writable": false, "enumerable": true, "configurable": false},
                    NO_ERROR: {"value": 0, "writable": false, "enumerable": true, "configurable": false},
                    INVALID_ENUM: {"value": 1280, "writable": false, "enumerable": true, "configurable": false},
                    INVALID_VALUE: {"value": 1281, "writable": false, "enumerable": true, "configurable": false},
                    INVALID_OPERATION: {"value": 1282, "writable": false, "enumerable": true, "configurable": false},
                    OUT_OF_MEMORY: {"value": 1285, "writable": false, "enumerable": true, "configurable": false},
                    CW: {"value": 2304, "writable": false, "enumerable": true, "configurable": false},
                    CCW: {"value": 2305, "writable": false, "enumerable": true, "configurable": false},
                    LINE_WIDTH: {"value": 2849, "writable": false, "enumerable": true, "configurable": false},
                    ALIASED_POINT_SIZE_RANGE: {
                        "value": 33901,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    ALIASED_LINE_WIDTH_RANGE: {
                        "value": 33902,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    CULL_FACE_MODE: {"value": 2885, "writable": false, "enumerable": true, "configurable": false},
                    FRONT_FACE: {"value": 2886, "writable": false, "enumerable": true, "configurable": false},
                    DEPTH_RANGE: {"value": 2928, "writable": false, "enumerable": true, "configurable": false},
                    DEPTH_WRITEMASK: {"value": 2930, "writable": false, "enumerable": true, "configurable": false},
                    DEPTH_CLEAR_VALUE: {"value": 2931, "writable": false, "enumerable": true, "configurable": false},
                    DEPTH_FUNC: {"value": 2932, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_CLEAR_VALUE: {"value": 2961, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_FUNC: {"value": 2962, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_FAIL: {"value": 2964, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_PASS_DEPTH_FAIL: {
                        "value": 2965,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    STENCIL_PASS_DEPTH_PASS: {
                        "value": 2966,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    STENCIL_REF: {"value": 2967, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_VALUE_MASK: {"value": 2963, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_WRITEMASK: {"value": 2968, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_BACK_FUNC: {"value": 34816, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_BACK_FAIL: {"value": 34817, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_BACK_PASS_DEPTH_FAIL: {
                        "value": 34818,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    STENCIL_BACK_PASS_DEPTH_PASS: {
                        "value": 34819,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    STENCIL_BACK_REF: {"value": 36003, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_BACK_VALUE_MASK: {
                        "value": 36004,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    STENCIL_BACK_WRITEMASK: {
                        "value": 36005,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    VIEWPORT: {"value": 2978, "writable": false, "enumerable": true, "configurable": false},
                    SCISSOR_BOX: {"value": 3088, "writable": false, "enumerable": true, "configurable": false},
                    COLOR_CLEAR_VALUE: {"value": 3106, "writable": false, "enumerable": true, "configurable": false},
                    COLOR_WRITEMASK: {"value": 3107, "writable": false, "enumerable": true, "configurable": false},
                    UNPACK_ALIGNMENT: {"value": 3317, "writable": false, "enumerable": true, "configurable": false},
                    PACK_ALIGNMENT: {"value": 3333, "writable": false, "enumerable": true, "configurable": false},
                    MAX_TEXTURE_SIZE: {"value": 3379, "writable": false, "enumerable": true, "configurable": false},
                    MAX_VIEWPORT_DIMS: {"value": 3386, "writable": false, "enumerable": true, "configurable": false},
                    SUBPIXEL_BITS: {"value": 3408, "writable": false, "enumerable": true, "configurable": false},
                    RED_BITS: {"value": 3410, "writable": false, "enumerable": true, "configurable": false},
                    GREEN_BITS: {"value": 3411, "writable": false, "enumerable": true, "configurable": false},
                    BLUE_BITS: {"value": 3412, "writable": false, "enumerable": true, "configurable": false},
                    ALPHA_BITS: {"value": 3413, "writable": false, "enumerable": true, "configurable": false},
                    DEPTH_BITS: {"value": 3414, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_BITS: {"value": 3415, "writable": false, "enumerable": true, "configurable": false},
                    POLYGON_OFFSET_UNITS: {
                        "value": 10752,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    POLYGON_OFFSET_FACTOR: {
                        "value": 32824,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    TEXTURE_BINDING_2D: {"value": 32873, "writable": false, "enumerable": true, "configurable": false},
                    SAMPLE_BUFFERS: {"value": 32936, "writable": false, "enumerable": true, "configurable": false},
                    SAMPLES: {"value": 32937, "writable": false, "enumerable": true, "configurable": false},
                    SAMPLE_COVERAGE_VALUE: {
                        "value": 32938,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    SAMPLE_COVERAGE_INVERT: {
                        "value": 32939,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    COMPRESSED_TEXTURE_FORMATS: {
                        "value": 34467,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    DONT_CARE: {"value": 4352, "writable": false, "enumerable": true, "configurable": false},
                    FASTEST: {"value": 4353, "writable": false, "enumerable": true, "configurable": false},
                    NICEST: {"value": 4354, "writable": false, "enumerable": true, "configurable": false},
                    GENERATE_MIPMAP_HINT: {
                        "value": 33170,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    BYTE: {"value": 5120, "writable": false, "enumerable": true, "configurable": false},
                    UNSIGNED_BYTE: {"value": 5121, "writable": false, "enumerable": true, "configurable": false},
                    SHORT: {"value": 5122, "writable": false, "enumerable": true, "configurable": false},
                    UNSIGNED_SHORT: {"value": 5123, "writable": false, "enumerable": true, "configurable": false},
                    INT: {"value": 5124, "writable": false, "enumerable": true, "configurable": false},
                    UNSIGNED_INT: {"value": 5125, "writable": false, "enumerable": true, "configurable": false},
                    FLOAT: {"value": 5126, "writable": false, "enumerable": true, "configurable": false},
                    DEPTH_COMPONENT: {"value": 6402, "writable": false, "enumerable": true, "configurable": false},
                    ALPHA: {"value": 6406, "writable": false, "enumerable": true, "configurable": false},
                    RGB: {"value": 6407, "writable": false, "enumerable": true, "configurable": false},
                    RGBA: {"value": 6408, "writable": false, "enumerable": true, "configurable": false},
                    LUMINANCE: {"value": 6409, "writable": false, "enumerable": true, "configurable": false},
                    LUMINANCE_ALPHA: {"value": 6410, "writable": false, "enumerable": true, "configurable": false},
                    UNSIGNED_SHORT_4_4_4_4: {
                        "value": 32819,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    UNSIGNED_SHORT_5_5_5_1: {
                        "value": 32820,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    UNSIGNED_SHORT_5_6_5: {
                        "value": 33635,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FRAGMENT_SHADER: {"value": 35632, "writable": false, "enumerable": true, "configurable": false},
                    VERTEX_SHADER: {"value": 35633, "writable": false, "enumerable": true, "configurable": false},
                    MAX_VERTEX_ATTRIBS: {"value": 34921, "writable": false, "enumerable": true, "configurable": false},
                    MAX_VERTEX_UNIFORM_VECTORS: {
                        "value": 36347,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    MAX_VARYING_VECTORS: {"value": 36348, "writable": false, "enumerable": true, "configurable": false},
                    MAX_COMBINED_TEXTURE_IMAGE_UNITS: {
                        "value": 35661,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    MAX_VERTEX_TEXTURE_IMAGE_UNITS: {
                        "value": 35660,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    MAX_TEXTURE_IMAGE_UNITS: {
                        "value": 34930,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    MAX_FRAGMENT_UNIFORM_VECTORS: {
                        "value": 36349,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    SHADER_TYPE: {"value": 35663, "writable": false, "enumerable": true, "configurable": false},
                    DELETE_STATUS: {"value": 35712, "writable": false, "enumerable": true, "configurable": false},
                    LINK_STATUS: {"value": 35714, "writable": false, "enumerable": true, "configurable": false},
                    VALIDATE_STATUS: {"value": 35715, "writable": false, "enumerable": true, "configurable": false},
                    ATTACHED_SHADERS: {"value": 35717, "writable": false, "enumerable": true, "configurable": false},
                    ACTIVE_UNIFORMS: {"value": 35718, "writable": false, "enumerable": true, "configurable": false},
                    ACTIVE_ATTRIBUTES: {"value": 35721, "writable": false, "enumerable": true, "configurable": false},
                    SHADING_LANGUAGE_VERSION: {
                        "value": 35724,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    CURRENT_PROGRAM: {"value": 35725, "writable": false, "enumerable": true, "configurable": false},
                    NEVER: {"value": 512, "writable": false, "enumerable": true, "configurable": false},
                    LESS: {"value": 513, "writable": false, "enumerable": true, "configurable": false},
                    EQUAL: {"value": 514, "writable": false, "enumerable": true, "configurable": false},
                    LEQUAL: {"value": 515, "writable": false, "enumerable": true, "configurable": false},
                    GREATER: {"value": 516, "writable": false, "enumerable": true, "configurable": false},
                    NOTEQUAL: {"value": 517, "writable": false, "enumerable": true, "configurable": false},
                    GEQUAL: {"value": 518, "writable": false, "enumerable": true, "configurable": false},
                    ALWAYS: {"value": 519, "writable": false, "enumerable": true, "configurable": false},
                    KEEP: {"value": 7680, "writable": false, "enumerable": true, "configurable": false},
                    REPLACE: {"value": 7681, "writable": false, "enumerable": true, "configurable": false},
                    INCR: {"value": 7682, "writable": false, "enumerable": true, "configurable": false},
                    DECR: {"value": 7683, "writable": false, "enumerable": true, "configurable": false},
                    INVERT: {"value": 5386, "writable": false, "enumerable": true, "configurable": false},
                    INCR_WRAP: {"value": 34055, "writable": false, "enumerable": true, "configurable": false},
                    DECR_WRAP: {"value": 34056, "writable": false, "enumerable": true, "configurable": false},
                    VENDOR: {"value": 7936, "writable": false, "enumerable": true, "configurable": false},
                    RENDERER: {"value": 7937, "writable": false, "enumerable": true, "configurable": false},
                    VERSION: {"value": 7938, "writable": false, "enumerable": true, "configurable": false},
                    NEAREST: {"value": 9728, "writable": false, "enumerable": true, "configurable": false},
                    LINEAR: {"value": 9729, "writable": false, "enumerable": true, "configurable": false},
                    NEAREST_MIPMAP_NEAREST: {
                        "value": 9984,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    LINEAR_MIPMAP_NEAREST: {
                        "value": 9985,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    NEAREST_MIPMAP_LINEAR: {
                        "value": 9986,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    LINEAR_MIPMAP_LINEAR: {"value": 9987, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE_MAG_FILTER: {"value": 10240, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE_MIN_FILTER: {"value": 10241, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE_WRAP_S: {"value": 10242, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE_WRAP_T: {"value": 10243, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE: {"value": 5890, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE_CUBE_MAP: {"value": 34067, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE_BINDING_CUBE_MAP: {
                        "value": 34068,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    TEXTURE_CUBE_MAP_POSITIVE_X: {
                        "value": 34069,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    TEXTURE_CUBE_MAP_NEGATIVE_X: {
                        "value": 34070,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    TEXTURE_CUBE_MAP_POSITIVE_Y: {
                        "value": 34071,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    TEXTURE_CUBE_MAP_NEGATIVE_Y: {
                        "value": 34072,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    TEXTURE_CUBE_MAP_POSITIVE_Z: {
                        "value": 34073,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    TEXTURE_CUBE_MAP_NEGATIVE_Z: {
                        "value": 34074,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    MAX_CUBE_MAP_TEXTURE_SIZE: {
                        "value": 34076,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    TEXTURE0: {"value": 33984, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE1: {"value": 33985, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE2: {"value": 33986, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE3: {"value": 33987, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE4: {"value": 33988, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE5: {"value": 33989, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE6: {"value": 33990, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE7: {"value": 33991, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE8: {"value": 33992, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE9: {"value": 33993, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE10: {"value": 33994, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE11: {"value": 33995, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE12: {"value": 33996, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE13: {"value": 33997, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE14: {"value": 33998, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE15: {"value": 33999, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE16: {"value": 34000, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE17: {"value": 34001, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE18: {"value": 34002, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE19: {"value": 34003, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE20: {"value": 34004, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE21: {"value": 34005, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE22: {"value": 34006, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE23: {"value": 34007, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE24: {"value": 34008, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE25: {"value": 34009, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE26: {"value": 34010, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE27: {"value": 34011, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE28: {"value": 34012, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE29: {"value": 34013, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE30: {"value": 34014, "writable": false, "enumerable": true, "configurable": false},
                    TEXTURE31: {"value": 34015, "writable": false, "enumerable": true, "configurable": false},
                    ACTIVE_TEXTURE: {"value": 34016, "writable": false, "enumerable": true, "configurable": false},
                    REPEAT: {"value": 10497, "writable": false, "enumerable": true, "configurable": false},
                    CLAMP_TO_EDGE: {"value": 33071, "writable": false, "enumerable": true, "configurable": false},
                    MIRRORED_REPEAT: {"value": 33648, "writable": false, "enumerable": true, "configurable": false},
                    FLOAT_VEC2: {"value": 35664, "writable": false, "enumerable": true, "configurable": false},
                    FLOAT_VEC3: {"value": 35665, "writable": false, "enumerable": true, "configurable": false},
                    FLOAT_VEC4: {"value": 35666, "writable": false, "enumerable": true, "configurable": false},
                    INT_VEC2: {"value": 35667, "writable": false, "enumerable": true, "configurable": false},
                    INT_VEC3: {"value": 35668, "writable": false, "enumerable": true, "configurable": false},
                    INT_VEC4: {"value": 35669, "writable": false, "enumerable": true, "configurable": false},
                    BOOL: {"value": 35670, "writable": false, "enumerable": true, "configurable": false},
                    BOOL_VEC2: {"value": 35671, "writable": false, "enumerable": true, "configurable": false},
                    BOOL_VEC3: {"value": 35672, "writable": false, "enumerable": true, "configurable": false},
                    BOOL_VEC4: {"value": 35673, "writable": false, "enumerable": true, "configurable": false},
                    FLOAT_MAT2: {"value": 35674, "writable": false, "enumerable": true, "configurable": false},
                    FLOAT_MAT3: {"value": 35675, "writable": false, "enumerable": true, "configurable": false},
                    FLOAT_MAT4: {"value": 35676, "writable": false, "enumerable": true, "configurable": false},
                    SAMPLER_2D: {"value": 35678, "writable": false, "enumerable": true, "configurable": false},
                    SAMPLER_CUBE: {"value": 35680, "writable": false, "enumerable": true, "configurable": false},
                    VERTEX_ATTRIB_ARRAY_ENABLED: {
                        "value": 34338,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    VERTEX_ATTRIB_ARRAY_SIZE: {
                        "value": 34339,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    VERTEX_ATTRIB_ARRAY_STRIDE: {
                        "value": 34340,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    VERTEX_ATTRIB_ARRAY_TYPE: {
                        "value": 34341,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    VERTEX_ATTRIB_ARRAY_NORMALIZED: {
                        "value": 34922,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    VERTEX_ATTRIB_ARRAY_POINTER: {
                        "value": 34373,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: {
                        "value": 34975,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    IMPLEMENTATION_COLOR_READ_TYPE: {
                        "value": 35738,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    IMPLEMENTATION_COLOR_READ_FORMAT: {
                        "value": 35739,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    COMPILE_STATUS: {"value": 35713, "writable": false, "enumerable": true, "configurable": false},
                    LOW_FLOAT: {"value": 36336, "writable": false, "enumerable": true, "configurable": false},
                    MEDIUM_FLOAT: {"value": 36337, "writable": false, "enumerable": true, "configurable": false},
                    HIGH_FLOAT: {"value": 36338, "writable": false, "enumerable": true, "configurable": false},
                    LOW_INT: {"value": 36339, "writable": false, "enumerable": true, "configurable": false},
                    MEDIUM_INT: {"value": 36340, "writable": false, "enumerable": true, "configurable": false},
                    HIGH_INT: {"value": 36341, "writable": false, "enumerable": true, "configurable": false},
                    FRAMEBUFFER: {"value": 36160, "writable": false, "enumerable": true, "configurable": false},
                    RENDERBUFFER: {"value": 36161, "writable": false, "enumerable": true, "configurable": false},
                    RGBA4: {"value": 32854, "writable": false, "enumerable": true, "configurable": false},
                    RGB5_A1: {"value": 32855, "writable": false, "enumerable": true, "configurable": false},
                    RGB565: {"value": 36194, "writable": false, "enumerable": true, "configurable": false},
                    DEPTH_COMPONENT16: {"value": 33189, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_INDEX8: {"value": 36168, "writable": false, "enumerable": true, "configurable": false},
                    DEPTH_STENCIL: {"value": 34041, "writable": false, "enumerable": true, "configurable": false},
                    RENDERBUFFER_WIDTH: {"value": 36162, "writable": false, "enumerable": true, "configurable": false},
                    RENDERBUFFER_HEIGHT: {"value": 36163, "writable": false, "enumerable": true, "configurable": false},
                    RENDERBUFFER_INTERNAL_FORMAT: {
                        "value": 36164,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    RENDERBUFFER_RED_SIZE: {
                        "value": 36176,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    RENDERBUFFER_GREEN_SIZE: {
                        "value": 36177,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    RENDERBUFFER_BLUE_SIZE: {
                        "value": 36178,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    RENDERBUFFER_ALPHA_SIZE: {
                        "value": 36179,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    RENDERBUFFER_DEPTH_SIZE: {
                        "value": 36180,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    RENDERBUFFER_STENCIL_SIZE: {
                        "value": 36181,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: {
                        "value": 36048,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: {
                        "value": 36049,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: {
                        "value": 36050,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: {
                        "value": 36051,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    COLOR_ATTACHMENT0: {"value": 36064, "writable": false, "enumerable": true, "configurable": false},
                    DEPTH_ATTACHMENT: {"value": 36096, "writable": false, "enumerable": true, "configurable": false},
                    STENCIL_ATTACHMENT: {"value": 36128, "writable": false, "enumerable": true, "configurable": false},
                    DEPTH_STENCIL_ATTACHMENT: {
                        "value": 33306,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    NONE: {"value": 0, "writable": false, "enumerable": true, "configurable": false},
                    FRAMEBUFFER_COMPLETE: {
                        "value": 36053,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FRAMEBUFFER_INCOMPLETE_ATTACHMENT: {
                        "value": 36054,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: {
                        "value": 36055,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FRAMEBUFFER_INCOMPLETE_DIMENSIONS: {
                        "value": 36057,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FRAMEBUFFER_UNSUPPORTED: {
                        "value": 36061,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    FRAMEBUFFER_BINDING: {"value": 36006, "writable": false, "enumerable": true, "configurable": false},
                    RENDERBUFFER_BINDING: {
                        "value": 36007,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    MAX_RENDERBUFFER_SIZE: {
                        "value": 34024,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    INVALID_FRAMEBUFFER_OPERATION: {
                        "value": 1286,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    UNPACK_FLIP_Y_WEBGL: {"value": 37440, "writable": false, "enumerable": true, "configurable": false},
                    UNPACK_PREMULTIPLY_ALPHA_WEBGL: {
                        "value": 37441,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    CONTEXT_LOST_WEBGL: {"value": 37442, "writable": false, "enumerable": true, "configurable": false},
                    UNPACK_COLORSPACE_CONVERSION_WEBGL: {
                        "value": 37443,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    BROWSER_DEFAULT_WEBGL: {
                        "value": 37444,
                        "writable": false,
                        "enumerable": true,
                        "configurable": false
                    },
                    [Symbol.toStringTag]: {
                        value: "WebGLRenderingContext",
                        writable: false,
                        enumerable: false,
                        configurable: true
                    },
                })
                let t = proxy(new WebGLRenderingContext(), 'WebGLRenderingContext11')
                // let t = new WebGLRenderingContext()
                this._context = t;
            }
        // console.log('contextId res', this._context)

            return this._context;
        }

        notImplemented(
            "HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)",
            this._ownerDocument._defaultView
        );
        return null;
    }

    toDataURL(...args) {
        const canvas = this._getCanvas();
        if (canvas) {
            // //
            // // ctx.clearRect(0, 0, 200, 200); // 擦除(0,0)位置大小为200x200的矩形，擦除的意思是把该区域变为透明
            // ctx.fillStyle = '#dddddd'; // 设置颜色
            // ctx.fillRect(parseInt(Math.random() * 20 + 20), parseInt(Math.random() * 20 + 20), parseInt(Math.random() * 20 + 20), parseInt(Math.random() * 20 + 20)); // 把(10,10)位置大小为130x130的矩形涂色
            if (this.width > 100 && this.height > 100) {
                for (let i = 0; i < randInt(10, 20); i++) {
                    let ctx = canvas.getContext('2d');

                    let color = Math.floor(Math.random() * 150);
                    ctx.fillStyle = "rgba(" + color + "," + color + "," + color + ",1)";
                    ctx.fillRect(randInt(0, this.width), randInt(0, this.height), 1, 1)
                }
            }

            let res = canvas.toDataURL(...args);
            console.log(this.width, this.height, 'canvas.toDataUrl', res)
            return res;
            // return 'data:image/png;base64, ';
        }

        notImplemented(
            "HTMLCanvasElement.prototype.toDataURL (without installing the canvas npm package)",
            this._ownerDocument._defaultView
        );
        return null;
    }

    toBlob(callback, type, qualityArgument) {
        const window = this._ownerDocument._defaultView;
        const canvas = this._getCanvas();
        if (canvas) {
            const options = {};
            switch (type) {
                case "image/jpg":
                case "image/jpeg":
                    type = "image/jpeg";
                    options.quality = qualityArgument;
                    break;
                default:
                    type = "image/png";
            }
            canvas.toBuffer((err, buff) => {
                if (err) {
                    throw err;
                }
                callback(new window.Blob([buff], {type}));
            }, type, options);
        } else {
            notImplemented(
                "HTMLCanvasElement.prototype.toBlob (without installing the canvas npm package)",
                window
            );
        }
    }

    get width() {
        const parsed = parseInt(this.getAttributeNS(null, "width"));
        return isNaN(parsed) || parsed < 0 || parsed > 2147483647 ? 300 : parsed;
    }

    set width(v) {
        v = v > 2147483647 ? 300 : v;
        this.setAttributeNS(null, "width", String(v));
    }

    get height() {
        const parsed = parseInt(this.getAttributeNS(null, "height"));
        return isNaN(parsed) || parsed < 0 || parsed > 2147483647 ? 150 : parsed;
    }

    set height(v) {
        v = v > 2147483647 ? 150 : v;
        this.setAttributeNS(null, "height", String(v));
    }
}

// We need to wrap the methods that receive an image or canvas object
// (luckily, always as the first argument), so that these objects can be
// unwrapped an the expected types passed.
function wrapNodeCanvasMethod(ctx, name) {
    const prev = ctx[name];
    ctx[name] = function (image, ...rest) {
        const impl = idlUtils.implForWrapper(image);
        if (impl) {
            if (impl instanceof HTMLCanvasElementImpl && !impl._canvas) {
                impl._getCanvas();
            }
            image = impl._image || impl._canvas;
        }
        return prev.call(ctx, image, ...rest);
    };
}

module.exports = {
    implementation: HTMLCanvasElementImpl
};
