ios icon indicating copy to clipboard operation
ios copied to clipboard

Function names are not printed when use console.trace()

Open Natalia-Hristova opened this issue 5 years ago • 1 comments

  1. Run tns create AppJS --js
  2. Add console.trace();
  3. Run tns debug ios and open the URL in Chrome

Actual:

at <anonymous> (file:///app/bundle.js:286:17)
at <anonymous> (file:///app/vendor.js:3620:32)
at <anonymous> (file:///app/vendor.js:3640:18)
at <anonymous> (file:///app/vendor.js:15540:19)

Here's how it looks in android:

main-view-model.js:40 Trace
at viewModel.onTap (file:///data/data/org.nativescript.AppDebugJS/files/app/bundle.js:294:17)
at push.../node_modules/@nativescript/core/data/observable/observable.js.Observable.notify (file:///data/data/org.nativescript.AppDebugJS/files/app/vendor.js:3537:32)
at push.../node_modules/@nativescript/core/data/observable/observable.js.Observable._emit (file:///data/data/org.nativescript.AppDebugJS/files/app/vendor.js:3557:18)
at ClickListenerImpl.onClick (file:///data/data/org.nativescript.AppDebugJS/files/app/vendor.js:14715:23)

Natalia-Hristova avatar Nov 18 '19 09:11 Natalia-Hristova

The full file paths are pretty long on iOS and are intentionally stripped as it makes stacktraces harder to read.

Consider this:

at <anonymous> (file:///var/containers/Bundle/Application/94891CB2-71B9-4DF6-99FB-742E82210A7A/TestRunner.app/app/index.js:6:17)
at test (file:///var/containers/Bundle/Application/94891CB2-71B9-4DF6-99FB-742E82210A7A/TestRunner.app/app/index.js:8:21)
at <anonymous> (file:///var/containers/Bundle/Application/94891CB2-71B9-4DF6-99FB-742E82210A7A/TestRunner.app/app/index.js:9:3)
at require (VM)

In contrast to this:

at <anonymous> (file:///app/index.js:6:17)
at test (file:///app/index.js:8:21)
at <anonymous> (file:///app/index.js:9:3)
at require (VM)

On the other hand we have an issue that prevents the runtime from properly collecting function names in stack traces. Notice the <anonymous> names in the stacktrace.

Let's consider the following example:

(function test() {
    const viewModel = new Object();
    viewModel.onTap = () => { console.trace("ok"); };
    viewModel.onTap.apply(viewModel, []);
})();

Which produces:

at <anonymous> (file:///app/index.js:6:17)
at test (file:///app/index.js:8:21)
at <anonymous> (file:///app/index.js:9:3)
at require (VM)

instead of the expected:

at viewModel.onTap (file:///app/index.js:6:17)
at test (file:///app/index.js:8:21)
at <anonymous> (file:///app/index.js:9:3)
at require (VM)

darind avatar Nov 19 '19 08:11 darind