Bug 132890 - Script worlds are hard to use correctly and easy to leak.
Summary: Script worlds are hard to use correctly and easy to leak.
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andreas Kling
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2014-05-13 15:49 PDT by Andreas Kling
Modified: 2015-08-04 09:42 PDT (History)
8 users (show)

See Also:


Attachments
Patch (1.88 KB, patch)
2014-05-13 16:16 PDT, Andreas Kling
no flags Details | Formatted Diff | Diff
Patch II (6.77 KB, patch)
2014-05-14 02:12 PDT, Andreas Kling
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from webkit-ews-13 for mac-mountainlion-wk2 (470.71 KB, application/zip)
2014-05-14 05:12 PDT, Build Bot
no flags Details
Idea for EWS (11.18 KB, patch)
2014-05-15 01:06 PDT, Andreas Kling
no flags Details | Formatted Diff | Diff
Idea for EWS with crash fix (11.55 KB, patch)
2014-05-15 16:00 PDT, Andreas Kling
no flags Details | Formatted Diff | Diff
For my future self (15.42 KB, patch)
2014-05-16 15:01 PDT, Andreas Kling
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Kling 2014-05-13 15:49:35 PDT
<rdar://problem/16886955>
Comment 1 Andreas Kling 2014-05-13 16:16:18 PDT
Created attachment 231414 [details]
Patch
Comment 2 Geoffrey Garen 2014-05-13 16:58:32 PDT
Comment on attachment 231414 [details]
Patch

r=me

I wonder if this should be built into WebCore::DOMWrapperWorld.
Comment 3 Andreas Kling 2014-05-14 02:12:52 PDT
Created attachment 231437 [details]
Patch II

InjectedBundleScriptWorld should only clearWrappers() for DOMWrapperWorlds that it "owns". The previous patch broke the case where the WTR bundle was using InjectedBundleScriptWorld to wrap already existing DOMWrapperWorlds.
Comment 4 Build Bot 2014-05-14 05:12:48 PDT
Comment on attachment 231437 [details]
Patch II

Attachment 231437 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/5779318680584192

New failing tests:
http/tests/security/isolatedWorld/window-setTimeout-string.html
http/tests/security/isolatedWorld/dispatchEvent.html
Comment 5 Build Bot 2014-05-14 05:12:51 PDT
Created attachment 231445 [details]
Archive of layout-test-results from webkit-ews-13 for mac-mountainlion-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: webkit-ews-13  Port: mac-mountainlion-wk2  Platform: Mac OS X 10.8.5
Comment 6 Darin Adler 2014-05-14 09:23:09 PDT
Comment on attachment 231437 [details]
Patch II

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

Do you know why these two tests fail?

  http/tests/security/isolatedWorld/dispatchEvent.html [ Failure ]
  http/tests/security/isolatedWorld/window-setTimeout-string.html [ Failure ]

> Source/WebKit2/Shared/API/c/WKDeprecatedFunctions.cpp:83
> +void WKBundleScriptWorldClearWrappers(WKBundleScriptWorldRef)
> +{
> +}

Without any comment it’s not obvious why we are keeping this around. I presume the reason is specifically to keep old versions of Safari working, but perhaps there are other reasons? I don’t think that “once nobody uses them” is precise enough. We’d really like something here that could make it easy for a future contributor to be able to make the right decision about when to delete this.
Comment 7 Andreas Kling 2014-05-14 13:18:35 PDT
Comment on attachment 231437 [details]
Patch II

Ownership model isn't quite right here. This needs more work.
Comment 8 Andreas Kling 2014-05-15 01:06:52 PDT
Created attachment 231495 [details]
Idea for EWS
Comment 9 Andreas Kling 2014-05-15 16:00:49 PDT
Created attachment 231538 [details]
Idea for EWS with crash fix
Comment 10 WebKit Commit Bot 2014-05-15 16:02:29 PDT
Attachment 231538 [details] did not pass style-queue:


ERROR: Source/WebCore/bindings/js/ScriptController.cpp:98:  One line control clauses should not use braces.  [whitespace/braces] [4]
Total errors found: 1 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 11 Andreas Kling 2014-05-15 16:18:19 PDT
My plan here is to let DOMWrapperWorld directly own the JSDOMWindowShells.

JSDOMWindowShell gets a DOMWrapperWorld& instead of a Ref<DOMWrapperWorld> since it's now strongly owned from the world.

The main difference is that once a DOMWrapperWorld's refcount goes to zero, the JSDOMWindowShell will be up for GC. (Do note that JSEventListener refs the DOMWrapperWorld, for example.)

Previously, DOMWrapperWorld would have a +1 ref from being in ScriptController's ShellMap. Calling clearWrappers() was the only way to bust out of that map before ScriptController destruction. With these changes, that's no longer necessary, just let your RefPtr<DOMWrapperWorld> go out of scope and it'll take care of the rest.
Comment 12 Andreas Kling 2014-05-15 16:20:19 PDT
I think it might also make sense to call this something like "ScriptWorld" instead of DOMWrapperWorld.
Comment 13 Andreas Kling 2014-05-16 15:01:58 PDT
Created attachment 231595 [details]
For my future self

I'm not going to work on this right now, so I'm uploading the patch as far as I got it.
Comment 14 Csaba Osztrogonác 2014-06-04 03:24:08 PDT
Comment on attachment 231414 [details]
Patch

Cleared Geoffrey Garen's review+ from obsolete attachment 231414 [details] so that this bug does not appear in http://webkit.org/pending-commit.