Clean up sequence handling in Blob constructor

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: http://svn.webkit.org/repository/webkit/trunk@159323 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d40e29d9
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.
......
......@@ -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
......
......@@ -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'");
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
......
......@@ -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())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment