TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Beyond Source Maps

53 pointsby mnemonikabout 11 years ago

5 comments

sillysaurus3about 11 years ago
In case anyone else is wondering what a source map is, it's apparently Javascript's version of C's debug symbols. That is, given a chunk of optimized runtime code, it will show you which part of your original source code generated it.
评论 #7388571 未加载
评论 #7388775 未加载
kevingaddabout 11 years ago
Glad to see people thinking about making source maps useful for more real world scenarios. As mentioned in my other comment (<a href="https://news.ycombinator.com/item?id=7388775" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7388775</a>) they are not useful for most &#x27;js as compilation target&#x27; scenarios.
评论 #7388830 未加载
bluerobotcatabout 11 years ago
I&#x27;m not completely sure I&#x27;m reading this proposal correctly, but at first blush it seems like it would only support lexically scoped variables. If so then that would be an unfortunate limitation.<p>ClojureScript, for instance, supports dynamic bindings.
评论 #7392656 未加载
cromwellianabout 11 years ago
We&#x27;ve had some of these problems with GWT, but I think some of them can be solved with a much simpler mechanism than serializing an AST.<p>For example, for each symbol we record, we can simply introduce something called a &#x27;scope identifier&#x27; and then define a language specific mechanism by which debuggers can compute scope identifiers.<p>Consider the following problem for GWT:<p>class Foo { String hello; }<p>class Bar { String world; }<p>Both of these can be compiled and obfuscated an an object with field &#x27;a&#x27;. So when encountering a heap reference to an object with field &#x27;a&#x27;, does it deobfuscate to &#x27;hello&#x27; or deobfuscate to &#x27;world&#x27;?<p>We have many kinds of scopes: global scope, object scope, function scope, etc. In this case, its an object scope. If we uniquely identify each scope, we can perform the mapping as long as there&#x27;s a way to compute runtime type, e.g.<p>Store &#x27;a&#x27; as &#x27;2:a&#x27; (scope identifier &#x27;2&#x27;) Put a mapping in the sourcemap that &#x27;Foo&#x27; maps to &#x27;2&#x27;, and now we can introspect the heap reference, determine it is &#x27;Foo&#x27;, map it to &#x27;2&#x27;, and properly display it as &#x27;hello&#x27;<p>Different languages may have different ways of setting up classes and defining runtime types. GWT for example, does not rely on JS constructors, but instead hangs a classId off of the prototype. I think Dart does something different. In any case, it is a simple extension to the existing format and backwards compatible. The only runtime API needed is a function getScopeIdForReference(obj) which takes a compiled object and gives its scope.<p>The AST approach I think has several problems:<p>1) if the annotations are present in the shipped obfuscated code, it leaks information that people don&#x27;t want. Many people do not want to leak the source filenames or directory structure of production apps.<p>2) it increases the download size for consumers who are not developers and don&#x27;t need the maps<p>3) if written out as a separate file that co-exists with a stripped binary, it increases memory requirements of the debugger.<p>The way Google deploys Gmail, for example, we use sourcemaps in production as well as development. When exceptions are thrown on the client, the stack traces are reported back to servers, deobfuscated via sourcemaps, and put into a triage system. A person looking at a bug report sees a deobfuscated trace, but the consumers aren&#x27;t burned with having to download the sourcemaps in annotated js.<p>I think the idea of defining an actual sourcemap API for the debugger (getDisplayValues, getLocals, eval, etc) has a lot of value, because these function are source-language dependent, so having GWT&#x2F;Dart&#x2F;Emscripten&#x2F;CoffeeScript&#x2F;etc generate them is useful.<p>But I don&#x27;t think annotating the actual JS, or switching the sourcemap format to an AST is a big win. Yes, it is a simplification, but it also trades off other useful properties of sourcemaps.
评论 #7389122 未加载
elwellabout 11 years ago
Or just sit back and hope for a super cool Google dev tools update.
评论 #7390039 未加载