diff --git a/packages/utils/src/mini-adapter/XMLHttpRequest.ts b/packages/utils/src/mini-adapter/XMLHttpRequest.ts index ed0ac3973d..6987309407 100755 --- a/packages/utils/src/mini-adapter/XMLHttpRequest.ts +++ b/packages/utils/src/mini-adapter/XMLHttpRequest.ts @@ -23,7 +23,7 @@ function _changeReadyState(readyState, event = { readyState }) { _triggerEvent.call(this, 'readystatechange', event); } -export class XMLHttpRequest extends EventTarget { +export class $XMLHttpRequest extends EventTarget { public static UNSEND: number; public static OPENED: number; public static HEADERS_RECEIVED: number; @@ -107,7 +107,7 @@ export class XMLHttpRequest extends EventTarget { public open(method, url /* GET/POST*/, flag) { this._method = method; this._url = url; - _changeReadyState.call(this, XMLHttpRequest.OPENED); + // _changeReadyState.call(this, XMLHttpRequest.OPENED); } public overrideMimeType() {} @@ -130,45 +130,45 @@ export class XMLHttpRequest extends EventTarget { this.response = null; const onSuccess = ({ data, status, headers }) => { - status = status === undefined ? 200 : status; + // status = status === undefined ? 200 : status; - try { - if ( - data == null || - (data instanceof ArrayBuffer && data.byteLength == 0) - ) { - status = 404; - } - } catch (e) {} + // try { + // if ( + // data == null || + // (data instanceof ArrayBuffer && data.byteLength == 0) + // ) { + // status = 404; + // } + // } catch (e) {} - this.status = status; - if (headers) { - _responseHeader.set('responseHeader', headers); - } - _triggerEvent.call(this, 'loadstart'); - _changeReadyState.call(this, XMLHttpRequest.HEADERS_RECEIVED); - _changeReadyState.call(this, XMLHttpRequest.LOADING); + // this.status = status; + // if (headers) { + // _responseHeader.set('responseHeader', headers); + // } + // _triggerEvent.call(this, 'loadstart'); + // // _changeReadyState.call(this, XMLHttpRequest.HEADERS_RECEIVED); + // // _changeReadyState.call(this, XMLHttpRequest.LOADING); - this.response = data; + // this.response = data; - if (data instanceof ArrayBuffer) { - // TODO temporary solution, fix native gc error. - this.response = data.slice(0); - Object.defineProperty(this, 'responseText', { - enumerable: true, - configurable: true, - get() { - throw new Error( - 'InvalidStateError : responseType is ' + this._responseType, - ); - }, - }); - } else { - this.responseText = data; - } - _changeReadyState.call(this, XMLHttpRequest.DONE); - _triggerEvent.call(this, 'load'); - _triggerEvent.call(this, 'loadend'); + // if (data instanceof ArrayBuffer) { + // // TODO temporary solution, fix native gc error. + // this.response = data.slice(0); + // Object.defineProperty(this, 'responseText', { + // enumerable: true, + // configurable: true, + // get() { + // throw new Error( + // 'InvalidStateError : responseType is ' + this._responseType, + // ); + // }, + // }); + // } else { + // this.responseText = data; + // } + // _changeReadyState.call(this, XMLHttpRequest.DONE); + // _triggerEvent.call(this, 'load'); + // _triggerEvent.call(this, 'loadend'); }; const onFail = (e) => { @@ -229,8 +229,8 @@ export class XMLHttpRequest extends EventTarget { } // TODO 没法模拟 HEADERS_RECEIVED 和 LOADING 两个状态 -XMLHttpRequest.UNSEND = 0; -XMLHttpRequest.OPENED = 1; -XMLHttpRequest.HEADERS_RECEIVED = 2; -XMLHttpRequest.LOADING = 3; -XMLHttpRequest.DONE = 4; +$XMLHttpRequest.UNSEND = 0; +$XMLHttpRequest.OPENED = 1; +$XMLHttpRequest.HEADERS_RECEIVED = 2; +$XMLHttpRequest.LOADING = 3; +$XMLHttpRequest.DONE = 4; diff --git a/packages/utils/src/mini-adapter/document.ts b/packages/utils/src/mini-adapter/document.ts index 315a80e5c5..df61f05ff1 100644 --- a/packages/utils/src/mini-adapter/document.ts +++ b/packages/utils/src/mini-adapter/document.ts @@ -4,7 +4,7 @@ import { Event } from './Event'; import { HTMLElement } from './HTMLElement'; import { HTMLVideoElement } from './HTMLVideoElement'; import { Image } from './Image'; -import { location } from './location'; +import { $location } from './location'; class Body extends HTMLElement { constructor() { @@ -55,7 +55,7 @@ export const $document = { scripts: [], style: {}, - location: location, + location: $location, ontouchstart: null, ontouchmove: null, diff --git a/packages/utils/src/mini-adapter/index.ts b/packages/utils/src/mini-adapter/index.ts index e8bdbc770a..b4359b5ddd 100644 --- a/packages/utils/src/mini-adapter/index.ts +++ b/packages/utils/src/mini-adapter/index.ts @@ -13,7 +13,7 @@ import { HTMLMediaElement } from './HTMLMediaElement'; import { HTMLVideoElement } from './HTMLVideoElement'; import { Image } from './Image'; import { ImageData } from './ImageData'; -import { location } from './location'; +import { $location } from './location'; import { navigator } from './navigator'; import { Node } from './Node'; import { performance } from './performance'; @@ -25,7 +25,7 @@ import { screen } from './screen'; import { URL } from './url'; import { WebGLRenderingContext } from './WebGL'; import { WebGL2RenderingContext } from './WebGL2'; -import { XMLHttpRequest } from './XMLHttpRequest'; +import { $XMLHttpRequest } from './XMLHttpRequest'; import { globalWindow } from './global' @@ -58,7 +58,7 @@ export const miniWindow = { requestAnimationFrame, cancelAnimationFrame, screen, - XMLHttpRequest, + XMLHttpRequest: $XMLHttpRequest, performance, URL, WebGLRenderingContext, @@ -81,8 +81,8 @@ export const miniWindow = { } as Window & typeof globalThis; export const $window = isMini ? miniWindow : globalWindow; -export const $XMLHttpRequest = isMini ? XMLHttpRequest: globalWindow.XMLHttpRequest; -export const $location = isMini ? location : globalWindow.location; +export const $XMLHttpRequest = isMini ? $XMLHttpRequest: globalWindow.XMLHttpRequest; +export const $location = isMini ? $location : globalWindow.location; // TODO: // export { registerCanvas, registerCanvas2D } from './register'; diff --git a/packages/utils/src/mini-adapter/location.ts b/packages/utils/src/mini-adapter/location.ts index 11532dfefc..e9468fba8a 100644 --- a/packages/utils/src/mini-adapter/location.ts +++ b/packages/utils/src/mini-adapter/location.ts @@ -1,6 +1,6 @@ // @ts-nocheck // tslint:disable -export let location = { +export let $location = { href: '', protocol: '', host:''