Chromium Code Reviews| Index: Source/bindings/v8/custom/V8BlobCustom.cpp |
| diff --git a/Source/bindings/v8/custom/V8BlobCustom.cpp b/Source/bindings/v8/custom/V8BlobCustom.cpp |
| index 96ba6135987e8bb9f0019d176ef202a3b0c34047..418cb24b1e7172bd80273b2351efe0c131d0158c 100644 |
| --- a/Source/bindings/v8/custom/V8BlobCustom.cpp |
| +++ b/Source/bindings/v8/custom/V8BlobCustom.cpp |
| @@ -31,12 +31,7 @@ |
| #include "config.h" |
| #include "V8Blob.h" |
| -#include "bindings/v8/Dictionary.h" |
| -#include "bindings/v8/ExceptionMessages.h" |
| -#include "bindings/v8/V8Binding.h" |
| -#include "bindings/v8/V8Utilities.h" |
| -#include "bindings/v8/custom/V8ArrayBufferCustom.h" |
| -#include "bindings/v8/custom/V8ArrayBufferViewCustom.h" |
| +#include "bindings/v8/custom/V8BlobCustomHelpers.h" |
| #include "core/fileapi/BlobBuilder.h" |
| #include "wtf/RefPtr.h" |
|
haraken
2013/11/15 08:40:05
Nit: This won't be needed.
pwnall-personal
2013/11/15 10:28:53
Done.
Thank you!
|
| @@ -61,62 +56,25 @@ void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
| } |
| } |
| - String type; |
| + String contentType; |
| String endings = "transparent"; |
|
haraken
2013/11/15 08:40:05
Nit: How about setting 'endings = "transparent"' i
pwnall-personal
2013/11/15 10:28:53
I can't get rid of the default easily, because pro
haraken
2013/11/15 10:39:12
Understood. Let's keep it as is.
|
| - |
| if (info.Length() > 1) { |
| if (!info[1]->IsObject()) { |
| throwTypeError(ExceptionMessages::failedToConstruct("Blob", "The 2nd argument is not of type Object."), info.GetIsolate()); |
| return; |
| } |
| - V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsolate())); |
| - |
| - V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings)); |
| - if (containsEndings) { |
| - if (endings != "transparent" && endings != "native") { |
| - throwTypeError(ExceptionMessages::failedToConstruct("Blob", "The 2nd argument's \"endings\" property must be either \"transparent\" or \"native\"."), info.GetIsolate()); |
| - return; |
| - } |
| - } |
| - |
| - V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); |
| - UNUSED_PARAM(containsType); |
| - if (!type.containsOnlyASCII()) { |
| - throwError(v8SyntaxError, ExceptionMessages::failedToConstruct("Blob", "The 2nd argument's \"type\" property must consist of ASCII characters."), info.GetIsolate()); |
| + if (!V8BlobCustomHelpers::processBlobPropertyBag(info[1], info.GetIsolate(), "Blob", contentType, endings)) |
|
haraken
2013/11/15 08:40:05
processBlobPropertyBag => processBlobDictionary ?
pwnall-personal
2013/11/15 08:58:42
I used BlobPropertyBag because that's the name tha
haraken
2013/11/15 09:09:40
Then let's call it processBlobPropertyBag. Sorry a
pwnall-personal
2013/11/15 10:28:53
FWIW, I also find the name a bit awkward :)
|
| return; |
| - } |
| - type = type.lower(); |
| } |
| - |
| ASSERT(endings == "transparent" || endings == "native"); |
| BlobBuilder blobBuilder; |
| v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]); |
| - for (uint32_t i = 0; i < length; ++i) { |
| - v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, info.GetIsolate())); |
| - if (item.IsEmpty()) |
| - return; |
| - |
| - if (V8ArrayBuffer::hasInstance(item, info.GetIsolate(), worldType(info.GetIsolate()))) { |
| - ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Object>::Cast(item)); |
| - ASSERT(arrayBuffer); |
| - blobBuilder.append(arrayBuffer); |
| - } else if (V8ArrayBufferView::hasInstance(item, info.GetIsolate(), worldType(info.GetIsolate()))) { |
| - ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::Handle<v8::Object>::Cast(item)); |
| - ASSERT(arrayBufferView); |
| - blobBuilder.append(arrayBufferView); |
| - } else if (V8Blob::hasInstance(item, info.GetIsolate(), worldType(info.GetIsolate()))) { |
| - Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); |
| - ASSERT(blob); |
| - blobBuilder.append(blob); |
| - } else { |
| - V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue, item); |
| - blobBuilder.append(stringValue, endings); |
| - } |
| - } |
| + if (!V8BlobCustomHelpers::processBlobParts(blobParts, length, info.GetIsolate(), endings, blobBuilder)) |
| + return; |
| - RefPtr<Blob> blob = blobBuilder.getBlob(type); |
| + RefPtr<Blob> blob = blobBuilder.createBlob(contentType); |
| info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate())); |
|
haraken
2013/11/15 08:40:05
Use v8SetReturnValue() in V8Binding.h.
pwnall-personal
2013/11/15 10:28:53
Done.
|
| } |