Bug 168022 - document.origin doesn't match spec
Summary: document.origin doesn't match spec
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-08 15:00 PST by Boris Zbarsky
Modified: 2017-02-13 10:30 PST (History)
12 users (show)

See Also:


Attachments
WIP Patch (5.54 KB, patch)
2017-02-10 15:58 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews104 for mac-elcapitan-wk2 (1.11 MB, application/zip)
2017-02-10 16:41 PST, Build Bot
no flags Details
Patch (11.10 KB, patch)
2017-02-10 19:10 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Zbarsky 2017-02-08 15:00:45 PST
STEPS TO REPRODUCE:

1)  Load https://webkit.org
2)  Evaluate document.origin in the console.

EXPECTED RESULTS: Returns "https://webkit.org"

ACTUAL RESULTS: Returns "https_webkit.org_0

DETAILS: Spec is at https://dom.spec.whatwg.org/#dom-document-origin
Comment 1 Chris Dumez 2017-02-08 15:07:00 PST
I can reproduce. Thanks for the bug report. I'll take a look soon.
Comment 2 Boris Zbarsky 2017-02-09 08:42:48 PST
Note that there is a proposal from Blink to just remove document.origin altogether in favor of self.origin.
Comment 3 Chris Dumez 2017-02-10 15:58:10 PST
Created attachment 301208 [details]
WIP Patch
Comment 4 Build Bot 2017-02-10 16:41:43 PST
Comment on attachment 301208 [details]
WIP Patch

Attachment 301208 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/3065179

New failing tests:
http/tests/media/media-stream/enumerate-devices-source-id-persistent.html
Comment 5 Build Bot 2017-02-10 16:41:47 PST
Created attachment 301214 [details]
Archive of layout-test-results from ews104 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 6 Boris Zbarsky 2017-02-10 18:51:31 PST
Chris, I'm not sure whether you saw comment 2?
Comment 7 Chris Dumez 2017-02-10 19:10:20 PST
Created attachment 301237 [details]
Patch
Comment 8 Chris Dumez 2017-02-10 19:12:36 PST
(In reply to comment #6)
> Chris, I'm not sure whether you saw comment 2?

I saw. I don't think we would remove it short-term though. So for now, it is better to match the spec and other shipping browsers. If we end up removing it later on (after we implement self.origin), so be it.
Comment 9 WebKit Commit Bot 2017-02-10 20:42:13 PST
Comment on attachment 301237 [details]
Patch

Clearing flags on attachment: 301237

Committed r212178: <http://trac.webkit.org/changeset/212178>
Comment 10 WebKit Commit Bot 2017-02-10 20:42:20 PST
All reviewed patches have been landed.  Closing bug.
Comment 11 Alexey Proskuryakov 2017-02-13 09:33:34 PST
This code was added in https://trac.webkit.org/changeset/164036, and it's really surprising if it wasn't breaking a whole lot of things besides the visible value of document.origin. Is it really not used anywhere else in the engine?

+PassRefPtr<Document> Document::create(ScriptExecutionContext& context)
+{
+    RefPtr<Document> document = adoptRef(new Document(nullptr, URL()));
+    document->setSecurityOrigin(context.securityOrigin());
+    return document;
+}
+

...
 
+String Document::origin() const
+{
+    return securityOrigin()->databaseIdentifier();
+}
+
Comment 12 Chris Dumez 2017-02-13 09:38:07 PST
(In reply to comment #11)
> This code was added in https://trac.webkit.org/changeset/164036, and it's
> really surprising if it wasn't breaking a whole lot of things besides the
> visible value of document.origin. Is it really not used anywhere else in the
> engine?
> 
> +PassRefPtr<Document> Document::create(ScriptExecutionContext& context)
> +{
> +    RefPtr<Document> document = adoptRef(new Document(nullptr, URL()));
> +    document->setSecurityOrigin(context.securityOrigin());
> +    return document;
> +}
> +
> 
> ...
>  
> +String Document::origin() const
> +{
> +    return securityOrigin()->databaseIdentifier();
> +}
> +

What do you mean by anywhere *else*. Document::origin() is not used *anywhere* in the engine and therefore my patch only changes the value exposed to the Web to match the specification and other browsers.

Our internal code relies on securityOrigin(), not origin().
Comment 13 Alexey Proskuryakov 2017-02-13 10:16:15 PST
As the diff shows, the original change was setting securityOrigin from origin, so both were incorrect.
Comment 14 Alexey Proskuryakov 2017-02-13 10:30:14 PST
Sorry, misread the original patch.