Merge pull request #705 from javascript-obfuscator/disable-console-output-proto

Fixed console functions prototype
This commit is contained in:
Timofey Kachalov
2020-08-14 01:18:12 +03:00
committed by GitHub
5 changed files with 36 additions and 5 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
@@ -14,7 +14,9 @@ export function ConsoleOutputDisableTemplate (): string {
const methodName = methods[index];
const originalFunction = consoleObject[methodName] || func;
func.__proto__ = {callControllerFunctionName}.bind({callControllerFunctionName});
func.toString = originalFunction.toString.bind(originalFunction);
consoleObject[methodName] = func;
}
});
@@ -44,13 +44,15 @@ const getPartialConsoleObjectGlobalVariableTemplate: () => string = () => `
/**
* @param templateData
* @param {string} callsControllerFunctionName
* @param {string} consoleMethod
* @param {keyof Console} consoleMethod
* @param {string} additionalCode
* @returns {Function}
*/
function getFunctionFromTemplate (
templateData: any,
callsControllerFunctionName: string,
consoleMethod: keyof Console
consoleMethod: keyof Console,
additionalCode: string = ''
): Function {
const formattedTemplate: string = format(ConsoleOutputDisableTemplate(), templateData);
@@ -67,6 +69,8 @@ function getFunctionFromTemplate (
console.${consoleMethod}(1);
console.${consoleMethod}.toString();
${additionalCode}
`);
}
@@ -186,6 +190,31 @@ describe('ConsoleOutputDisableTemplate', () => {
});
});
describe('`bind` call', () => {
consoleMethods.forEach((consoleMethodName: keyof Console, index: number) => {
describe(`Variant #${index + 1}: \`console.${consoleMethodName}\` call`, () => {
let testFunc: () => void;
beforeEach(() => {
testFunc = () => getFunctionFromTemplate(
{
consoleLogDisableFunctionName,
callControllerFunctionName,
globalVariableTemplate: GlobalVariableTemplate1(),
},
callControllerFunctionName,
consoleMethodName,
`console.${consoleMethodName}.bind();`
)();
});
it(`should does not throw error during \`console.${consoleMethodName}.bind\` call`, () => {
assert.doesNotThrow(testFunc);
});
});
});
});
afterEach(() => {
consoleObjectStubs.forEach((stub: sinon.SinonStub) => stub.restore());
});