Changeset 271112 in webkit


Ignore:
Timestamp:
Dec 30, 2020 4:04:56 PM (19 months ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Update WebAssembly instance's exports object
https://bugs.webkit.org/show_bug.cgi?id=220189

Reviewed by Alexey Shvayka.

JSTests:

  • stress/sampling-profiler-wasm-name-section.js:

(platformSupportsSamplingProfiler.vm.isWasmSupported):

  • stress/sampling-profiler-wasm.js:

(platformSupportsSamplingProfiler.vm.isWasmSupported):

  • wasm/js-api/test_basic_api.js:

(const.c.in.constructorProperties.switch):

  • wasm/stress/exports-object.js: Added.

(async try):
(catch):

LayoutTests/imported/w3c:

  • web-platform-tests/wasm/jsapi/constructor/instantiate.any-expected.txt:
  • web-platform-tests/wasm/jsapi/constructor/instantiate.any.worker-expected.txt:
  • web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt:
  • web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt:
  • web-platform-tests/wasm/jsapi/table/grow-reftypes.tentative.any-expected.txt:

Source/JavaScriptCore:

This patch aligns the WebAssembly Instance's exports object to the updated spec.

  1. exports object is a plain object which Prototype? is null[1]. We were using module namespace object. Also, the object should be frozen.
  2. exported functions' name should be index, according to the spec[2].

[1]: https://webassembly.github.io/spec/js-api/index.html#create-an-exports-object
[2]: https://webassembly.github.io/spec/js-api/index.html#exported-function-exotic-objects

  • wasm/js/JSWebAssembly.cpp:

(JSC::resolve):

  • wasm/js/JSWebAssemblyInstance.cpp:

(JSC::JSWebAssemblyInstance::finishCreation):
(JSC::JSWebAssemblyInstance::visitChildren):
(JSC::JSWebAssemblyInstance::finalizeCreation):
(JSC::JSWebAssemblyInstance::tryCreate):

  • wasm/js/JSWebAssemblyInstance.h:
  • wasm/js/WebAssemblyInstancePrototype.cpp:

(JSC::JSC_DEFINE_HOST_FUNCTION):

  • wasm/js/WebAssemblyModuleRecord.cpp:

(JSC::WebAssemblyModuleRecord::visitChildren):
(JSC::WebAssemblyModuleRecord::link):

  • wasm/js/WebAssemblyModuleRecord.h:
Location:
trunk
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r271100 r271112  
     12020-12-29  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Update WebAssembly instance's exports object
     4        https://bugs.webkit.org/show_bug.cgi?id=220189
     5
     6        Reviewed by Alexey Shvayka.
     7
     8        * stress/sampling-profiler-wasm-name-section.js:
     9        (platformSupportsSamplingProfiler.vm.isWasmSupported):
     10        * stress/sampling-profiler-wasm.js:
     11        (platformSupportsSamplingProfiler.vm.isWasmSupported):
     12        * wasm/js-api/test_basic_api.js:
     13        (const.c.in.constructorProperties.switch):
     14        * wasm/stress/exports-object.js: Added.
     15        (async try):
     16        (catch):
     17
    1182020-12-27  Dmitry Bezhetskov  <dbezhetskov@igalia.com>
    219
  • trunk/JSTests/stress/sampling-profiler-wasm-name-section.js

    r264304 r271112  
    7070        return instance.exports._parrot(1);
    7171    };
    72     runTest(wasmEntry, ["_silly", "(unknown)", "<?>.wasm-function[_eggs]", "<?>.wasm-function[_bacon]", "<?>.wasm-function[_spam]", "<?>.wasm-function[_parrot]", "wasm-stub", "_parrot", "wasmEntry"]);
     72    runTest(wasmEntry, ["_silly", "(unknown)", "<?>.wasm-function[_eggs]", "<?>.wasm-function[_bacon]", "<?>.wasm-function[_spam]", "<?>.wasm-function[_parrot]", "wasm-stub", "24", "wasmEntry"]);
    7373}
  • trunk/JSTests/stress/sampling-profiler-wasm.js

    r264304 r271112  
    99        return instance.exports.loop(10000000);
    1010    };
    11     runTest(wasmEntry, ["<?>.wasm-function[0]", "wasm-stub", "loop", "wasmEntry"]);
     11    runTest(wasmEntry, ["<?>.wasm-function[0]", "wasm-stub", "0", "wasmEntry"]);
    1212}
  • trunk/JSTests/wasm/js-api/test_basic_api.js

    r247457 r271112  
    8585        assert.eq(Reflect.isExtensible(instance.exports), false);
    8686        assert.eq(Symbol.iterator in instance.exports, false);
    87         assert.eq(Symbol.toStringTag in instance.exports, true);
    88         assert.eq(Object.getOwnPropertySymbols(instance.exports).length, 1);
    89         assert.eq(Object.getOwnPropertySymbols(instance.exports)[0], Symbol.toStringTag);
     87        assert.eq(Symbol.toStringTag in instance.exports, false);
     88        assert.eq(Object.getOwnPropertySymbols(instance.exports).length, 0);
    9089        assert.throws(() => instance.exports[Symbol.toStringTag] = 42, TypeError, `Attempted to assign to readonly property.`);
    9190        break;
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r271092 r271112  
     12020-12-29  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Update WebAssembly instance's exports object
     4        https://bugs.webkit.org/show_bug.cgi?id=220189
     5
     6        Reviewed by Alexey Shvayka.
     7
     8        * web-platform-tests/wasm/jsapi/constructor/instantiate.any-expected.txt:
     9        * web-platform-tests/wasm/jsapi/constructor/instantiate.any.worker-expected.txt:
     10        * web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt:
     11        * web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt:
     12        * web-platform-tests/wasm/jsapi/table/grow-reftypes.tentative.any-expected.txt:
     13
    1142020-12-26  Alexey Shvayka  <shvaikalesh@gmail.com>
    215
  • trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate.any-expected.txt

    r269866 r271112  
    1414PASS imports: BufferSource argument
    1515PASS imports: Module argument
    16 FAIL No imports: BufferSource argument assert_array_equals: matching export keys expected property 2 to be "table" but got "global" (expected array ["fn", "fn2", "table", "global", "global2", "memory"] got ["fn", "fn2", "global", "global2", "memory", "table"])
    17 FAIL No imports: Module argument assert_array_equals: matching export keys expected property 2 to be "table" but got "global" (expected array ["fn", "fn2", "table", "global", "global2", "memory"] got ["fn", "fn2", "global", "global2", "memory", "table"])
    18 FAIL exports and imports: BufferSource argument assert_false: fn: writable expected false got true
    19 FAIL exports and imports: Module argument assert_false: fn: writable expected false got true
     16PASS No imports: BufferSource argument
     17PASS No imports: Module argument
     18PASS exports and imports: BufferSource argument
     19PASS exports and imports: Module argument
    2020FAIL i64 exports and imports: BufferSource argument promise_test: Unhandled rejection with value: object "LinkError: imported global module:global cannot be an i64"
    2121FAIL i64 exports and imports: Module argument promise_test: Unhandled rejection with value: object "LinkError: imported global module:global cannot be an i64"
    22 FAIL import with i32-returning function: BufferSource argument assert_false: fn2: writable expected false got true
    23 FAIL import with i32-returning function: Module argument assert_false: fn2: writable expected false got true
    24 FAIL import with function that takes and returns i32: BufferSource argument assert_false: fn2: writable expected false got true
    25 FAIL import with function that takes and returns i32: Module argument assert_false: fn2: writable expected false got true
    26 FAIL import with i64-returning function: BufferSource argument assert_false: fn2: writable expected false got true
    27 FAIL import with i64-returning function: Module argument assert_false: fn2: writable expected false got true
    28 FAIL import with function that takes and returns i64: BufferSource argument assert_false: fn2: writable expected false got true
    29 FAIL import with function that takes and returns i64: Module argument assert_false: fn2: writable expected false got true
    30 FAIL import with i32-taking function: BufferSource argument assert_false: fn: writable expected false got true
    31 FAIL import with i32-taking function: Module argument assert_false: fn: writable expected false got true
    32 FAIL import with i64-taking function: BufferSource argument assert_false: fn: writable expected false got true
    33 FAIL import with i64-taking function: Module argument assert_false: fn: writable expected false got true
    34 FAIL export i64-returning function: BufferSource argument assert_false: fn: writable expected false got true
    35 FAIL export i64-returning function: Module argument assert_false: fn: writable expected false got true
    36 FAIL i32 mutable WebAssembly.Global import: BufferSource argument assert_false: fn: writable expected false got true
    37 FAIL i32 mutable WebAssembly.Global import: Module argument assert_false: fn: writable expected false got true
     22PASS import with i32-returning function: BufferSource argument
     23PASS import with i32-returning function: Module argument
     24PASS import with function that takes and returns i32: BufferSource argument
     25PASS import with function that takes and returns i32: Module argument
     26FAIL import with i64-returning function: BufferSource argument assert_true: Should have called into JS expected true got false
     27FAIL import with i64-returning function: Module argument assert_true: Should have called into JS expected true got false
     28FAIL import with function that takes and returns i64: BufferSource argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn2()')"
     29FAIL import with function that takes and returns i64: Module argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn2()')"
     30PASS import with i32-taking function: BufferSource argument
     31PASS import with i32-taking function: Module argument
     32FAIL import with i64-taking function: BufferSource argument assert_throws_js: function "() => instance.exports.fn(6)" threw object "RuntimeError: WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'instance.exports.fn(6)')" ("RuntimeError") expected instance of function "function TypeError() {
     33    [native code]
     34}" ("TypeError")
     35FAIL import with i64-taking function: Module argument assert_throws_js: function "() => instance.exports.fn(6)" threw object "RuntimeError: WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'instance.exports.fn(6)')" ("RuntimeError") expected instance of function "function TypeError() {
     36    [native code]
     37}" ("TypeError")
     38FAIL export i64-returning function: BufferSource argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn()')"
     39FAIL export i64-returning function: Module argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn()')"
     40PASS i32 mutable WebAssembly.Global import: BufferSource argument
     41PASS i32 mutable WebAssembly.Global import: Module argument
    3842FAIL i64 mutable WebAssembly.Global import: BufferSource argument WebAssembly.Global does not accept i64 initial value
    3943FAIL i64 mutable WebAssembly.Global import: Module argument WebAssembly.Global does not accept i64 initial value
    40 FAIL Multiple i64 arguments: BufferSource argument assert_false: fn: writable expected false got true
    41 FAIL Multiple i64 arguments: Module argument assert_false: fn: writable expected false got true
     44FAIL Multiple i64 arguments: BufferSource argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'fn(1n, 0n)')"
     45FAIL Multiple i64 arguments: Module argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'fn(1n, 0n)')"
    4246PASS stray argument: BufferSource argument
    4347PASS stray argument: Module argument
  • trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate.any.worker-expected.txt

    r269866 r271112  
    1414PASS imports: BufferSource argument
    1515PASS imports: Module argument
    16 FAIL No imports: BufferSource argument assert_array_equals: matching export keys expected property 2 to be "table" but got "global" (expected array ["fn", "fn2", "table", "global", "global2", "memory"] got ["fn", "fn2", "global", "global2", "memory", "table"])
    17 FAIL No imports: Module argument assert_array_equals: matching export keys expected property 2 to be "table" but got "global" (expected array ["fn", "fn2", "table", "global", "global2", "memory"] got ["fn", "fn2", "global", "global2", "memory", "table"])
    18 FAIL exports and imports: BufferSource argument assert_false: fn: writable expected false got true
    19 FAIL exports and imports: Module argument assert_false: fn: writable expected false got true
     16PASS No imports: BufferSource argument
     17PASS No imports: Module argument
     18PASS exports and imports: BufferSource argument
     19PASS exports and imports: Module argument
    2020FAIL i64 exports and imports: BufferSource argument promise_test: Unhandled rejection with value: object "LinkError: imported global module:global cannot be an i64"
    2121FAIL i64 exports and imports: Module argument promise_test: Unhandled rejection with value: object "LinkError: imported global module:global cannot be an i64"
    22 FAIL import with i32-returning function: BufferSource argument assert_false: fn2: writable expected false got true
    23 FAIL import with i32-returning function: Module argument assert_false: fn2: writable expected false got true
    24 FAIL import with function that takes and returns i32: BufferSource argument assert_false: fn2: writable expected false got true
    25 FAIL import with function that takes and returns i32: Module argument assert_false: fn2: writable expected false got true
    26 FAIL import with i64-returning function: BufferSource argument assert_false: fn2: writable expected false got true
    27 FAIL import with i64-returning function: Module argument assert_false: fn2: writable expected false got true
    28 FAIL import with function that takes and returns i64: BufferSource argument assert_false: fn2: writable expected false got true
    29 FAIL import with function that takes and returns i64: Module argument assert_false: fn2: writable expected false got true
    30 FAIL import with i32-taking function: BufferSource argument assert_false: fn: writable expected false got true
    31 FAIL import with i32-taking function: Module argument assert_false: fn: writable expected false got true
    32 FAIL import with i64-taking function: BufferSource argument assert_false: fn: writable expected false got true
    33 FAIL import with i64-taking function: Module argument assert_false: fn: writable expected false got true
    34 FAIL export i64-returning function: BufferSource argument assert_false: fn: writable expected false got true
    35 FAIL export i64-returning function: Module argument assert_false: fn: writable expected false got true
    36 FAIL i32 mutable WebAssembly.Global import: BufferSource argument assert_false: fn: writable expected false got true
    37 FAIL i32 mutable WebAssembly.Global import: Module argument assert_false: fn: writable expected false got true
     22PASS import with i32-returning function: BufferSource argument
     23PASS import with i32-returning function: Module argument
     24PASS import with function that takes and returns i32: BufferSource argument
     25PASS import with function that takes and returns i32: Module argument
     26FAIL import with i64-returning function: BufferSource argument assert_true: Should have called into JS expected true got false
     27FAIL import with i64-returning function: Module argument assert_true: Should have called into JS expected true got false
     28FAIL import with function that takes and returns i64: BufferSource argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn2()')"
     29FAIL import with function that takes and returns i64: Module argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn2()')"
     30PASS import with i32-taking function: BufferSource argument
     31PASS import with i32-taking function: Module argument
     32FAIL import with i64-taking function: BufferSource argument assert_throws_js: function "() => instance.exports.fn(6)" threw object "RuntimeError: WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'instance.exports.fn(6)')" ("RuntimeError") expected instance of function "function TypeError() {
     33    [native code]
     34}" ("TypeError")
     35FAIL import with i64-taking function: Module argument assert_throws_js: function "() => instance.exports.fn(6)" threw object "RuntimeError: WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'instance.exports.fn(6)')" ("RuntimeError") expected instance of function "function TypeError() {
     36    [native code]
     37}" ("TypeError")
     38FAIL export i64-returning function: BufferSource argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn()')"
     39FAIL export i64-returning function: Module argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn()')"
     40PASS i32 mutable WebAssembly.Global import: BufferSource argument
     41PASS i32 mutable WebAssembly.Global import: Module argument
    3842FAIL i64 mutable WebAssembly.Global import: BufferSource argument WebAssembly.Global does not accept i64 initial value
    3943FAIL i64 mutable WebAssembly.Global import: Module argument WebAssembly.Global does not accept i64 initial value
    40 FAIL Multiple i64 arguments: BufferSource argument assert_false: fn: writable expected false got true
    41 FAIL Multiple i64 arguments: Module argument assert_false: fn: writable expected false got true
     44FAIL Multiple i64 arguments: BufferSource argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'fn(1n, 0n)')"
     45FAIL Multiple i64 arguments: Module argument promise_test: Unhandled rejection with value: object "RuntimeError: WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'fn(1n, 0n)')"
    4246PASS stray argument: BufferSource argument
    4347PASS stray argument: Module argument
  • trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt

    r269866 r271112  
    1010FAIL getter order for imports object assert_array_equals: expected property 1 to be "global1 getter" but got "memory getter" (expected array ["module getter", "global1 getter", "module2 getter", "global3 getter", "module getter", "memory getter", "module getter", "global2 getter"] got ["module getter", "memory getter", "module getter", "global1 getter", "module2 getter", "global3 getter", "module getter", "global2 getter"])
    1111PASS imports
    12 FAIL No imports assert_array_equals: matching export keys expected property 2 to be "table" but got "global" (expected array ["fn", "fn2", "table", "global", "global2", "memory"] got ["fn", "fn2", "global", "global2", "memory", "table"])
    13 FAIL exports and imports assert_false: fn: writable expected false got true
     12PASS No imports
     13PASS exports and imports
    1414FAIL i64 exports and imports imported global module:global cannot be an i64 (evaluating 'new WebAssembly.Instance(module, ...args)')
    15 FAIL import with i32-returning function assert_false: fn2: writable expected false got true
    16 FAIL import with function that takes and returns i32 assert_false: fn2: writable expected false got true
    17 FAIL import with i64-returning function assert_false: fn2: writable expected false got true
    18 FAIL import with function that takes and returns i64 assert_false: fn2: writable expected false got true
    19 FAIL import with i32-taking function assert_false: fn: writable expected false got true
    20 FAIL import with i64-taking function assert_false: fn: writable expected false got true
    21 FAIL export i64-returning function assert_false: fn: writable expected false got true
    22 FAIL i32 mutable WebAssembly.Global import assert_false: fn: writable expected false got true
     15PASS import with i32-returning function
     16PASS import with function that takes and returns i32
     17FAIL import with i64-returning function assert_true: Should have called into JS expected true got false
     18FAIL import with function that takes and returns i64 WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn2()')
     19PASS import with i32-taking function
     20FAIL import with i64-taking function assert_throws_js: function "() => instance.exports.fn(6)" threw object "RuntimeError: WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'instance.exports.fn(6)')" ("RuntimeError") expected instance of function "function TypeError() {
     21    [native code]
     22}" ("TypeError")
     23FAIL export i64-returning function WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn()')
     24PASS i32 mutable WebAssembly.Global import
    2325FAIL i64 mutable WebAssembly.Global import WebAssembly.Global does not accept i64 initial value
    24 FAIL Multiple i64 arguments assert_false: fn: writable expected false got true
     26FAIL Multiple i64 arguments WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'fn(1n, 0n)')
    2527PASS stray argument
    2628
  • trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt

    r269866 r271112  
    1010FAIL getter order for imports object assert_array_equals: expected property 1 to be "global1 getter" but got "memory getter" (expected array ["module getter", "global1 getter", "module2 getter", "global3 getter", "module getter", "memory getter", "module getter", "global2 getter"] got ["module getter", "memory getter", "module getter", "global1 getter", "module2 getter", "global3 getter", "module getter", "global2 getter"])
    1111PASS imports
    12 FAIL No imports assert_array_equals: matching export keys expected property 2 to be "table" but got "global" (expected array ["fn", "fn2", "table", "global", "global2", "memory"] got ["fn", "fn2", "global", "global2", "memory", "table"])
    13 FAIL exports and imports assert_false: fn: writable expected false got true
     12PASS No imports
     13PASS exports and imports
    1414FAIL i64 exports and imports imported global module:global cannot be an i64 (evaluating 'new WebAssembly.Instance(module, ...args)')
    15 FAIL import with i32-returning function assert_false: fn2: writable expected false got true
    16 FAIL import with function that takes and returns i32 assert_false: fn2: writable expected false got true
    17 FAIL import with i64-returning function assert_false: fn2: writable expected false got true
    18 FAIL import with function that takes and returns i64 assert_false: fn2: writable expected false got true
    19 FAIL import with i32-taking function assert_false: fn: writable expected false got true
    20 FAIL import with i64-taking function assert_false: fn: writable expected false got true
    21 FAIL export i64-returning function assert_false: fn: writable expected false got true
    22 FAIL i32 mutable WebAssembly.Global import assert_false: fn: writable expected false got true
     15PASS import with i32-returning function
     16PASS import with function that takes and returns i32
     17FAIL import with i64-returning function assert_true: Should have called into JS expected true got false
     18FAIL import with function that takes and returns i64 WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn2()')
     19PASS import with i32-taking function
     20FAIL import with i64-taking function assert_throws_js: function "() => instance.exports.fn(6)" threw object "RuntimeError: WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'instance.exports.fn(6)')" ("RuntimeError") expected instance of function "function TypeError() {
     21    [native code]
     22}" ("TypeError")
     23FAIL export i64-returning function WebAssembly function that returns i64 can't be called from JavaScript (evaluating 'instance.exports.fn()')
     24PASS i32 mutable WebAssembly.Global import
    2325FAIL i64 mutable WebAssembly.Global import WebAssembly.Global does not accept i64 initial value
    24 FAIL Multiple i64 arguments assert_false: fn: writable expected false got true
     26FAIL Multiple i64 arguments WebAssembly function with an i64 argument can't be called from JavaScript (evaluating 'fn(1n, 0n)')
    2527PASS stray argument
    2628
  • trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow-reftypes.tentative.any-expected.txt

    r260690 r271112  
    11
    2 FAIL Grow with exported-function argument assert_equals: expected (function) function "function fn() {
     2FAIL Grow with exported-function argument assert_equals: expected (function) function "function 0() {
    33    [native code]
    44}" but got (object) null
  • trunk/Source/JavaScriptCore/ChangeLog

    r271100 r271112  
     12020-12-29  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Update WebAssembly instance's exports object
     4        https://bugs.webkit.org/show_bug.cgi?id=220189
     5
     6        Reviewed by Alexey Shvayka.
     7
     8        This patch aligns the WebAssembly Instance's exports object to the updated spec.
     9
     10        1. exports object is a plain object which [[Prototype]] is null[1]. We were using module namespace object. Also, the object should be frozen.
     11        2. exported functions' name should be index, according to the spec[2].
     12
     13        [1]: https://webassembly.github.io/spec/js-api/index.html#create-an-exports-object
     14        [2]: https://webassembly.github.io/spec/js-api/index.html#exported-function-exotic-objects
     15
     16        * wasm/js/JSWebAssembly.cpp:
     17        (JSC::resolve):
     18        * wasm/js/JSWebAssemblyInstance.cpp:
     19        (JSC::JSWebAssemblyInstance::finishCreation):
     20        (JSC::JSWebAssemblyInstance::visitChildren):
     21        (JSC::JSWebAssemblyInstance::finalizeCreation):
     22        (JSC::JSWebAssemblyInstance::tryCreate):
     23        * wasm/js/JSWebAssemblyInstance.h:
     24        * wasm/js/WebAssemblyInstancePrototype.cpp:
     25        (JSC::JSC_DEFINE_HOST_FUNCTION):
     26        * wasm/js/WebAssemblyModuleRecord.cpp:
     27        (JSC::WebAssemblyModuleRecord::visitChildren):
     28        (JSC::WebAssemblyModuleRecord::link):
     29        * wasm/js/WebAssemblyModuleRecord.h:
     30
    1312020-12-27  Dmitry Bezhetskov  <dbezhetskov@igalia.com>
    232
  • trunk/Source/JavaScriptCore/wasm/js/JSWebAssembly.cpp

    r267594 r271112  
    4646#include "StructureInlines.h"
    4747#include "ThrowScope.h"
     48#include "WebAssemblyModuleRecord.h"
    4849
    4950namespace JSC {
     
    183184        promise->resolve(globalObject, instance);
    184185    else if (resolveKind == Resolve::WithModuleRecord) {
    185         auto* moduleRecord = instance->moduleNamespaceObject()->moduleRecord();
     186        auto* moduleRecord = instance->moduleRecord();
    186187        if (UNLIKELY(Options::dumpModuleRecord()))
    187188            moduleRecord->dump();
  • trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp

    r270208 r271112  
    5858}
    5959
    60 void JSWebAssemblyInstance::finishCreation(VM& vm, JSWebAssemblyModule* module, JSModuleNamespaceObject* moduleNamespaceObject)
     60void JSWebAssemblyInstance::finishCreation(VM& vm, JSWebAssemblyModule* module, WebAssemblyModuleRecord* moduleRecord)
    6161{
    6262    Base::finishCreation(vm);
     
    6464
    6565    m_module.set(vm, this, module);
    66     m_moduleNamespaceObject.set(vm, this, moduleNamespaceObject);
     66    m_moduleRecord.set(vm, this, moduleRecord);
    6767
    6868    vm.heap.reportExtraMemoryAllocated(m_instance->extraMemoryAllocated());
     
    8282    visitor.append(thisObject->m_module);
    8383    visitor.append(thisObject->m_codeBlock);
    84     visitor.append(thisObject->m_moduleNamespaceObject);
     84    visitor.append(thisObject->m_moduleRecord);
    8585    visitor.append(thisObject->m_memory);
    8686    for (unsigned i = 0; i < thisObject->instance().module().moduleInformation().tableCount(); ++i)
     
    138138    }
    139139
    140     auto* moduleRecord = jsCast<WebAssemblyModuleRecord*>(m_moduleNamespaceObject->moduleRecord());
    141     moduleRecord->prepareLink(vm, this);
     140    m_moduleRecord->prepareLink(vm, this);
    142141
    143142    if (creationMode == Wasm::CreationMode::FromJS) {
    144         moduleRecord->link(globalObject, jsNull(), importObject, creationMode);
     143        m_moduleRecord->link(globalObject, jsNull(), importObject, creationMode);
    145144        RETURN_IF_EXCEPTION(scope, void());
    146145
    147         JSValue startResult = moduleRecord->evaluate(globalObject);
     146        JSValue startResult = m_moduleRecord->evaluate(globalObject);
    148147        UNUSED_PARAM(startResult);
    149148        RETURN_IF_EXCEPTION(scope, void());
     
    177176    RETURN_IF_EXCEPTION(throwScope, nullptr);
    178177
    179     JSModuleNamespaceObject* moduleNamespace = moduleRecord->getModuleNamespace(globalObject);
    180 
    181178    auto storeTopCallFrame = [&vm] (void* topCallFrame) {
    182179        vm.topCallFrame = bitwise_cast<CallFrame*>(topCallFrame);
     
    186183    auto* jsInstance = new (NotNull, allocateCell<JSWebAssemblyInstance>(vm.heap)) JSWebAssemblyInstance(vm, instanceStructure,
    187184        Wasm::Instance::create(&vm.wasmContext, WTFMove(module), &vm.topEntryFrame, vm.addressOfSoftStackLimit(), WTFMove(storeTopCallFrame)));
    188     jsInstance->finishCreation(vm, jsModule, moduleNamespace);
     185    jsInstance->finishCreation(vm, jsModule, moduleRecord);
    189186    RETURN_IF_EXCEPTION(throwScope, nullptr);
    190187
  • trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h

    r260415 r271112  
    4141class JSModuleNamespaceObject;
    4242class JSWebAssemblyModule;
     43class WebAssemblyModuleRecord;
    4344
    4445namespace Wasm {
     
    6869   
    6970    Wasm::Instance& instance() { return m_instance.get(); }
    70     JSModuleNamespaceObject* moduleNamespaceObject() { return m_moduleNamespaceObject.get(); }
     71    WebAssemblyModuleRecord* moduleRecord() { return m_moduleRecord.get(); }
    7172
    7273    JSWebAssemblyMemory* memory() { return m_memory.get(); }
     
    104105private:
    105106    JSWebAssemblyInstance(VM&, Structure*, Ref<Wasm::Instance>&&);
    106     void finishCreation(VM&, JSWebAssemblyModule*, JSModuleNamespaceObject*);
     107    void finishCreation(VM&, JSWebAssemblyModule*, WebAssemblyModuleRecord*);
    107108    static void visitChildren(JSCell*, SlotVisitor&);
    108109
     
    113114    WriteBarrier<JSWebAssemblyModule> m_module;
    114115    WriteBarrier<JSWebAssemblyCodeBlock> m_codeBlock;
    115     WriteBarrier<JSModuleNamespaceObject> m_moduleNamespaceObject;
     116    WriteBarrier<WebAssemblyModuleRecord> m_moduleRecord;
    116117    WriteBarrier<JSWebAssemblyMemory> m_memory;
    117118    Vector<WriteBarrier<JSWebAssemblyTable>> m_tables;
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.cpp

    r267594 r271112  
    3333#include "JSModuleNamespaceObject.h"
    3434#include "JSWebAssemblyInstance.h"
     35#include "WebAssemblyModuleRecord.h"
    3536
    3637namespace JSC {
     
    6970    JSWebAssemblyInstance* instance = getInstance(globalObject, vm, callFrame->thisValue());
    7071    RETURN_IF_EXCEPTION(throwScope, { });
    71     return JSValue::encode(instance->moduleNamespaceObject());
     72    RELEASE_AND_RETURN(throwScope, JSValue::encode(instance->moduleRecord()->exportsObject()));
    7273}
    7374
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp

    r270965 r271112  
    8585    visitor.append(thisObject->m_instance);
    8686    visitor.append(thisObject->m_startFunction);
     87    visitor.append(thisObject->m_exportsObject);
    8788}
    8889
     
    361362
    362363    unsigned functionImportCount = codeBlock->functionImportCount();
    363     auto makeFunctionWrapper = [&] (const String& field, uint32_t index) -> JSValue {
     364    auto makeFunctionWrapper = [&] (uint32_t index) -> JSValue {
    364365        // If we already made a wrapper, do not make a new one.
    365366        JSValue wrapper = m_instance->instance().getFunctionWrapper(index);
     
    388389            Wasm::SignatureIndex signatureIndex = module->signatureIndexFromFunctionIndexSpace(index);
    389390            const Wasm::Signature& signature = Wasm::SignatureInformation::get(signatureIndex);
    390             WebAssemblyFunction* function = WebAssemblyFunction::create(vm, globalObject, globalObject->webAssemblyFunctionStructure(), signature.argumentCount(), field, m_instance.get(), embedderEntrypointCallee, entrypointLoadLocation, signatureIndex);
     391            WebAssemblyFunction* function = WebAssemblyFunction::create(vm, globalObject, globalObject->webAssemblyFunctionStructure(), signature.argumentCount(), makeString(index), m_instance.get(), embedderEntrypointCallee, entrypointLoadLocation, signatureIndex);
    391392            wrapper = function;
    392393        }
     
    399400
    400401    for (auto index : moduleInformation.referencedFunctions())
    401         makeFunctionWrapper("Referenced function", index);
     402        makeFunctionWrapper(index);
    402403
    403404    // Globals
     
    412413            } else if (global.initializationType == Wasm::GlobalInformation::FromRefFunc) {
    413414                ASSERT(global.initialBitsOrImportNumber < moduleInformation.functionIndexSpaceSize());
    414                 ASSERT(makeFunctionWrapper("Global init expr", global.initialBitsOrImportNumber).isCallable(vm));
    415                 initialBits = JSValue::encode(makeFunctionWrapper("Global init expr", global.initialBitsOrImportNumber));
     415                ASSERT(makeFunctionWrapper(global.initialBitsOrImportNumber).isCallable(vm));
     416                initialBits = JSValue::encode(makeFunctionWrapper(global.initialBitsOrImportNumber));
    416417            } else
    417418                initialBits = global.initialBitsOrImportNumber;
     
    438439
    439440    // Let exports be a list of (string, JS value) pairs that is mapped from each external value e in instance.exports as follows:
     441    // https://webassembly.github.io/spec/js-api/index.html#create-an-exports-object
     442    JSObject* exportsObject = constructEmptyObject(vm, globalObject->nullPrototypeObjectStructure());
    440443    JSModuleEnvironment* moduleEnvironment = JSModuleEnvironment::create(vm, globalObject, nullptr, exportSymbolTable, JSValue(), this);
    441444    for (const auto& exp : moduleInformation.exports) {
     
    443446        switch (exp.kind) {
    444447        case Wasm::ExternalKind::Function: {
    445             exportedValue = makeFunctionWrapper(String::fromUTF8(exp.field), exp.kindIndex);
     448            exportedValue = makeFunctionWrapper(exp.kindIndex);
    446449            ASSERT(exportedValue.isCallable(vm));
    447             ASSERT(makeFunctionWrapper(String::fromUTF8(exp.field), exp.kindIndex) == exportedValue);
     450            ASSERT(makeFunctionWrapper(exp.kindIndex) == exportedValue);
    448451            break;
    449452        }
     
    495498        }
    496499
     500        Identifier propertyName = Identifier::fromString(vm, String::fromUTF8(exp.field));
     501
    497502        bool shouldThrowReadOnlyError = false;
    498503        bool ignoreReadOnlyErrors = true;
    499504        bool putResult = false;
    500         symbolTablePutTouchWatchpointSet(moduleEnvironment, globalObject, Identifier::fromString(vm, String::fromUTF8(exp.field)), exportedValue, shouldThrowReadOnlyError, ignoreReadOnlyErrors, putResult);
     505        symbolTablePutTouchWatchpointSet(moduleEnvironment, globalObject, propertyName, exportedValue, shouldThrowReadOnlyError, ignoreReadOnlyErrors, putResult);
    501506        scope.assertNoException();
    502507        RELEASE_ASSERT(putResult);
     508
     509        if (Optional<uint32_t> index = parseIndex(propertyName)) {
     510            exportsObject->putDirectIndex(globalObject, index.value(), exportedValue);
     511            RETURN_IF_EXCEPTION(scope, void());
     512        } else
     513            exportsObject->putDirect(vm, propertyName, exportedValue);
    503514    }
     515
     516    objectConstructorFreeze(globalObject, exportsObject);
     517    RETURN_IF_EXCEPTION(scope, void());
     518    m_exportsObject.set(vm, this, exportsObject);
    504519
    505520    bool hasStart = !!moduleInformation.startFunctionIndexSpace;
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h

    r253237 r271112  
    6363    JS_EXPORT_PRIVATE JSValue evaluate(JSGlobalObject*);
    6464
     65    JSObject* exportsObject() const { return m_exportsObject.get(); }
     66
    6567private:
    6668    WebAssemblyModuleRecord(VM&, Structure*, const Identifier&);
     
    7274    WriteBarrier<JSWebAssemblyInstance> m_instance;
    7375    WriteBarrier<JSObject> m_startFunction;
     76    WriteBarrier<JSObject> m_exportsObject;
    7477};
    7578
Note: See TracChangeset for help on using the changeset viewer.