From bc1ccfc751c5cac5f225996a9439e761088c3c2d Mon Sep 17 00:00:00 2001 From: rossberg-chromium Date: Mon, 15 May 2017 11:17:30 +0200 Subject: Clarify generativity of JS host functions values (#987) --- JS.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'JS.md') diff --git a/JS.md b/JS.md index fb1bcc7..02f07dd 100644 --- a/JS.md +++ b/JS.md @@ -309,6 +309,12 @@ is thrown. If the list of is not empty and `Type(importObject)` is not Object, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) is thrown. +Note: Imported JavaScript functions are wrapped as [host function](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/instance.ml#L9) values in the following algorithm. For the purpose of the algorithm, a _new_ [host function](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/instance.ml#L9) value is always generated fresh and considered distinct from any other previously created host function value, including those wrapping the same JavaScript function object. +Consequently, two [closure](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/instance.ml#L7) values are considered equal if and only if: + +* Either they are both WebAssembly functions for the same instance and referring to the same function definition. +* Or they are the same host function value. + Let `funcs`, `memories` and `tables` be initially-empty lists of callable JavaScript objects, `WebAssembly.Memory` objects and `WebAssembly.Table` objects, respectively. Let `imports` be an initially-empty list of [`external`](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/instance.ml#L11) values. @@ -329,8 +335,8 @@ For each [`import`](https://github.com/WebAssembly/spec/blob/master/interpreter/ by `Eval.init` below.) 1. Let `closure` be `v.[[Closure]]`. 1. Otherwise: - 1. Let `closure` be a new [host function](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/instance.ml#L9) - of the given signature: + 1. Let `closure` be a new [host function](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/instance.ml#L9) value + of the given signature and the following behavior: 1. If the signature contains an `i64` (as argument or result), the host function immediately throws a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) when called. @@ -437,11 +443,6 @@ each [external](https://github.com/WebAssembly/spec/blob/master/interpreter/spec 1. Assert: There is an element `table` in `tables` whose `table.[[Table]]` is `t`. 1. Return that `table`. -Note: For the purpose of the above algorithm, two [closure](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/instance.ml#L7) values are considered equal if and only if: - -* Either they are both WebAssembly functions for the same instance and referring to the same function definition. -* Or they are identical host functions (i.e., each host function value created from a JavaScript function is considered fresh). - Let `exportsObject` be a new [frozen](https://tc39.github.io/ecma262/#sec-object.freeze) plain JS object with [[Prototype]] set to Null and with properties defined by mapping each export in `exports` to an enumerable, non-writable, -- cgit v1.2.3