window.crypto doesn't preserve custom properties
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Oct 2013 20:28:55 +0000 (20:28 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Oct 2013 20:28:55 +0000 (20:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122770

Reviewed by Mark Hahnenberg.

Source/WebCore:

Test: security/crypto-gc.html

Generate isReachableFromOpaqueRoots that makes Crypto live as long as the document
lives (because that's when it's observable through window object).

* page/Crypto.cpp:
(WebCore::Crypto::Crypto):
(WebCore::Crypto::~Crypto):
(WebCore::Crypto::document):
* page/Crypto.h:
(WebCore::Crypto::create):
Made Crypto a ContextDestructionObserver, so that it can report its document to bindings.
Removed ScriptWrappable, because it seems to have served no purpose in this class.

* page/Crypto.idl: Added GenerateIsReachable. Removed ImplementationLacksVTable,
because the class now has a vtable, and can be checked for bindings integrity.

* page/DOMWindow.cpp: (WebCore::DOMWindow::crypto): Pass a document when creating
crypto.

LayoutTests:

* security/crypto-gc-expected.txt: Added.
* security/crypto-gc.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@157417 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/security/crypto-gc-expected.txt [new file with mode: 0644]
LayoutTests/security/crypto-gc.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/Crypto.cpp
Source/WebCore/page/Crypto.h
Source/WebCore/page/Crypto.idl
Source/WebCore/page/DOMWindow.cpp

index ed2dfd8..12b7246 100644 (file)
@@ -1,3 +1,13 @@
+2013-10-14  Alexey Proskuryakov  <ap@apple.com>
+
+        window.crypto doesn't preserve custom properties
+        https://bugs.webkit.org/show_bug.cgi?id=122770
+
+        Reviewed by Mark Hahnenberg.
+
+        * security/crypto-gc-expected.txt: Added.
+        * security/crypto-gc.html: Added.
+
 2013-10-14  Hans Muller  <hmuller@adobe.com>
 
         [CSS Shapes] Image valued shape-outside shapes should update the layout after the image has been loaded
diff --git a/LayoutTests/security/crypto-gc-expected.txt b/LayoutTests/security/crypto-gc-expected.txt
new file mode 100644 (file)
index 0000000..0e9b8a9
--- /dev/null
@@ -0,0 +1,10 @@
+Test that window.crypto wrapper preserves custom properties.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS window.crypto.foo is "bar"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/security/crypto-gc.html b/LayoutTests/security/crypto-gc.html
new file mode 100644 (file)
index 0000000..a9c7590
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src="../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+
+description("Test that window.crypto wrapper preserves custom properties.");
+jsTestIsAsync = true;
+
+function startTest()
+{
+    window.crypto.foo = "bar";
+    gc();
+    setTimeout(continueTest, 10);
+}
+
+function continueTest()
+{
+    gc();
+    setTimeout(finishTest, 10);
+}
+
+function finishTest()
+{
+    gc();
+    shouldBe('window.crypto.foo', '"bar"');
+    finishJSTest();
+}
+
+window.onload = startTest;
+
+</script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
index 3423e16..b755e7d 100644 (file)
@@ -1,3 +1,30 @@
+2013-10-14  Alexey Proskuryakov  <ap@apple.com>
+
+        window.crypto doesn't preserve custom properties
+        https://bugs.webkit.org/show_bug.cgi?id=122770
+
+        Reviewed by Mark Hahnenberg.
+
+        Test: security/crypto-gc.html
+
+        Generate isReachableFromOpaqueRoots that makes Crypto live as long as the document
+        lives (because that's when it's observable through window object).
+
+        * page/Crypto.cpp:
+        (WebCore::Crypto::Crypto):
+        (WebCore::Crypto::~Crypto):
+        (WebCore::Crypto::document):
+        * page/Crypto.h:
+        (WebCore::Crypto::create):
+        Made Crypto a ContextDestructionObserver, so that it can report its document to bindings.
+        Removed ScriptWrappable, because it seems to have served no purpose in this class.
+
+        * page/Crypto.idl: Added GenerateIsReachable. Removed ImplementationLacksVTable,
+        because the class now has a vtable, and can be checked for bindings integrity.
+
+        * page/DOMWindow.cpp: (WebCore::DOMWindow::crypto): Pass a document when creating
+        crypto.
+
 2013-10-14  Andreas Kling  <akling@apple.com>
 
         CTTE: NamedNodeMap always has a corresponding Element.
index fcd922f..d505e57 100644 (file)
@@ -30,8 +30,8 @@
 #include "config.h"
 #include "Crypto.h"
 
+#include "Document.h"
 #include "ExceptionCode.h"
-#include "ScriptWrappableInlines.h"
 #include <runtime/ArrayBufferView.h>
 #include <wtf/CryptographicallyRandomNumber.h>
 
@@ -46,10 +46,20 @@ bool isIntegerArray(ArrayBufferView* array)
 
 }
 
-Crypto::Crypto()
+Crypto::Crypto(Document& document)
+    : ContextDestructionObserver(&document)
 {
 }
 
+Crypto::~Crypto()
+{
+}
+
+Document* Crypto::document() const
+{
+    return toDocument(scriptExecutionContext());
+}
+
 void Crypto::getRandomValues(ArrayBufferView* array, ExceptionCode& ec)
 {
     if (!array || !isIntegerArray(array)) {
index 86552bc..f2b8163 100644 (file)
@@ -29,7 +29,7 @@
 #ifndef Crypto_h
 #define Crypto_h
 
-#include "ScriptWrappable.h"
+#include "ContextDestructionObserver.h"
 #include <wtf/Forward.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
@@ -42,14 +42,19 @@ namespace WebCore {
 
 typedef int ExceptionCode;
 
-class Crypto : public ScriptWrappable, public RefCounted<Crypto> {
+class Document;
+
+class Crypto : public ContextDestructionObserver, public RefCounted<Crypto> {
 public:
-    static PassRefPtr<Crypto> create() { return adoptRef(new Crypto()); }
+    static PassRefPtr<Crypto> create(Document& document) { return adoptRef(new Crypto(document)); }
+    virtual ~Crypto();
+
+    Document* document() const;
 
     void getRandomValues(JSC::ArrayBufferView*, ExceptionCode&);
 
 private:
-    Crypto();
+    Crypto(Document&);
 };
 
 }
index a8d62f2..6f97ed9 100644 (file)
@@ -28,7 +28,7 @@
 
 [
     NoInterfaceObject,
-    ImplementationLacksVTable,
+    GenerateIsReachable=ImplDocument,
     OperationsNotDeletable
 ] interface Crypto {
     [Custom, RaisesException] ArrayBufferView getRandomValues(ArrayBufferView array);
index 3db15c5..2c9e195 100644 (file)
@@ -591,10 +591,11 @@ History* DOMWindow::history() const
 
 Crypto* DOMWindow::crypto() const
 {
+    // FIXME: Why is crypto not available when the window is not currently displayed in a frame?
     if (!isCurrentlyDisplayedInFrame())
         return 0;
     if (!m_crypto)
-        m_crypto = Crypto::create();
+        m_crypto = Crypto::create(*document());
     return m_crypto.get();
 }