Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6937467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:21:59+00:00 2026-05-27T12:21:59+00:00

I am trying to get the surrounding js code of the current scope as

  • 0

I am trying to get the surrounding js code of the current scope as text. It’s meant to be embedded in a live editor afterwards. Is that possible? In the worst case, it can go through Rhino.

thanks a lot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:22:00+00:00Added an answer on May 27, 2026 at 12:22 pm

    In general, no. JavaScript does not provide a reliable way to introspect over variable definitions or the call stack.

    arguments.callee and arguments.caller do provide introspection into the set of functions on the call stack as long as there are no recursive calls, so you can extract source code by walking that. But it can be defeated by

    function defeatArgumentsCaller(f, args, called) {
      if (!called) { return defeatArgumentsCaller(f, args, true); }
      return f.apply(args);
    }
    
    function f() {
      defeatArgumentsCaller(g, []);
    }
    

    When f is called, g will be unable to determine that it was called by f by looking at arguments.caller.

    function g() {
      var fn = arguments.callee;
      while (true) {
        alert(fn.name);
        var caller = fn.caller;
        // defaultArgumentsCaller is itself, not f.
        if (!caller || caller == fn) { break; }
        fn = caller;
      }
    }
    

    They don’t allow introspection over the set of defined symbols, e.g. those introduced via with or catch so any attempt to enumerate the available local variables at the ... in

    function f(o) {
      try {
        throw null;
      } catch (e) {
        with (o) { 
          ...
        }
      }
    }
    

    by examining the call stack and function source code will miss some defined symbols.

    The call stack is also different from the stack of closures. For example, in

    function counter() {
      var n;
      return function (f) { return f(n++); };
    }
    
    counter()(eval);
    

    eval runs in a context that has more symbols available than the call stack would suggest since counter is not on the call stack at the point eval is called.

    Rhino allows access to the current scope as a Scriptable which exposes the getIds method which can be used to enumerate the names in the current stack frame, and you can walk up to higher stack frames via getPrototype.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get comfortable with jQuery and I have encountered some sample code that
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
My Code preg_match_all('/\{([\w]+)(\s.*)?[^\}]\}(.*)\{\/\w+[^\}]\}/', $nbody, $matches ); My Template rtrim: Beginning Text{rtrim} String {/rtrim}Surrounding Text
I'm trying to write some code which will highlight any text selected on a
Trying to get MVC running on Mono 2.4 (which is possible, according to some
I am trying get a div that I have hidden to show in the
Trying to get a list of all possible combinations of 2 arrays passed in
I am trying get all commments relateed to my current post , I am
Trying to get my css / C# functions to look like this: body {
Trying to get an ASP application deployed; it worked for a while but then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.