call stack not complete

24 views
Skip to first unread message

Paul Harris

unread,
Nov 29, 2012, 10:18:48 AM11/29/12
to v8-u...@googlegroups.com
Hi,

I have a small bit of code that looks something like this:
(function (a, b, c) {
   return {
      read_something: function(i) { if (i < 0) this.die(); return a; }
   };
});

I then do something like this:
comp = Script::Compile(code);
wrapper = comp->Run();
binder = wrapper->Call( global, 3, args );
global->Set( ident, binder );

which compiles, runs (to get the factory-function), then calls the factory-function with arguments,
resulting in the {} object with read_something function inside.
I then bind this to the global object.
I use this to give me access to data, but at the same time ensure the data is read-only.

This works well.  If I call binder.read_something(-1) within javascript, it correctly dies when trying to call this.die().

However, the callstack that is printed out only shows the details for the code within the wrapper,
it does not print out the callstack up to the calling code (which is compiled and run later).

Any ideas why this might be?  I am hoping to (eg) find the place where the calling script calls with a -1 parameter.

thanks,
Paul

Yang Guo

unread,
Dec 10, 2012, 5:14:41 AM12/10/12
to v8-u...@googlegroups.com
Not sure what you mean, for this following code:

function factory(a) {
   return {
      read_something: function(i) { if (i < 0) this.die(); return a; }
   };
};


factory(2).read_something(-1);

I get:

test2.js:3: TypeError: Object #<Object> has no method 'die'
      read_something: function(i) { if (i < 0) this.die(); return a; }
                                                    ^
TypeError: Object #<Object> has no method 'die'
    at Object.read_something (test2.js:3:53)
    at test2.js:8:12


which seems perfectly fine to me.

Yang

Paul Harris

unread,
Dec 10, 2012, 10:09:46 AM12/10/12
to v8-u...@googlegroups.com
I'll have to make a more complete example, because I am doing more than just putting all that code in one JS script.

I have the factory in a separate script, which I Compile() and Run(),
The Run() returns the factory function,
which I then Exec() with parameters.  The result is the { read_something } object,
which I then attach to the global object.

Only then do I compile and run the code that uses the generated wrapper.

Paul Harris

unread,
Dec 11, 2012, 1:29:31 AM12/11/12
to v8-u...@googlegroups.com
Ok,

I have traced the problem due to the way I was throwing my exceptions.

In JS, I did something like
if (this === that) throw 'thats not good';

When I should have done this
if (this === that) throw new Error('thats not good');

I was not aware of this technique,

For other people's reference, here is a great page about it:

and a v8 wiki page on it:

thanks again Yang for your responses, I appreciate it.
Paul
Reply all
Reply to author
Forward
0 new messages