-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specify display conventions for wasm locations #1053
Changes from 3 commits
b9ca72f
a2c18aa
759732f
44f9459
40727c8
fc10e38
2c19e3a
aaa35d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,53 @@ MIME type mismatch or `opaque` response types | |
[reject](http://tc39.github.io/ecma262/#sec-rejectpromise) the Promise with a | ||
`WebAssembly.CompileError`. | ||
|
||
## Developer-facing display conventions | ||
|
||
Browsers, JavaScript engines, and offline tools have common ways of referring to | ||
JavaScript artifacts and language constructs. For example, locations in | ||
JavaScript source code are printed in stack traces or error messages, and are | ||
represented naturally as decimal-format lines and columns in text files. Names | ||
of functions and variables are taken directly from the sources. Therefore (for | ||
example) even though the exact format of Error.stack strings does not always | ||
match, the locations are easily understandable and the same across browsers. | ||
|
||
To achive the same goal of a common representations for WebAssembly constructs, the | ||
following conventions are adopted. | ||
|
||
A WebAssembly location is a reference to a particular instruction in the binary, and may be | ||
displayed by a browser or engine in similar contexts as JavaScript source locations. | ||
It has the following format: | ||
`${url}:wasm-function[${funcIndex}]:${pcOffset}` | ||
Where | ||
* `${url}` is the URL associated with the module (e.g. via a response | ||
object), or other module identifier (see notes). | ||
* `${funcIndex}` is an index the [function index space](Modules.md#function-index-space). | ||
* `${pcOffset}` is the offset in the module binary of the first byte | ||
of the instruction, printed in hexadecimal with lower-case digits, | ||
with a leading `0x` prefix. | ||
|
||
Notes: | ||
* The URL field may be interpreted differently depending on the context. For | ||
example offline tools may use a file name; or when the ArrayBuffer-based | ||
`WebAssembly.instantiate` API is used in a browser, it may display the | ||
location of the API call instead. It should not be empty however; a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. API calls may not have useful source locations either, e.g. when performed as part of an |
||
developer should be able to write their code such that modules from | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you suggesting that programmers should be able to rely on unambiguous location URLs? If so, I don't think that can work in general, e.g. for the aforementioned reason, but also because of URL ambiguities in general. I would rather drop that half-sentence. |
||
different sources are displayed with different identifiers. | ||
* Using hexadecimal for module offsets matches common conventions in native tools | ||
such as objdump (where addresses are printed in hex) and makes them visually | ||
distinct from JavaScript line numbers. Other numbers are represented in decimal. | ||
|
||
Names of functions may also be displayed if the module contains a `"name"` | ||
section; these can be used in the same contexts as JavaScript functions. | ||
If there are no names provided, then engines should simply ensure that | ||
the location can still be identified (e.g. by showing the function | ||
number instead, if the full location is not already being shown). | ||
Note also that this document does | ||
not specify the full format of strings such as stack frame representations; | ||
this allows engines to continue using their existing formats for JavaScript | ||
(which existing code may already be depending on) while still printing | ||
WebAssembly frames in a format consistent with JavaScript. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also add a Note saying somewhere that these conventions do not describe the value of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha good point. Would we want a way to map one to the other as a standalone function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You you mean like some new JS API for producing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. My thinking it: we already let developers access the name section so they don't have to parse their own module... but then they need to parse the name section to get that information! Cut the middle-person. 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that makes sense if client code would otherwise be doing their own binary parsing that we've already done. With the other Module reflection methods, our motivating use case was module loaders (and specific experience with incorporating wasm into SystemJS). It'd be nice to have some specific user who is wanting to programmatically access these function names. Anyhow, this probably belongs in a different issue. |
||
|
||
## Modules | ||
|
||
WebAssembly's [modules](Modules.md) allow for natural [integration with | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: missing "in"