Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!