HaxeFoundation / HaxeFoundation/haxe

Call stack missing type names on JS in Chrome

Open
#11,735 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

This seems like a significant oversight, so in addition to reporting this, I'm kinda hoping for a sanity check and maybe some additional historical context from anybody who knows (was this definitely tested before?).

When `haxe.CallStack.callStack()` is called on the javascript target with ES5 code generation, running in Chrome (or presumably anywhere that V8 is used), any `Method` stack item that comes from a static or abstract function call will include the type information, but those that come from function calls on an instance of a type will not.

Running the same when ES6 code generation is enabled is even worse. No type names at all are included.

try.haxe program: https://try.haxe.org/#98c971A4

```haxe
import js.lib.Error;

using StringTools;

class Test {
static function main() {
staticFunction();
}

static function staticFunction()
{
var abstractObject = new AbstractObject(new RealObject());
abstractObject.abstractFunction();
}
}

abstract AbstractObject(RealObject)
{
public function new(real:RealObject)
{
this = real;
}

public function abstractFunction()
{
this.instanceFunction();
}
}

class RealObject
{
public function new()
{

}

public function instanceFunction()
{
//js.Syntax.code("debugger");
var stack = haxe.CallStack.callStack();

for(stackItem in stack)
{
trace(stackItem);
}
/* ES5
Test.hx:44:,FilePos(Method(null,instanceFunction),_,_,_)
Test.hx:44:,FilePos(Method(AbstractObject,abstractFunction),_,_,_)
Test.hx:44:,FilePos(Method(Test,staticFunction),_,_,_)
Test.hx:44:,FilePos(Method(Test,main),_,_,_)
Test.hx:44:,FilePos(null,_,_,_)
Test.hx:44:,FilePos(null,_,_,_)
*/

/* ES6
Test.hx:44:,FilePos(Method(null,instanceFunction),_,_,_)
Test.hx:44:,FilePos(Method(null,abstractFunction),_,_,_)
Test.hx:44:,FilePos(Method(null,staticFunction),_,_,_)
Test.hx:44:,FilePos(Method(null,main),_,_,_)
Test.hx:44:,FilePos(null,_,_,_)
Test.hx:44:,FilePos(null,_,_,_)
*/
}
}
```

This is simple enough to fix in the standard library's javascript implementation of `NativeStackTrace.prepareHxStackTrace` for ES5 code. I have a commit prepared with a fix for that case (https://github.com/justin-espedal/haxe/commit/243c4d972b15b3d787700e25756c82adcf155748), but thought I'd withhold it pending discussion. For ES6 code I have no idea because `site.getTypeName()`, `site.getFunctionName()`, and `site.getMethodName()` all don't provide the needed information for static functions and abstracts.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.