6.7.0 - Alpha6 - Fine tuning

This commit is contained in:
SuperMonster003
2025-10-01 00:13:00 +08:00
parent 4fe314d301
commit f3e04b9ca2
165 changed files with 2356 additions and 2413 deletions

View File

@@ -1,33 +1,35 @@
(function(){
let {setReadonlyAttribute} = require("modules/axios/browser-libs/utils.js");
(function () {
let { setReadonlyAttribute } = require('modules/axios/browser-libs/utils.js');
let Event = function(type) {
setReadonlyAttribute(this, 'bubbles', false);
setReadonlyAttribute(this, 'eventPhase', 0);
//是否可取消
setReadonlyAttribute(this, 'cancelable', false)
this.cancelBubble = false;
setReadonlyAttribute(this, 'defaultPrevented', false)
//节点
setReadonlyAttribute(this, 'target', null)
setReadonlyAttribute(this, 'currentTarget', null)
setReadonlyAttribute(this, 'type', type)
//时间截
Object.defineProperty(this, 'timeStamp', {
get: function() {
return Date.now() - Event._loadTimeStamp;
}
})
setReadonlyAttribute(this, 'isTrusted', false)
}
Event.prototype[Symbol.toStringTag] = 'Event';
Event._loadTimeStamp = Date.now();
Event.prototype.preventDefault = function() {}
Event.prototype.stopPropagation = function() {}
Event.prototype.stopImmediatePropagation = function() {
let Event = function (type) {
setReadonlyAttribute(this, 'bubbles', false);
setReadonlyAttribute(this, 'eventPhase', 0);
// 是否可取消
setReadonlyAttribute(this, 'cancelable', false);
this.cancelBubble = false;
setReadonlyAttribute(this, 'defaultPrevented', false);
// 节点
setReadonlyAttribute(this, 'target', null);
setReadonlyAttribute(this, 'currentTarget', null);
setReadonlyAttribute(this, 'type', type);
// 时间截
Object.defineProperty(this, 'timeStamp', {
get: function () {
return Date.now() - Event._loadTimeStamp;
},
});
setReadonlyAttribute(this, 'isTrusted', false);
};
Event.prototype[Symbol.toStringTag] = 'Event';
Event._loadTimeStamp = Date.now();
Event.prototype.preventDefault = function () {
};
Event.prototype.stopPropagation = function () {
};
Event.prototype.stopImmediatePropagation = function () {
}
};
module.exports = Event
})()
module.exports = Event;
})();

View File

@@ -24,7 +24,7 @@
let atl = new AsyncThreadLock();
///////XMLHttpRequest对象
// XMLHttpRequest 对象
let XMLHttpRequest = function () {
this.responseType = 'text';
this.timeout = 0;
@@ -80,7 +80,7 @@
return body.byteStream();
},
parser: function (type, xhr, body) {
//log('resType:', type)
// log('resType:', type)
const fn = this[type.toLowerCase()] || this['text'];
xhr._setReadyState(3);
const data = fn.call(this, xhr, body);
@@ -104,7 +104,7 @@
this._requestData.url.username(user).password(password);
}
this._setReadyState(1);
//log(arguments)
// log(arguments)
};
XMLHttpRequest.prototype.send = function (body) {
atl.addTask();
@@ -202,25 +202,25 @@
let type = xhr._requestData.headers.get('content-type');
const method = xhr._requestData.method.toLowerCase();
const url = xhr._requestData.url;
//需要请求体的http方法
// 需要请求体的 http 方法
const dataMethod = [ 'post', 'put', 'patch', 'delete' ];
if (type === 'application/x-www-form-urlencoded') type = null;
if (dataMethod.some(val => val === method)) {
if (body instanceof RequestBody) return body;
if (body instanceof FormData) {
//表单对象
// 表单对象
return body._toRequseBody();
} else if (body instanceof Blob) {
//Blob对象
// Blob 对象
return RequestBody.create(MediaType.parse(type || body.type), body._file);
} else if (body instanceof InputStream) {
//java输入流
// java 输入流
return RequestBody.create(MediaType.parse(type || 'application/octet-stream'), body);
} else if (typeof body === 'string') {
//字符串
// 字符串
return RequestBody.create(MediaType.parse(type || 'text/plain'), body);
} else if (body) {
//json
// json
return RequestBody.create(MediaType.parse('application/json'), JSON.stringify(body));
}
return RequestBody.create(MediaType.parse('text/plain'), '');

View File

@@ -1,12 +1,12 @@
(function() {
(function () {
function setReadonlyAttribute(obj, att, value, enumerable) {
enumerable = (enumerable === undefined) ? true : enumerable
enumerable = (enumerable === undefined) ? true : enumerable;
Object.defineProperty(obj, att, {
value,
writable: false,
configurable: true,
enumerable,
})
});
}
function copyInputStream(inputstream, outputstream) {
@@ -17,40 +17,43 @@
}
outputstream.flush();
}
//此对象用于确保在多线程执行异步任务时主线程不会因空闲而停止
// 此对象用于确保在多线程执行异步任务时主线程不会因空闲而停止
function AsyncThreadLock() {
this.lock = threads.lock();
this.tasks = 0;
this.intervalId = null;
}
setReadonlyAttribute(AsyncThreadLock, 'teeFn', function() {
setReadonlyAttribute(AsyncThreadLock, 'teeFn', function () {
this.intervalId = setInterval(() => {
this.lock.lock();
if (this.tasks === 0) {
clearInterval(this.intervalId)
clearInterval(this.intervalId);
this.intervalId = null;
}
this.lock.unlock();
}, 200)
}, false)
}, 200);
}, false);
AsyncThreadLock.prototype.addTask = function() {
AsyncThreadLock.prototype.addTask = function () {
this.lock.lock();
this.tasks++;
if (this.intervalId === null) {
AsyncThreadLock.teeFn.call(this)
AsyncThreadLock.teeFn.call(this);
}
this.lock.unlock();
}
AsyncThreadLock.prototype.removeTask = function() {
};
AsyncThreadLock.prototype.removeTask = function () {
this.lock.lock();
this.tasks--;
this.lock.unlock();
}
};
module.exports = {
setReadonlyAttribute,
copyInputStream,
AsyncThreadLock,
}
})()
};
})();