zy-补环境框架-实现-window补环境

This commit is contained in:
aiyingfeng 2023-08-12 15:13:35 +08:00
parent 71808525cb
commit d01ecdf3b0
7 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,40 @@
import fs from 'fs'
// 框架的工具模块
import vmtools from './tools/node.js'
import htmlElements from './browser/HTMLElements/htmlElements.node.js'
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default function GetCode(config,fun_text){
let code = ''
// 引入框架的工具代码
code += vmtools() +'\r\n'
// 引入用户框架配置
for (let item in config) {
code += 'catvm.memory.config.' + item + '=' + config[item] + '\r\n'
}
// 引入浏览器相关,引入尽量按浏览器顺序执行
code += fs.readFileSync(`${__dirname}/browser/eventTarget.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/windowProperties.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/window.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/location.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/navigator.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/history.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/screen.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/storage.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/mimeType.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/plugin.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/pluginArray.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/mimeTypeArray.js`) + '\r\n'
code += htmlElements() + '\r\n'
code += fs.readFileSync(`${__dirname}/browser/document.js`) + '\r\n'
// 引入用户自定义环境
code += 'debugger;\r\n'
return code
}

View File

@ -0,0 +1,9 @@
global.catvm = {}
// 框架运行内存
catvm.memory = {
config: {print: false, proxy: false},
}
catvm.memory.htmlElements = {}
catvm.memory.listeners = {}
catvm.memory.PluginArray = {}

View File

@ -0,0 +1,15 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default function GetCode(){
let code = ''
code += fs.readFileSync(`${__dirname}/memory.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/safefunction.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/print.js`) + '\r\n'
code += fs.readFileSync(`${__dirname}/proxy.js`) + '\r\n'
return code
}

View File

@ -0,0 +1,15 @@
// 框架日志功能
catvm.print = {}
catvm.memory.print = []
// 是否输出日志
catvm.print.log = function(){
if (catvm.memory.config.print){
}
}
// 获得所有日志
catvm.print.getall = function(){
}

View File

@ -0,0 +1,22 @@
// 框架代理功能
catvm.proxy = function(o){
if(catvm.memory.config.proxy == false){return o}
return new Proxy(o,{
set(target,key,value)
{
console.log('set',target,key,value);
return Reflect.set(...arguments);
},
get(target,key,receiver)
{
console.log('get',target,key,target[key]);
return target[key];
},
deleteProperty:function(target,key){
console.log('delete',target,key);
return true
}
});
}

View File

@ -0,0 +1,27 @@
// 补环境的自定义方法通过toString方法被检测
;(() => {
'use strict';
const $toString = Function.toString
const myFunction_toString_symbol = Symbol('('.concat('', ')_', (Math.random() + '').toString(36)))
const myToString = function () {
return typeof this == 'function' && this[myFunction_toString_symbol] || $toString.call(this)
}
function set_native(func, key, value) {
Object.defineProperty(func, key, {
"enumerable": false,
'configurable': true,
'writable': true,
'value': value
})
}
delete Function.prototype['toString'];// 删除原型链上的toString
set_native(Function.prototype, 'toString', myToString);// 自己定义一个getter方法
// 套娃给 toString 方法设置一个 toString
set_native(Function.prototype.toString, myFunction_toString_symbol, 'function toString(){ [native code] }')
this.catvm.safefunction = (func) => {
set_native(func, myFunction_toString_symbol, `function ${myFunction_toString_symbol, func.name || ''}() { [native code] }`)
}
}).call(this);

View File

@ -0,0 +1,5 @@
//更改浏览器某些参数
catvm.AddPlugin = function(data){
}