V8 c++ and JS : How to share objects between contextsV8 Android, creating the context causes ASSERT … CHECK(object->IsJSFunction()) failedHow do I access and call Javascript Object properties and methods from C++ using V8?How to pass a wrapped C++ object to a Javascript callback?Creating different v8 contexts that are clones of anotherhow to create REAL global object in v8?How to properly restore Javascript context in v8?v8::Context memory leaksHow to use the same context across multiple functions in v8 Javascript?Handling JavaScript objects in a C++ node nan addonHow to reset global object in embedded V8?

Understanding "audieritis" in Psalm 94

Was Spock the First Vulcan in Starfleet?

is this a spam?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?

Products and sum of cubes in Fibonacci

How could Frankenstein get the parts for his _second_ creature?

Why are on-board computers allowed to change controls without notifying the pilots?

What will be the benefits of Brexit?

Can criminal fraud exist without damages?

Curses work by shouting - How to avoid collateral damage?

What is difference between behavior and behaviour

Is it correct to write "is not focus on"?

Is there an Impartial Brexit Deal comparison site?

Greatest common substring

Your magic is very sketchy

Tiptoe or tiphoof? Adjusting words to better fit fantasy races

Go Pregnant or Go Home

How to be diplomatic in refusing to write code that breaches the privacy of our users

Can somebody explain Brexit in a few child-proof sentences?

At which point does a character regain all their Hit Dice?

Is a roofing delivery truck likely to crack my driveway slab?

Short story about space worker geeks who zone out by 'listening' to radiation from stars

Can I use my Chinese passport to enter China after I acquired another citizenship?



V8 c++ and JS : How to share objects between contexts


V8 Android, creating the context causes ASSERT … CHECK(object->IsJSFunction()) failedHow do I access and call Javascript Object properties and methods from C++ using V8?How to pass a wrapped C++ object to a Javascript callback?Creating different v8 contexts that are clones of anotherhow to create REAL global object in v8?How to properly restore Javascript context in v8?v8::Context memory leaksHow to use the same context across multiple functions in v8 Javascript?Handling JavaScript objects in a C++ node nan addonHow to reset global object in embedded V8?













0















i'm looking for a method/solution for sharing js objects declared into a context (i.e. context A) into another context (i.e. Context B). Both are in the same isolate.
In detail:
I'm using v8 c++ wrapper for make available c++ class (i.e. cppClass) into js code. So, i can call cppClass.myfunction() or cppClass.myProperty directly into js code.



I have an only one isolate, and a main context for loading and running a complex js file (composed by many js files and many objects/functions declared).



Furthermore i have others contexts where other simple js code is running. All contexts are in the same isolate.



Suppose to have an AObject declared and used in the contextA, which has a property like AObject.foo=10 . I'm wondering if is it possible to access to AObject in the ContextB and read/change AObject.foo property such as :



 // JS code in ContextA
var AObject=new cppClass();
AOBject.foo=10;
...

// JS code in ContextB
var newvalue=AObject.foo +1; //or something like myWrapMethod.AObject.foo+1;
Console.Log(" The new value is : " + newvalue );
// The new value is : 11


Can i access to AObject (i.e. call its functions or set its attributes/properties) from ContextB?
Thank you in advance



Andrea










