Skip to content

Move segment and start operations to the end of instantiation in JS.md #780

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

Merged
merged 3 commits into from
Sep 5, 2016

Conversation

lukewagner
Copy link
Member

The way JS.md is currently written, failures can occur after the Elements and/or Data segments have been written to globally-visible (imported) tables/memories and/or after start is called. This sort of partial initialization seems undesirable so this PR moves all the globally-visible operations to the very end so failure makes more sense and you can't end up with partially-written segments.

If any of the elements of an [Elements section](Modules.md#elements-section)
refer to an imported function which is not an
[Exported Function Exotic Object](#exported-function-exotic-objects), throw a
[`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because they don't have a type that call_indirect can check? Why can't it use the respective import signature?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just mirroring the MVP constraints added in #775 that tables only contain WebAssembly functions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And so if we relaxed that restriction it'd be trivial to relax here; it's the same underlying implementation challenge.)

@lukewagner
Copy link
Member Author

Any other comments? @gahaas?

Note: this synchronously executes the [`start`](Modules.md#module-start-function)
function, if present.
Let `instance` be the result of creating a new
[`Eval.instance`](https://github.com/WebAssembly/spec/blob/master/ml-proto/spec/eval.ml#L15)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if a link to (https://github.com/WebAssembly/design/blob/master/JS.md#webassemblyinstance-objects) would be more helpful here than a link to the spec. In (https://github.com/WebAssembly/design/blob/master/JS.md#webassemblyinstance-objects) the link to the spec is helpful because there is some text which tells you what to expect from that link. Here, however, I did not know what this link actually means.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is a bit subtle, but there are two things here: the abstract wasm-spec-defined Eval.instance (which probably we'll rename and relink once we have a prose spec in the spec repo) and the JS WebAssembly.Instance object we're constructing which "wraps" it. Here we're making the former; only at the end do we construct the latter. We create the former here because it is needed to create the exported functions below. Does that clear it up for you any?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do understand that Eval.instance != WebAssembly.Instance. The reason why I mentioned (https://github.com/WebAssembly/design/blob/master/JS.md#webassemblyinstance-objects) is because it is the section which contains the definition of Eval.instance in JS.md. Is there a way to create a link to the definition of Eval.instance directly?

Copy link
Member Author

@lukewagner lukewagner Sep 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's what I was attempting to do with https://github.com/WebAssembly/spec/blob/master/ml-proto/spec/eval.ml#L15. That's a stand-in for what will be the prose-spec's abstract definition of a wasm instance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you have something different in mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you are right that the prose spec will eventually fix this problem anyways.

@lukewagner
Copy link
Member Author

@gahaas / @rossberg-chromium Any further comments?

@rossberg
Copy link
Member

rossberg commented Sep 5, 2016

LGTM

1 similar comment
@gahaas
Copy link
Contributor

gahaas commented Sep 5, 2016

LGTM

@lukewagner lukewagner merged commit 1e6bf08 into master Sep 5, 2016
@lukewagner lukewagner deleted the all-or-nothing-init branch September 5, 2016 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants