ChakraCore icon indicating copy to clipboard operation
ChakraCore copied to clipboard

'stack' member of Exception

Open bkimman opened this issue 3 years ago • 1 comments

I wrote the following script to test the retrieval of the stack trace when there is an exception in the script:

function func_1() { var a = func_2(); // line 3 : call another function }

function func_2() { var b = func_3(); // line 8 : call another function }

function func_3() { var x, y; var z = x[y]; // line 14 : trigger an exception since x is undefined return z; }

When I call the function call, "func_1", with JsCallFunction, the return value is script exception.

Using JsGetAndClearExceptionWithMetadata, I retrieved the exception. When I dump the properties of this object I get (the dump has member name, type, and value) - for Error which is an object, it recurses and dumps the properties of that object.

exception Error

  •    message String Unable to get property 'undefined' of undefine or null reference
    
  •    description String Unable to get property 'undefined' of undefine or null reference
    
  •    number Number -2146823281
    
  •    stack String TypeError: Unable to get property 'undefined' of undefined or null reference
    
  •   at func_3 (xx:14:5)
    
  •   at func_2 (xx:8:2)
    
  •   at func_1 (xx:3:2)
    

source String var z = x[y]; line Number 13 column Number 4 length Number 0 url String xx

The stack looks fine .. but ..

The column numbers seem incorrect - are they reflecting the 'token' number within that statement?

Also what is the 'Number' property of the Error object?

K

bkimman avatar Sep 09 '22 12:09 bkimman

Running it directly in the shell messes up column numbers as well, though differently:

$ cat 6834.js 
function func_1()
{
var a = func_2(); // line 3 : call another function
}

function func_2()
{
var b = func_3(); // line 8 : call another function
}

function func_3()
{
var x, y;
var z = x[y]; // line 14 : trigger an exception since x is undefined
return z;
}

func_1();
$ ./ch 6834.js 
TypeError: Unable to get property 'undefined' of undefined or null reference
   at func_3 (/local/petr/ChakraCore/6834.js:14:1)
   at func_2 (/local/petr/ChakraCore/6834.js:8:1)
   at func_1 (/local/petr/ChakraCore/6834.js:3:1)
   at Global code (/local/petr/ChakraCore/6834.js:18:1)

I vaguely remember this wasn't accurate, and that maybe there was a discussion about fixing it. @rhuanjl do you remember anything?

ppenzin avatar Sep 17 '22 06:09 ppenzin

The Number property is a chakra addition to spec which I think was intended for interface with other microsoft tools, so errors passed in or out of chakra could have error numbers.

The column numbers in the stack seem to be clearly wrong EDIT: maybe not - it appears to be the offset of the start pf the statement that contains the error e.g.

function func_1()
{
var a = func_2(); // line 3 : call another function
}

function func_2()
{
var c = 5; var b = func_3(); // line 8 : call another function
}

function func_3()
{
var x, y;
var z = x[y]; // line 14 : trigger an exception since x is undefined
return z;
}

func_1();

Shows a modified stack trace where the column for the func_2 frame is the start of the second var statement, I think this is correct behaviour after all.

rhuanjl avatar Sep 27 '22 22:09 rhuanjl