Skip to content

Conversation

@LuanRT
Copy link
Owner

@LuanRT LuanRT commented Feb 21, 2025

This fixes an issue where a conflic with reserved keywords would happen inside the interpreter if a string being evaluated was 'break' or 'continue'.

Related issues:
LuanRT/YouTube.js#905
FreeTubeApp/FreeTube#6845
iv-org/invidious-companion#50
FreeTubeApp/FreeTube#6701
imputnet/cobalt#1123

Example:

var arr = ['a', 'break', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'];
arr[0] = arr;

function mod(I, u) {
    if (I.length != 0) {
        u = (u % I.length + I.length) % I.length;
        var test = I[0];  // Circular reference.
        console.log('Array ref:', test);
        const breakString = I[u];
        console.log({
            iVal: I[u],
            u: I[0]
        })
        // The interpreter will halt here and jump to the 
        // end of the function.
        // So I[u] = test is never executed.
        I[0] = breakString;
        console.log({
            iVal: I[0]
        })
        I[u] = test;
        console.log({
            iVal: I[u]
        });
    }
}

mod(arr, 1);

Expected output:

Array ref: <ref *1> [
  [Circular *1],
  'break',
  'c',
  'd',
  'e',
  'f',
  'g',
  'h',
  'i',
  'j',
  'k',
  'l'
]
{
  iVal: 'break',
  u: <ref *1> [
    [Circular *1],
    'break',
    'c',
    'd',
    'e',
    'f',
    'g',
    'h',
    'i',
    'j',
    'k',
    'l'
  ]
}
{ iVal: 'break' }
{
  iVal: <ref *1> [
    'break',
    [Circular *1],
    'c',
    'd',
    'e',
    'f',
    'g',
    'h',
    'i',
    'j',
    'k',
    'l'
  ]
}

Current output:

Array ref: <ref *1> [
  [Circular *1], 'break',
  'c',           'd',
  'e',           'f',
  'g',           'h',
  'i',           'j',
  'k',           'l'
]
{
  iVal: 'break',
  u: <ref *1> [
    [Circular *1], 'break',
    'c',           'd',
    'e',           'f',
    'g',           'h',
    'i',           'j',
    'k',           'l'
  ]
}

@LuanRT LuanRT merged commit dfeed9b into main Feb 21, 2025
2 checks passed
@LuanRT LuanRT deleted the fix/internal-conflicts branch February 21, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants