Hi Michael,

Thanks for your reply. I had a look into SilkJS and learned many useful
things about V8 !
After a deeper look, it seems that I found strange (maybe normal)
behaviours when running scripts in the V8 engine. Let's take for example:

== lib.js ==
var f = function() { /* ... */ }

== script.js ==
include("lib.js");
f();

In that case, if you run script.js with SilkJS, all goes fine. Let's go
further:

== lib.js ==
 var f = function() { /* ... */ }
var c = "some variable";

== script.js ==
include("lib.js");
f();
var x = c+" with some value"

Here, when one want to run script.js, the engine cries that the variable
'c' is not defined (but 'f' still is) ! That sounds weird for me => in that
case, shouldn't 'f' also be undefined ?
Now as another weird behaviour, let's take a look at some function
overriding:

== lib.js ==
var f = function() { return "Library"; }

== script.js ==
include("lib.js");
var f = function() { return "Script"; }
f(); //yields 'Script'

Ok, the overriding looks fine in that case.

== lib.js ==
function f() { return "Library"; }

== script.js ==
include("lib.js");
function f() { return "Script"; }
 f(); //yields 'Library'

And here the overriding doesn't work... It seems that semantically, it is
exactly the same, so what's the change behind ? Probably I also missed some
point here :-) Hopefully, some of you can hellp me understand what's going
on...

Best regards,
Cédric

On Thu, Feb 2, 2012 at 15:38, Michael Schwartz <[email protected]> wrote:

> Take a look at SilkJS.  It wraps v8 in C++, and provides both include()
> and require() methods.  You're describing require(), which only loads the
> library once, but returns the module or namespace for it as many times as
> you import/require it.
>
> http://github.com/mschwartz/SilkJS
>
> And commons.org for docs on require()
>
> Sent from my iPhone
>
> On Feb 1, 2012, at 2:50 PM, Cédric Tabin <[email protected]> wrote:
>
> > Hello,
> >
> > I'm a new user of the V8 framework and try to play with it :-)
> > Currently, I'd like to handle a library (in javascript) that will be
> > used by other scripts, all run by the V8's engine. For example I will
> > have something like that:
> >
> > == library.js ==
> > function doSomething() { print "library"; }
> >
> > == script1.js ==
> > /* import/include library.js */
> > function doSomething() { print "script1"; } //override the doSomething
> > method from library.js
> > doSomething(); //should return *script1*
> >
> > == script2.js ==
> > /* import/include library.js */
> > doSomething(); //should return *library*
> >
> >
> > My goal is to avoid reexecuting the whole file library.js before
> > running script1.js or script2.js. In my C++ code, I'd like to do
> > something like that:
> > a) prepare environment (Context, Scope, ...)
> > b) compile & execute library.js
> > c) take a "snapshot" of the current state (or something like that)
> > d) compile & execute script1.js
> > e) reset the state in (c)
> > f) compile & execute script2.js (so it runs like if script1.js was
> > never ran, withou re-running library.js)
> >
> > I had a look to the Contexts, but it is to run for independant code
> > which is clearly not my case... I also tried to play with Scope and
> > HandleScope with no result.
> >
> > Is there a way to handle this problem ?
> >
> > Thanks & best regards,
> > Cedric
> >
> > --
> > v8-users mailing list
> > [email protected]
> > http://groups.google.com/group/v8-users
>
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to