Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Message from discussion Is there any way to create a Handle<ObjectTemplate> from a Handle<Object>?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Isaac Z. Schlueter  
View profile  
 More options Mar 8 2009, 11:03 pm
From: "Isaac Z. Schlueter" <i...@foohack.com>
Date: Sun, 8 Mar 2009 20:03:03 -0700 (PDT)
Local: Sun, Mar 8 2009 11:03 pm
Subject: Re: Is there any way to create a Handle<ObjectTemplate> from a Handle<Object>?
So, I did eventually get this to work very much like SpiderMonkey's
evalcx function.  Here's the code if anyone else is interested:

usage:
evalcx( code_to_execute, global_object (default: this), keep_changes
(bool, should changed global be written back to the object?) )
returns the result of the executed code.

static v8::Handle<v8::Value> EvalCX (const v8::Arguments& args)
{
        HandleScope handle_scope;
        Handle<Context> context = Context::New();
        context->SetSecurityToken(
                Context::GetCurrent()->GetSecurityToken()
        );

        Context::Scope context_scope(context);
        Handle<String> code = args[0]->ToString();
        Handle<Object> sandbox = args.Length() >= 1 ? args[1]->ToObject() :
Context::GetCurrent()->Global();

        // share global datas
        copy_obj( sandbox, context->Global());
        context->Enter();

        Handle<Script> script = Script::Compile(code, String::New("evalcx"));
        Handle<Value> result;
        if (script.IsEmpty()) {
                result = ThrowException(String::New("Error parsing script"));
        } else {
                result = script->Run();
                if (result.IsEmpty()) {
                        result = v8::ThrowException(v8::String::New("Error running
script"));
                }
        }
        if (args.Length() >= 3 && args[2]->IsTrue()) {
                copy_obj( context->Global(), sandbox );
        }
        context->DetachGlobal();
        context->Exit();
        return result;

}

--i

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.