Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed global loop variable which is corrupted. #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions jsfuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@
output = "+[]";

if (number > 0){ output = "+!" + output; }
for (i = 1; i < number; i++){ output = "+!+[]" + output; }
for (var i = 1; i < number; i++){ output = "+!+[]" + output; }
if (number > 1){ output = output.substr(1); }

MAPPING[number] = "[" + output + "]";
}
}

function replaceMap(){
var character = "", value, original, i, key;
var value;

function replace(pattern, replacement){
value = value.replace(
Expand All @@ -156,22 +156,34 @@
var output = "+[]";

if (head > 0){ output = "+!" + output; }
for (i = 1; i < head; i++){ output = "+!+[]" + output; }
for (var i = 1; i < head; i++){ output = "+!+[]" + output; }
if (head > 1){ output = output.substr(1); }

return [output].concat(values).join("+").replace(/(\d)/g, digitReplacer);
}

for (i = MIN; i <= MAX; i++){
character = String.fromCharCode(i);
for (var i = MIN; i <= MAX; i++){
var character = String.fromCharCode(i);
value = MAPPING[character];
if(!value) {continue;}
original = value;

for (key in CONSTRUCTORS){
replace("\\b" + key, CONSTRUCTORS[key] + '["constructor"]');
}

var original = value;

// Due to mutual dependencies of CONSTRUCTORS replacements,
// iterate until no more matches can be replaced.
var changed = false;
do {
changed = false;
for (key in CONSTRUCTORS){
function detect_changed(match){
changed = true;
return CONSTRUCTORS[key] + '["constructor"]';
}
replace("\\b" + key, detect_changed);
}
} while(changed);

// Change handling like CONSTRUCTORS is not necessary
// since SIMPLE has no mutual dependencie
for (key in SIMPLE){
replace(key, SIMPLE[key]);
}
Expand Down