share|improve this question


























    0















    i'm looking for a method/solution for sharing js objects declared into a context (i.e. context A) into another context (i.e. Context B). Both are in the same isolate.
    In detail:
    I'm using v8 c++ wrapper for make available c++ class (i.e. cppClass) into js code. So, i can call cppClass.myfunction() or cppClass.myProperty directly into js code.



    I have an only one isolate, and a main context for loading and running a complex js file (composed by many js files and many objects/functions declared).



    Furthermore i have others contexts where other simple js code is running. All contexts are in the same isolate.



    Suppose to have an AObject declared and used in the contextA, which has a property like AObject.foo=10 . I'm wondering if is it possible to access to AObject in the ContextB and read/change AObject.foo property such as :



     // JS code in ContextA
    var AObject=new cppClass();
    AOBject.foo=10;
    ...

    // JS code in ContextB
    var newvalue=AObject.foo +1; //or something like myWrapMethod.AObject.foo+1;
    Console.Log(" The new value is : " + newvalue );
    // The new value is : 11


    Can i access to AObject (i.e. call its functions or set its attributes/properties) from ContextB?
    Thank you in advance



    Andrea










    share|improve this question
























      0












      0








      0








      i'm looking for a method/solution for sharing js objects declared into a context (i.e. context A) into another context (i.e. Context B). Both are in the same isolate.
      In detail:
      I'm using v8 c++ wrapper for make available c++ class (i.e. cppClass) into js code. So, i can call cppClass.myfunction() or cppClass.myProperty directly into js code.



      I have an only one isolate, and a main context for loading and running a complex js file (composed by many js files and many objects/functions declared).



      Furthermore i have others contexts where other simple js code is running. All contexts are in the same isolate.



      Suppose to have an AObject declared and used in the contextA, which has a property like AObject.foo=10 . I'm wondering if is it possible to access to AObject in the ContextB and read/change AObject.foo property such as :



       // JS code in ContextA
      var AObject=new cppClass();
      AOBject.foo=10;
      ...

      // JS code in ContextB
      var newvalue=AObject.foo +1; //or something like myWrapMethod.AObject.foo+1;
      Console.Log(" The new value is : " + newvalue );
      // The new value is : 11


      Can i access to AObject (i.e. call its functions or set its attributes/properties) from ContextB?
      Thank you in advance



      Andrea










      share|improve this question














      i'm looking for a method/solution for sharing js objects declared into a context (i.e. context A) into another context (i.e. Context B). Both are in the same isolate.
      In detail:
      I'm using v8 c++ wrapper for make available c++ class (i.e. cppClass) into js code. So, i can call cppClass.myfunction() or cppClass.myProperty directly into js code.



      I have an only one isolate, and a main context for loading and running a complex js file (composed by many js files and many objects/functions declared).



      Furthermore i have others contexts where other simple js code is running. All contexts are in the same isolate.



      Suppose to have an AObject declared and used in the contextA, which has a property like AObject.foo=10 . I'm wondering if is it possible to access to AObject in the ContextB and read/change AObject.foo property such as :



       // JS code in ContextA
      var AObject=new cppClass();
      AOBject.foo=10;
      ...

      // JS code in ContextB
      var newvalue=AObject.foo +1; //or something like myWrapMethod.AObject.foo+1;
      Console.Log(" The new value is : " + newvalue );
      // The new value is : 11


      Can i access to AObject (i.e. call its functions or set its attributes/properties) from ContextB?
      Thank you in advance



      Andrea







      v8






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 11:33









      MrMartiniMrMartini

      81




      81






















          2 Answers
          2






          active

          oldest

          votes


















          0














          a possible answer to my question could be the following approach. In c++, suppose to have the following code:



           Handle<Context> contextA=myIsolate::GetCurrentContext();
          ... some code
          Handle<Context> contextB=GetMyBContext();
          ... some code

          contextA->Enter(); // change the context to A Context

          auto global_obj = contextA->Global();
          v8::Local<v8::Value> desiredValue = global_obj->Get(String::NewFromUtf8(myIsolate,"AObject"));
          contextA->Exit(); // change the context to B Context
          // Now AObject can be used also in the context B (another script js)
          myIsolate->GetCurrentContext()->Global()->Set(v8::String::NewFromUtf8(myIsolate, "AObject"), desiredValue ->ToObject());


          After that, in the js file (related to B context), i can use AObject with the same values it has in AContext.



          Hope to be useful.
          Kind regards.



          Andrea






          share|improve this answer






























            0














            You should set both Context security tokens to be the same.
            Then you can get an object Ref from a Context, and store/use it from the other.



            From v8.h header file:



             /**
            * Sets the security token for the context. To access an object in
            * another context, the security tokens must match.
            */
            void SetSecurityToken(Local<Value> token);





            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042805%2fv8-c-and-js-how-to-share-objects-between-contexts%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              a possible answer to my question could be the following approach. In c++, suppose to have the following code:



               Handle<Context> contextA=myIsolate::GetCurrentContext();
              ... some code
              Handle<Context> contextB=GetMyBContext();
              ... some code

              contextA->Enter(); // change the context to A Context

              auto global_obj = contextA->Global();
              v8::Local<v8::Value> desiredValue = global_obj->Get(String::NewFromUtf8(myIsolate,"AObject"));
              contextA->Exit(); // change the context to B Context
              // Now AObject can be used also in the context B (another script js)
              myIsolate->GetCurrentContext()->Global()->Set(v8::String::NewFromUtf8(myIsolate, "AObject"), desiredValue ->ToObject());


              After that, in the js file (related to B context), i can use AObject with the same values it has in AContext.



              Hope to be useful.
              Kind regards.



              Andrea






              share|improve this answer



























                0














                a possible answer to my question could be the following approach. In c++, suppose to have the following code:



                 Handle<Context> contextA=myIsolate::GetCurrentContext();
                ... some code
                Handle<Context> contextB=GetMyBContext();
                ... some code

                contextA->Enter(); // change the context to A Context

                auto global_obj = contextA->Global();
                v8::Local<v8::Value> desiredValue = global_obj->Get(String::NewFromUtf8(myIsolate,"AObject"));
                contextA->Exit(); // change the context to B Context
                // Now AObject can be used also in the context B (another script js)
                myIsolate->GetCurrentContext()->Global()->Set(v8::String::NewFromUtf8(myIsolate, "AObject"), desiredValue ->ToObject());


                After that, in the js file (related to B context), i can use AObject with the same values it has in AContext.



                Hope to be useful.
                Kind regards.



                Andrea






                share|improve this answer

























                  0












                  0








                  0







                  a possible answer to my question could be the following approach. In c++, suppose to have the following code:



                   Handle<Context> contextA=myIsolate::GetCurrentContext();
                  ... some code
                  Handle<Context> contextB=GetMyBContext();
                  ... some code

                  contextA->Enter(); // change the context to A Context

                  auto global_obj = contextA->Global();
                  v8::Local<v8::Value> desiredValue = global_obj->Get(String::NewFromUtf8(myIsolate,"AObject"));
                  contextA->Exit(); // change the context to B Context
                  // Now AObject can be used also in the context B (another script js)
                  myIsolate->GetCurrentContext()->Global()->Set(v8::String::NewFromUtf8(myIsolate, "AObject"), desiredValue ->ToObject());


                  After that, in the js file (related to B context), i can use AObject with the same values it has in AContext.



                  Hope to be useful.
                  Kind regards.



                  Andrea






                  share|improve this answer













                  a possible answer to my question could be the following approach. In c++, suppose to have the following code:



                   Handle<Context> contextA=myIsolate::GetCurrentContext();
                  ... some code
                  Handle<Context> contextB=GetMyBContext();
                  ... some code

                  contextA->Enter(); // change the context to A Context

                  auto global_obj = contextA->Global();
                  v8::Local<v8::Value> desiredValue = global_obj->Get(String::NewFromUtf8(myIsolate,"AObject"));
                  contextA->Exit(); // change the context to B Context
                  // Now AObject can be used also in the context B (another script js)
                  myIsolate->GetCurrentContext()->Global()->Set(v8::String::NewFromUtf8(myIsolate, "AObject"), desiredValue ->ToObject());


                  After that, in the js file (related to B context), i can use AObject with the same values it has in AContext.



                  Hope to be useful.
                  Kind regards.



                  Andrea







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 7 at 15:54









                  MrMartiniMrMartini

                  81




                  81























                      0














                      You should set both Context security tokens to be the same.
                      Then you can get an object Ref from a Context, and store/use it from the other.



                      From v8.h header file:



                       /**
                      * Sets the security token for the context. To access an object in
                      * another context, the security tokens must match.
                      */
                      void SetSecurityToken(Local<Value> token);





                      share|improve this answer



























                        0














                        You should set both Context security tokens to be the same.
                        Then you can get an object Ref from a Context, and store/use it from the other.



                        From v8.h header file:



                         /**
                        * Sets the security token for the context. To access an object in
                        * another context, the security tokens must match.
                        */
                        void SetSecurityToken(Local<Value> token);





                        share|improve this answer

























                          0












                          0








                          0







                          You should set both Context security tokens to be the same.
                          Then you can get an object Ref from a Context, and store/use it from the other.



                          From v8.h header file:



                           /**
                          * Sets the security token for the context. To access an object in
                          * another context, the security tokens must match.
                          */
                          void SetSecurityToken(Local<Value> token);





                          share|improve this answer













                          You should set both Context security tokens to be the same.
                          Then you can get an object Ref from a Context, and store/use it from the other.



                          From v8.h header file:



                           /**
                          * Sets the security token for the context. To access an object in
                          * another context, the security tokens must match.
                          */
                          void SetSecurityToken(Local<Value> token);






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 15 at 17:36









                          hyperandroidhyperandroid

                          5112




                          5112



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042805%2fv8-c-and-js-how-to-share-objects-between-contexts%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              1928 у кіно

                              Захаров Федір Захарович

                              Ель Греко