RESOLVED FIXED 198710
Add support for WeakRef
https://bugs.webkit.org/show_bug.cgi?id=198710
Summary Add support for WeakRef
Keith Miller
Reported 2019-06-10 04:17:41 PDT
Add support for WeakRef
Attachments
Patch (43.76 KB, patch)
2019-06-10 06:39 PDT, Keith Miller
no flags
Patch (55.31 KB, patch)
2019-06-12 07:24 PDT, Keith Miller
no flags
Archive of layout-test-results from ews101 for mac-highsierra (313.72 KB, application/zip)
2019-06-12 08:28 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews106 for mac-highsierra-wk2 (324.10 KB, application/zip)
2019-06-12 08:31 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews115 for mac-highsierra (359.77 KB, application/zip)
2019-06-12 08:35 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews125 for ios-simulator-wk2 (704.21 KB, application/zip)
2019-06-12 08:36 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews210 for win-future (3.81 MB, application/zip)
2019-06-12 09:21 PDT, EWS Watchlist
no flags
Patch (56.20 KB, patch)
2019-06-13 02:35 PDT, Keith Miller
no flags
Archive of layout-test-results from ews115 for mac-highsierra (340.15 KB, application/zip)
2019-06-13 03:47 PDT, EWS Watchlist
no flags
Patch (56.48 KB, patch)
2019-06-13 05:44 PDT, Keith Miller
no flags
Patch for landing (56.49 KB, patch)
2019-06-18 13:18 PDT, Keith Miller
no flags
Keith Miller
Comment 1 2019-06-10 06:39:36 PDT
Michael Saboff
Comment 2 2019-06-10 10:01:06 PDT
Comment on attachment 371736 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=371736&action=review r=me > Source/JavaScriptCore/runtime/JSWeakObjectRef.cpp:2 > + * Copyright (C) 2015-2016 Apple, Inc. All rights reserved. Update the copyright year. > Source/JavaScriptCore/runtime/WeakRefConstructor.h:30 > +class  à : public InternalFunction { Is there something wrong with the nam or encoding of the name of this class?
Keith Miller
Comment 3 2019-06-10 11:23:31 PDT
Comment on attachment 371736 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=371736&action=review >> Source/JavaScriptCore/runtime/WeakRefConstructor.h:30 >> +class  à : public InternalFunction { > > Is there something wrong with the nam or encoding of the name of this class? Woah... I have no idea. I didn’t think C++ supported Unicode... will fix.
Saam Barati
Comment 4 2019-06-10 11:56:57 PDT
Comment on attachment 371736 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=371736&action=review > Source/JavaScriptCore/runtime/VM.cpp:1099 > + finalizeSynchronousJSExecution(); Don't you need something like this for the micro task queue in browser?
Saam Barati
Comment 5 2019-06-10 11:57:13 PDT
(In reply to Saam Barati from comment #4) > Comment on attachment 371736 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=371736&action=review > > > Source/JavaScriptCore/runtime/VM.cpp:1099 > > + finalizeSynchronousJSExecution(); > > Don't you need something like this for the micro task queue in browser? E.g, call this function from that micro task queue.
Keith Miller
Comment 6 2019-06-12 07:24:49 PDT
EWS Watchlist
Comment 7 2019-06-12 08:28:55 PDT
Comment on attachment 371952 [details] Patch Attachment 371952 [details] did not pass mac-ews (mac): Output: https://webkit-queues.webkit.org/results/12454780 Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 8 2019-06-12 08:28:57 PDT
Created attachment 371958 [details] Archive of layout-test-results from ews101 for mac-highsierra The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews101 Port: mac-highsierra Platform: Mac OS X 10.13.6
EWS Watchlist
Comment 9 2019-06-12 08:31:20 PDT
Comment on attachment 371952 [details] Patch Attachment 371952 [details] did not pass mac-wk2-ews (mac-wk2): Output: https://webkit-queues.webkit.org/results/12454777 Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 10 2019-06-12 08:31:22 PDT
Created attachment 371959 [details] Archive of layout-test-results from ews106 for mac-highsierra-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews106 Port: mac-highsierra-wk2 Platform: Mac OS X 10.13.6
EWS Watchlist
Comment 11 2019-06-12 08:35:52 PDT
Comment on attachment 371952 [details] Patch Attachment 371952 [details] did not pass mac-debug-ews (mac): Output: https://webkit-queues.webkit.org/results/12454710 Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 12 2019-06-12 08:35:53 PDT
Created attachment 371960 [details] Archive of layout-test-results from ews115 for mac-highsierra The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews115 Port: mac-highsierra Platform: Mac OS X 10.13.6
EWS Watchlist
Comment 13 2019-06-12 08:36:01 PDT
Comment on attachment 371952 [details] Patch Attachment 371952 [details] did not pass ios-sim-ews (ios-simulator-wk2): Output: https://webkit-queues.webkit.org/results/12454674 Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 14 2019-06-12 08:36:02 PDT
Created attachment 371961 [details] Archive of layout-test-results from ews125 for ios-simulator-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews125 Port: ios-simulator-wk2 Platform: Mac OS X 10.14.5
EWS Watchlist
Comment 15 2019-06-12 09:21:26 PDT
Comment on attachment 371952 [details] Patch Attachment 371952 [details] did not pass win-ews (win): Output: https://webkit-queues.webkit.org/results/12454927 Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 16 2019-06-12 09:21:28 PDT
Created attachment 371970 [details] Archive of layout-test-results from ews210 for win-future The attached test failures were seen while running run-webkit-tests on the win-ews. Bot: ews210 Port: win-future Platform: CYGWIN_NT-10.0-17763-3.0.5-338.x86_64-x86_64-64bit
Keith Miller
Comment 17 2019-06-13 02:35:16 PDT
EWS Watchlist
Comment 18 2019-06-13 03:47:07 PDT
Comment on attachment 372038 [details] Patch Attachment 372038 [details] did not pass mac-debug-ews (mac): Output: https://webkit-queues.webkit.org/results/12463119 Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 19 2019-06-13 03:47:09 PDT
Created attachment 372044 [details] Archive of layout-test-results from ews115 for mac-highsierra The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews115 Port: mac-highsierra Platform: Mac OS X 10.13.6
Keith Miller
Comment 20 2019-06-13 05:44:48 PDT
Yusuke Suzuki
Comment 21 2019-06-16 06:13:44 PDT
Comment on attachment 372046 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=372046&action=review r=me for JSC part. > Source/JavaScriptCore/runtime/JSWeakObjectRef.h:32 > +class JSWeakObjectRef final : public JSObject { The base class needs to be JSNonFinalObject. > Source/JavaScriptCore/runtime/JSWeakObjectRef.h:34 > + using Base = JSObject; Ditto. > Source/JavaScriptCore/runtime/WeakObjectRefConstructor.cpp:76 > + JSWeakObjectRef* WeakObjectRef = JSWeakObjectRef::create(vm, WeakObjectRefStructure, exec->uncheckedArgument(0).getObject()); > + RETURN_IF_EXCEPTION(scope, encodedJSValue()); > + return JSValue::encode(WeakObjectRef); We can make this as `RELEASE_AND_RETURN(scope, JSWeakObjectRef::create(vm, WeakObjectRefStructure, exec->uncheckedArgument(0).getObject()));`. > Source/JavaScriptCore/runtime/WeakObjectRefConstructor.h:30 > +class WeakObjectRefConstructor : public InternalFunction { Annotate it with `final`. > Source/JavaScriptCore/runtime/WeakObjectRefConstructor.h:32 > + typedef InternalFunction Base; Use `using`. > Source/JavaScriptCore/runtime/WeakObjectRefConstructor.h:51 > +}; Add `static_assert(sizeof(WeakObjectRefConstructor) == sizeof(InternalFunction));`, to ensure that WeakObjectRefConstructor is OK to be allocated from IsoSubspace of InternalFunction. > Source/JavaScriptCore/runtime/WeakObjectRefPrototype.h:34 > + typedef JSNonFinalObject Base; Use `using`.
Ryosuke Niwa
Comment 22 2019-06-17 15:19:53 PDT
Comment on attachment 372046 [details] Patch The microqueue change looks sane to me.
Keith Miller
Comment 23 2019-06-18 13:16:09 PDT
Comment on attachment 372046 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=372046&action=review Fixed the other things they were because I just copied the code from JSWeakSet equivalent files. I'll follow up in another bug with the fixes for those files too. >> Source/JavaScriptCore/runtime/JSWeakObjectRef.h:32 >> +class JSWeakObjectRef final : public JSObject { > > The base class needs to be JSNonFinalObject. Whoops! Nice catch.
Keith Miller
Comment 24 2019-06-18 13:18:53 PDT
Created attachment 372370 [details] Patch for landing
WebKit Commit Bot
Comment 25 2019-06-18 14:02:26 PDT
Comment on attachment 372370 [details] Patch for landing Clearing flags on attachment: 372370 Committed r246565: <https://trac.webkit.org/changeset/246565>
WebKit Commit Bot
Comment 26 2019-06-18 14:02:28 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 27 2019-06-18 14:03:19 PDT
Daniel Ehrenberg
Comment 29 2020-05-19 07:47:25 PDT
It's great to see WeakRefs landed in JSC. The write barrier trick to keep the object alive when deref'd is nice. I don't think any of the changes that the spec has undergone in the months since then affect the contents of this patch. Were you planning on implementing FinalizationRegistry, and shipping the pair? After a lot of discussion at TC39, including making cleanupSome "normative option" following JSC's concerns (in practice, I'd exclude it for now, as documented in the HTML integration patch), I think we can consider both the WeakRef and FinalizationRegistry specs stable; based on this, V8/Chrome have shipped the two.
Keith Miller
Comment 30 2020-05-19 12:18:48 PDT
(In reply to Daniel Ehrenberg from comment #29) > It's great to see WeakRefs landed in JSC. The write barrier trick to keep > the object alive when deref'd is nice. I don't think any of the changes that > the spec has undergone in the months since then affect the contents of this > patch. > > Were you planning on implementing FinalizationRegistry, and shipping the > pair? After a lot of discussion at TC39, including making cleanupSome > "normative option" following JSC's concerns (in practice, I'd exclude it for > now, as documented in the HTML integration patch), I think we can consider > both the WeakRef and FinalizationRegistry specs stable; based on this, > V8/Chrome have shipped the two. I have a patch for the old FinalizationGroup API but I haven't had a chance to update it for the new Registry version. Fortunately, that's mostly just deleting all the iterator code. Right now I'm focusing on cleaning up my for-of optimizations that I have been working on though. V8/Chrome shipping FinalizationRegistry seems reasonable to me; I would be very surprised if anything new came up with the new API.
Note You need to log in before you can comment on or make changes to this bug.