Clean up sequence handling in Blob constructor
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Nov 2013 00:55:45 +0000 (00:55 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Nov 2013 00:55:45 +0000 (00:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=124343

Patch by Victor Costan <costan@gmail.com> on 2013-11-14
Reviewed by Alexey Proskuryakov.

Source/WebCore:

Added test case to LayoutTests/fast/files/blob-constructor.html

* bindings/js/JSBlobCustom.cpp:
(WebCore::JSBlobConstructor::constructJSBlob):
    Handle exceptions in sequences, eliminate double type-checking for
    ArrayBuffer, ArrayBufferView and Blob parts.

LayoutTests:

* fast/files/blob-constructor-expected.txt:
* fast/files/script-tests/blob-constructor.js:
    Add test with sequence that throws an error on property access.
(get Object):

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

LayoutTests/ChangeLog
LayoutTests/fast/files/blob-constructor-expected.txt
LayoutTests/fast/files/script-tests/blob-constructor.js
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSBlobCustom.cpp

index 81a9f01..2c006b5 100644 (file)
@@ -1,3 +1,15 @@
+2013-11-14  Victor Costan  <costan@gmail.com>
+
+        Clean up sequence handling in Blob constructor
+        https://bugs.webkit.org/show_bug.cgi?id=124343
+
+        Reviewed by Alexey Proskuryakov.
+
+        * fast/files/blob-constructor-expected.txt:
+        * fast/files/script-tests/blob-constructor.js:
+            Add test with sequence that throws an error on property access.
+        (get Object):
+
 2013-11-14  Tim Horton  <timothy_horton@apple.com>
 
         Change Fail->Failure in some recent expectations.
index 8743503..652d448 100644 (file)
@@ -78,6 +78,7 @@ PASS new Blob({length: 1, 0: 'string'}).size is 6
 PASS new Blob({length: 2, 0: new Uint8Array(100), 1: new Int16Array(100)}).size is 300
 PASS new Blob({length: 1, 0: 'string'}, {type: 'text/html'}).type is 'text/html'
 PASS new Blob({length: 0}, {endings:'illegal'}) threw exception TypeError: The endings property must be either "transparent" or "native".
+PASS new Blob(throwingSequence) threw exception Error: Misbehaving property.
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 5a329ae..fc72258 100644 (file)
@@ -106,3 +106,15 @@ shouldBe("new Blob({length: 1, 0: 'string'}).size", "6");
 shouldBe("new Blob({length: 2, 0: new Uint8Array(100), 1: new Int16Array(100)}).size", "300");
 shouldBe("new Blob({length: 1, 0: 'string'}, {type: 'text/html'}).type", "'text/html'");
 shouldThrow("new Blob({length: 0}, {endings:'illegal'})", "'TypeError: The endings property must be either \"transparent\" or \"native\"'");
+
+// Test passing blog parts in a sequence-like object that throws on property access.
+var throwingSequence = {length: 4, 0: 'hello', 3: 'world'};
+Object.defineProperty(throwingSequence, "1", {
+    get: function() { throw new Error("Misbehaving property"); },
+    enumerable: true, configurable: true
+});
+Object.defineProperty(throwingSequence, "2", {
+    get: function() { throw new Error("This should not be thrown"); },
+    enumerable: true, configurable: true
+});
+shouldThrow("new Blob(throwingSequence)", "'Error: Misbehaving property'");
index c253c73..3e5a612 100644 (file)
@@ -1,3 +1,17 @@
+2013-11-14  Victor Costan  <costan@gmail.com>
+
+        Clean up sequence handling in Blob constructor
+        https://bugs.webkit.org/show_bug.cgi?id=124343
+
+        Reviewed by Alexey Proskuryakov.
+
+        Added test case to LayoutTests/fast/files/blob-constructor.html
+
+        * bindings/js/JSBlobCustom.cpp:
+        (WebCore::JSBlobConstructor::constructJSBlob):
+            Handle exceptions in sequences, eliminate double type-checking for
+            ArrayBuffer, ArrayBufferView and Blob parts.
+
 2013-11-14  Oliver Hunt  <oliver@apple.com>
 
         Make CLoop easier to build, and make it work
index 72ad961..bfcd4d1 100644 (file)
@@ -114,15 +114,18 @@ EncodedJSValue JSC_HOST_CALL JSBlobConstructor::constructJSBlob(ExecState* exec)
 
     for (unsigned i = 0; i < blobPartsLength; ++i) {
         JSValue item = blobParts->get(exec, i);
+        if (exec->hadException())
+            return JSValue::encode(jsUndefined());
+
 #if ENABLE(BLOB)
-        if (item.inherits(JSArrayBuffer::info()))
-            blobBuilder.append(toArrayBuffer(item));
-        else if (item.inherits(JSArrayBufferView::info()))
-            blobBuilder.append(toArrayBufferView(item));
+        if (ArrayBuffer* arrayBuffer = toArrayBuffer(item))
+            blobBuilder.append(arrayBuffer);
+        else if (RefPtr<ArrayBufferView> arrayBufferView = toArrayBufferView(item))
+            blobBuilder.append(arrayBufferView.release());
         else
 #endif
-        if (item.inherits(JSBlob::info()))
-            blobBuilder.append(toBlob(item));
+        if (Blob* blob = toBlob(item))
+            blobBuilder.append(blob);
         else {
             String string = item.toString(exec)->value(exec);
             if (exec->hadException())