DART是否支持预定义宏?

3

DART是否支持预定义的宏,例如:

__LINE__

或者

__FUNCTION__

我提问的原因是,转换器DART2JS使控制台日志无用,因为所有的日志都显示为: js_primitives.dart:30

[更新BasE]

当使用转换器dart2js时,print("hello world");会导致以下结果:

JS('void', r'console.log(#)', "hello world);

需要从位于库dart2js._js_primitives中的函数printString(String string)调用

这导致控制台日志消息始终包含相同的行号,无论在DART代码中的哪个位置使用print()。(由于console.log将自动添加文件名和行号到驻留在dart2js._js_primitives中的包装函数的控制台显示),由于当前实现向console.log消息添加文件名和行号是无用的,如果有另一种方法允许显示附加信息将会更好。

例如,print("hello world" __FUNCTION__ __LINE__);将导致显示更多有用的调试信息。


2
不,没有,但我不明白它的存在(或不存在)与你关于控制台日志记录的问题有什么关系。你能否尝试问一下你想要看到哪些具体变化? - matanlurey
刚刚向原始问题中添加了更多的文本。 - Bas E
2个回答

2

嗨,Gunter,我刚试了一下你的建议。它生成了很多信息。确实,在第二行中打印了文件名和行号。错误 在 Object.StackTrace_current (core_patch.dart:680) 处 在 testCase_readWrite.dart:59 处 在 _wrapJsFunctionForAsync_closure.$protected (async_patch.dart:213) 处 ... ... - Bas E
你可以尝试使用stack_trace包中的terse函数来减少噪音 https://dev59.com/qIjca4cB1Zd3GeqP0K5c#29013592。这可能会导致一些内存使用和性能方面的开销,但我发现它在调试时经常很有用。 - Günter Zöchbauer
通过使用以下代码: print(new Trace.from(StackTrace.current).terse); 将会得到如下输出结果: main.dart.js 13338:40 Object.StackTrace_current main.dart.js 68378:44 <fn> main.dart.js 6883:15 _wrapJsFunctionForAsync_closure.$protected 它会剥离函数名。 - Bas E
使用以下代码:print(new Trace.from(StackTrace.current).vmTrace); 结果为: #1 Object.StackTrace_current (http://localhost:64250/main.dart.js:13338:40) #2 <anonymous closure> (http://localhost:64250/main.dart.js:68380:44) #3 _wrapJsFunctionForAsync_closure.$protected (http://localhost:64250/main.dart.js:6883:15) 它还删除了函数名称。 - Bas E
1
使用 print(new Trace.from(StackTrace.current).original); 将会给我最好的结果。 错误 在 Object.StackTrace_current (core_patch.dart:680) 在 testCase_readWrite.dart:66 在 _wrapJsFunctionForAsync_closure.$protected (async_patch.dart:213) - Bas E

0

看起来你需要的是dart2js创建的源映射,其中包含从javascript位置重新创建原始dart文件中行号所需的信息。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接