Browse files

Merge pull request #77 from gleber/include-stack-in-error-proplist

Include stack in error proplist
  • Loading branch information...
2 parents daa0bec + 40ea990 commit 157a7db0a9c284ea1da107fe3272ff7b19813d26 @yrashk yrashk committed Nov 30, 2012
Showing with 32 additions and 9 deletions.
  1. +5 −4 c_src/erlv8_proplist.cc
  2. +1 −0 include/erlv8.hrl
  3. +5 −1 src/erlv8_array.erl
  4. +6 −1 src/erlv8_object.erl
  5. +14 −0 src/erlv8_utils.erl
  6. +1 −3 src/erlv8_vm.erl
View
9 c_src/erlv8_proplist.cc
@@ -10,11 +10,12 @@ TickHandler(ProplistTickHandler) {
v8::Handle<v8::Array> keys;
if (res->val->IsNativeError()) { //workaround for V8 bug #1595
- keys = v8::Array::New(2);
- keys->Set(v8::String::New("0"), v8::String::New("name"));
- keys->Set(v8::String::New("1"), v8::String::New("message"));
+ keys = v8::Array::New(3);
+ keys->Set(v8::String::New("0"), v8::String::New("name"));
+ keys->Set(v8::String::New("1"), v8::String::New("message"));
+ keys->Set(v8::String::New("2"), v8::String::New("stack"));
} else {
- keys = res->val->ToObject()->GetPropertyNames();
+ keys = res->val->ToObject()->GetPropertyNames();
}
ERL_NIF_TERM *arr = (ERL_NIF_TERM *) malloc(sizeof(ERL_NIF_TERM) * keys->Length());
View
1 include/erlv8.hrl
@@ -16,3 +16,4 @@
vm}). %% or proplist()
+-define(is_v8(X), (is_record(X, erlv8_object) orelse is_record(X, erlv8_fun) orelse is_record(X, erlv8_array))).
View
6 src/erlv8_array.erl
@@ -6,7 +6,7 @@
-compile({no_auto_import,[length/1]}).
--export([list/1, object/1, length/1, push/2, unshift/2, delete/2,
+-export([list/1, object/1, length/1, push/2, unpush/1, unshift/2, delete/2,
new/1, new/2]).
@@ -29,6 +29,10 @@ push(Val, Self) ->
M = Self:object(),
M:set_value(length(Self),Val).
+unpush(Self) ->
+ M = Self:object(),
+ M:delete(M:length()-1).
+
unshift(Val, Self) ->
M = Self:object(),
L = length(Self),
View
7 src/erlv8_object.erl
@@ -2,13 +2,18 @@
-include("erlv8.hrl").
--export([proplist/1, set_value/3, set_value/4, set_hidden_value/3, get_value/2, get_value/3, get_hidden_value/2, get_hidden_value/3,
+-export([vm/1,
+
+ proplist/1, set_value/3, set_value/4, set_hidden_value/3, get_value/2, get_value/3, get_hidden_value/2, get_hidden_value/3,
internal_field_count/1, get_internal_field/2, set_internal_field/3,
set_prototype/2, get_prototype/1, delete/2, set_accessor/3, set_accessor/4, set_accessor/5, set_accessor/6,
equals/2, strict_equals/2, call/2, call/3,
new/1, new/2]).
+vm({Erlv8Obj, _Resource, VM}) when ?is_v8(Erlv8Obj) ->
+ VM.
+
proplist({_Erlv8Obj, Resource, VM}) ->
erlv8_vm:enqueue_tick(VM,{proplist, Resource}).
View
14 src/erlv8_utils.erl
@@ -0,0 +1,14 @@
+-module(erlv8_utils).
+
+-export([clone/1,
+ copy_properties/2]).
+
+-include("erlv8.hrl").
+
+clone(Source) ->
+ erlv8_vm:taint(Source:vm(), ?V8Obj(Source:proplist())).
+
+copy_properties(Destination, Source) ->
+ lists:foreach(fun({K, V}) ->
+ Destination:set_value(K, V)
+ end, Source:proplist()).
View
4 src/erlv8_vm.erl
@@ -110,9 +110,7 @@ next_tick(Server, Tick, Timeout) ->
next_tick(Server, Tick, Timeout, Ref) when is_reference(Ref) ->
gen_server2:call(Server,{next_tick, Tick, Ref}, Timeout).
-taint(Server, {Tag, _R, _Vm} = Value) when Tag == erlv8_object;
- Tag == erlv8_fun;
- Tag == erlv8_array ->
+taint(Server, Value) when ?is_v8(Value) ->
enqueue_tick(Server, {taint, Value});
taint(Server, {Error, _} = Value) when Error == error;

0 comments on commit 157a7db

Please sign in to comment.