-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fallback to default toString() implementation #11
Comments
or maybe the better solution is to allow to override the default dumper routine used there. something like if (njs) {
njs.dump = function(arg) {
// whatever
}
} |
some more on this: >> [[1,1],[2,2],[3,3]]
1,1,2,2,3,3 |
@drsm Is it a good idea to use JSON.stringify(arg, undefined,1) as the default dumper function? It would solve the null proto issue as well. something like this: >>console.log([{a:1,b:{c:2}},1])
[
{
"a": 1,
"b": {
"c": 2
}
},
1
] |
@xeioex yes, i think this is good solution, but, please note that empty array items would incorrectly rendered here: console.log(JSON.stringify([{a:1,b:{c:[,]}},1]))
[{"a":1,"b":{"c":[null]}},1] and this will break tests, so some extension (internal) to JSON.stringify is also needed, i think |
Hi @drsm Please, take a look at the following patch.
|
Hi @xeioex! >> Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor');
{
value: [Function: native],
configurable: false,
enumerable: false,
writable: false
}
>> console.log(Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor'));
[object Object]
undefined
>> console.log(njs.dump(Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor')));
{value:[Function: native],configurable:false,enumerable:false,writable:false}
undefined
>> pretty awesome, thanks! |
just a side note. Line 3093 in 5c1255d
maybe better to extend diagnostics here? also, found a killing regression >> var x = { toString: function() { throw "test"; } }
undefined
>> x
{
toString: [Function]
}
>> console.log(x)
'test'
>> try { console.log(x) } catch (e) { console.log('err: ' + e)}
err: test
null
Segmentation fault |
@drsm Thank you for the feedback. Will be fixed. Another question is whether console.log() should output the default toString() representation of a value (as it is now) or the pretty version of it. |
@xeioex i think, the best way is to leave console.log() as is, for now, and probably shortcut a |
looks like an unrelated problem. It is better to create a separate issue. |
This patch fixes
|
yeah, it is a separate bug. i just overlooked it... |
@drsm just committed the patch above (Segmentation fault related). |
Hi @xeioex ! >> var fn = function() { throw 'test'; }
undefined
>> var x = { toString: fn, toJSON: fn }
undefined
>> x
{
toString: [Function],
toJSON: [Function]
}
>> console.log(x)
'test'
>> JSON.stringify(x)
'test'
>> var fn = function() { throw Error('test'); }
undefined
>> var x = { toString: fn, toJSON: fn }
undefined
>> JSON.stringify(x)
Error: test
at anonymous (:1)
at JSON.stringify (native)
at main (native)
>> console.log(x)
Error: test
at anonymous (:1)
at console.log (native)
at console.log (native)
at main (native)
>> |
here is the updated version of the patch Now external objects like console can also be printed >> console
{
log: {type:"method",props:["method"]},
dump: {type:"method",props:["method"]},
help: {type:"method",props:["method"]}
} console.log(val) console.dump([value1[, values]])
|
Hi @xeioex >> (function() { throw 'test' })()
'test' |
in console.* & interactive shell
The text was updated successfully, but these errors were encountered: