Bug 184689 - [WebAssembly][Modules] Implement function import from wasm modules
Summary: [WebAssembly][Modules] Implement function import from wasm modules
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on: 184717
Blocks:
  Show dependency treegraph
 
Reported: 2018-04-17 06:26 PDT by Yusuke Suzuki
Modified: 2018-04-18 02:49 PDT (History)
9 users (show)

See Also:


Attachments
Patch (63.38 KB, patch)
2018-04-17 06:37 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (68.36 KB, patch)
2018-04-17 06:45 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (68.33 KB, patch)
2018-04-17 06:55 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (68.81 KB, patch)
2018-04-17 07:00 PDT, Yusuke Suzuki
jfbastien: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2018-04-17 06:26:14 PDT
[WebAssembly][Modules] Implement function import from wasm modules
Comment 1 Yusuke Suzuki 2018-04-17 06:37:02 PDT
Created attachment 338105 [details]
Patch
Comment 2 Yusuke Suzuki 2018-04-17 06:45:40 PDT
Created attachment 338106 [details]
Patch
Comment 3 Yusuke Suzuki 2018-04-17 06:55:46 PDT
Created attachment 338107 [details]
Patch
Comment 4 Yusuke Suzuki 2018-04-17 07:00:05 PDT
Created attachment 338108 [details]
Patch
Comment 5 JF Bastien 2018-04-17 09:43:02 PDT
Comment on attachment 338108 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=338108&action=review

Wooh! Very cool :)
r=me

> Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:58
> +            specifier->importedName() == analyzer.vm().propertyNames->timesIdentifier,

It's nicer to have an enum class here, like:
  specifier->importedName() == analyzer.vm().propertyNames->timesIdentifier ? IMPORT_ENTIRE_NAMESPACE : IMPORT_SINGLE_IDENTIFIER

> Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp:203
> +            false,

Ditto here for enum class.

> Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp:158
> +                throwSyntaxError(exec, scope, makeString("Importing binding name 'default' cannot be resolved by star export entries."));

This message confused me. How can it happen?

> Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp:184
> +            value = jsUndefined();

Isn't it a TDZ in this case? IIUC that's where you have a circular import, and you're going to try using it in evaluate() ? That should fail wasm loading, just like TDZ does for JS.

> Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp:230
> +        }

Drop extra braces here and below.

> Tools/Scripts/run-jsc-stress-tests:1017
> +def runWebAssemblyDirect

Maybe it's better to rename runWebAssembly above? The one you're adding is really the "run the simple thing", whereas above is "run with all these extra imports". This could be a follow-up cleanup.
Comment 6 Yusuke Suzuki 2018-04-17 10:41:21 PDT
Comment on attachment 338108 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=338108&action=review

Thanks!

>> Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:58
>> +            specifier->importedName() == analyzer.vm().propertyNames->timesIdentifier,
> 
> It's nicer to have an enum class here, like:
>   specifier->importedName() == analyzer.vm().propertyNames->timesIdentifier ? IMPORT_ENTIRE_NAMESPACE : IMPORT_SINGLE_IDENTIFIER

Cool. Fixed.

>> Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp:203
>> +            false,
> 
> Ditto here for enum class.

Fixed.

>> Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp:158
>> +                throwSyntaxError(exec, scope, makeString("Importing binding name 'default' cannot be resolved by star export entries."));
> 
> This message confused me. How can it happen?

It is a bit complicated thing :) If "default" query hits with export *, and default export, this error happens. I'll add a test for this

>> Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp:184
>> +            value = jsUndefined();
> 
> Isn't it a TDZ in this case? IIUC that's where you have a circular import, and you're going to try using it in evaluate() ? That should fail wasm loading, just like TDZ does for JS.

If it is TDZ, it's empty. And the following `if (!value.isFunction())` should fail. But right now, we cannot `isFunction()` to JSEmpty. (We do not perform such predicate for JSEmpty).
So now, we just use undefined here. And it soon raises an error in the following switch statement. This meets the description in the proposal. https://github.com/WebAssembly/esm-integration/tree/master/proposals/esm-integration#instantiation

>> Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp:230
>> +        }
> 
> Drop extra braces here and below.

OK fixed.

>> Tools/Scripts/run-jsc-stress-tests:1017
>> +def runWebAssemblyDirect
> 
> Maybe it's better to rename runWebAssembly above? The one you're adding is really the "run the simple thing", whereas above is "run with all these extra imports". This could be a follow-up cleanup.

OK, I'll do it in a follow-up patch.
Comment 7 Yusuke Suzuki 2018-04-17 11:00:13 PDT
Committed r230720: <https://trac.webkit.org/changeset/230720>
Comment 8 Radar WebKit Bug Importer 2018-04-17 11:02:20 PDT
<rdar://problem/39496166>
Comment 9 WebKit Commit Bot 2018-04-17 17:01:31 PDT
Re-opened since this is blocked by bug 184717