<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>265151</bug_id>
          
          <creation_ts>2023-11-20 10:40:32 -0800</creation_ts>
          <short_desc>`WebAssembly` is no longer part of the global object</short_desc>
          <delta_ts>2023-11-23 13:48:46 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>Other</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 14</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Blocker</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>263763</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ivan Enderlin">ivan</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>justin_michaud</cc>
    
    <cc>karlcow</cc>
    
    <cc>mark.lam</cc>
    
    <cc>mike</cc>
    
    <cc>ross.kirsling</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1993949</commentid>
    <comment_count>0</comment_count>
    <who name="Ivan Enderlin">ivan</who>
    <bug_when>2023-11-20 10:40:32 -0800</bug_when>
    <thetext>Hi,

Before the update to macOS 14 (Sonoma), `WebAssembly` was defined on the global object (from a `JSContext` + `JSContextGetGlobalObject` + `JSObjectGetProperty`).  Since the update, `WebAssembly` is undefined. Worst: evaluating the following simple script `const wasm = WebAssembly.Instance` makes the process crash with a SIGSEGV. It seems to affect macOS and iOS (the latter must be confirmed). I&apos;m using XCode 15. I&apos;m also using the JavaScriptCore bundled framework, with the C API.

Is it normal? Is it expected? I didn&apos;t see any announcement or anything particular. It&apos;s a blocker because it&apos;s a breaking change.

Thanks for your help.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1993950</commentid>
    <comment_count>1</comment_count>
    <who name="Ivan Enderlin">ivan</who>
    <bug_when>2023-11-20 10:46:48 -0800</bug_when>
    <thetext>Other people reproduce the error, like here https://github.com/endoli/javascriptcore.rs/issues/33 or here https://mastodon.social/@ccgus/111428590581033066.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1993987</commentid>
    <comment_count>2</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-11-20 14:33:41 -0800</bug_when>
    <thetext>Thanks Ivan. 
Maybe Justin will have something to say about this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1993988</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-11-20 14:33:51 -0800</bug_when>
    <thetext>&lt;rdar://problem/118662587&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1993990</commentid>
    <comment_count>4</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-11-20 14:35:32 -0800</bug_when>
    <thetext>A clear simple testcase should be added to this bug report.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994019</commentid>
    <comment_count>5</comment_count>
    <who name="Ross Kirsling">ross.kirsling</who>
    <bug_when>2023-11-20 17:35:25 -0800</bug_when>
    <thetext>(Note that bug 263763 is not relevant here; the patch that was ultimately landed there, 270100@main, just made it possible to pass --useWebAssembly=1 when JIT is off.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994060</commentid>
    <comment_count>6</comment_count>
      <attachid>468698</attachid>
    <who name="Ross Kirsling">ross.kirsling</who>
    <bug_when>2023-11-20 20:47:14 -0800</bug_when>
    <thetext>Created attachment 468698
Test case

Hmm, I&apos;m not managing to reproduce this on an Intel MBP with Sonoma 14.1.1 (Safari 17.1, Xcode 15.0.1).

The attached test file does what was described in the bug report, namely:
1. get WebAssembly property on global object and verify it&apos;s an object with an Instance property
2. execute the one-line script `const wasm = WebAssembly.Instance;`

Compiling this with the following command produces an executable which works as expected:
&gt; clang++ -framework JavaScriptCore -std=c++20 -o ./main wasm-test.cpp

It also works via Xcode, by setting up a Command Line Tool project which depends on JavaScriptCore.framework.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994087</commentid>
    <comment_count>7</comment_count>
    <who name="Ivan Enderlin">ivan</who>
    <bug_when>2023-11-20 23:30:59 -0800</bug_when>
    <thetext>Thanks Ross for your test case. I&apos;ve modified line 11 to:

```cpp
    assert(!exception);
    assert(JSValueIsObject(globalContext, wasmValue));
```

Running the script if your command-line:

```shell
$ clang++ -framework JavaScriptCore -std=c++20 -o ./wasm-test wasm-test.cp
$ ./wasm-test
Assertion failed: (JSValueIsObject(globalContext, wasmValue)), function main, file wasm-test.cpp, line 12.
```

I&apos;ve added this new assertion before line 11:

```cpp
    assert(JSValueIsUndefined(globalContext, wasmValue));
```

and it passes. So `wasmValue` is indeed undefined, and… `WebAssembly` isn&apos;t a property of the global object.

I&apos;m using macOS Sonoma 14.1.1 (23B81) if that helps, on a MacBook Pro M1.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994091</commentid>
    <comment_count>8</comment_count>
    <who name="Ivan Enderlin">ivan</who>
    <bug_when>2023-11-21 00:01:09 -0800</bug_when>
    <thetext>Someone else has tried this test program on macOS Sonoma, but on x86_64, and it works, just like for Ross. It seems to be an issue on aarch64 only. Maybe.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994146</commentid>
    <comment_count>9</comment_count>
    <who name="Ross Kirsling">ross.kirsling</who>
    <bug_when>2023-11-21 05:13:42 -0800</bug_when>
    <thetext>(In reply to Ivan Enderlin from comment #8)
&gt; Someone else has tried this test program on macOS Sonoma, but on x86_64, and
&gt; it works, just like for Ross. It seems to be an issue on aarch64 only. Maybe.

Looks like it. I&apos;ve had a chance to try on an M1 machine now, and I repro the behavior you describe (though unfortunately I won&apos;t have time to dig deeper right away).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994179</commentid>
    <comment_count>10</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2023-11-21 07:58:47 -0800</bug_when>
    <thetext>Ivan, your test case implies that you&apos;re using the JSC API, which I don&apos;t think officially supported WebAssembly.  WebAssembly is still available in WebViews.

You say this is a breaking change and a blocker.  What app is this breaking, and why does it need WebAssembly?  Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994181</commentid>
    <comment_count>11</comment_count>
    <who name="Ivan Enderlin">ivan</who>
    <bug_when>2023-11-21 08:06:30 -0800</bug_when>
    <thetext>Mark, I&apos;m using JSC to execute Wasm on iOS, where I can&apos;t use another Wasm runtime (like wasmtime for instance). Our Rust SDK needs to work on multiple platforms.

`WebAssembly` is defined in the global object, except now on aarch64, but I believe it&apos;s a bug/regression. It was previously working, it&apos;s no longer the case only on aarch64, that&apos;s a good sign of a regression :-). I&apos;ve not tested on iOS though, but we need it to work on macOS too for development purposes.

Using a WebView isn&apos;t an option here, it would imply to rewrite an entire component of our infrastructure just because of this regression.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994182</commentid>
    <comment_count>12</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2023-11-21 08:26:06 -0800</bug_when>
    <thetext>(In reply to Ivan Enderlin from comment #11)
&gt; Mark, I&apos;m using JSC to execute Wasm on iOS, where I can&apos;t use another Wasm
&gt; runtime (like wasmtime for instance). Our Rust SDK needs to work on multiple
&gt; platforms.
&gt; 
&gt; `WebAssembly` is defined in the global object, except now on aarch64, but I
&gt; believe it&apos;s a bug/regression. It was previously working, it&apos;s no longer the
&gt; case only on aarch64, that&apos;s a good sign of a regression :-). I&apos;ve not
&gt; tested on iOS though, but we need it to work on macOS too for development
&gt; purposes.
&gt; 
&gt; Using a WebView isn&apos;t an option here, it would imply to rewrite an entire
&gt; component of our infrastructure just because of this regression.

Currently, JSC&apos;s Wasm implementation still requires JIT support in order to work. On iOS, JSC API clients never had JIT support.  So, it&apos;s never been possible to run Wasm on iOS via a JSC API client.  If you were using a WKWebView / SFSafariViewController, then Wasm is available.  If `WebAssembly` is defined in the global object via the JSC API on iOS, then that&apos;s a bug that the symbol was ever exposed.  Even so, Wasm would not have run.

On macOS for aarch64, if your app is opted into the hardened runtime option (which adds greater security), then there is also no JIT support via the JSC APIs.  This has been the case since before macOS Sonoma.  Hence, it is not a regression.  However, if your app did not opt into the hardened runtime, then it will be able to use the JIT, and Wasm will work.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994183</commentid>
    <comment_count>13</comment_count>
    <who name="Ivan Enderlin">ivan</who>
    <bug_when>2023-11-21 08:38:12 -0800</bug_when>
    <thetext>Mark, do you mean that the fact it was working before _was a bug_, and now it _is fixed_? Well, since it works on x86_64, it means that the bug “is fixed” only on aarch64, but not yet on x86_64?

What I don&apos;t understand is: where/how LLInt fits here? If JIT is disabled, isn&apos;t it possible to run Wasm only with the interpreter? That&apos;s what I thought was happening to be honest.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994189</commentid>
    <comment_count>14</comment_count>
    <who name="Ivan Enderlin">ivan</who>
    <bug_when>2023-11-21 09:11:23 -0800</bug_when>
    <thetext>With this patch https://github.com/WebKit/WebKit/commit/2c0494fcc3fe018670c408476931c3698d9b2ee2, it is possible to use WebAssembly if JIT is off/disabled. Why JSC C API cannot have this configuration by default?

Again, since this bug (described here) only happens on aarch64, is WebAssembly turns on and JIT off for x86_84?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994198</commentid>
    <comment_count>15</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2023-11-21 09:57:33 -0800</bug_when>
    <thetext>(In reply to Ivan Enderlin from comment #13)
&gt; Mark, do you mean that the fact it was working before _was a bug_, and now
&gt; it _is fixed_? Well, since it works on x86_64, it means that the bug “is
&gt; fixed” only on aarch64, but not yet on x86_64?

You were mistaken about it ever working on iOS.

On macOS, I think x86_64 does not support the hardened runtime option in your Xcode project.  On aarch64, the hardened runtime option is supported.  If you enable the hardened runtime option, then JIT will not be supported and you won’t be able to use Wasm.  If you disable it, you can use it if you disable the hardened runtime option for your app’s Xcode project.


&gt; What I don&apos;t understand is: where/how LLInt fits here? If JIT is disabled,
&gt; isn&apos;t it possible to run Wasm only with the interpreter? That&apos;s what I
&gt; thought was happening to be honest.

The current Wasm implementation still use JIT glue for marshaling arguments.  Even the LLInt replies in this.

(In reply to Ivan Enderlin from comment #14)
&gt; With this patch
&gt; https://github.com/WebKit/WebKit/commit/
&gt; 2c0494fcc3fe018670c408476931c3698d9b2ee2, it is possible to use WebAssembly
&gt; if JIT is off/disabled. Why JSC C API cannot have this configuration by
&gt; default?

That is Sony’s prep work for paving the way to Wasm LLInt working without JIT.  AFAIK, LLInt still relies on JIT glue code today.

&gt; Again, since this bug (described here) only happens on aarch64, is
&gt; WebAssembly turns on and JIT off for x86_84?

Again, this is not a bug and there is no regression. The feature you’re asking for has never existed on iOS.  On macOS, you can use Wasm if you opt out of the hardened runtime option in your Xcode project.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994320</commentid>
    <comment_count>16</comment_count>
    <who name="Ivan Enderlin">ivan</who>
    <bug_when>2023-11-22 00:11:45 -0800</bug_when>
    <thetext>Mark,

I can&apos;t use a `WKWebView` because I need my Wasm module import functions to be defined as JS callbacks, so that I can implement them in Rust. As far as I know, it&apos;s not possible to pass `Function` objects from the “host” to a `WKWebView` via `postMessage`. Is there a safe way to achieve that maybe?

&gt; You were mistaken about it ever working on iOS.

I&apos;m sorry but… before running into this project, we have tested running Wasm on iOS and it was working great via JSC. 2 persons have tested it on 2 different devices, and we have seen the same thing: Wasm was running on iOS via JSC. 

Anyway, is there a chance that we will be able to run Wasm in a short-future without JIT, only purely with LLInt? Or is there a chance that JIT will be enabled inside JSC C API? Do you have a public roadmap about that topic?

Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994474</commentid>
    <comment_count>17</comment_count>
    <who name="Justin Michaud">justin_michaud</who>
    <bug_when>2023-11-22 17:34:12 -0800</bug_when>
    <thetext>&gt;I can&apos;t use a `WKWebView` because I need my Wasm module import functions to be defined as JS callbacks

If you try https://developer.apple.com/documentation/webkit/wkscriptmessagehandler with worker + SAB + Async.await, you can probably get a nice speed improvement.

In particular, I have been meaning to hack up a demo of how to do this for a while. It is a recipe for a much more responsive user experience, but I understand it is a lot of glue code.

&gt; I&apos;m sorry but… before running into this project, we have tested running Wasm on iOS and it was working great via JSC

Do you have a test case that reproduces this? The current test case does not actually execute any wasm. As Mark said, this should have crashed the second you tried to actually use WASM, unless you were using a WKWebView. Simulator acts mostly like macOS, so it is super important to test on real hardware.

&gt; Anyway, is there a chance that we will be able to run Wasm in a short-future without JIT, only purely with LLInt? Or is there a chance that JIT will be enabled inside JSC C API? Do you have a public roadmap about that topic?

We have nothing public at this time

&gt; where I can&apos;t use another Wasm runtime
You totally can, you just can&apos;t use JIT. For example, this claims to support iOS: https://github.com/wasm3/wasm3 (I have never used this, this is not an endorsement).

We certainly do hope you try to use a WKWebView + callbacks though.

Above all, the key takeaway is this: 

***Opt out of hardened runtime on macOS to continue JITTIng. If that doesn&apos;t fix your problem, then this is a bug on our end that we need to fix. ***

If wasm was ever running on iOS outside of a WKWebView, that certainly surprises everyone on our end.

Cheers!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994505</commentid>
    <comment_count>18</comment_count>
    <who name="Ivan Enderlin">ivan</who>
    <bug_when>2023-11-23 02:48:46 -0800</bug_when>
    <thetext>&gt; Simulator acts mostly like macOS, so it is super important to test on real hardware.

It was using a simulator, which likely explains why it was working.

&gt; You totally can, you just can&apos;t use JIT. For example, this claims to support iOS: https://github.com/wasm3/wasm3 (I have never used this, this is not an endorsement).


Yeah, I was trying to use `wasm3` or any other interpreters out there.

You should consider allowing Wasm to run with JavaScriptCore. That could be awesome :-).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994586</commentid>
    <comment_count>19</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2023-11-23 13:48:46 -0800</bug_when>
    <thetext>Resolving as WONTFIX because the code is behaving as intended.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>468698</attachid>
            <date>2023-11-20 20:47:14 -0800</date>
            <delta_ts>2023-11-20 20:47:14 -0800</delta_ts>
            <desc>Test case</desc>
            <filename>wasm-test.cpp</filename>
            <type>text/x-csrc</type>
            <size>1157</size>
            <attacher name="Ross Kirsling">ross.kirsling</attacher>
            
              <data encoding="base64">I2luY2x1ZGUgPEphdmFTY3JpcHRDb3JlL0phdmFTY3JpcHRDb3JlLmg+CiNpbmNsdWRlIDxjYXNz
ZXJ0PgoKaW50IG1haW4oKSB7CiAgICBKU0dsb2JhbENvbnRleHRSZWYgZ2xvYmFsQ29udGV4dCA9
IEpTR2xvYmFsQ29udGV4dENyZWF0ZShudWxscHRyKTsKICAgIEpTT2JqZWN0UmVmIGdsb2JhbE9i
amVjdCA9IEpTQ29udGV4dEdldEdsb2JhbE9iamVjdChnbG9iYWxDb250ZXh0KTsKICAgIEpTVmFs
dWVSZWYgZXhjZXB0aW9uID0gbnVsbHB0cjsKCiAgICBKU1N0cmluZ1JlZiB3YXNtUHJvcGVydHlO
YW1lID0gSlNTdHJpbmdDcmVhdGVXaXRoVVRGOENTdHJpbmcoIldlYkFzc2VtYmx5Iik7CiAgICBK
U1ZhbHVlUmVmIHdhc21WYWx1ZSA9IEpTT2JqZWN0R2V0UHJvcGVydHkoZ2xvYmFsQ29udGV4dCwg
Z2xvYmFsT2JqZWN0LCB3YXNtUHJvcGVydHlOYW1lLCAmZXhjZXB0aW9uKTsK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