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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:19:41+00:00 2026-06-08T20:19:41+00:00

I want to call JSON.stringify method from the C++ side with modified arguments, but

  • 0

I want to call JSON.stringify method from the C++ side with modified arguments, but any solution that came to my mind results in a weird segfault with all frames being at “??”.

I want to do the following:
api::Console is a custom console implementation for debugging purposes and has therefore static methods like api::Console::handleLog or api::Console::handleDebug.

For handleDebug which is passed correctly to the console’s ObjectTemplate, the following doesn’t work, v8gl::context is the current execution context and is correctly usable in other api implementations:

v8::Handle<v8::Value> Console::handleDebug(const v8::Arguments& args) {

    if (args.Length() < 1) {
        return v8::Undefined();
    }

    v8::HandleScope scope;

    v8::Handle<v8::Object> global = v8gl::context->Global();
    v8::Handle<v8::Object> JSON = global->Get(v8::String::New("JSON"))->ToObject();
    v8::Handle<v8::Function> JSON_stringify = v8::Handle<v8::Function>::Cast(JSON->Get(v8::String::New("stringify")));


    for (signed a = 0; a < args.Length(); a++) {

        for (int m = 0; m < consoleMargin; m++) {
            fprintf(stdout, "\t");
        }

        v8::Handle<v8::Value> passargs[1];
        // alternative try was:
        // passargs[0] = v8::String::New("{foo:'bar'}");
        passargs[0] = v8::String::New(*v8::String::Utf8Value(args[a]->ToString()));


        v8::String::Utf8Value value(JSON_stringify->Call(JSON, 1, passargs));
        char* message = *value;

        fprintf(stdout, "%s\n", message);

    }


    return scope.Close(v8::Undefined());

}

The backtrace in gdb is somehow weird and I have no idea why:

(gdb) backtrace
#0  0x00000000004a0880 in v8::Context::Global() ()
#1  0x00000000004128ea in api::Console::handleDebug(v8::Arguments const&) ()
#2  0x00000000004b9eab in v8::internal::Builtin_HandleApiCall(v8::internal::(anonymous namespace)::BuiltinArguments<(v8::internal::BuiltinExtraArguments)1>, v8::internal::Isolate*) ()
#3  0x000004cd67f0618e in ?? ()
#4  0x000004cd67f12998 in ?? ()
#5  0x000004cd67f060e1 in ?? ()
# (... etc ...)

So my question is the following:

How do I cast correctly from the Local value”v8::Arguments& args” to “v8::Handle<v8::Value>*” for usage with the Call() method of v8::Function?

If I want to use the args[a] directly in the loop, compiler errors are thrown for the differing signature of v8::Function::Call, which is correct due to args being a Local Value. The signature of v8::Function::Call is the following:

v8::Local<v8::Value> v8::Function::Call(v8::Handle<v8::Object>, int, v8::Handle <v8::Value>*)

// Edit: Updated passargs[false index]

  • 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-08T20:19:42+00:00Added an answer on June 8, 2026 at 8:19 pm

    You have error there:

        v8::Handle<v8::Value> passargs[1];
    
        passargs[1/* SHOULD BE 0!!!*/] = 
             v8::String::New(*v8::String::Utf8Value(args[a]->ToString()));
    

    So you try to access element out of array bounds.

    BTW: v8::Local<> is inherited from v8::Handle<> so you don’t need any magic to convert Local to Handle.

    Edit: Most of v8 features require not only v8::HandleScope but also v8::Context::Scope seems you need to create context scope too.
    You can get valid context form args:

    Local<Object> self = args.Holder();
    Persistent<Context> context(self->CreationContext());
    

    Then create handle scope and context scope:

    Context::Scope work_in_context_scope(context);
    HandleScope work_in_this_function_scope;
    

    Then do you job.

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

Sidebar

Related Questions

I want to call a method say success(message) of javascript from android activity. I
I want to call a JSON method on my textbox change event using jquery.
I want to make call to authenticate user and get back token in json
I want to call a web service that requires an authentication cookie. I have
I want to call a function which is in another php class that I
I want to call a webservice using jQuery.ajax() but the webervice doesn't get called.
I want to call a web service method in javascript. (asp.net 3.5) I have
I have a JSON web service that I want to run on the same
I have a text file that is formatted like JSON, but in a print/view
Is there a reliable way to JSON.stringify a JavaScript object that guarantees that the

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.