Skip to content

Commit

Permalink
protect __tostring for remaining data types
Browse files Browse the repository at this point in the history
  • Loading branch information
siffiejoe committed Jul 30, 2014
1 parent 365ffd9 commit b24f29a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
22 changes: 11 additions & 11 deletions src/microscope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ local function db_node( db, val, depth, key )
(key == nil or not db.prune[ key ]) then
db.n_nodes = db.n_nodes + 1
node = {
id = tostring( db.n_nodes ),
id = db.n_nodes.."",
value = val,
depth = depth,
shape = nil, label = nil, draw = nil, next = nil,
Expand Down Expand Up @@ -435,7 +435,7 @@ end
local function make_label_elem( tnode, v, db, subid, depth, alt )
local t = type( v )
if t == "number" or t == "boolean" then
return escape( tostring( v ), db.use_html )
return escape( ptostring( v ), db.use_html )
elseif t == "string" then
return quote( escape( abbrev( v ), db.use_html ) )
else -- userdata, function, thread, table
Expand Down Expand Up @@ -465,7 +465,7 @@ local function make_html_table( db, node, val )
-- first the array part
local n, v = 1, rawget( val, 1 )
while v ~= nil do
local el_label = make_label_elem( node, v, db, tostring( n ), depth )
local el_label = make_label_elem( node, v, db, n.."", depth )
label = label .. [[
<TR><TD PORT="]] .. n .. [[" COLSPAN="2">]] .. el_label .. [[
</TD></TR>
Expand Down Expand Up @@ -503,7 +503,7 @@ local function make_record_table( db, node, val )
-- first the array part
local n,v = 1, rawget( val, 1 )
while v ~= nil do
local el_label = make_label_elem( node, v, db, tostring( n ), depth )
local el_label = make_label_elem( node, v, db, n.."", depth )
label = label .. " | <" .. n .. "> " .. el_label
handled[ n ] = true
n = n + 1
Expand Down Expand Up @@ -550,7 +550,7 @@ local function make_html_stack( db, node )
n = n + 1
for i = #frame, 1, -1 do
label = label .. ' <TR><TD>' ..
escape( tostring( i ), true ) .. '</TD><TD>' ..
escape( i.."", true ) .. '</TD><TD>' ..
escape( abbrev( frame[ i ][ 1 ] ), true ) ..
'</TD><TD PORT="' .. n .. '">' ..
make_label_elem( node, frame[ i ][ 2 ], db, n, depth ) ..
Expand Down Expand Up @@ -582,7 +582,7 @@ local function make_record_stack( db, node )
n = n + 1
local nums, keys, values = {}, {}, {}
for i = #frame, 1, -1 do
nums[ #nums+1 ] = escape( tostring( i ), false )
nums[ #nums+1 ] = escape( i.."", false )
keys[ #keys+1 ] = escape( abbrev( frame[ i ][ 1 ] ), false )
values[ #values+1 ] = "<" .. n .. "> " ..
make_label_elem( node, frame[ i ][ 2 ], db, n, depth )
Expand Down Expand Up @@ -713,7 +713,7 @@ end


local function dottify_thread( db, node, val )
local label = escape( abbrev( tostring( val ) ), false )
local label = escape( abbrev( ptostring( val ) ), false )
node.group = label
if getsize then
label = label.." ["..getsize( val ).."]"
Expand All @@ -730,7 +730,7 @@ end


local function dottify_function( db, node, val )
local label = escape( abbrev( tostring( val ) ), false )
local label = escape( abbrev( ptostring( val ) ), false )
if getsize then
label = label.." ["..getsize( val ).."]"
end
Expand All @@ -751,14 +751,14 @@ end


local function dottify_other( db, node, val )
node.label = escape( abbrev( tostring( val ) ), false )
node.label = escape( abbrev( ptostring( val ) ), false )
node.shape = "plaintext"
end


local function dottify_stack( db, node )
if node.thread then
node.group = escape( abbrev( tostring( node.thread ) ), false )
node.group = escape( abbrev( ptostring( node.thread ) ), false )
end
if db.use_html then
make_html_stack( db, node )
Expand All @@ -769,7 +769,7 @@ end


local function dottify_size( db, node, val )
node.label = escape( abbrev( tostring( val ) ), false )
node.label = escape( abbrev( val.."" ), false )
node.shape = "circle"
node.width = "0.3"
node.margin = "0.01"
Expand Down
12 changes: 6 additions & 6 deletions tests/microscope1.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,16 @@ end

do
local t = {}
setmetatable( t, {
__tostring = function( v )
error( "Argh!" )
end
} )
local mt = { __tostring = function() error( "Argh!" ) end }
setmetatable( t, mt )
local u = newproxy( true )
getmetatable( u ).__tostring = function( u )
error( "Argh!" )
end
dot( { t, u }, "__tostring raising error" )
debug.setmetatable( 1, mt )
debug.setmetatable( true, mt )
dot( { t, u, false, 123 }, "__tostring raising error" )
mt.__tostring = nil
end

-- TODO ;-)
Expand Down

0 comments on commit b24f29a

Please sign in to comment.