On Tue, Sep 6, 2016 at 2:37 PM, Renier <[email protected]> wrote:
> I have an application that embeds v8 and I want to include a series of
> helper javascript functions at the time of compiling a code snippet so that
> the user is able to use my helper functions.
> These functions don't interact with C++ at all and are merely there as
> helper functions.
>
> i.e.
> function doStuff(x, y){
>    return x + y + "weeee";
> }
> function doSomethingElse(){
> }
>
>
> Is there a sample of the above?
>
> I have tried to use an v8::ObjectTemplate and merely doing the following
> without any success as I get `Reference error: doSomethingElse is not
> defined`
>
> v8::Handle<v8::ObjectTemplate> result = v8::ObjectTemplate::New();
> result->Set(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(),
> *functionName), v8::String::NewFromUtf8(v8::Isolate::GetCurrent(),
> *functionSource));
>
> functionName is set to "doStuff" and the definition of the function lives
> inside of the functionSource.
>
> I have then created a context with this template and I get the above
> mentioned error message when I attempt to access these functions.
>
> Regards
> Renier

Compile (and run) the source with v8::Script or v8::ScriptCompiler.

You could also use v8::RegisterExtension() but that's a bit more work.

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to