function deEnvironment_defineHeader_function_proto(ObjEct){ //第一步 定义头部函数,并关联上级原型链 ObjEct.name = ObjEct.constructor.name; let jsCode = ""; try { new ObjEct() jsCode += `${ObjEct.name} = function ${ObjEct.name}(){ debugger;\r\n};` + "\r\n"; }catch (e){ jsCode += `${ObjEct.name} = function ${ObjEct.name}(){ plugin.throwError(${e.constructor.name},'${e.message}');\r\n};` + "\r\n" } jsCode += `plugin.func_set_native(${ObjEct.name})` + "\r\n"; jsCode += `plugin.rename(${ObjEct.name}.prototype, "${ObjEct.name}")` + "\r\n"; if (ObjEct.__proto__.name != "Object" && ObjEct.__proto__.name != ""){ jsCode += `Object.setPrototypeOf(${ObjEct.name}.prototype,${ObjEct.__proto__.name}.prototype)` + "\r\n"; } return jsCode; } function deEnvironment_Shelling_proto(ObjEct,myThis){ //第二步 脱取原型链属性 let jsCode = ""; let temp = myThis; let isSos; try { while (true){ temp = temp.__proto__; if(temp.constructor.name === ObjEct.name){ isSos = true; break; } } }catch (e) { console.error(`未找到该对象${myThis.constructor.name}上的原型${ObjEct.name}`) } if (isSos){ function getCode(OwnPropertyName,OwnPropertyDescriptor){ function getValueOrGetSet(functionName){ let jsCodeTemp = ""; if(OwnPropertyDescriptor.value == undefined){ if(value === "" || value === undefined || value === "''"){ jsCodeTemp = `plugin.defineProperty(${ObjEct.name}.prototype,'${OwnPropertyName}',undefined,${OwnPropertyDescriptor.configurable},${OwnPropertyDescriptor.enumerable},${OwnPropertyDescriptor.writable},function (){ debugger; },function (value){ debugger; });plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${ObjEct.name}.prototype)['${OwnPropertyName}'].get,'get ${OwnPropertyName}');plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${ObjEct.name}.prototype)['${OwnPropertyName}'].set,'set ${OwnPropertyName}');` }else { jsCodeTemp = `plugin.defineProperty(${ObjEct.name}.prototype,'${OwnPropertyName}',undefined,${OwnPropertyDescriptor.configurable},${OwnPropertyDescriptor.enumerable},${OwnPropertyDescriptor.writable},function (){ debugger; },function (value){ debugger; });plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${ObjEct.name}.prototype)['${OwnPropertyName}'].get,'get ${OwnPropertyName}');plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${ObjEct.name}.prototype)['${OwnPropertyName}'].set,'set ${OwnPropertyName}');` } }else { jsCodeTemp = `plugin.defineProperty(${ObjEct.name}.prototype,'${OwnPropertyName}',${value},${OwnPropertyDescriptor.configurable},${OwnPropertyDescriptor.enumerable},${OwnPropertyDescriptor.writable});` if (functionName){ jsCodeTemp += `plugin.func_set_native(${ObjEct.name}.prototype.${functionName});`; } } return jsCodeTemp; } let code = ""; let value = myThis[OwnPropertyName]; switch (typeof value){ case "string": value = `'${value}'`; code = getValueOrGetSet(); break; case "number": code = getValueOrGetSet(); break; case "function": const functionName = value.name; value = `function ${functionName}(){ debugger; }` code = getValueOrGetSet(functionName); break; case "object": // if(value instanceof Array){ // value = "[]"; // }else if(value == null){ // value = "null" // }else { // value = "{}"; // } value = "(function(){debugger;})()"; code = getValueOrGetSet(); break; case "boolean": code = getValueOrGetSet(); break; case "undefined": value = `undefined`; code = getValueOrGetSet(); break; default: debugger; } return code; } let OwnPropertyNames = Object.getOwnPropertyNames(temp); let OwnPropertyDescriptors = Object.getOwnPropertyDescriptors(temp); OwnPropertyNames.forEach((key) =>{ if (key !== "constructor" && key !== "arguments" && key !== "caller" && key !== "length" && key !== "name"){ jsCode += getCode(key,OwnPropertyDescriptors[key]) + "\r\n"; } }) } return jsCode; } function deEnvironment_main_proto(ObjEct,myThis){ let jsCode = ""; jsCode += deEnvironment_defineHeader_function_proto(ObjEct) + "\r\n"; //第一步 定义头部函数,并关联上级原型链 jsCode += deEnvironment_Shelling_proto(ObjEct,myThis) + "\r\n"; //第二步 脱取原型链属性 return jsCode; } function deEnvironment_defineHeader_function(myThis,name){ let jsCode = ""; jsCode += `${name} = {};` + "\r\n"; if (myThis.constructor.name != "" && myThis.constructor.name != "Object"){ jsCode += `Object.setPrototypeOf(${name}, ${myThis.constructor.name}.prototype);` + "\r\n"; } return jsCode; } function deEnvironment_Shelling(myThis,name){ let jsCode = ""; function getCode(OwnPropertyName,OwnPropertyDescriptor){ function getValueOrGetSet(functionName){ let jsCodeTemp = ""; if(OwnPropertyDescriptor.value == undefined){ jsCodeTemp = `plugin.defineProperty(${name},'${OwnPropertyName}',undefined,${OwnPropertyDescriptor.configurable},${OwnPropertyDescriptor.enumerable},${OwnPropertyDescriptor.writable},function (){ debugger; },function (){ debugger; });plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${name})['${OwnPropertyName}'].get,'get ${OwnPropertyName}');plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${name})['${OwnPropertyName}'].set,'set ${OwnPropertyName}');` }else { jsCodeTemp = `plugin.defineProperty(${name},'${OwnPropertyName}',${value},${OwnPropertyDescriptor.configurable},${OwnPropertyDescriptor.enumerable},${OwnPropertyDescriptor.writable});` if (functionName){ jsCodeTemp += `plugin.func_set_native(${name}.${functionName});`; } } return jsCodeTemp; } let code = ""; let value = myThis[OwnPropertyName]; switch (typeof value){ case "string": value = `'${value}'`; code = getValueOrGetSet(); break; case "number": code = getValueOrGetSet(); break; case "function": const functionName = value.name; value = `function ${functionName}(){ debugger; }` code = getValueOrGetSet(functionName); break; case "object": // if(value instanceof Array){ // value = "[]"; // }else if(value == null){ // value = "null" // }else { // value = "{}"; // } value = "(function(){debugger;})()"; code = getValueOrGetSet(); break; case "boolean": code = getValueOrGetSet(); break; case "undefined": value = `undefined`; code = getValueOrGetSet(); break; default: debugger; } return code; } let OwnPropertyNames = Object.getOwnPropertyNames(myThis); let OwnPropertyDescriptors = Object.getOwnPropertyDescriptors(myThis); OwnPropertyNames.forEach((key) =>{ if (key !== "constructor" && key !== "arguments" && key !== "caller" && key !== "length" && key !== "name"){ if (key,OwnPropertyDescriptors[key] == undefined) { return; } jsCode += getCode(key,OwnPropertyDescriptors[key]) + "\r\n"; } }) return jsCode; } function deEnvironment_main(myThis,name){ let jsCode = ""; jsCode += deEnvironment_defineHeader_function(myThis,name) + "\r\n"; //第一步 定义头部函数,并关联上级原型链 jsCode += deEnvironment_Shelling(myThis,name) + "\r\n"; //第二步 脱取对象属性 return jsCode; } let code = ''; // code = deEnvironment_main(document.body.style,"CSSStyleDeclaration"); code = deEnvironment_main_proto(HTMLDivElement,document.createElement("div")); copy(code) console.log(code)
标签:function,code,jsCode,name,一键,ObjEct,环境,value From: https://www.cnblogs.com/angdh/p/17533603.html