Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sure, let's do that :)

    if( Function.prototype.toString.call(add).includes("multiplier") ) throw "boom!";
> Edit: OK I think we are stretching HN comment ettiquete to far with this much code. This was fun though. Thanks.

Huh? Would you mind to educate me about what part of the ettiquete we are not following?



IDK not a real thing, you just never see it. I feel like it's a forum not a chat room and it doesn't collapse deep threads by default so the long code makes the page very long. Probably doesn't matter though.

At this point we can go ahead and break the world:

  add.toString = () => `function add({ ...args }) { const { a, b, ...rest } = args; if (typeof a !== "number" || typeof b !== "number") { throw "no"; } if (Object.keys(rest).length > 0) { throw "no";} return a + b;}`;
  _add.toString = () => `function add({ ...args }) { const { a, b, ...rest } = args; if (typeof a !== "number" || typeof b !== "number") { throw "no"; } if (Object.keys(rest).length > 0) { throw "no";} return a + b;}`;
  Function.prototype.toString = () => `function add({ ...args }) { const { a, b, ...rest } = args; if (typeof a !== "number" || typeof b !== "number") { throw "no"; } if (Object.keys(rest).length > 0) { throw "no";} return a + b;}`;


I think it's very interesting for others to follow this.

Now, we are leaving the original scope (not just changing a function, but modifying globals). read-only globals even. But prepare for my counter:

    let frame = document.createElement('x');
    document.body.appendChild(frame);
    if( frame.contentWindow.Function.toString.call(add).includes("multiplier")  ) throw "boom!";
You might go to also kill "document.createElement", but there are many ways for me to get a new frame. I think when we come to the point where all these are disabled, I would say only a small fraction of the websites that use javascript would still properly operate. It would be your victory though. ;)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: