Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
How to turn a function into a string without activation/use of any modules in javascript

Apparently this might look at a duplicate.. but let me explain the problem.
For the sake of the question ALL I can assume is that my code will be run, I do not know anything about the modules(if they're fake or something) and can only trust the things that get set in instances that only my code will control(or originally set that they cannot be configured)

What I want to do is to as my heading says, to convert a function to a string.. however all my attempts at conversion depend on a module that can be overwritten by the client

Function.prototype.toString=()=>"pwned" //work of the client
//failed attempts to convert to string below
console.log(`${Object.keys}`) //"pwned"
console.log(Object.keys+'') //"pwned"
console.log(Object.keys.toLocaleString()) //"pwned"

Starting out with the only assumption I'm making(that my code is being run), I tried this below however it returns undefined(I thought returning nothing would somehow make it the default string)

//infinityLoop is a function I write(all this is inside another self calling function) and the name suggests what it does
//the concept in this example is to run the code and if it smells anything suspicious, infinite loop
try{(function(href){
var symbol=Symbol.toPrimitive, c=1, here=arguments.callee
var testObj={[symbol]:function(){return here===arguments.callee.caller?c++:infinityLoop()}}
if(testObj-0!==1 || c!==2){throw "bruh"}
function str(item){
  var measure=null, unit={}, count=0
  function verifier(hint){
    const condition=hint!=="default" || this!==item || verifier.caller!==str || count!==0
    if(condition){infinityLoop()}  else{ measure=unit; count++ }
  }
  item[symbol]=verifier; const string=item+''
  if(measure!==unit || count !==1){throw "bruh"}
  delete item[symbol]; return string
}
str(Object.keys) //"undefined"
//I get to control the conversion but I still can't convert it ;-;
})()}catch{infinityLoop()}

Is it possible to convert a function to string without overwritable modules or is this a ridiculous impossible question?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is not possible.

If you don't control and/or trust the environment that is running the code, you also cannot control and/or trust what the code does.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda