<?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>301334</bug_id>
          
          <creation_ts>2025-10-23 03:08:41 -0700</creation_ts>
          <short_desc>Dereferenced WeakRef&apos;s are not strongified</short_desc>
          <delta_ts>2025-11-18 18:42:04 -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>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>olivf</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>keith_miller</cc>
    
    <cc>olivf</cc>
    
    <cc>omerkatz</cc>
    
    <cc>syg</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2153636</commentid>
    <comment_count>0</comment_count>
    <who name="">olivf</who>
    <bug_when>2025-10-23 03:08:41 -0700</bug_when>
    <thetext>While discussing a user reported OOM exception in V8 (http://crbug.com/42202112) we noticed that JSC does not behave spec compliant with regards to weak refs. Namely it seems to either not implement `9.11 AddToKeptObjects` or call `9.10 ClearKeptObjects` earlier than allowed.

Quoting (https://tc39.es/ecma262/#sec-weakref-invariants) &quot;When WeakRef.prototype.deref is called, the referent (if undefined is not returned) is kept alive so that subsequent, synchronous accesses also return the same value&quot;. 

In other words a dereferenced weak ref temporarily makes it strong until the end of the current microtask.

Here is a repro which prints &quot;not defined&quot; but is supposed to print &quot;defined&quot;.

```
let o = {};
let wr1;
let wr2;
(function() {
  wr1 = new WeakRef(o);
  wr2 = new WeakRef(o);
})();
o = null;

setTimeout(function() {
  (function () { wr1.deref(); })();
  wr1 = null;
  gc();
  if (typeof wr2.deref() === &apos;undefined&apos;) {
    print(&quot;undefined&quot;);
  } else {
    print(&quot;not undefined&quot;);
  }
}, 0);
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2155210</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-10-30 03:09:11 -0700</bug_when>
    <thetext>&lt;rdar://problem/163702155&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2159762</commentid>
    <comment_count>2</comment_count>
    <who name="Keith Miller">keith_miller</who>
    <bug_when>2025-11-18 18:42:04 -0800</bug_when>
    <thetext>Oh, interesting, I guess either I misunderstood the spec or it changed at some point. 

We basically make the WeakRef a strong pointer when it gets derefed until the next event loop turn. From an our implementation perspective that&apos;s certainly a lot easier (and more performant), that said, it does seem like we don&apos;t implement the spec.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>