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 8719841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:53:41+00:00 2026-06-13T06:53:41+00:00

Does someone know how I could look up local variables in a nested function

  • 0

Does someone know how I could look up local variables in a nested function call from C++?
Consider the following example:

// e.g. a global variable in the browser
var global = "global_value";

function foo(){
    var global = "local_value";
    myCppFunction("global", global);
}

foo();

My question now is how in the implementation of myCppFunction I could access the function local variable “global” (NOT value, this would be given by the 2nd parameter) from ‘foo’?

Handle<Value> MyCppFunction(const Arguments& args){
    Local<String> varName = args[0]->ToString();
    Local<String> varValue = args[1]->ToString(); // this holds "local_value"
    // how to access the variable "global" in the scope of 'foo' ?
}
  • 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-06-13T06:53:43+00:00Added an answer on June 13, 2026 at 6:53 am

    I managed to find it out by myself. See the example below for how to find the value on the stack (and also replace it – here by the example of a string variable).

    Two remarks beforehand:

    • I have not tested this for undesired behavior except from my very use cases where I use this in my master thesis – there (may) be dragons.
    • I don’t know exactly why in my tests sfl.FindJavaScriptFrame(0) yields the desired stack frame – but, as it works independently of the calling depth, I suspect the stack frame indexed by 0 to always be the immediate caller’s frame (in my case I know that I want exactly that).

    And the code:

    // Prepare identification of the variable,assuming varName as in the question
    // More convenient conversions would be appreciated, at least by me
    Local<String> varName = args[0]->ToString();        
    std::string varStr = *String::AsciiValue(varName);
    // I'm using 'namespace i = internal;' (within v8-namespace)
    i::Vector<const char> tmpVar(varStr.data(), varStr.length());
    i::Handle<i::String> varIStr = i::Isolate::Current()->factory()->NewStringFromAscii(tmpVar, i::TENURED);
    
    // Now hunt down the stack frame of interest, be sure to consider my remarks above
    i::StackFrameLocator sfl;
    // Comment from the code: The caller must guarantee that such a frame exists.
    i::JavaScriptFrame* jsf = sfl.FindJavaScriptFrame(0);
    // create some replacement
    i::Vector<const char> tmp("there you go", 12);
    i::Handle<i::String> insert = i::Isolate::Current()->factory()->NewStringFromAscii(tmp, i::TENURED);
    i::Object* insertObj = insert->ToObjectChecked();
    
    // by the help of JavaScriptFrame::Print I came up with this:
    i::Object* fun = jsf->function();
    if (fun->IsJSFunction()){
        i::Handle<i::ScopeInfo> scope_info(i::ScopeInfo::Empty());
        i::Handle<i::SharedFunctionInfo> shared((i::JSFunction::cast(fun))->shared());
        scope_info = i::Handle<i::ScopeInfo>(shared->scope_info());
        i::Object* script_obj = shared->script();
        if (script_obj->IsScript()) {
            int stack_locals_count = scope_info->StackLocalCount();
            for (int i = 0; i < stack_locals_count; i++) {
                if (scope_info->StackLocalName(i)->Equals(*varIStr)){
                    // replace the value on the stack
                    jsf->SetExpression(i,insertObj);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In jQuery ajax function there is xhr option. Does someone know more details, usability
Does someone know how I could extend and TabPage so that there is a
Hi could someone have a look at this and see if they know where
Does someone know a simple way to set the default zoom and latitude/longitude with
Does someone know how to find the longest common subsequence of a set of
Does someone know why i never get the first value of my array? it
does someone know how to draw 3D surfaces and hide the invisible lines? I
Does someone know of a Sqlite manager that I can put on my site,
Does someone know or have an idea of how to reload the contents of
Does someone know why this is not a strict quine ? _0='_0=%r;print _0%%_0';print _0%_0

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.